@@ -115,10 +115,15 @@ func NewClient(obj *sourcev1.Bucket, secret *corev1.Secret) (c *BlobClient, err
115115 // Compose token chain based on environment.
116116 // This functions as a replacement for azidentity.NewDefaultAzureCredential
117117 // to not shell out.
118- if token , err = chainCredentialWithSecret (secret ); err != nil {
118+ token , err = chainCredentialWithSecret (secret )
119+ if err != nil {
119120 err = fmt .Errorf ("failed to create environment credential chain: %w" , err )
120121 return nil , err
121122 }
123+ if token != nil {
124+ c .ServiceClient , err = azblob .NewServiceClient (obj .Spec .Endpoint , token , nil )
125+ return
126+ }
122127
123128 // Fallback to simple client.
124129 c .ServiceClient , err = azblob .NewServiceClientWithNoCredential (obj .Spec .Endpoint , nil )
@@ -353,6 +358,8 @@ func sharedCredentialFromSecret(endpoint string, secret *corev1.Secret) (*azblob
353358// azidentity.ChainedTokenCredential if at least one of the following tokens was
354359// successfully created:
355360// - azidentity.EnvironmentCredential
361+ // - azidentity.ManagedIdentityCredential with Client ID from AZURE_CLIENT_ID
362+ // environment variable, if found.
356363// - azidentity.ManagedIdentityCredential
357364// If a Secret with an `authorityHost` is provided, this is set on the
358365// azidentity.EnvironmentCredentialOptions. It may return nil.
@@ -369,6 +376,13 @@ func chainCredentialWithSecret(secret *corev1.Secret) (azcore.TokenCredential, e
369376 if token , _ := azidentity .NewEnvironmentCredential (credOpts ); token != nil {
370377 creds = append (creds , token )
371378 }
379+ if clientID := os .Getenv ("AZURE_CLIENT_ID" ); clientID != "" {
380+ if token , _ := azidentity .NewManagedIdentityCredential (& azidentity.ManagedIdentityCredentialOptions {
381+ ID : azidentity .ClientID (clientID ),
382+ }); token != nil {
383+ creds = append (creds , token )
384+ }
385+ }
372386 if token , _ := azidentity .NewManagedIdentityCredential (nil ); token != nil {
373387 creds = append (creds , token )
374388 }
0 commit comments