Skip to content

Commit 7e464ac

Browse files
pierluigilenocituunit
authored andcommitted
refactor: rename secretKeys to requiredSecretKeys with explicit defaults
Address maintainer feedback from PR review: - Renamed config.secretKeys to config.requiredSecretKeys for clarity - Moved default values from template to values.yaml as suggested - Removed the '| default' logic from templates Changes: - values.yaml: Define requiredSecretKeys with explicit defaults: [client-id, client-secret, cookie-secret] - _helpers.tpl: Use requiredSecretKeys directly without fallback - deployment.yaml: Use requiredSecretKeys directly without fallback This makes the configuration more explicit and easier to understand, following Helm best practices of defining defaults in values.yaml rather than in templates. Addresses: #384 (review comments) Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
1 parent 2aa7bf7 commit 7e464ac

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

helm/oauth2-proxy/templates/_helpers.tpl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,13 @@ metricsServer:
164164
{{- end -}}
165165

166166
{{- define "oauth2-proxy.secrets" -}}
167-
{{- $secretKeys := .Values.config.secretKeys | default (list "client-id" "client-secret" "cookie-secret") -}}
168-
{{- if has "cookie-secret" $secretKeys }}
167+
{{- if has "cookie-secret" .Values.config.requiredSecretKeys }}
169168
cookie-secret: {{ tpl .Values.config.cookieSecret $ | b64enc | quote }}
170169
{{- end }}
171-
{{- if has "client-secret" $secretKeys }}
170+
{{- if has "client-secret" .Values.config.requiredSecretKeys }}
172171
client-secret: {{ tpl .Values.config.clientSecret $ | b64enc | quote }}
173172
{{- end }}
174-
{{- if has "client-id" $secretKeys }}
173+
{{- if has "client-id" .Values.config.requiredSecretKeys }}
175174
client-id: {{ tpl .Values.config.clientID $ | b64enc | quote }}
176175
{{- end }}
177176
{{- end -}}

helm/oauth2-proxy/templates/deployment.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,22 +182,21 @@ spec:
182182
{{- end }}
183183
env:
184184
{{- if .Values.proxyVarsAsSecrets }}
185-
{{- $secretKeys := .Values.config.secretKeys | default (list "client-id" "client-secret" "cookie-secret") }}
186-
{{- if has "client-id" $secretKeys }}
185+
{{- if has "client-id" .Values.config.requiredSecretKeys }}
187186
- name: OAUTH2_PROXY_CLIENT_ID
188187
valueFrom:
189188
secretKeyRef:
190189
name: {{ template "oauth2-proxy.secretName" . }}
191190
key: client-id
192191
{{- end }}
193-
{{- if has "client-secret" $secretKeys }}
192+
{{- if has "client-secret" .Values.config.requiredSecretKeys }}
194193
- name: OAUTH2_PROXY_CLIENT_SECRET
195194
valueFrom:
196195
secretKeyRef:
197196
name: {{ template "oauth2-proxy.secretName" . }}
198197
key: client-secret
199198
{{- end }}
200-
{{- if has "cookie-secret" $secretKeys }}
199+
{{- if has "cookie-secret" .Values.config.requiredSecretKeys }}
201200
- name: OAUTH2_PROXY_COOKIE_SECRET
202201
valueFrom:
203202
secretKeyRef:

helm/oauth2-proxy/values.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ config:
2323
clientID: "XXXXXXX"
2424
# OAuth client secret
2525
clientSecret: "XXXXXXXX"
26-
# List of secret keys to include in the secret and expose as environment variables
27-
# If not set, defaults to all three secrets: ["client-id", "client-secret", "cookie-secret"]
28-
# Useful for authentication methods that don't require a client secret
29-
# (e.g., Azure Entra ID federated token authentication)
26+
# List of secret keys to include in the secret and expose as environment variables.
27+
# By default, all three secrets are required. To exclude certain secrets
28+
# (e.g., when using federated token authentication), remove them from this list.
3029
# Example to exclude client-secret:
31-
# secretKeys:
30+
# requiredSecretKeys:
3231
# - client-id
3332
# - cookie-secret
34-
secretKeys: []
33+
requiredSecretKeys:
34+
- client-id
35+
- client-secret
36+
- cookie-secret
3537
# Create a new secret with the following command
3638
# openssl rand -base64 32 | head -c 32 | base64
3739
# Use an existing secret for OAuth2 credentials (see secret.yaml for required fields)

0 commit comments

Comments
 (0)