diff --git a/pkg/blockstorage/azure/auth.go b/pkg/blockstorage/azure/auth.go index a8d1f9f7b7f..415ee9c707e 100644 --- a/pkg/blockstorage/azure/auth.go +++ b/pkg/blockstorage/azure/auth.go @@ -26,13 +26,6 @@ func isMSICredsAvailable(config map[string]string) bool { config[blockstorage.AzureClientSecret] == "" } -func isDefaultCredsAvailable(config map[string]string) bool { - _, clientIDok := config[blockstorage.AzureClientID] - _, tenantIDok := config[blockstorage.AzureTenantID] - _, clientSecretOk := config[blockstorage.AzureClientSecret] - return !clientIDok && !tenantIDok && !clientSecretOk -} - type ClientCredentialsConfig struct { ClientID string ClientSecret string @@ -72,32 +65,11 @@ func NewAzureAuthenticator(config map[string]string) (AzureAuthenticator, error) return &MsiAuthenticator{}, nil case isClientCredsAvailable(config): return &ClientSecretAuthenticator{}, nil - case isDefaultCredsAvailable(config): - return &DefaultAuthenticator{}, nil default: return nil, errors.New("Fail to get an authenticator for provided creds combination") } } -// authenticate with default credential -type DefaultAuthenticator struct { - azcore.TokenCredential -} - -func (d *DefaultAuthenticator) GetAuthorizer() azcore.TokenCredential { - return d.TokenCredential -} - -func (d *DefaultAuthenticator) Authenticate(creds map[string]string) error { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - return errors.Wrap(err, "Failed to create an Azure Default Identity credential") - } - d.TokenCredential = cred - // creds passed authentication - return nil -} - // authenticate with MSI creds type MsiAuthenticator struct { azcore.TokenCredential @@ -106,10 +78,9 @@ type MsiAuthenticator struct { func (m *MsiAuthenticator) GetAuthorizer() azcore.TokenCredential { return m.TokenCredential } -func (m *MsiAuthenticator) Authenticate(creds map[string]string) error { +func (m *MsiAuthenticator) Authenticate(config map[string]string) error { // check if MSI endpoint is available - - clientID, ok := creds[blockstorage.AzureClientID] + clientID, ok := config[blockstorage.AzureClientID] if !ok || clientID == "" { return errors.New("Failed to fetch azure clientID") } @@ -120,7 +91,7 @@ func (m *MsiAuthenticator) Authenticate(creds map[string]string) error { return errors.Wrap(err, "Failed to create an Azure Managed Identity credential") } m.TokenCredential = cred - // creds passed authentication + // config passed authentication return nil } diff --git a/pkg/blockstorage/azure/auth_test.go b/pkg/blockstorage/azure/auth_test.go index 55c6e15ed15..543412edb74 100644 --- a/pkg/blockstorage/azure/auth_test.go +++ b/pkg/blockstorage/azure/auth_test.go @@ -101,11 +101,11 @@ func (s *AuthSuite) TestNewAzureAuthenticator(c *C) { c.Assert(err, IsNil) c.Assert(authenticator, NotNil) - // successful with no creds, but uses azure default credential + // unsuccessful with no creds config = map[string]string{} authenticator, err = NewAzureAuthenticator(config) - c.Assert(err, IsNil) - c.Assert(authenticator, NotNil) + c.Assert(err, NotNil) + c.Assert(authenticator, IsNil) // unsuccessful with an undefined combo of credss config = map[string]string{