Skip to content

Commit

Permalink
Add the ability to auth via certs without storing them in etcd secret
Browse files Browse the repository at this point in the history
  • Loading branch information
enxebre authored and bryan-cox committed Oct 23, 2024
1 parent 9ba44ee commit 7ad2b68
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions api/v1beta1/azureclusteridentity_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ type AzureClusterIdentitySpec struct {
// ClientSecret is a secret reference which should contain either a Service Principal password or certificate secret.
// +optional
ClientSecret corev1.SecretReference `json:"clientSecret,omitempty"`
// certPath is the path where certicates exist. When set, it takes precedence over ClientSecret for types that uses certs like ServicePrincipalCertificate.
// +optional
CertPath string `json:"certPath,omitempty"`
// TenantID is the service principal primary tenant id.
TenantID string `json:"tenantID"`
// AllowedNamespaces is used to identify the namespaces the clusters are allowed to use the identity from.
Expand Down
18 changes: 14 additions & 4 deletions azure/scope/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package scope

import (
"context"
"os"
"reflect"

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

case infrav1.ServicePrincipalCertificate:
clientSecret, err := p.GetClientSecret(ctx)
if err != nil {
return nil, errors.Wrap(err, "failed to get client secret")
var certsContent []byte
if p.Identity.Spec.CertPath != "" {
certsContent, err = os.ReadFile(p.Identity.Spec.CertPath)
if err != nil {
return nil, errors.Wrap(err, "failed to read certificate file")
}
} else {
clientSecret, err := p.GetClientSecret(ctx)
if err != nil {
return nil, errors.Wrap(err, "failed to get client secret")
}
certsContent = []byte(clientSecret)
}
certs, key, err := azidentity.ParseCertificates([]byte(clientSecret), nil)
certs, key, err := azidentity.ParseCertificates(certsContent, nil)
if err != nil {
return nil, errors.Wrap(err, "failed to parse certificate data")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: object
certPath:
description: certPath is the path where certicates exist. When set,
it takes precedence over ClientSecret for types that uses certs
like ServicePrincipalCertificate.
type: string
clientID:
description: |-
ClientID is the service principal client ID.
Expand Down

0 comments on commit 7ad2b68

Please sign in to comment.