Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Commit be89813

Browse files
committed
🔒 Autogenerate the OAuth2 client secret and cookie secret for a simplified and more secure setup
1 parent 4846d98 commit be89813

File tree

5 files changed

+137
-142
lines changed

5 files changed

+137
-142
lines changed

‎README.md‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -293,17 +293,6 @@ cd ..
293293
## Configuration
294294
Configure [helm values](deploy/values.yaml), based on the instructions below.
295295

296-
### Keycloak
297-
```
298-
# Generate a client secret and encryption key for keycloak (or provide your own)
299-
300-
# To generate a value for the Keycloak client secret
301-
head /dev/urandom | tr -dc A-Za-z0-9 | head -c32
302-
# To generate a value for the Keycloak encryption key
303-
head /dev/urandom | tr -dc A-Za-z0-9 | head -c16
304-
```
305-
Use these for the `keycloak.clientSecret` and `keycloak.cookieSecret` Helm values - replacing the defaults for security.
306-
307296
### Domain
308297

309298
Set the `domain` value, based on the domain that you would like to run your workstation on.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{{- define "rand32" -}}
2+
{{- randAlphaNum 32 | nospace -}}
3+
{{- end -}}
4+
5+
{{- define "rand16" -}}
6+
{{- randAlphaNum 16 | nospace -}}
7+
{{- end -}}

‎deploy/templates/keycloak.yaml‎

Lines changed: 130 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{{- $clientSecret := include "rand32" . }}
2+
{{- $cookieSecret := include "rand16" . }}
13
apiVersion: keycloak.org/v1alpha1
24
kind: Keycloak
35
metadata:
@@ -54,7 +56,7 @@ spec:
5456
composite: false
5557
client:
5658
clientId: workstation
57-
secret: {{ .Values.keycloak.clientSecret }}
59+
secret: {{ $clientSecret }}
5860
standardFlowEnabled: true
5961
redirectUris:
6062
- "*"
@@ -352,4 +354,131 @@ spec:
352354
- Egress
353355
egress:
354356
- {}
357+
{{ end }}
358+
---
359+
apiVersion: apps/v1
360+
kind: Deployment
361+
metadata:
362+
name: oauth2-proxy
363+
labels:
364+
app: oauth2-proxy
365+
spec:
366+
replicas: 1
367+
selector:
368+
matchLabels:
369+
app: oauth2-proxy
370+
template:
371+
metadata:
372+
labels:
373+
app: oauth2-proxy
374+
spec:
375+
{{ toYaml .Values.podDefaults | nindent 6 }}
376+
containers:
377+
- name: oauth2-proxy
378+
image: {{ .Values.oauth2Proxy.image }}
379+
args:
380+
- "--session-cookie-minimal"
381+
- "--session-store-type=redis"
382+
- "--redis-connection-url=redis://{{ .Release.Name }}-redis-master:6379"
383+
ports:
384+
- containerPort: 4180
385+
protocol: TCP
386+
resources: {{ toYaml .Values.oauth2Proxy.resources | nindent 10 }}
387+
env:
388+
# OIDC Config
389+
- name: "OAUTH2_PROXY_SCOPE"
390+
value: "openid profile"
391+
- name: "OAUTH2_PROXY_PROVIDER"
392+
value: "oidc"
393+
- name: "OAUTH2_PROXY_OIDC_ISSUER_URL"
394+
value: "https://keycloak.{{ .Values.domain }}/auth/realms/workstation"
395+
- name: "OAUTH2_PROXY_CLIENT_ID"
396+
value: workstation
397+
- name: "OAUTH2_PROXY_CLIENT_SECRET"
398+
value: {{ $clientSecret }}
399+
# Cookie Config
400+
- name: "OAUTH2_PROXY_COOKIE_SECRET"
401+
value: "{{ $cookieSecret }}"
402+
- name: "OAUTH2_PROXY_COOKIE_DOMAINS"
403+
value: ".{{ .Values.domain }}"
404+
# Proxy config
405+
- name: "OAUTH2_PROXY_EMAIL_DOMAINS"
406+
value: "*"
407+
- name: "OAUTH2_PROXY_WHITELIST_DOMAINS"
408+
value: ".{{ .Values.domain }}"
409+
- name: "OAUTH2_PROXY_HTTP_ADDRESS"
410+
value: "0.0.0.0:4180"
411+
- name: "OAUTH2_PROXY_SET_XAUTHREQUEST"
412+
value: "true"
413+
- name: "OAUTH2_PROXY_UPSTREAMS"
414+
value: "file:///dev/null"
415+
---
416+
apiVersion: autoscaling/v2beta2
417+
kind: HorizontalPodAutoscaler
418+
metadata:
419+
name: oauth2-proxy
420+
spec:
421+
scaleTargetRef:
422+
apiVersion: apps/v1
423+
kind: Deployment
424+
name: oauth2-proxy
425+
minReplicas: 1
426+
maxReplicas: 3
427+
metrics:
428+
- type: Object
429+
object:
430+
metric:
431+
name: requests-per-second
432+
describedObject:
433+
apiVersion: networking.k8s.io/v1
434+
kind: Ingress
435+
name: oauth2-proxy
436+
target:
437+
type: Value
438+
value: 5k
439+
---
440+
apiVersion: v1
441+
kind: Service
442+
metadata:
443+
name: oauth2-proxy
444+
labels:
445+
app: oauth2-proxy
446+
spec:
447+
ports:
448+
- name: http
449+
port: 4180
450+
protocol: TCP
451+
targetPort: 4180
452+
selector:
453+
app: oauth2-proxy
454+
{{ if eq .Values.policies.enabled true }}
455+
---
456+
apiVersion: networking.k8s.io/v1
457+
kind: NetworkPolicy
458+
metadata:
459+
name: oauth2-proxy
460+
spec:
461+
podSelector:
462+
matchLabels:
463+
app: oauth2-proxy
464+
policyTypes:
465+
- Ingress
466+
- Egress
467+
ingress:
468+
- from:
469+
- podSelector:
470+
matchLabels:
471+
app: ingress-nginx
472+
- namespaceSelector: {}
473+
egress:
474+
- to:
475+
- podSelector:
476+
matchLabels:
477+
app: ingress-nginx
478+
- namespaceSelector: {}
479+
- to:
480+
- podSelector:
481+
matchLabels:
482+
app: keycloak
483+
component: keycloak
355484
{{ end }}

‎deploy/templates/oauth2-proxy.yaml‎

Lines changed: 0 additions & 126 deletions
This file was deleted.

‎deploy/values.yaml‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ initializers:
3535

3636
# Keycloak
3737
keycloak:
38-
# Change me!
39-
clientSecret: OkSR7DMXAXzIrZIoWyN8yh0sFkiYrfJd
40-
# Change me!
41-
cookieSecret: 2u2iS0FH7pPjOUUn
4238
resources: {}
4339
operator:
4440
image: quay.io/keycloak/keycloak-operator:16.1.0

0 commit comments

Comments
 (0)