-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[Identity] Skip IMDS probe when MI selected in DAC via env #43080
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
Conversation
4234377 to
5135a08
Compare
When the environment variable AZURE_TOKEN_CREDENTIALS is explicitly set to ManagedIdentityCredential, DefaultAzureCredential should not do IMDA probing. Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
5135a08 to
107d41d
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 implements a performance optimization for DefaultAzureCredential when the AZURE_TOKEN_CREDENTIALS environment variable is explicitly set to "managedidentitycredential". The change eliminates the IMDS endpoint probe that occurs when using ManagedIdentityCredential within the credential chain, allowing it to skip directly to token acquisition with full retry logic.
- Adds
_skip_probe_in_chainparameter to ManagedIdentityCredential and ImdsCredential classes - Modifies DefaultAzureCredential to detect when only ManagedIdentityCredential is enabled and skip the probe
- Updates the IMDS endpoint probing logic to respect the skip flag
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| azure/identity/_credentials/default.py | Sets _skip_probe_in_chain=True when only managed identity is enabled in DefaultAzureCredential |
| azure/identity/aio/_credentials/default.py | Async version of the same DefaultAzureCredential changes |
| azure/identity/_credentials/managed_identity.py | Adds _skip_probe_in_chain parameter and passes it to ImdsCredential |
| azure/identity/aio/_credentials/managed_identity.py | Async version of the same ManagedIdentityCredential changes |
| azure/identity/_credentials/imds.py | Modifies probe logic to skip when _skip_probe_in_chain is True |
| azure/identity/aio/_credentials/imds.py | Async version of the same ImdsCredential probe changes |
| tests/test_default.py | Updates test expectations to include new _skip_probe_in_chain parameter |
| tests/test_default_async.py | Async version of the same test updates |
| tests/test_token_credentials_env.py | Adds test verifying probe is skipped when environment variable is set |
| tests/test_token_credentials_env_async.py | Async version of the new test |
| CHANGELOG.md | Documents the behavior change |
sdk/identity/azure-identity/azure/identity/_credentials/managed_identity.py
Outdated
Show resolved
Hide resolved
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
When the environment variable AZURE_TOKEN_CREDENTIALS is explicitly set to ManagedIdentityCredential, DefaultAzureCredential should not do IMDS probing.
Closes: #43046