@@ -66,22 +66,16 @@ type BlobClient struct {
66
66
//
67
67
// - azidentity.ClientSecretCredential when `tenantId`, `clientId` and
68
68
// `clientSecret` fields are found.
69
- // - azidentity.ClientSecretCredential when `tenant`, `appId` and `password`
70
- // fields are found. To match with the JSON from:
71
- // https://docs.microsoft.com/en-us/azure/aks/kubernetes-service-principal?tabs=azure-cli#manually-create-a-service-principal
72
69
// - azidentity.ClientCertificateCredential when `tenantId`,
73
70
// `clientCertificate` (and optionally `clientCertificatePassword`) fields
74
71
// are found.
75
72
// - azidentity.ManagedIdentityCredential for a User ID, when a `clientId`
76
73
// field but no `tenantId` is found.
77
- // - azidentity.ManagedIdentityCredential for a Resource ID, when a
78
- // `resourceId` field is found.
79
74
// - azblob.SharedKeyCredential when an `accountKey` field is found.
80
75
// The account name is extracted from the endpoint specified on the Bucket
81
76
// object.
82
77
// - azidentity.ChainedTokenCredential with azidentity.EnvironmentCredential
83
- // and azidentity.ManagedIdentityCredential with defaults if no Secret is
84
- // given.
78
+ // and azidentity.ManagedIdentityCredential.
85
79
//
86
80
// If no credentials are found, and the azidentity.ChainedTokenCredential can
87
81
// not be established. A simple client without credentials is returned.
@@ -292,16 +286,11 @@ func (c *BlobClient) ObjectIsNotFound(err error) bool {
292
286
// based on the data fields of the given Secret. It returns, in order:
293
287
// - azidentity.ClientSecretCredential when `tenantId`, `clientId` and
294
288
// `clientSecret` fields are found.
295
- // - azidentity.ClientSecretCredential when `tenant`, `appId` and `password`
296
- // fields are found. To match with the JSON from:
297
- // https://docs.microsoft.com/en-us/azure/aks/kubernetes-service-principal?tabs=azure-cli#manually-create-a-service-principal
298
289
// - azidentity.ClientCertificateCredential when `tenantId`,
299
290
// `clientCertificate` (and optionally `clientCertificatePassword`) fields
300
291
// are found.
301
292
// - azidentity.ManagedIdentityCredential for a User ID, when a `clientId`
302
293
// field but no `tenantId` is found.
303
- // - azidentity.ManagedIdentityCredential for a Resource ID, when a
304
- // `resourceId` field is found.
305
294
// - Nil, if no valid set of credential fields was found.
306
295
func tokenCredentialFromSecret (secret * corev1.Secret ) (azcore.TokenCredential , error ) {
307
296
if secret == nil {
@@ -357,10 +346,14 @@ func sharedCredentialFromSecret(endpoint string, secret *corev1.Secret) (*azblob
357
346
// chainCredentialWithSecret tries to create a set of tokens, and returns an
358
347
// azidentity.ChainedTokenCredential if at least one of the following tokens was
359
348
// successfully created:
360
- // - azidentity.EnvironmentCredential
361
- // - azidentity.ManagedIdentityCredential
362
- // If a Secret with an `authorityHost` is provided, this is set on the
363
- // azidentity.EnvironmentCredentialOptions. It may return nil.
349
+ //
350
+ // - azidentity.EnvironmentCredential with `authorityHost` from Secret, if
351
+ // provided.
352
+ // - azidentity.ManagedIdentityCredential with Client ID from AZURE_CLIENT_ID
353
+ // environment variable, if found.
354
+ // - azidentity.ManagedIdentityCredential with defaults.
355
+ //
356
+ // If no valid token is created, it returns nil.
364
357
func chainCredentialWithSecret (secret * corev1.Secret ) (azcore.TokenCredential , error ) {
365
358
var creds []azcore.TokenCredential
366
359
@@ -374,6 +367,13 @@ func chainCredentialWithSecret(secret *corev1.Secret) (azcore.TokenCredential, e
374
367
if token , _ := azidentity .NewEnvironmentCredential (credOpts ); token != nil {
375
368
creds = append (creds , token )
376
369
}
370
+ if clientID := os .Getenv ("AZURE_CLIENT_ID" ); clientID != "" {
371
+ if token , _ := azidentity .NewManagedIdentityCredential (& azidentity.ManagedIdentityCredentialOptions {
372
+ ID : azidentity .ClientID (clientID ),
373
+ }); token != nil {
374
+ creds = append (creds , token )
375
+ }
376
+ }
377
377
if token , _ := azidentity .NewManagedIdentityCredential (nil ); token != nil {
378
378
creds = append (creds , token )
379
379
}
0 commit comments