@@ -63,15 +63,15 @@ type BlobClient struct {
63
63
// Bucket and Secret. It detects credentials in the Secret in the following
64
64
// order:
65
65
//
66
- // - azidentity.ManagedIdentityCredential for a Resource ID, when a
67
- // `resourceId` field is found.
68
- // - azidentity.ManagedIdentityCredential for a User ID, when a `clientId`
69
- // field but no `tenantId` is found.
66
+ // - azidentity.ClientSecretCredential when `tenantId`, `clientId` and
67
+ // `clientSecret` fields are found.
70
68
// - azidentity.ClientCertificateCredential when `tenantId`,
71
69
// `clientCertificate` (and optionally `clientCertificatePassword`) fields
72
70
// are found.
73
- // - azidentity.ClientSecretCredential when `tenantId`, `clientId` and
74
- // `clientSecret` fields are found.
71
+ // - azidentity.ManagedIdentityCredential for a User ID, when a `clientId`
72
+ // field but no `tenantId` is found.
73
+ // - azidentity.ManagedIdentityCredential for a Resource ID, when a
74
+ // `resourceId` field is found.
75
75
// - azblob.SharedKeyCredential when an `accountKey` field is found.
76
76
// The account name is extracted from the endpoint specified on the Bucket
77
77
// object.
@@ -271,31 +271,30 @@ func (c *BlobClient) ObjectIsNotFound(err error) bool {
271
271
}
272
272
273
273
func tokenCredentialFromSecret (secret * corev1.Secret ) (azcore.TokenCredential , error ) {
274
- var token azcore.TokenCredential
275
- if resourceID , ok := secret .Data [resourceIDField ]; ok {
276
- return azidentity .NewManagedIdentityCredential (& azidentity.ManagedIdentityCredentialOptions {
277
- ID : azidentity .ResourceID (resourceID ),
278
- })
279
- }
280
- if clientID , hasClientID := secret .Data [clientIDField ]; hasClientID {
281
- tenantID , hasTenantID := secret .Data [tenantIDField ]
282
- if ! hasTenantID {
283
- return azidentity .NewManagedIdentityCredential (& azidentity.ManagedIdentityCredentialOptions {
284
- ID : azidentity .ClientID (clientID ),
285
- })
274
+ clientID , hasClientID := secret .Data [clientIDField ]
275
+ if tenantID , hasTenantID := secret .Data [tenantIDField ]; hasTenantID && hasClientID {
276
+ if clientSecret , hasClientSecret := secret .Data [clientSecretField ]; hasClientSecret && len (clientSecret ) > 0 {
277
+ return azidentity .NewClientSecretCredential (string (tenantID ), string (clientID ), string (clientSecret ), nil )
286
278
}
287
- if clientCertificate , hasClientCertificate := secret .Data [clientCertificateField ]; hasClientCertificate {
279
+ if clientCertificate , hasClientCertificate := secret .Data [clientCertificateField ]; hasClientCertificate && len ( clientCertificate ) > 0 {
288
280
certs , key , err := azidentity .ParseCertificates (clientCertificate , secret .Data [clientCertificatePasswordField ])
289
281
if err != nil {
290
282
return nil , fmt .Errorf ("failed to parse client certificates: %w" , err )
291
283
}
292
284
return azidentity .NewClientCertificateCredential (string (tenantID ), string (clientID ), certs , key , nil )
293
285
}
294
- if clientSecret , hasClientSecret := secret .Data [clientSecretField ]; hasClientSecret {
295
- return azidentity .NewClientSecretCredential (string (tenantID ), string (clientID ), string (clientSecret ), nil )
296
- }
297
286
}
298
- return token , nil
287
+ if hasClientID {
288
+ return azidentity .NewManagedIdentityCredential (& azidentity.ManagedIdentityCredentialOptions {
289
+ ID : azidentity .ClientID (clientID ),
290
+ })
291
+ }
292
+ if resourceID , hasResourceID := secret .Data [resourceIDField ]; hasResourceID {
293
+ return azidentity .NewManagedIdentityCredential (& azidentity.ManagedIdentityCredentialOptions {
294
+ ID : azidentity .ResourceID (resourceID ),
295
+ })
296
+ }
297
+ return nil , nil
299
298
}
300
299
301
300
func sharedCredentialFromSecret (endpoint string , secret * corev1.Secret ) (* azblob.SharedKeyCredential , error ) {
0 commit comments