Skip to content

Commit

Permalink
Require to opt-in for the global service account (#60)
Browse files Browse the repository at this point in the history
* Require to opt in the global service account

* Rename
  • Loading branch information
RichardChen820 authored Jul 29, 2024
1 parent 257ccae commit 9049e02
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/oss/go/microsoft/golang:1.22-cbl-mariner2.0 as builder
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/oss/go/microsoft/golang:1.22-cbl-mariner2.0 AS builder

ARG MODULE_VERSION
WORKDIR /workspace
Expand Down
2 changes: 1 addition & 1 deletion deploy/parameter/helm-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ requestTracing:

workloadIdentity:
enabled: true
disableGlobalServiceAccount: false
globalServiceAccountEnabled: false

serviceAccount:
# Specifies whether a service account should be created
Expand Down
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 and (.Values.workloadIdentity.enabled) (not .Values.workloadIdentity.disableGlobalServiceAccount) }}
{{- if and (.Values.workloadIdentity.enabled) }}
azure.workload.identity/use: "true"
{{- end }}
{{- end }}
Expand Down
4 changes: 2 additions & 2 deletions deploy/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ spec:
{{- end }}
- name: WORKLOAD_IDENTITY_ENABLED
value: "{{ .Values.workloadIdentity.enabled }}"
- name: WORKLOAD_IDENTITY_DISABLE_GLOBAL_SERVICE_ACCOUNT
value: "{{ .Values.workloadIdentity.disableGlobalServiceAccount }}"
- name: WORKLOAD_IDENTITY_GLOBAL_SERVICE_ACCOUNT_ENABLED
value: "{{ .Values.workloadIdentity.globalServiceAccountEnabled }}"
{{- if and (hasKey .Values "global")
(hasKey .Values.global "azure")
(hasKey .Values.global.azure "extension")
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 and (.Values.workloadIdentity.enabled) (not .Values.workloadIdentity.disableGlobalServiceAccount) }}
{{- if and (.Values.workloadIdentity.enabled) (.Values.workloadIdentity.globalServiceAccountEnabled) }}
azure.workload.identity/client-id: ""
{{- end }}
{{- end }}
10 changes: 5 additions & 5 deletions internal/controller/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
MinimalSecretRefreshInterval time.Duration = time.Minute
MinimalFeatureFlagRefreshInterval time.Duration = time.Second
WorkloadIdentityEnabled string = "WORKLOAD_IDENTITY_ENABLED"
WorkloadIdentityDisableGlobalServiceAccount string = "WORKLOAD_IDENTITY_DISABLE_GLOBAL_SERVICE_ACCOUNT"
WorkloadIdentityGlobalServiceAccountEnabled string = "WORKLOAD_IDENTITY_GLOBAL_SERVICE_ACCOUNT_ENABLED"
)

func verifyObject(spec acpv1.AzureAppConfigurationProviderSpec) error {
Expand Down Expand Up @@ -247,15 +247,15 @@ func verifyWorkloadIdentityParameters(workloadIdentity *acpv1.WorkloadIdentityPa
var authCount int = 0

if workloadIdentity.ManagedIdentityClientId != nil {
if strings.EqualFold(os.Getenv(WorkloadIdentityDisableGlobalServiceAccount), "true") {
return loader.NewArgumentError("auth.workloadIdentity.managedIdentityClientId", fmt.Errorf("'managedIdentityClientId' is not allowed since global service account is disabled"))
if strings.EqualFold(os.Getenv(WorkloadIdentityGlobalServiceAccountEnabled), "false") {
return loader.NewArgumentError("auth.workloadIdentity.managedIdentityClientId", fmt.Errorf("using a global service account is no longer permitted with workload identity. See https://aka.ms/appconfig/k8sglobalserviceaccount for more information"))
}
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 global service account is disabled"))
if strings.EqualFold(os.Getenv(WorkloadIdentityGlobalServiceAccountEnabled), "false") {
return loader.NewArgumentError("auth.workloadIdentity.managedIdentityClientIdReference", fmt.Errorf("using a global service account is no longer permitted with workload identity. See https://aka.ms/appconfig/k8sglobalserviceaccount for more information"))
}
authCount++
}
Expand Down

0 comments on commit 9049e02

Please sign in to comment.