Skip to content

Commit f5d7a37

Browse files
committed
Support fields from az generated Azure SP
This supports the fields as documented in the AKS documentation: https://docs.microsoft.com/en-us/azure/aks/kubernetes-service-principal?tabs=azure-cli#manually-create-a-service-principal Signed-off-by: Hidde Beydals <[email protected]>
1 parent b2fc678 commit f5d7a37

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

pkg/azure/blob.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ const (
5151
clientCertificateField = "clientCertificate"
5252
clientCertificatePasswordField = "clientCertificatePassword"
5353
accountKeyField = "accountKey"
54+
55+
// Ref: https://docs.microsoft.com/en-us/azure/aks/kubernetes-service-principal?tabs=azure-cli#manually-create-a-service-principal
56+
tenantField = "tenant"
57+
appIDField = "appId"
58+
passwordField = "password"
5459
)
5560

5661
// BlobClient is a minimal Azure Blob client for fetching objects.
@@ -65,6 +70,9 @@ type BlobClient struct {
6570
//
6671
// - azidentity.ClientSecretCredential when `tenantId`, `clientId` and
6772
// `clientSecret` fields are found.
73+
// - azidentity.ClientSecretCredential when `tenant`, `appId` and `password`
74+
// fields are found. To match with the JSON from:
75+
// https://docs.microsoft.com/en-us/azure/aks/kubernetes-service-principal?tabs=azure-cli#manually-create-a-service-principal
6876
// - azidentity.ClientCertificateCredential when `tenantId`,
6977
// `clientCertificate` (and optionally `clientCertificatePassword`) fields
7078
// are found.
@@ -130,6 +138,13 @@ func ValidateSecret(secret *corev1.Secret) error {
130138
}
131139
}
132140
}
141+
if _, hasTenant := secret.Data[tenantField]; hasTenant {
142+
if _, hasAppID := secret.Data[appIDField]; hasAppID {
143+
if _, hasPassword := secret.Data[passwordField]; hasPassword {
144+
valid = true
145+
}
146+
}
147+
}
133148
if _, hasResourceID := secret.Data[resourceIDField]; hasResourceID {
134149
valid = true
135150
}
@@ -284,6 +299,13 @@ func tokenCredentialFromSecret(secret *corev1.Secret) (azcore.TokenCredential, e
284299
return azidentity.NewClientCertificateCredential(string(tenantID), string(clientID), certs, key, nil)
285300
}
286301
}
302+
if tenant, hasTenant := secret.Data[tenantField]; hasTenant {
303+
if appId, hasAppID := secret.Data[appIDField]; hasAppID {
304+
if password, hasPassword := secret.Data[passwordField]; hasPassword {
305+
return azidentity.NewClientSecretCredential(string(tenant), string(appId), string(password), nil)
306+
}
307+
}
308+
}
287309
if hasClientID {
288310
return azidentity.NewManagedIdentityCredential(&azidentity.ManagedIdentityCredentialOptions{
289311
ID: azidentity.ClientID(clientID),

pkg/azure/blob_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ func TestValidateSecret(t *testing.T) {
7676
},
7777
},
7878
},
79+
{
80+
name: "valid ServicePrincipal Secret",
81+
secret: &corev1.Secret{
82+
Data: map[string][]byte{
83+
tenantField: []byte("some-tenant-id-"),
84+
appIDField: []byte("some-client-id-"),
85+
passwordField: []byte("some-client-secret-"),
86+
},
87+
},
88+
},
7989
{
8090
name: "valid SharedKey Secret",
8191
secret: &corev1.Secret{
@@ -230,6 +240,17 @@ func Test_tokenCredentialFromSecret(t *testing.T) {
230240
},
231241
want: &azidentity.ClientSecretCredential{},
232242
},
243+
{
244+
name: "with Tenant, AppID and Password fields",
245+
secret: &corev1.Secret{
246+
Data: map[string][]byte{
247+
appIDField: []byte("client-id"),
248+
tenantField: []byte("tenant-id"),
249+
passwordField: []byte("client-secret"),
250+
},
251+
},
252+
want: &azidentity.ClientSecretCredential{},
253+
},
233254
{
234255
name: "empty secret",
235256
secret: &corev1.Secret{},

0 commit comments

Comments
 (0)