Repository navigation
[Identity] Skip IMDS probe when MI selected in DAC via env - #43080
Merged
Merged
Conversation
Paul Van Eck (pvaneck)
force-pushed
the
identity-mi-dac-retry
branch
from
September 20, 2025 01:40
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>
Paul Van Eck (pvaneck)
force-pushed
the
identity-mi-dac-retry
branch
from
September 22, 2025 20:59
5135a08 to
107d41d
Compare
Paul Van Eck (pvaneck)
marked this pull request as ready for review
September 23, 2025 00:06
Paul Van Eck (pvaneck)
requested review from
a team and
Xiang Yan (xiangyan99)
as code owners
September 23, 2025 00:06
Contributor
There was a problem hiding this comment.
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 |
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>
Xiang Yan (xiangyan99)
approved these changes
Oct 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the environment variable AZURE_TOKEN_CREDENTIALS is explicitly set to ManagedIdentityCredential, DefaultAzureCredential should not do IMDS probing.
Closes: #43046