-
Notifications
You must be signed in to change notification settings - Fork 589
feat(providers) : Add support Azure AD token credentials and optional Azure CLI cached credential #4797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat(providers) : Add support Azure AD token credentials and optional Azure CLI cached credential #4797
Conversation
…d credential
- Add Options.UseAzureCLICredential (bool) to repo/blob/azure/Options.
This allows forcing the use of Azure CLI cached credential (azidentity.AzureCLICredential),
which reads the token cache created by `az login` or `az login --identity`.
- Implement Azure AD token credential flow in repo/blob/azure/azure_storage.go:
* If no SAS / storage key / client secret / client certificate / federated token is provided,
Kopia will try Azure AD token credentials.
* If UseAzureCLICredential == true -> use azidentity.NewAzureCLICredential()
* Otherwise -> use azidentity.NewDefaultAzureCredential() (env -> managed identity -> CLI -> ...)
- Add CLI flag wiring in cli/storage_azure.go:
* --azure-use-cli-credential (env: AZURE_USE_CLI_CREDENTIAL) mapped to Options.UseAzureCLICredential
- Update tests in repo/blob/azure/azure_storage_test.go:
* Add const for test env KOPIA_AZURE_USE_CLI_CREDENTIAL
* Add TestAzureCLICredential integration test (skipped unless KOPIA_PROVIDER_TEST and the boolean env var)
* Add detailed inline documentation on how to run provider tests
* Accept boolean-like values for KOPIA_AZURE_USE_CLI_CREDENTIAL ("1","0","true","false", ...)
Notes:
- Existing auth flows (SAS, shared key, client secret, client certificate, workload identity) are unchanged.
- When authenticating via Azure AD the principal must have RBAC permissions (e.g. Storage Blob Data Contributor).
| } | ||
| cred = cliCred | ||
| } else { | ||
| // Use DefaultAzureCredential as a safe default (env -> managed identity -> CLI -> ...). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarify comment, this is confusing:
(env -> managed identity -> CLI -> ...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Use DefaultAzureCredential, which attempts multiple authentication methods in order:
// environment variables → managed identity → Azure CLI → others.
// See: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity#DefaultAzureCredential
|
@alisonb-veeam @ryanmt PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds Azure AD token-based authentication support to Kopia's Azure Blob Storage provider, enabling authentication via Azure CLI cached credentials or DefaultAzureCredential when storage keys/SAS tokens are not provided.
Key changes:
- Add
UseAzureCLICredentialoption to force usage of Azure CLI token cache - Implement fallback Azure AD authentication when no explicit credentials are provided
- Add CLI flag
--azure-use-cli-credentialfor the new authentication option
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| repo/blob/azure/azure_options.go | Adds UseAzureCLICredential field to Options struct |
| repo/blob/azure/azure_storage.go | Implements Azure AD token credential authentication logic with CLI and default credential support |
| cli/storage_azure.go | Adds CLI flag for Azure CLI credential option |
| repo/blob/azure/azure_storage_test.go | Adds integration test for Azure CLI credential authentication |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4797 +/- ##
==========================================
+ Coverage 75.86% 76.38% +0.51%
==========================================
Files 470 530 +60
Lines 37301 40446 +3145
==========================================
+ Hits 28299 30895 +2596
- Misses 7071 7507 +436
- Partials 1931 2044 +113 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Reformatted line to comply with length limit and maintain readability.
debug short for "whitespace lint"
Co-authored-by: Julio Lopez <[email protected]> Co-authored-by: Copilot <[email protected]>
Marcel-MTL
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the improvements! I’ve addressed the minor style and linting issues (long lines, redundant comments, and whitespace rules). The logic is clear and the credential fallback is well handled.
| } | ||
| cred = cliCred | ||
| } else { | ||
| // Use DefaultAzureCredential as a safe default (env -> managed identity -> CLI -> ...). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Use DefaultAzureCredential, which attempts multiple authentication methods in order:
// environment variables → managed identity → Azure CLI → others.
// See: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity#DefaultAzureCredential
Summary
Allow Kopia to authenticate to Azure Blob Storage using Azure AD token credentials when no storage key or SAS token is provided. Add an option to explicitly use the Azure CLI token cache (e.g.
az loginoraz login --identity) as a credential source.This change enables workflows where Azure AD (Managed Identity, Service Principal, or CLI) is preferred over embedding storage keys or SAS tokens.
Key changes
Options / API
repo/blob/azure/Options: addUseAzureCLICredential boolto allow forcing the use of the Azure CLI token cache.Authentication
repo/blob/azure/azure_storage.go:StorageKey/SASToken/ClientSecret/ClientCertificate/AzureFederatedTokenFileis supplied, Kopia will attempt Azure AD token-based authentication.UseAzureCLICredential == true→ useazidentity.NewAzureCLICredential()(reads tokens from the Azure CLI cache).azidentity.NewDefaultAzureCredential()(fallback chain: env → managed identity → CLI → ...).CLI
cli/storage_azure.go: add CLI flag--azure-use-cli-credential(envAZURE_USE_CLI_CREDENTIAL) to wire this option from the CLI.Tests
repo/blob/azure/azure_storage_test.go:KOPIA_AZURE_USE_CLI_CREDENTIALconstant for integration testing.TestAzureCLICredentialintegration test (skipped unlessKOPIA_PROVIDER_TEST=1andKOPIA_AZURE_USE_CLI_CREDENTIALevaluates to true).Existing authentication flows (SAS, Shared Key, Client Secret, Client Certificate, Workload Identity) remain unchanged.
Why this change?
az logintokens (local) andaz login --identity(VM with Managed Identity).How to test (examples)
Build
Integration test: Azure CLI credential flow
Integration test: DefaultAzureCredential (managed identity / environment)