Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardChen820 committed May 22, 2024
1 parent 029de80 commit 8eca86e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion deploy/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Selector labels
app.kubernetes.io/name: {{ include "az-appconfig-k8s-provider.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
control-plane: controller-manager
{{- if eq .Values.workloadIdentity.enabled true }}
{{- if and (.Values.workloadIdentity.enabled) (not .Values.workloadIdentity.disableGlobalServiceAccount) }}
azure.workload.identity/use: "true"
{{- end }}
{{- end }}
Expand Down
2 changes: 1 addition & 1 deletion deploy/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ metadata:
{{- if .Values.serviceAccount.annotations }}
{{ toYaml .Values.serviceAccount.annotations . | nindent 4 }}
{{- end }}
{{- if eq .Values.workloadIdentity.enabled true }}
{{- if and (.Values.workloadIdentity.enabled) (not .Values.workloadIdentity.disableGlobalServiceAccount) }}
azure.workload.identity/client-id: ""
{{- end }}
{{- end }}
8 changes: 4 additions & 4 deletions internal/controller/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,14 @@ func verifyWorkloadIdentityParameters(workloadIdentity *acpv1.WorkloadIdentityPa

if workloadIdentity.ManagedIdentityClientId != nil {
if strings.EqualFold(os.Getenv(WorkloadIdentityDisableGlobalServiceAccount), "true") {
return loader.NewArgumentError("auth.workloadIdentity.managedIdentityClientId", fmt.Errorf("managedIdentityClientId is not allowed since only custom service account is allowed"))
return loader.NewArgumentError("auth.workloadIdentity.managedIdentityClientId", fmt.Errorf("'managedIdentityClientId' is not allowed since global service account is disabled"))
}
authCount++
}

if workloadIdentity.ManagedIdentityClientIdReference != nil {
if strings.EqualFold(os.Getenv(WorkloadIdentityDisableGlobalServiceAccount), "true") {
return loader.NewArgumentError("auth.workloadIdentity.managedIdentityClientIdReference", fmt.Errorf("managedIdentityClientIdReference is not allowed since only custom service account is allowed"))
return loader.NewArgumentError("auth.workloadIdentity.managedIdentityClientIdReference", fmt.Errorf("'managedIdentityClientIdReference' is not allowed since global service account is disabled"))
}
authCount++
}
Expand All @@ -265,11 +265,11 @@ func verifyWorkloadIdentityParameters(workloadIdentity *acpv1.WorkloadIdentityPa
}

if authCount == 0 {
return loader.NewArgumentError("auth.workloadIdentity", fmt.Errorf("one of managedIdentityClientId, managedIdentityClientIdReference and serviceAccountName is required"))
return loader.NewArgumentError("auth.workloadIdentity", fmt.Errorf("setting one of 'managedIdentityClientId', 'managedIdentityClientIdReference' or 'serviceAccountName' field is required"))
}

if authCount > 1 {
return loader.NewArgumentError("auth.workloadIdentity", fmt.Errorf("only one of managedIdentityClientId, managedIdentityClientIdReference and serviceAccountName is allowed"))
return loader.NewArgumentError("auth.workloadIdentity", fmt.Errorf("setting only one of 'managedIdentityClientId', 'managedIdentityClientIdReference' or 'serviceAccountName' field is allowed"))
}

if workloadIdentity.ManagedIdentityClientId != nil {
Expand Down
17 changes: 9 additions & 8 deletions internal/loader/configuration_client_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const (
MinBackoffDuration time.Duration = time.Second * 30
JitterRatio float64 = 0.25
SafeShiftLimit int = 63
AzureDefaultAudience string = "api://AzureADTokenExchange"
ApiTokenExchangeAudience string = "api://AzureADTokenExchange"
AnnotationClientID string = "azure.workload.identity/client-id"
AnnotationTenantID string = "azure.workload.identity/tenant-id"
)
Expand Down Expand Up @@ -493,17 +493,18 @@ func newClientAssertionCredential(ctx context.Context, serviceAccountName string
return nil, err
}

tenantId, ok := os.LookupEnv(strings.ToUpper(AzureTenantId))
if !ok {
return nil, fmt.Errorf("no tenant ID specified. Check pod configuration or set TenantID in the options")
}

if _, ok := serviceAccountObj.Annotations[AnnotationClientID]; !ok {
return nil, fmt.Errorf("service account %s/%s does not have annotation %s", serviceAccountNamespace, serviceAccountName, AnnotationClientID)
return nil, fmt.Errorf("annotation '%s' of service account %s/%s is required", AnnotationClientID, serviceAccountNamespace, serviceAccountName)
}

tenantId := ""

if _, ok := serviceAccountObj.Annotations[AnnotationTenantID]; ok {
tenantId = serviceAccountObj.Annotations[AnnotationTenantID]
} else if _, ok := os.LookupEnv(strings.ToUpper(AzureTenantId)); ok {
tenantId = os.Getenv(strings.ToUpper(AzureTenantId))
} else {
return nil, fmt.Errorf("annotation '%s' of service account %s/%s is required since using global service account for workload identity is disabled", AnnotationTenantID, serviceAccountNamespace, serviceAccountName)
}

getAssertionFunc := newGetAssertionFunc(serviceAccountNamespace, serviceAccountName)
Expand All @@ -517,7 +518,7 @@ func newClientAssertionCredential(ctx context.Context, serviceAccountName string
}

func newGetAssertionFunc(serviceAccountNamespace string, serviceAccountName string) func(ctx context.Context) (string, error) {
audiences := []string{AzureDefaultAudience}
audiences := []string{ApiTokenExchangeAudience}

return func(ctx context.Context) (string, error) {
cfg, err := ctrlcfg.GetConfig()
Expand Down

0 comments on commit 8eca86e

Please sign in to comment.