Skip to content

Commit

Permalink
refactor: rename AuthMethod to ArmAuthMethod for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
comtalyst committed Jun 7, 2024
1 parent 70c2e8e commit c3615b8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions pkg/auth/autorest_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

func NewAuthorizer(config *Config, env *azure.Environment) (autorest.Authorizer, error) {
// TODO (charliedmcb): need to get track 2 support for the skewer API, and align all auth under workload identity in the same way within cred.go
if config.AuthMethod == authMethodWorkloadIdentity {
if config.ArmAuthMethod == authMethodWorkloadIdentity {
klog.V(2).Infoln("auth: using workload identity for new authorizer")
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
Expand All @@ -39,7 +39,7 @@ func NewAuthorizer(config *Config, env *azure.Environment) (autorest.Authorizer,
return azidext.NewTokenCredentialAdapter(cred, []string{azidext.DefaultManagementScope}), nil
}

if config.AuthMethod == authMethodSysMSI {
if config.ArmAuthMethod == authMethodSysMSI {
klog.V(2).Infoln("auth: using system assigned MSI to retrieve access token")
msiEndpoint, err := adal.GetMSIVMEndpoint()
if err != nil {
Expand All @@ -55,5 +55,5 @@ func NewAuthorizer(config *Config, env *azure.Environment) (autorest.Authorizer,
return autorest.NewBearerAuthorizer(token), nil
}

return nil, fmt.Errorf("auth: unsupported auth method %s", config.AuthMethod)
return nil, fmt.Errorf("auth: unsupported auth method %s", config.ArmAuthMethod)
}
14 changes: 7 additions & 7 deletions pkg/auth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ type Config struct {
ResourceGroup string `json:"resourceGroup" yaml:"resourceGroup"`
VMType string `json:"vmType" yaml:"vmType"`

// AuthMethod determines how to authorize requests for the Azure cloud.
// ArmAuthMethod determines how to authorize requests for the Azure cloud.
// Valid options are "system-assigned-msi" and "workload-identity"
// The default is "workload-identity".
AuthMethod string `json:"authMethod" yaml:"authMethod"`
ArmAuthMethod string `json:"armAuthMethod" yaml:"armAuthMethod"`

// Managed identity for Kubelet (not to be confused with Azure cloud authorization)
KubeletIdentityClientID string `json:"kubeletIdentityClientID" yaml:"kubeletIdentityClientID"`
Expand Down Expand Up @@ -110,7 +110,7 @@ func (cfg *Config) Build() error {
cfg.VMType = strings.ToLower(os.Getenv("ARM_VM_TYPE"))
cfg.ClusterName = strings.TrimSpace(os.Getenv("AZURE_CLUSTER_NAME"))
cfg.NodeResourceGroup = strings.TrimSpace(os.Getenv("AZURE_NODE_RESOURCE_GROUP"))
cfg.AuthMethod = strings.TrimSpace(os.Getenv("ARM_AUTH_METHOD"))
cfg.ArmAuthMethod = strings.TrimSpace(os.Getenv("ARM_AUTH_METHOD"))
cfg.KubeletIdentityClientID = strings.TrimSpace(os.Getenv("ARM_KUBELET_IDENTITY_CLIENT_ID"))

return nil
Expand All @@ -122,8 +122,8 @@ func (cfg *Config) Default() error {
cfg.VMType = vmTypeVMSS
}

if cfg.AuthMethod == "" {
cfg.AuthMethod = authMethodWorkloadIdentity
if cfg.ArmAuthMethod == "" {
cfg.ArmAuthMethod = authMethodWorkloadIdentity
}

return nil
Expand All @@ -145,8 +145,8 @@ func (cfg *Config) Validate() error {
}
}

if cfg.AuthMethod != authMethodSysMSI && cfg.AuthMethod != authMethodWorkloadIdentity {
return fmt.Errorf("unsupported authorization method: %s", cfg.AuthMethod)
if cfg.ArmAuthMethod != authMethodSysMSI && cfg.ArmAuthMethod != authMethodWorkloadIdentity {
return fmt.Errorf("unsupported authorization method: %s", cfg.ArmAuthMethod)
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions pkg/auth/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestBuildAzureConfig(t *testing.T) {
ResourceGroup: "my-rg",
NodeResourceGroup: "my-node-rg",
VMType: "vmss",
AuthMethod: "workload-identity",
ArmAuthMethod: "workload-identity",
},
wantErr: false,
env: map[string]string{
Expand All @@ -60,7 +60,7 @@ func TestBuildAzureConfig(t *testing.T) {
ResourceGroup: "my-rg",
NodeResourceGroup: "my-node-rg",
VMType: "vm",
AuthMethod: "workload-identity",
ArmAuthMethod: "workload-identity",
},
wantErr: false,
env: map[string]string{
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestBuildAzureConfig(t *testing.T) {
ResourceGroup: "my-rg",
NodeResourceGroup: "my-node-rg",
VMType: "vmss",
AuthMethod: "system-assigned-msi",
ArmAuthMethod: "system-assigned-msi",
},
wantErr: false,
env: map[string]string{
Expand All @@ -114,7 +114,7 @@ func TestBuildAzureConfig(t *testing.T) {
ResourceGroup: "my-rg",
NodeResourceGroup: "my-node-rg",
VMType: "vmss",
AuthMethod: "workload-identity",
ArmAuthMethod: "workload-identity",
},
wantErr: false,
env: map[string]string{
Expand All @@ -134,7 +134,7 @@ func TestBuildAzureConfig(t *testing.T) {
ResourceGroup: "my-rg",
NodeResourceGroup: "my-node-rg",
VMType: "vmss",
AuthMethod: "system-assigned-msi",
ArmAuthMethod: "system-assigned-msi",
KubeletIdentityClientID: "11111111-2222-3333-4444-555555555555",
},
wantErr: false,
Expand Down
6 changes: 3 additions & 3 deletions pkg/auth/cred.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ func NewCredential(cfg *Config) (azcore.TokenCredential, error) {
return nil, fmt.Errorf("failed to create credential, nil config provided")
}

if cfg.AuthMethod == authMethodWorkloadIdentity {
if cfg.ArmAuthMethod == authMethodWorkloadIdentity {
klog.V(2).Infoln("cred: using workload identity for new credential")
return azidentity.NewDefaultAzureCredential(nil)
}

if cfg.AuthMethod == authMethodSysMSI {
if cfg.ArmAuthMethod == authMethodSysMSI {
klog.V(2).Infoln("cred: using system assigned MSI for new credential")
msiCred, err := azidentity.NewManagedIdentityCredential(nil)
if err != nil {
Expand All @@ -44,5 +44,5 @@ func NewCredential(cfg *Config) (azcore.TokenCredential, error) {
return msiCred, nil
}

return nil, fmt.Errorf("cred: unsupported auth method: %s", cfg.AuthMethod)
return nil, fmt.Errorf("cred: unsupported auth method: %s", cfg.ArmAuthMethod)
}
6 changes: 3 additions & 3 deletions pkg/auth/cred_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestNewCredential(t *testing.T) {
{
name: "unsupported auth method",
cfg: &Config{
AuthMethod: "unsupported",
ArmAuthMethod: "unsupported",
},
want: nil,
wantErr: true,
Expand All @@ -57,15 +57,15 @@ func TestNewCredential(t *testing.T) {
{
name: "auth method system-assigned-msi",
cfg: &Config{
AuthMethod: authMethodSysMSI,
ArmAuthMethod: authMethodSysMSI,
},
want: reflect.TypeOf(&azidentity.ManagedIdentityCredential{}),
wantErr: false,
},
{
name: "auth method workload-identity",
cfg: &Config{
AuthMethod: authMethodWorkloadIdentity,
ArmAuthMethod: authMethodWorkloadIdentity,
},
want: reflect.TypeOf(&azidentity.DefaultAzureCredential{}),
wantErr: false,
Expand Down

0 comments on commit c3615b8

Please sign in to comment.