-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[Identity] Respect region env vars for non-MSAL based credentials #44347
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
[Identity] Respect region env vars for non-MSAL based credentials #44347
Conversation
Currently, only MSAL confidential client based credentials allow passing in a region through the `AZURE_REGIONAL_AUTHORITY_NAME`. For the other non-MSAL based confidential flows, we should have parity with the MSAL ones. Signed-off-by: Paul Van Eck <[email protected]>
8a3012f to
716174b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for the AZURE_REGIONAL_AUTHORITY_NAME environment variable to non-MSAL-based credentials in the Azure Identity SDK, providing parity with MSAL-based credentials. The implementation allows credentials to use regional authority endpoints, which can improve performance and reliability by routing authentication traffic to region-specific endpoints.
Key changes:
- Added regional authority initialization logic to
AadClientBaseand both sync/asyncAadClientimplementations - Support for both
AZURE_REGIONAL_AUTHORITY_NAMEandMSAL_FORCE_REGIONenvironment variables, with auto-discovery capability via IMDS - Updated token URL generation to use regional authority when configured
- Added comprehensive tests covering regional authority initialization and usage scenarios
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/identity/azure-identity/azure/identity/_internal/aad_client_base.py | Added base methods for regional authority URL building, environment variable reading, and IMDS region discovery |
| sdk/identity/azure-identity/azure/identity/_internal/aad_client.py | Sync client now initializes regional authority in __init__ and implements region discovery logic |
| sdk/identity/azure-identity/azure/identity/aio/_internal/aad_client.py | Async client implements lazy regional authority initialization called on each token request, with async region discovery |
| sdk/identity/azure-identity/tests/test_aad_client.py | Added tests for token URL generation with regional authority and initialization logic |
| sdk/identity/azure-identity/tests/test_aad_client_async.py | Added async tests for regional authority in token requests, lazy initialization, and auto-discovery scenarios |
| sdk/identity/azure-identity/CHANGELOG.md | Documents the bug fix for regional authority environment variable support |
sdk/identity/azure-identity/azure/identity/_internal/aad_client.py
Outdated
Show resolved
Hide resolved
sdk/identity/azure-identity/azure/identity/aio/_internal/aad_client.py
Outdated
Show resolved
Hide resolved
Signed-off-by: Paul Van Eck <[email protected]>
sdk/identity/azure-identity/azure/identity/_internal/aad_client.py
Outdated
Show resolved
Hide resolved
Signed-off-by: Paul Van Eck <[email protected]>
Currently, only MSAL confidential client based credentials allow passing in a region through the
AZURE_REGIONAL_AUTHORITY_NAME. For the other non-MSAL based confidential flows, we should have parity with the MSAL ones.I validated these changes on AKS using async WorkloadIdentityCredential with the following configurations:
AZURE_REGIONAL_AUTHORITY_NAME=westus2MSAL_FORCE_REGION=westus2AZURE_REGION_AUTHORITY_NAME=tryautodetect