Fix Key Vault challenge-based authentication tenant ID parsing for DSTSv2 authorities - #49007
Open
prasanna164-code wants to merge 2 commits into
Open
prasanna164-code wants to merge 2 commits into
prasanna164-code wants to merge 2 commits into
Conversation
HttpChallenge assumed the tenant ID is always the first path segment of the challenge's authorization URI. DSTSv2 authorities use the form https://<host>/dstsv2/<tenant-id>, so the literal string "dstsv2" was passed to the credential as tenant_id and token acquisition targeted the wrong tenant. Detect the "dstsv2" path segment and read the tenant ID from the segment that follows it, matching the behavior of the .NET Key Vault libraries. Applied to azure-keyvault-keys, -secrets, -certificates, -administration and -securitydomain. Added parsing tests covering Microsoft Entra ID and DSTSv2 authorization URIs plus sync and async 401 -> 200 pipeline tests asserting the tenant ID passed to the credential. Fixes Azure#45326
Contributor
|
Thank you for your contribution prasanna164-code! We will review the pull request and get back to you soon. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). 7 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved blocking issues were identified.
Pull request overview
Fixes DSTSv2 tenant ID parsing in Key Vault challenge authentication across five packages.
Changes:
- Parses tenant IDs following the case-insensitive
dstsv2path segment. - Adds synchronous and asynchronous regression tests.
- Updates changelogs and the Secrets package version.
File summaries
| File | Description |
|---|---|
sdk/keyvault/azure-keyvault-securitydomain/tests/test_challenge_auth.py |
Adds parsing and sync flow tests. |
sdk/keyvault/azure-keyvault-securitydomain/tests/test_challenge_auth_async.py |
Adds async flow coverage. |
sdk/keyvault/azure-keyvault-securitydomain/CHANGELOG.md |
Documents the fix. |
sdk/keyvault/azure-keyvault-securitydomain/azure/keyvault/securitydomain/_internal/http_challenge.py |
Adds DSTSv2 tenant parsing. |
sdk/keyvault/azure-keyvault-secrets/tests/test_challenge_auth.py |
Adds parsing and sync flow tests. |
sdk/keyvault/azure-keyvault-secrets/tests/test_challenge_auth_async.py |
Adds async flow coverage. |
sdk/keyvault/azure-keyvault-secrets/CHANGELOG.md |
Adds unreleased fix notes. |
sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_version.py |
Bumps the package version. |
sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_shared/http_challenge.py |
Adds DSTSv2 tenant parsing. |
sdk/keyvault/azure-keyvault-keys/tests/test_challenge_auth.py |
Adds parsing and sync flow tests. |
sdk/keyvault/azure-keyvault-keys/tests/test_challenge_auth_async.py |
Adds async flow coverage. |
sdk/keyvault/azure-keyvault-keys/CHANGELOG.md |
Documents the fix. |
sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/_shared/http_challenge.py |
Adds DSTSv2 tenant parsing. |
sdk/keyvault/azure-keyvault-certificates/tests/test_challenge_auth.py |
Adds parsing and sync flow tests. |
sdk/keyvault/azure-keyvault-certificates/tests/test_challenge_auth_async.py |
Adds async flow coverage. |
sdk/keyvault/azure-keyvault-certificates/CHANGELOG.md |
Documents the fix. |
sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_shared/http_challenge.py |
Adds DSTSv2 tenant parsing. |
sdk/keyvault/azure-keyvault-administration/tests/test_challenge_auth.py |
Adds sync and async regression coverage. |
sdk/keyvault/azure-keyvault-administration/CHANGELOG.md |
Documents the fix. |
sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_internal/http_challenge.py |
Adds DSTSv2 tenant parsing. |
Review details
- Files reviewed: 20/20 changed files
- Comments generated: 0
- Review effort level: Lite (auto)
Note
Copilot is running an experiment and ran this review at Lite.
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
prasanna164-code
requested review from
jenny (JennyPng),
Daniel Jurek (danieljurek),
Libba Lawrence (l0lawrence) and
Laia Patiño (laiapat)
as code owners
September 15, 2026 00:51
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.
Description
Fixes #45326
HttpChallengeextracts the tenant ID from theauthorization/authorization_uriparameter of theWWW-Authenticatechallenge by taking the first path segment of the URI. That is correct for Microsoft Entra ID authorities (https://login.microsoftonline.com/{tenant-id}), but DSTSv2 authorities have the formhttps://<host>/dstsv2/{tenant-id}, so the literal stringdstsv2was passed to the credential astenant_idand token acquisition failed or targeted the wrong tenant.This change moves the parsing into
HttpChallenge._parse_tenant_id, which detects thedstsv2path segment (case-insensitively) and reads the tenant ID from the segment that follows it. It matches the fix that shipped in the .NET libraries in Azure/azure-sdk-for-net#56416. All other authorization URIs are parsed exactly as before, including the existingNoneresult for a URI without a path.The fix is applied to every copy of
http_challenge.py:azure-keyvault-keys,azure-keyvault-secrets,azure-keyvault-certificates,azure-keyvault-administrationandazure-keyvault-securitydomain.CHANGELOG entries were added under Bugs Fixed.
azure-keyvault-secretshad no unreleased section (4.11.2 was released on 2026-08-25), so a4.11.3 (Unreleased)section was added and_version.pybumped accordingly, mirroring what the release automation does.Testing
New tests in
test_challenge_auth.py/test_challenge_auth_async.pyfor each of the five packages:test_challenge_parsing_tenant_id- parametrized over Entra ID authorities (with and without a trailing path), DSTSv2 authorities (mixed case, trailing slash), a DSTSv2 authority without a tenant segment, and an authority without a path.test_tenant_dstsv2(sync and async, parametrized overAccessToken/AccessTokenInfo) - full401 -> 200pipeline flow asserting the tenant ID that followsdstsv2is passed to the credential.Without the source change the DSTSv2 cases fail with
assert 'dstsv2' == 'de763a21-...', confirming they cover the bug.Verified locally (Python 3.14): the challenge-auth test modules of all five packages pass, and the added code is
black-clean at line length 120.All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines