Repository navigation
[Identity] Parse azd expiresOn as UTC in AzureDeveloperCliCredential - #49590
Conversation
|
Thank you for your contribution digit50! 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. |
There was a problem hiding this comment.
🔵 Needs a closer look
Authentication-related token-expiry changes require human security review under repository guidance.
1 open issue
What changed in this PR
Fixes #49589 by interpreting Azure Developer CLI token expiry as UTC in the parser shared by synchronous and asynchronous credentials.
Changes:
- Corrects expiry parsing and its docstring.
- Updates fixtures to UTC and adds non-UTC regression coverage.
- Documents the fix and bumps the version to 1.26.1.
| File | Description |
|---|---|
| sdk/identity/azure-identity/tests/test_azd_cli_credential.py | Updates fixtures and tests timezone-independent expiry. |
| sdk/identity/azure-identity/tests/test_azd_cli_credential_async.py | Updates async fixtures to UTC. |
| sdk/identity/azure-identity/CHANGELOG.md | Documents the expiry fix. |
| sdk/identity/azure-identity/azure/identity/_version.py | Bumps version to 1.26.1. |
| sdk/identity/azure-identity/azure/identity/_credentials/azd_cli.py | Parses expiry explicitly as UTC. |
Review effort: Balanced
|
|
||
| ### Bugs Fixed | ||
|
|
||
| - Fixed `AzureDeveloperCliCredential` reading the UTC `expiresOn` value from `azd auth token` as local time, which made the token's `expires_on` off by the local UTC offset. ([#49589](https://github.com/Azure/azure-sdk-for-python/issues/49589)) |
Victor Vazquez (vhvb1989)
left a comment
There was a problem hiding this comment.
Thanks for the fix. I checked the behavior from the azd side and in the other language SDKs; details are in #49589 (comment). azd always writes expiresOn as UTC with a trailing Z, and .NET, Java, JS, and Go already parse it as UTC. Parsing with .replace(tzinfo=timezone.utc) is correct and matches those SDKs.
Required: rebase onto current main
1.27.0shipped (#49612) after this PR was opened, andmainalready hasVERSION = "1.27.1"and a## 1.27.1 (Unreleased)CHANGELOG section. Please drop the_version.pychange and move the CHANGELOG entry into the existing1.27.1 (Unreleased)→### Bugs Fixedsection. Don't add a new1.26.1section. The current diff will conflict and would roll the version back.
Suggestions (non-blocking)
test_azd_cli_credential_async.pygets the corrected fixtures but no time zone regression test. The async credential uses the sameparse_token, so the sync test does cover the bug. Still, the identity tests usually keep sync and async coverage matched, so a matchingtest_expires_on_is_utcthere would guard against the async path ever getting its own parser.- In
test_expires_on_is_utc, themonkeypatch.undo()+time.tzset()infinallyis correct. A small fixture that setsTZ, callstzset(), and restores both on teardown would read more cleanly and could be shared with the async test.
The core change and the fixture corrections look good to me. I confirmed the new test would fail on the old code under America/Los_Angeles and Asia/Tokyo (offsets of +8h and −9h).
AzureDeveloperCliCredential parsed the expiresOn value from azd auth token as a naive datetime, so the token's expires_on was off by the local UTC offset. The value is UTC, so it is now parsed with a UTC timezone. The test fixtures now write UTC, and new sync and async tests parse a token under non-UTC time zones.
df0dcf6 to
ab71d6b
Compare
|
windows 312 test is existing failure |

Description
closes #49589
AzureDeveloperCliCredentialparsed theexpiresOnvalue fromazd auth tokenwithdatetime.strptime(..., "%Y-%m-%dT%H:%M:%SZ"), which matches theZas a literal and returns a naive datetime, andtimestamp()then read it as local time. The token'sexpires_onwas therefore off by the host's UTC offset: west of UTC an expired token kept being used, east of UTC every token was already expired when returned.This change attaches
timezone.utcto the parsed value before converting it to epoch seconds, and corrects theparse_tokendocstring, which described the value as a naive local datetime. The async credential uses the sameparse_token, so it is fixed too.The existing sync and async test fixtures built
expiresOnfrom local time with aZsuffix, which hid the bug, so they now write UTC. The newtest_expires_on_is_utcparses a fixed UTCexpiresOnunderTZ=America/Los_AngelesandTZ=Asia/Tokyoand checks the expected epoch value for bothget_tokenandget_token_info. It fails without the fix and passes with it.The CHANGELOG has a new 1.26.1 (Unreleased) section with the fix, and
_version.pyis bumped to match.All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines