Skip to content

Commit 01cae4f

Browse files
committed
azure: support system-assigned managed identity
System-assigned managed identities can be used in the same manner as user-assigned managed identities, simply by leaving the ID unset.
1 parent 0666062 commit 01cae4f

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

azure/scope/identity.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ func (p *AzureCredentialsProvider) GetTokenCredential(ctx context.Context, resou
154154
ClientOptions: azcore.ClientOptions{
155155
TracingProvider: tracingProvider,
156156
},
157-
ID: azidentity.ClientID(p.Identity.Spec.ClientID),
157+
}
158+
if p.Identity.Spec.ClientID != "" {
159+
options.ID = azidentity.ClientID(p.Identity.Spec.ClientID)
158160
}
159161
cred, authErr = p.cache.GetOrStoreManagedIdentity(&options)
160162

azure/scope/identity_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,28 @@ func TestGetTokenCredential(t *testing.T) {
420420
}))
421421
},
422422
},
423+
{
424+
name: "system-assigned identity",
425+
cluster: &infrav1.AzureCluster{
426+
Spec: infrav1.AzureClusterSpec{
427+
AzureClusterClassSpec: infrav1.AzureClusterClassSpec{
428+
IdentityRef: &corev1.ObjectReference{
429+
Kind: infrav1.AzureClusterIdentityKind,
430+
},
431+
},
432+
},
433+
},
434+
identity: &infrav1.AzureClusterIdentity{
435+
Spec: infrav1.AzureClusterIdentitySpec{
436+
Type: infrav1.UserAssignedMSI,
437+
},
438+
},
439+
cacheExpect: func(cache *mock_azure.MockCredentialCache) {
440+
cache.EXPECT().GetOrStoreManagedIdentity(gomock.Cond(func(opts *azidentity.ManagedIdentityCredentialOptions) bool {
441+
return opts.ID == nil
442+
}))
443+
},
444+
},
423445
{
424446
name: "UserAssignedIdentityCredential",
425447
cluster: &infrav1.AzureCluster{

0 commit comments

Comments
 (0)