Skip to content

[Identity] Add custom IMDS retry policy - #42330

Merged
Paul Van Eck (pvaneck) merged 1 commit into
Azure:mainfrom
pvaneck:identity-410-retry
Aug 5, 2025
Merged

Paul Van Eck (pvaneck) merged 1 commit into
Azure:mainfrom
pvaneck:identity-410-retry

Conversation

@pvaneck

Copy link
Copy Markdown
Member

This custom policy adds logic to increase the retry backoff factor in the event that a response is a 410. It can take up to 70 seconds for IMDS to become available.

Closes: #41741

This custom policy adds logic to increase the retry backoff factor in
the event that a response is a 410. It can take up to 70 seconds for
IMDS to become available.

Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
@Ivanyy5

Ivanyy5 commented Aug 1, 2025

Copy link
Copy Markdown

This custom policy adds logic to increase the retry backoff factor in the event that a response is a 410. It can take up to 70 seconds for IMDS to become available.

Closes: #41741

Idependencies {
implementation("org.slf4j:slf4j-api:1.7.15")
}

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 a custom IMDS retry policy to the Azure Identity library to handle IMDS endpoint unavailability scenarios. The change specifically addresses the requirement that IMDS 410 status responses should be retried for at least 70 seconds total duration, as documented in Azure IMDS specifications.

Key changes:

  • Introduces custom retry policies (ImdsRetryPolicy and AsyncImdsRetryPolicy) with extended backoff for 410 responses
  • Modifies pipeline construction to support custom retry policy classes
  • Updates IMDS credential classes to use the new custom retry policies

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
azure/identity/_credentials/imds.py Adds ImdsRetryPolicy class and updates ImdsCredential to use custom retry policy
azure/identity/aio/_credentials/imds.py Adds AsyncImdsRetryPolicy class and updates async ImdsCredential to use custom retry policy
azure/identity/_internal/pipeline.py Modifies pipeline builders to support custom retry policy classes via retry_policy_class parameter
tests/test_imds_credential.py Adds comprehensive tests for the new retry policy behavior
tests/test_imds_credential_async.py Adds comprehensive tests for the async retry policy behavior
CHANGELOG.md Documents the new retry behavior for IMDS 410 responses
Comments suppressed due to low confidence (2)

sdk/identity/azure-identity/tests/test_imds_credential.py:160

  • The test doesn't verify the backoff factor is reset after handling a 410 response. Consider adding a test case that verifies the policy correctly resets the backoff factor when switching from a 410 response to a different status code.
        request = Mock(spec=HttpRequest, body=None, files=None)

sdk/identity/azure-identity/tests/test_imds_credential_async.py:366

  • The async test has the same limitation as the sync version - it doesn't verify the backoff factor is reset after handling a 410 response. Consider adding a test case that verifies the policy correctly resets the backoff factor when switching from a 410 response to a different status code.
        request = Mock(spec=HttpRequest, body=None, files=None)

@pvaneck
Paul Van Eck (pvaneck) merged commit 8a42e73 into Azure:main Aug 5, 2025
@github-project-automation github-project-automation Bot moved this from Untriaged to Done in Azure Identity SDK Improvements Aug 5, 2025
@pvaneck
Paul Van Eck (pvaneck) deleted the identity-410-retry branch August 5, 2025 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

ManagedIdentityCredential retry policy should handle 410 status response

4 participants