Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(authproxy): cookie secret creation and reference using env valueFrom #180

Merged
merged 5 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions charts/cryostat/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,22 @@ Get or generate a default secret key for object storage.
{{- end -}}

{{/*
Generate or retrieve a default value for cookieSecret.
Get or generate a default secret key for auth proxy cookies.
*/}}
{{- define "cryostat.cookieSecret" -}}
{{- $secret := (lookup "v1" "Secret" .Release.Namespace (printf "%s-cookie-secret" .Release.Name)) -}}
{{- if $secret -}}
{{/*
Use the current secret. Do not regenerate.
Use current secret. Do not regenerate.
*/}}
{{- $secret.data.COOKIE_SECRET | b64dec | quote -}}
{{- $secret.data.COOKIE_SECRET -}}
{{- else -}}
{{/*
Generate a new secret.
Generate new secret
*/}}
{{- $newSecret := randAlphaNum 24 | b64enc -}}
{{- $newSecret | quote -}}
{{- end }}
{{- end }}
{{- (randAlphaNum 32) | b64enc | quote -}}
{{- end -}}
{{- end -}}

{{/*
Get sanitized list or defaults (if not disabled) as comma-separated list.
Expand Down
6 changes: 5 additions & 1 deletion charts/cryostat/templates/_oauth2Proxy.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ Create OAuth2 Proxy container. Configurations defined in alpha_config.yaml
- name: OAUTH2_PROXY_REDIRECT_URL
value: "http://localhost:4180/oauth2/callback"
- name: OAUTH2_PROXY_COOKIE_SECRET
value: {{ include "cryostat.cookieSecret" . }}
valueFrom:
secretKeyRef:
name: {{ .Release.Name }}-cookie-secret
key: COOKIE_SECRET
optional: false
- name: OAUTH2_PROXY_EMAIL_DOMAINS
value: "*"
{{- if .Values.authentication.basicAuth.enabled }}
Expand Down
9 changes: 8 additions & 1 deletion charts/cryostat/templates/_openshiftOauthProxy.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ Create OpenShift OAuth Proxy container.
securityContext:
{{- toYaml .Values.openshiftOauthProxy.securityContext | nindent 4 }}
image: "{{ .Values.openshiftOauthProxy.image.repository }}:{{ .Values.openshiftOauthProxy.image.tag }}"
env:
- name: COOKIE_SECRET
valueFrom:
secretKeyRef:
name: {{ .Release.Name }}-cookie-secret
key: COOKIE_SECRET
optional: false
args:
- --skip-provider-button={{ not .Values.authentication.basicAuth.enabled }}
- --pass-access-token=false
Expand All @@ -14,7 +21,7 @@ Create OpenShift OAuth Proxy container.
- --upstream=http://localhost:8181/
- --upstream=http://localhost:3000/grafana/
- --upstream=http://localhost:8333/storage/
- --cookie-secret={{ include "cryostat.cookieSecret" . }}
- --cookie-secret="$(COOKIE_SECRET)"
- --openshift-service-account={{ include "cryostat.serviceAccountName" . }}
- --proxy-websockets=true
- --http-address=0.0.0.0:4180
Expand Down
7 changes: 7 additions & 0 deletions charts/cryostat/templates/cookie_secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ .Release.Name }}-cookie-secret
type: Opaque
data:
COOKIE_SECRET: {{ include "cryostat.cookieSecret" . }}
20 changes: 20 additions & 0 deletions charts/cryostat/tests/cookie_secret_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
suite: test cookie_secret.yaml
templates:
- cookie_secret.yaml

tests:
- it: should create a Cookie Secret with correct settings
asserts:
- hasDocuments:
count: 1
- equal:
path: kind
value: Secret
- equal:
path: metadata.name
value: RELEASE-NAME-cookie-secret
- equal:
path: type
value: Opaque
- exists:
path: data.COOKIE_SECRET