Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Azure authentication in ASO #3698

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions azure/scope/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

const azureSecretKey = "clientSecret"
// AzureSecretKey is the value for they client secret key.
const AzureSecretKey = "clientSecret"

// CredentialsProvider defines the behavior for azure identity based credential providers.
type CredentialsProvider interface {
Expand Down Expand Up @@ -220,7 +221,7 @@ func (p *AzureCredentialsProvider) GetClientSecret(ctx context.Context) (string,
if err := p.Client.Get(ctx, key, secret); err != nil {
return "", errors.Wrap(err, "Unable to fetch ClientSecret")
}
return string(secret.Data[azureSecretKey]), nil
return string(secret.Data[AzureSecretKey]), nil
}
return "", nil
}
Expand Down
8 changes: 8 additions & 0 deletions azure/services/aso/aso.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-azure/azure"
"sigs.k8s.io/cluster-api-provider-azure/util/aso"
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -46,6 +47,9 @@ const (

createOrUpdateFutureType = "ASOCreateOrUpdate"
deleteFutureType = "ASODelete"

// SecretNameAnnotation is the annotation key for ASO's credentials to use.
SecretNameAnnotation = "serviceoperator.azure.com/credential-from"
Copy link
Contributor

@CecileRobertMichon CecileRobertMichon Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a place this can be imported from in ASO? Seems like there should be since it's a well known value (if not we should suggest it / add it @nojnhuh)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and various other constants I've looked for are defined in internal ASO packages. Opened Azure/azure-service-operator#3149.

)

// Service is an implementation of the Reconciler interface. It handles creation
Expand Down Expand Up @@ -181,6 +185,10 @@ func (s *Service) CreateOrUpdateResource(ctx context.Context, spec azure.ASOReso
annotations[ReconcilePolicyAnnotation] = ReconcilePolicyManage
}

// Set the secret name annotation in order to leverage the ASO resource credential scope as defined in
// https://azure.github.io/azure-service-operator/guide/authentication/credential-scope/#resource-scope.
annotations[SecretNameAnnotation] = aso.GetASOSecretName(s.clusterName)

if len(labels) == 0 {
labels = nil
}
Expand Down
4 changes: 4 additions & 0 deletions azure/services/aso/aso_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func TestCreateOrUpdateResource(t *testing.T) {
}))
g.Expect(created.Annotations).To(Equal(map[string]string{
ReconcilePolicyAnnotation: ReconcilePolicySkip,
SecretNameAnnotation: "cluster-aso-secret",
}))
g.Expect(created.Spec).To(Equal(asoresourcesv1.ResourceGroup_Spec{
Location: ptr.To("location"),
Expand Down Expand Up @@ -425,6 +426,7 @@ func TestCreateOrUpdateResource(t *testing.T) {
g.Expect(c.Get(ctx, types.NamespacedName{Name: "name", Namespace: "namespace"}, updated)).To(Succeed())
g.Expect(updated.Annotations).To(Equal(map[string]string{
ReconcilePolicyAnnotation: ReconcilePolicyManage,
SecretNameAnnotation: "cluster-aso-secret",
}))
})

Expand Down Expand Up @@ -482,6 +484,7 @@ func TestCreateOrUpdateResource(t *testing.T) {
g.Expect(c.Get(ctx, types.NamespacedName{Name: "name", Namespace: "namespace"}, updated)).To(Succeed())
g.Expect(updated.Annotations).To(Equal(map[string]string{
ReconcilePolicyAnnotation: ReconcilePolicyManage,
SecretNameAnnotation: "cluster-aso-secret",
}))
})

Expand Down Expand Up @@ -603,6 +606,7 @@ func TestCreateOrUpdateResource(t *testing.T) {
},
Annotations: map[string]string{
ReconcilePolicyAnnotation: ReconcilePolicyManage,
SecretNameAnnotation: "cluster-aso-secret",
},
},
Spec: asoresourcesv1.ResourceGroup_Spec{
Expand Down
Loading