Skip to content

physical/azure: fall back to ExpiresOn when refreshing MSI tokens - #32168

Open
Sanjays2402 wants to merge 2 commits into
hashicorp:mainfrom
Sanjays2402:fix/azure-msi-token-expiry-expireson-fallback
Open

Sanjays2402 wants to merge 2 commits into
hashicorp:mainfrom
Sanjays2402:fix/azure-msi-token-expiry-expireson-fallback

Conversation

@Sanjays2402

Copy link
Copy Markdown

Description

Fixes #30258.

The Azure storage backend's MSI token refresh callback only reads the relative ExpiresIn claim to schedule the next refresh. When Azure AD returns an absolute ExpiresOn timestamp instead, ExpiresIn.Int64() fails, the callback logs an error and returns 0, so the refresh is never scheduled properly.

The expiry computation is now a small helper, tokenExpiryInSeconds, which prefers ExpiresIn and falls back to ExpiresOn (converted to a relative duration), returning an error only when neither claim is present. The refresh callback itself is unchanged apart from calling it.

Tests: new TestAzureBackend_tokenExpiryInSeconds covers ExpiresIn-only, ExpiresOn-only, both present (ExpiresIn wins), and neither (error). I verified the ExpiresOn-only case fails with the old inline logic and passes with the helper. The package builds and vets clean; the remaining tests in the package need a live Azurite/docker setup, so I could not run those here.

Fixes hashicorp#30258.

The MSI token refresh callback only read the relative ExpiresIn claim
to schedule the next refresh. When Azure AD returns an absolute
ExpiresOn timestamp instead, ExpiresIn.Int64() fails, the callback logs
an error and returns 0, so refreshes are never scheduled properly.
Extract the expiry computation into tokenExpiryInSeconds, which prefers
ExpiresIn and falls back to ExpiresOn.
@Sanjays2402
Sanjays2402 requested a review from a team as a code owner October 18, 2026 01:19
@Sanjays2402
Sanjays2402 requested a review from s-dhal October 18, 2026 01:19
@hashicorp-cla-app

Copy link
Copy Markdown

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

1 similar comment
@hashicorp-cla-app

Copy link
Copy Markdown

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The authorization token is not being refreshed for the Azure backend

1 participant