Skip to content

Commit

Permalink
Add new authentication type for managed Azure HCP
Browse files Browse the repository at this point in the history
This commit adds a new authentication type for managed Azure HCP called UserAssignedIdentityCredentials. This new authentication type replaces the previous authentication method for managed Azure HCP.

Signed-off-by: Bryan Cox <[email protected]>
  • Loading branch information
bryan-cox committed Feb 17, 2025
1 parent d6c6f6c commit c6ed87f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
15 changes: 13 additions & 2 deletions pkg/storage/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/Azure/go-autorest/autorest"
autorestazure "github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/to"
"github.com/Azure/msi-dataplane/pkg/dataplane"
"github.com/jongio/azidext/go/azidext"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -371,9 +372,19 @@ func (d *driver) storageAccountsClient(cfg *Azure, environment autorestazure.Env
cred azcore.TokenCredential
err error
)
// Managed Identity Override for ARO HCP
managedIdentityClientID := os.Getenv("ARO_HCP_MI_CLIENT_ID")
if managedIdentityClientID != "" {
userAssignedIdentityCredentialsFilePath := os.Getenv("MANAGED_AZURE_HCP_CREDENTIALS_FILE_PATH")
if userAssignedIdentityCredentialsFilePath != "" {
// UserAssignedIdentityCredentials for managed Azure HCP
clientOptions := azcore.ClientOptions{
Cloud: cloudConfig,
}
cred, err = dataplane.NewUserAssignedIdentityCredential(context.Background(), userAssignedIdentityCredentialsFilePath, dataplane.WithClientOpts(clientOptions))
if err != nil {
return storage.AccountsClient{}, err
}
} else if managedIdentityClientID != "" {
// Managed Identity Override for ARO HCP
klog.V(2).Info("Using client certification Azure authentication for ARO HCP")
options := &azidentity.ClientCertificateCredentialOptions{
ClientOptions: azcore.ClientOptions{
Expand Down
16 changes: 13 additions & 3 deletions pkg/storage/azure/azureclient/azureclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/container"
autorestazure "github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/to"
"github.com/Azure/msi-dataplane/pkg/dataplane"
"github.com/openshift/cluster-image-registry-operator/pkg/filewatcher"
"k8s.io/klog/v2"
)
Expand Down Expand Up @@ -103,10 +104,19 @@ func (c *Client) getCreds(ctx context.Context) (azcore.TokenCredential, error) {
err error
creds azcore.TokenCredential
)

// Managed Identity Override for ARO HCP
managedIdentityClientID := os.Getenv("ARO_HCP_MI_CLIENT_ID")
if managedIdentityClientID != "" {
userAssignedIdentityCredentialsFilePath := os.Getenv("MANAGED_AZURE_HCP_CREDENTIALS_FILE_PATH")
if userAssignedIdentityCredentialsFilePath != "" {
// UserAssignedIdentityCredentials for managed Azure HCP
clientOptions := azcore.ClientOptions{
Cloud: c.clientOpts.Cloud,
}
creds, err = dataplane.NewUserAssignedIdentityCredential(ctx, userAssignedIdentityCredentialsFilePath, dataplane.WithClientOpts(clientOptions))
if err != nil {
return nil, err
}
} else if managedIdentityClientID != "" {
// Managed Identity Override for ARO HCP
klog.V(2).Info("Using client certification Azure authentication for ARO HCP")
options := &azidentity.ClientCertificateCredentialOptions{
ClientOptions: azcore.ClientOptions{
Expand Down

0 comments on commit c6ed87f

Please sign in to comment.