feat(storage-azure): add support for Entra managed identity authentication - #17598
Open
SergeyFilenko wants to merge 1 commit into
Open
feat(storage-azure): add support for Entra managed identity authentication#17598SergeyFilenko wants to merge 1 commit into
SergeyFilenko wants to merge 1 commit into
Conversation
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.
What?
Adds Entra ID (managed identity) authentication to
@payloadcms/storage-azure.AzureStorageOptionsnow accepts either aconnectionString(existing behaviour) or acredential, which can be anyTokenCredentialfrom@azure/identitysuch asDefaultAzureCredential. The two options are mutually exclusive at the type level, so misconfiguration is caught at compile time.Why?
Connection strings require storing the storage account key as a secret. On Azure App Service, Container Apps or AKS, identity-based authentication is Microsoft's recommended approach. There are no long-lived secrets to store, rotate or leak, and access is controlled through RBAC and can be revoked at any time. It also makes it possible to harden security further by disabling storage account key access entirely.
This has been requested before in #13627 (and #12004 prior to it), which proposed the same
credentialoption. However, #13627 doesn't addressclientUploads: the SAS signing code ingenerateUploadInstructionsunconditionally casts the container client's credential toStorageSharedKeyCredential. With aTokenCredentialconfigured, that cast is wrong at runtime and client uploads fail.How?
getStorageClientnow builds theBlobServiceClientfrom either auth method and caches both the service and container clients per cache key. The service client is needed to request user delegation keys when signing client upload URLs.generateUploadInstructionsbranches on the actual credential type instead of casting:StorageSharedKeyCredentialsigns a service SAS, exactly as before, so there is no behaviour change for existing users.TokenCredentialfetches a user delegation key viagetUserDelegationKeyand signs a user delegation SAS. Keys are requested with twice the SAS lifetime and cached in aWeakMap, and only reused while their remaining validity still covers a full SAS window plus a clock-skew margin. In practice this means roughly one key fetch every three hours rather than one per upload.baseURLrequirement, theStorage Blob Data Contributorrole requirement, and a note on the SAS connection string limitation.sig/spandskoid/sktidSAS parameters), delegation key caching, and the error cases.Verified manually against a real storage account with a
DefaultAzureCredential: server uploads, client uploads (delegation SAS) and downloads all work, and misconfigurations produce the intended errors.