Skip to content

Commit db6df03

Browse files
Merge pull request #1082 from bryan-cox/IR-467
IR-467: Enable MSI override for ARO HCP
2 parents c9df196 + dfdd4b8 commit db6df03

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

pkg/storage/azure/azure.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"net/http"
77
"net/url"
8+
"os"
89
"reflect"
910
"regexp"
1011
"strings"
@@ -340,7 +341,21 @@ func (d *driver) storageAccountsClient(cfg *Azure, environment autorestazure.Env
340341
cred azcore.TokenCredential
341342
err error
342343
)
343-
if strings.TrimSpace(cfg.ClientSecret) == "" {
344+
// MSI Override for ARO HCP
345+
msi := os.Getenv("AZURE_MSI_AUTHENTICATION")
346+
if msi == "true" {
347+
options := azidentity.ManagedIdentityCredentialOptions{
348+
ClientOptions: azcore.ClientOptions{
349+
Cloud: cloudConfig,
350+
},
351+
}
352+
353+
var err error
354+
cred, err = azidentity.NewManagedIdentityCredential(&options)
355+
if err != nil {
356+
return storage.AccountsClient{}, err
357+
}
358+
} else if strings.TrimSpace(cfg.ClientSecret) == "" {
344359
options := azidentity.WorkloadIdentityCredentialOptions{
345360
ClientOptions: azcore.ClientOptions{
346361
Cloud: cloudConfig,

pkg/storage/azure/azureclient/azureclient.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"net/http"
7+
"os"
78
"strings"
89

910
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
@@ -85,7 +86,20 @@ func New(opts *Options) (*Client, error) {
8586
creds := opts.Creds
8687
if creds == nil {
8788
var err error
88-
if strings.TrimSpace(opts.ClientSecret) == "" {
89+
90+
// MSI Override for ARO HCP
91+
msi := os.Getenv("AZURE_MSI_AUTHENTICATION")
92+
if msi == "true" {
93+
options := azidentity.ManagedIdentityCredentialOptions{
94+
ClientOptions: azcore.ClientOptions{
95+
Cloud: cloudConfig,
96+
},
97+
}
98+
creds, err = azidentity.NewManagedIdentityCredential(&options)
99+
if err != nil {
100+
return nil, err
101+
}
102+
} else if strings.TrimSpace(opts.ClientSecret) == "" {
89103
options := azidentity.WorkloadIdentityCredentialOptions{
90104
ClientOptions: coreOpts,
91105
ClientID: opts.ClientID,
@@ -110,7 +124,6 @@ func New(opts *Options) (*Client, error) {
110124
return nil, err
111125
}
112126
}
113-
114127
}
115128

116129
coreOpts.Retry = policy.RetryOptions{

0 commit comments

Comments
 (0)