Cache Azure user delegation key for SAS signing#781
Open
emilk wants to merge 2 commits into
Open
Conversation
3aa759a to
2690d70
Compare
2690d70 to
5067d88
Compare
This was referenced Jun 25, 2026
kevinjqliu
reviewed
Jun 25, 2026
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.
Rationale for this change
AzureClient::signer()callsget_user_delegation_key()— aGetUserDelegationKeynetwork round-trip (POST /?restype=service&comp=userdelegationkey) — on everysigned_url/signed_urlscall. A user delegation key is reusable until its expiry, so re-fetching it per request is wasteful and, under load, gets throttled by Azure (HTTP 503ServerBusy).Notably the other backends do not make an uncached network call while signing: the AWS signer signs locally from its cached credential, and GCP caches its signing credentials. Azure is the outlier — it makes a
GetUserDelegationKeycall on top of the already-cached AAD token.We hit this in production: a workload issuing many presigned-URL requests against Azure Blob drove ~100k
GetUserDelegationKeyPOSTs in 2h (~840/min), ~35% of which returned 503. The retry client backed off 10× (~10s) and then surfaced the error to the caller.What changes are included in this PR?
Reuse the existing
TokenCache<T>to cache the user delegation key onAzureClient:TokenCacheonly returns a key with more than itsmin_ttl(2h here) remaining, so any SAS no longer than that is guaranteed to expire before its key (a SAS must not outlive the key it is signed with). The rare longer-lived SAS fetch a dedicated key.SignedExpiry), not when we requested.TokenCache’s refresh-race double-check and fetch backoff.TokenCache::with_min_ttlis extended to theazure-basefeature so the Azure client can configure the cache (previously gated toaws-base/gcp-base).The signed SAS tokens themselves are unchanged (still caller-specified
expires_in).Are there any user-facing changes?
No public API changes. Presigned-URL generation against Azure now performs far fewer
GetUserDelegationKeyrequests.Tests
Added
azure::client::tests::test_delegation_key_expiryfor the granted-vs-requested expiry parsing. The caching/refresh machinery itself is covered by the existingclient::tokentests.Related issues / PRs
No existing issue tracks this specifically. Related:
GetUserDelegationKeycall this PR caches.azure/mod.rssigned_url/signed_urls); orthogonal change, flagging for awareness of a possible minor merge interaction.