Skip to content

Commit 7ad2b68

Browse files
enxebrebryan-cox
authored andcommitted
Add the ability to auth via certs without storing them in etcd secret
1 parent 9ba44ee commit 7ad2b68

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

api/v1beta1/azureclusteridentity_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ type AzureClusterIdentitySpec struct {
5959
// ClientSecret is a secret reference which should contain either a Service Principal password or certificate secret.
6060
// +optional
6161
ClientSecret corev1.SecretReference `json:"clientSecret,omitempty"`
62+
// certPath is the path where certicates exist. When set, it takes precedence over ClientSecret for types that uses certs like ServicePrincipalCertificate.
63+
// +optional
64+
CertPath string `json:"certPath,omitempty"`
6265
// TenantID is the service principal primary tenant id.
6366
TenantID string `json:"tenantID"`
6467
// AllowedNamespaces is used to identify the namespaces the clusters are allowed to use the identity from.

azure/scope/identity.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package scope
1818

1919
import (
2020
"context"
21+
"os"
2122
"reflect"
2223

2324
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
@@ -127,11 +128,20 @@ func (p *AzureCredentialsProvider) GetTokenCredential(ctx context.Context, resou
127128
cred, authErr = azidentity.NewClientSecretCredential(p.GetTenantID(), p.Identity.Spec.ClientID, clientSecret, &options)
128129

129130
case infrav1.ServicePrincipalCertificate:
130-
clientSecret, err := p.GetClientSecret(ctx)
131-
if err != nil {
132-
return nil, errors.Wrap(err, "failed to get client secret")
131+
var certsContent []byte
132+
if p.Identity.Spec.CertPath != "" {
133+
certsContent, err = os.ReadFile(p.Identity.Spec.CertPath)
134+
if err != nil {
135+
return nil, errors.Wrap(err, "failed to read certificate file")
136+
}
137+
} else {
138+
clientSecret, err := p.GetClientSecret(ctx)
139+
if err != nil {
140+
return nil, errors.Wrap(err, "failed to get client secret")
141+
}
142+
certsContent = []byte(clientSecret)
133143
}
134-
certs, key, err := azidentity.ParseCertificates([]byte(clientSecret), nil)
144+
certs, key, err := azidentity.ParseCertificates(certsContent, nil)
135145
if err != nil {
136146
return nil, errors.Wrap(err, "failed to parse certificate data")
137147
}

config/crd/bases/infrastructure.cluster.x-k8s.io_azureclusteridentities.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ spec:
123123
type: object
124124
x-kubernetes-map-type: atomic
125125
type: object
126+
certPath:
127+
description: certPath is the path where certicates exist. When set,
128+
it takes precedence over ClientSecret for types that uses certs
129+
like ServicePrincipalCertificate.
130+
type: string
126131
clientID:
127132
description: |-
128133
ClientID is the service principal client ID.

0 commit comments

Comments
 (0)