Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove silent auth special case for home tenant aliases #375

Merged
merged 6 commits into from
Jan 25, 2023

Conversation

chlowell
Copy link
Collaborator

@chlowell chlowell commented Jan 24, 2023

#366 made access token cache reads prefer a user's home tenant over an alias for that tenant ("common", "organizations"). However, it didn't make a corresponding change to cache writes, which use the alias for the realm. The result is an unnecessary token request during silent auth because the cache wrote a token for e.g. "common" and the client searches for one matching the home tenant.

This PR prevents that unnecessary request by making the cache tenant agnostic according to the rationale here: AzureAD/microsoft-authentication-library-for-python#341 (comment). When the client requests a token from "common", for example, it will cache that token with realm "common". I first took the other approach, having cache writes follow reads in replacing aliases with the user's home tenant ID, but found making that work might require a separate implementation of AcquireTokenSilent for OBO authentication. The "tenant agnostic" approach is much simpler.

@chlowell chlowell added the bug Something isn't working label Jan 24, 2023
@chlowell chlowell marked this pull request as draft January 24, 2023 18:31
@chlowell chlowell changed the title Cache user tokens under home tenant instead of alias Remove silent auth special case for home tenant aliases Jan 24, 2023
@chlowell chlowell marked this pull request as ready for review January 24, 2023 20:07
@chlowell chlowell added bug Something isn't working and removed bug Something isn't working labels Jan 24, 2023
apps/confidential/confidential_test.go Outdated Show resolved Hide resolved
apps/internal/base/base.go Show resolved Hide resolved
@sonarcloud
Copy link

sonarcloud bot commented Jan 24, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

tenant := silent.TenantID
if tenant == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure looks simpler :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆 it's definitely that. For reference, here's AuthParams.WithTenant(), which sets the tenant for each authentication and uses the client's configured tenant when the caller doesn't specify an override.

Copy link
Member

@bgavrilMS bgavrilMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signing off on this provided that you've tested that MSAL continues to serve tokens from a cache after the upgrade.

@chlowell
Copy link
Collaborator Author

It does; this change passes the prior tests and adds coverage for the affected scenario, and we've also tested it downstream in the Azure SDK and azd.

@chlowell chlowell merged commit 4f16e86 into dev Jan 25, 2023
@chlowell chlowell deleted the chlowell/cache-realm branch January 25, 2023 19:17
@rayluo rayluo mentioned this pull request Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants