Skip to content

[Identity] Parse azd expiresOn as UTC in AzureDeveloperCliCredential - #49590

Merged
l0lawrence merged 1 commit into
Azure:mainfrom
digit50:fix/azd-credential-expireson-parse
Nov 17, 2026
Merged

l0lawrence merged 1 commit into
Azure:mainfrom
digit50:fix/azd-credential-expireson-parse

Conversation

@digit50

@digit50 digit50 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Description

closes #49589

AzureDeveloperCliCredential parsed the expiresOn value from azd auth token with datetime.strptime(..., "%Y-%m-%dT%H:%M:%SZ"), which matches the Z as a literal and returns a naive datetime, and timestamp() then read it as local time. The token's expires_on was 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.utc to the parsed value before converting it to epoch seconds, and corrects the parse_token docstring, which described the value as a naive local datetime. The async credential uses the same parse_token, so it is fixed too.

The existing sync and async test fixtures built expiresOn from local time with a Z suffix, which hid the bug, so they now write UTC. The new test_expires_on_is_utc parses a fixed UTC expiresOn under TZ=America/Los_Angeles and TZ=Asia/Tokyo and checks the expected epoch value for both get_token and get_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.py is bumped to match.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Copilot AI balanced review requested due to automatic review settings October 17, 2026 19:34
@digit50
digit50 requested a review from a team as a code owner October 17, 2026 19:34
@github-actions github-actions Bot added Azure.Identity Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Oct 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution digit50! We will review the pull request and get back to you soon.

@azure-pipelines

Copy link
Copy Markdown
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.

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.

🔵 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))

@vhvb1989 Victor Vazquez (vhvb1989) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.0 shipped (#49612) after this PR was opened, and main already has VERSION = "1.27.1" and a ## 1.27.1 (Unreleased) CHANGELOG section. Please drop the _version.py change and move the CHANGELOG entry into the existing 1.27.1 (Unreleased) → ### Bugs Fixed section. Don't add a new 1.26.1 section. The current diff will conflict and would roll the version back.

Suggestions (non-blocking)

  • test_azd_cli_credential_async.py gets the corrected fixtures but no time zone regression test. The async credential uses the same parse_token, so the sync test does cover the bug. Still, the identity tests usually keep sync and async coverage matched, so a matching test_expires_on_is_utc there would guard against the async path ever getting its own parser.
  • In test_expires_on_is_utc, the monkeypatch.undo() + time.tzset() in finally is correct. A small fixture that sets TZ, calls tzset(), 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.
@digit50
digit50 force-pushed the fix/azd-credential-expireson-parse branch from df0dcf6 to ab71d6b Compare November 17, 2026 07:16
@l0lawrence

Copy link
Copy Markdown
Member

windows 312 test is existing failure

@l0lawrence
l0lawrence merged commit 8cbb6c9 into Azure:main Nov 17, 2026
20 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure.Identity Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization.

Projects

Development

Successfully merging this pull request may close these issues.

AzureDeveloperCliCredential expires_on is off by the local UTC offset

4 participants