-
Notifications
You must be signed in to change notification settings - Fork 65
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
add keycloak #475
add keycloak #475
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
apiVersion: v2 | ||
name: cozy-keycloak | ||
version: 0.0.0 # Placeholder, the actual version will be automatically set during the build process |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: postgresql.cnpg.io/v1 | ||
kind: Cluster | ||
metadata: | ||
name: keycloak-db | ||
spec: | ||
instances: 2 | ||
storage: | ||
size: 20Gi | ||
|
||
inheritedMetadata: | ||
labels: | ||
policy.cozystack.io/allow-to-apiserver: "true" |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,36 @@ | ||||||
{{- $cozyConfig := lookup "v1" "ConfigMap" "cozy-system" "cozystack" }} | ||||||
{{- $host := index $cozyConfig.data "root-host" }} | ||||||
{{- $issuerType := (index $cozyConfig.data "clusterissuer") | default "http01" }} | ||||||
|
||||||
{{- $rootns := lookup "v1" "Namespace" "" "tenant-root" }} | ||||||
{{- $ingress := index $rootns.metadata.annotations "namespace.cozystack.io/ingress" }} | ||||||
|
||||||
apiVersion: networking.k8s.io/v1 | ||||||
kind: Ingress | ||||||
metadata: | ||||||
name: keycloak-ingress | ||||||
{{- with .Values.ingress.annotations }} | ||||||
annotations: | ||||||
{{- if ne $issuerType "cloudflare" }} | ||||||
acme.cert-manager.io/http01-ingress-class: {{ $ingress }} | ||||||
{{- end }} | ||||||
cert-manager.io/cluster-issuer: letsencrypt-prod | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Make cluster-issuer configurable The cert-manager cluster-issuer is hardcoded to 'letsencrypt-prod', which reduces flexibility for different environments. Make it configurable: - cert-manager.io/cluster-issuer: letsencrypt-prod
+ cert-manager.io/cluster-issuer: {{ .Values.ingress.certManager.issuer | default "letsencrypt-prod" }} 📝 Committable suggestion
Suggested change
|
||||||
{{- toYaml . | nindent 4 }} | ||||||
{{- end }} | ||||||
spec: | ||||||
ingressClassName: {{ $ingress }} | ||||||
tls: | ||||||
- hosts: | ||||||
- keycloak.{{ $host }} | ||||||
secretName: web-tls | ||||||
rules: | ||||||
- host: keycloak.{{ $host }} | ||||||
http: | ||||||
paths: | ||||||
- path: / | ||||||
pathType: Prefix | ||||||
backend: | ||||||
service: | ||||||
name: keycloak-http | ||||||
port: | ||||||
name: http |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,9 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
apiVersion: v1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
kind: Service | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
metadata: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
name: keycloak-headless | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
spec: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
type: ClusterIP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
clusterIP: None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
selector: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
app: keycloak-ha | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+1
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add essential service configurations The headless service definition needs the following essential improvements:
Apply this diff: apiVersion: v1
kind: Service
metadata:
name: keycloak-headless
+ namespace: {{ .Release.Namespace }}
spec:
type: ClusterIP
clusterIP: None
selector:
app: keycloak-ha
+ ports:
+ - name: http
+ port: 8080
+ targetPort: http
+ - name: https
+ port: 8443
+ targetPort: https 📝 Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: keycloak-http | ||
spec: | ||
type: ClusterIP | ||
ports: | ||
- name: http | ||
port: 8080 | ||
protocol: TCP | ||
selector: | ||
app: keycloak-ha |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,135 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
{{- $cozyConfig := lookup "v1" "ConfigMap" "cozy-system" "cozystack" }} | ||||||||||||||||||||||||||||||||||||||||||||||
{{- $host := index $cozyConfig.data "root-host" }} | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for ConfigMap lookup The ConfigMap lookup could fail if {{- $cozyConfig := lookup "v1" "ConfigMap" "cozy-system" "cozystack" }}
+{{- if not $cozyConfig }}
+ {{- fail "ConfigMap 'cozystack' not found in 'cozy-system' namespace" }}
+{{- end }}
{{- $host := index $cozyConfig.data "root-host" }}
+{{- if not $host }}
+ {{- fail "root-host key not found in cozystack ConfigMap" }}
+{{- end }} 📝 Committable suggestion
Suggested change
🧰 Tools🪛 yamllint[error] 1-1: syntax error: expected the node content, but found '-' (syntax) |
||||||||||||||||||||||||||||||||||||||||||||||
{{- $password := randAlphaNum 16 -}} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
apiVersion: v1 | ||||||||||||||||||||||||||||||||||||||||||||||
kind: Secret | ||||||||||||||||||||||||||||||||||||||||||||||
metadata: | ||||||||||||||||||||||||||||||||||||||||||||||
name: {{ .Release.Name }}-credentials | ||||||||||||||||||||||||||||||||||||||||||||||
stringData: | ||||||||||||||||||||||||||||||||||||||||||||||
admin: {{ $password }} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
--- | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
apiVersion: apps/v1 | ||||||||||||||||||||||||||||||||||||||||||||||
kind: StatefulSet | ||||||||||||||||||||||||||||||||||||||||||||||
metadata: | ||||||||||||||||||||||||||||||||||||||||||||||
name: keycloak | ||||||||||||||||||||||||||||||||||||||||||||||
labels: | ||||||||||||||||||||||||||||||||||||||||||||||
app: keycloak-ha | ||||||||||||||||||||||||||||||||||||||||||||||
spec: | ||||||||||||||||||||||||||||||||||||||||||||||
selector: | ||||||||||||||||||||||||||||||||||||||||||||||
matchLabels: | ||||||||||||||||||||||||||||||||||||||||||||||
app: keycloak-ha | ||||||||||||||||||||||||||||||||||||||||||||||
replicas: 2 | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+17
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve high availability configuration
labels:
- app: keycloak-ha
+ app.kubernetes.io/name: keycloak
+ app.kubernetes.io/instance: {{ .Release.Name }}
+ app.kubernetes.io/component: auth
spec:
selector:
matchLabels:
- app: keycloak-ha
+ app.kubernetes.io/name: keycloak
+ app.kubernetes.io/instance: {{ .Release.Name }}
+ template:
+ spec:
+ affinity:
+ podAntiAffinity:
+ requiredDuringSchedulingIgnoredDuringExecution:
+ - labelSelector:
+ matchExpressions:
+ - key: app.kubernetes.io/name
+ operator: In
+ values:
+ - keycloak
+ topologyKey: kubernetes.io/hostname
|
||||||||||||||||||||||||||||||||||||||||||||||
serviceName: keycloak-headless | ||||||||||||||||||||||||||||||||||||||||||||||
podManagementPolicy: Parallel | ||||||||||||||||||||||||||||||||||||||||||||||
updateStrategy: | ||||||||||||||||||||||||||||||||||||||||||||||
type: RollingUpdate | ||||||||||||||||||||||||||||||||||||||||||||||
template: | ||||||||||||||||||||||||||||||||||||||||||||||
metadata: | ||||||||||||||||||||||||||||||||||||||||||||||
labels: | ||||||||||||||||||||||||||||||||||||||||||||||
app: keycloak-ha | ||||||||||||||||||||||||||||||||||||||||||||||
spec: | ||||||||||||||||||||||||||||||||||||||||||||||
restartPolicy: Always | ||||||||||||||||||||||||||||||||||||||||||||||
securityContext: | ||||||||||||||||||||||||||||||||||||||||||||||
fsGroup: 1000 | ||||||||||||||||||||||||||||||||||||||||||||||
containers: | ||||||||||||||||||||||||||||||||||||||||||||||
- name: keycloak | ||||||||||||||||||||||||||||||||||||||||||||||
image: {{ .Values.image }} | ||||||||||||||||||||||||||||||||||||||||||||||
imagePullPolicy: Always | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+39
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specify explicit image tag Using implicit - image: {{ .Values.image }}
+ image: {{ .Values.image }}:{{ .Values.imageTag | default "latest" }} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
{{- if or .Values.resources.requests .Values.resources.limits }} | ||||||||||||||||||||||||||||||||||||||||||||||
resources: | ||||||||||||||||||||||||||||||||||||||||||||||
{{- if .Values.resources.limits }} | ||||||||||||||||||||||||||||||||||||||||||||||
limits: | ||||||||||||||||||||||||||||||||||||||||||||||
{{- toYaml .Values.resources.limits | nindent 14 }} | ||||||||||||||||||||||||||||||||||||||||||||||
{{- end }} | ||||||||||||||||||||||||||||||||||||||||||||||
{{- if .Values.resources.requests }} | ||||||||||||||||||||||||||||||||||||||||||||||
requests: | ||||||||||||||||||||||||||||||||||||||||||||||
{{- toYaml .Values.resources.requests | nindent 14 }} | ||||||||||||||||||||||||||||||||||||||||||||||
{{- end }} | ||||||||||||||||||||||||||||||||||||||||||||||
{{- end }} | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+41
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix YAML indentation in resources block The resources block has incorrect indentation which could cause issues. Fix the indentation to match Helm's standard: {{- if or .Values.resources.requests .Values.resources.limits }}
resources:
{{- if .Values.resources.limits }}
limits:
- {{- toYaml .Values.resources.limits | nindent 14 }}
+ {{- toYaml .Values.resources.limits | nindent 16 }}
{{- end }}
{{- if .Values.resources.requests }}
requests:
- {{- toYaml .Values.resources.requests | nindent 14 }}
+ {{- toYaml .Values.resources.requests | nindent 16 }}
{{- end }}
{{- end }} 📝 Committable suggestion
Suggested change
🧰 Tools🪛 yamllint[warning] 44-44: wrong indentation: expected 10 but found 12 (indentation) |
||||||||||||||||||||||||||||||||||||||||||||||
securityContext: | ||||||||||||||||||||||||||||||||||||||||||||||
runAsNonRoot: true | ||||||||||||||||||||||||||||||||||||||||||||||
runAsUser: 1000 | ||||||||||||||||||||||||||||||||||||||||||||||
capabilities: | ||||||||||||||||||||||||||||||||||||||||||||||
drop: | ||||||||||||||||||||||||||||||||||||||||||||||
- ALL | ||||||||||||||||||||||||||||||||||||||||||||||
- CAP_NET_RAW | ||||||||||||||||||||||||||||||||||||||||||||||
readOnlyRootFilesystem: false | ||||||||||||||||||||||||||||||||||||||||||||||
allowPrivilegeEscalation: false | ||||||||||||||||||||||||||||||||||||||||||||||
args: | ||||||||||||||||||||||||||||||||||||||||||||||
- start | ||||||||||||||||||||||||||||||||||||||||||||||
env: | ||||||||||||||||||||||||||||||||||||||||||||||
- name: KC_METRICS_ENABLED | ||||||||||||||||||||||||||||||||||||||||||||||
value: "true" | ||||||||||||||||||||||||||||||||||||||||||||||
- name: KC_LOG_LEVEL | ||||||||||||||||||||||||||||||||||||||||||||||
value: "info" | ||||||||||||||||||||||||||||||||||||||||||||||
- name: KC_CACHE | ||||||||||||||||||||||||||||||||||||||||||||||
value: "ispn" | ||||||||||||||||||||||||||||||||||||||||||||||
- name: KC_CACHE_STACK | ||||||||||||||||||||||||||||||||||||||||||||||
value: "kubernetes" | ||||||||||||||||||||||||||||||||||||||||||||||
- name: KC_PROXY | ||||||||||||||||||||||||||||||||||||||||||||||
value: "edge" | ||||||||||||||||||||||||||||||||||||||||||||||
- name: KEYCLOAK_ADMIN | ||||||||||||||||||||||||||||||||||||||||||||||
value: admin | ||||||||||||||||||||||||||||||||||||||||||||||
- name: KEYCLOAK_ADMIN_PASSWORD | ||||||||||||||||||||||||||||||||||||||||||||||
value: {{ $password }} | ||||||||||||||||||||||||||||||||||||||||||||||
- name: KC_DB | ||||||||||||||||||||||||||||||||||||||||||||||
value: "postgres" | ||||||||||||||||||||||||||||||||||||||||||||||
- name: KC_DB_URL_HOST | ||||||||||||||||||||||||||||||||||||||||||||||
valueFrom: | ||||||||||||||||||||||||||||||||||||||||||||||
secretKeyRef: | ||||||||||||||||||||||||||||||||||||||||||||||
name: keycloak-db-app | ||||||||||||||||||||||||||||||||||||||||||||||
key: "host" | ||||||||||||||||||||||||||||||||||||||||||||||
- name: KC_DB_URL_PORT | ||||||||||||||||||||||||||||||||||||||||||||||
valueFrom: | ||||||||||||||||||||||||||||||||||||||||||||||
secretKeyRef: | ||||||||||||||||||||||||||||||||||||||||||||||
name: keycloak-db-app | ||||||||||||||||||||||||||||||||||||||||||||||
key: "port" | ||||||||||||||||||||||||||||||||||||||||||||||
- name: KC_DB_USERNAME | ||||||||||||||||||||||||||||||||||||||||||||||
valueFrom: | ||||||||||||||||||||||||||||||||||||||||||||||
secretKeyRef: | ||||||||||||||||||||||||||||||||||||||||||||||
name: keycloak-db-app | ||||||||||||||||||||||||||||||||||||||||||||||
key: "username" | ||||||||||||||||||||||||||||||||||||||||||||||
- name: KC_DB_PASSWORD | ||||||||||||||||||||||||||||||||||||||||||||||
valueFrom: | ||||||||||||||||||||||||||||||||||||||||||||||
secretKeyRef: | ||||||||||||||||||||||||||||||||||||||||||||||
name: keycloak-db-app | ||||||||||||||||||||||||||||||||||||||||||||||
key: "password" | ||||||||||||||||||||||||||||||||||||||||||||||
- name: KC_DB_URL_DATABASE | ||||||||||||||||||||||||||||||||||||||||||||||
valueFrom: | ||||||||||||||||||||||||||||||||||||||||||||||
secretKeyRef: | ||||||||||||||||||||||||||||||||||||||||||||||
name: keycloak-db-app | ||||||||||||||||||||||||||||||||||||||||||||||
key: "dbname" | ||||||||||||||||||||||||||||||||||||||||||||||
- name: KC_FEATURES | ||||||||||||||||||||||||||||||||||||||||||||||
value: "docker" | ||||||||||||||||||||||||||||||||||||||||||||||
- name: KC_HOSTNAME | ||||||||||||||||||||||||||||||||||||||||||||||
value: https://keycloak.{{ $host }} | ||||||||||||||||||||||||||||||||||||||||||||||
- name: JAVA_OPTS_APPEND | ||||||||||||||||||||||||||||||||||||||||||||||
value: "-Djgroups.dns.query=keycloak-headless.cozy-keycloak.svc.cozy.local" | ||||||||||||||||||||||||||||||||||||||||||||||
ports: | ||||||||||||||||||||||||||||||||||||||||||||||
- name: http | ||||||||||||||||||||||||||||||||||||||||||||||
containerPort: 8080 | ||||||||||||||||||||||||||||||||||||||||||||||
protocol: TCP | ||||||||||||||||||||||||||||||||||||||||||||||
livenessProbe: | ||||||||||||||||||||||||||||||||||||||||||||||
httpGet: | ||||||||||||||||||||||||||||||||||||||||||||||
path: / | ||||||||||||||||||||||||||||||||||||||||||||||
port: http | ||||||||||||||||||||||||||||||||||||||||||||||
initialDelaySeconds: 120 | ||||||||||||||||||||||||||||||||||||||||||||||
timeoutSeconds: 5 | ||||||||||||||||||||||||||||||||||||||||||||||
readinessProbe: | ||||||||||||||||||||||||||||||||||||||||||||||
httpGet: | ||||||||||||||||||||||||||||||||||||||||||||||
path: /realms/master | ||||||||||||||||||||||||||||||||||||||||||||||
port: http | ||||||||||||||||||||||||||||||||||||||||||||||
initialDelaySeconds: 60 | ||||||||||||||||||||||||||||||||||||||||||||||
timeoutSeconds: 1 | ||||||||||||||||||||||||||||||||||||||||||||||
volumes: | ||||||||||||||||||||||||||||||||||||||||||||||
- name: init-script | ||||||||||||||||||||||||||||||||||||||||||||||
configMap: | ||||||||||||||||||||||||||||||||||||||||||||||
name: keycloak-init-script | ||||||||||||||||||||||||||||||||||||||||||||||
volumeMounts: | ||||||||||||||||||||||||||||||||||||||||||||||
- name: init-script | ||||||||||||||||||||||||||||||||||||||||||||||
mountPath: /scripts | ||||||||||||||||||||||||||||||||||||||||||||||
readOnly: true | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+131
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix volume mounts placement The volumes:
- name: init-script
configMap:
name: keycloak-init-script
- volumeMounts:
- - name: init-script
- mountPath: /scripts
- readOnly: true
terminationGracePeriodSeconds: 60
+ containers:
+ - name: keycloak
+ volumeMounts:
+ - name: init-script
+ mountPath: /scripts
+ readOnly: true 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
terminationGracePeriodSeconds: 60 |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,14 @@ | ||||||||||||||||||||||
image: quay.io/keycloak/keycloak:26.0.4 | ||||||||||||||||||||||
|
||||||||||||||||||||||
ingress: | ||||||||||||||||||||||
annotations: | ||||||||||||||||||||||
nginx.ingress.kubernetes.io/affinity: "cookie" | ||||||||||||||||||||||
nginx.ingress.kubernetes.io/session-cookie-expires: "86400" | ||||||||||||||||||||||
nginx.ingress.kubernetes.io/session-cookie-max-age: "86400" | ||||||||||||||||||||||
nginx.ingress.kubernetes.io/session-cookie-name: "keycloak-cookie" | ||||||||||||||||||||||
Comment on lines
+5
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance cookie security configuration The current cookie configuration lacks security-related settings. Consider adding secure flags and SameSite policy. nginx.ingress.kubernetes.io/affinity: "cookie"
nginx.ingress.kubernetes.io/session-cookie-expires: "86400"
nginx.ingress.kubernetes.io/session-cookie-max-age: "86400"
nginx.ingress.kubernetes.io/session-cookie-name: "keycloak-cookie"
+ nginx.ingress.kubernetes.io/session-cookie-secure: "true"
+ nginx.ingress.kubernetes.io/session-cookie-samesite: "Strict" 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
resources: | ||||||||||||||||||||||
limits: | ||||||||||||||||||||||
memory: 1500Mi | ||||||||||||||||||||||
requests: | ||||||||||||||||||||||
memory: 500Mi | ||||||||||||||||||||||
cpu: 100m |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
# Migration 7 --> 8 | ||
|
||
|
||
host=$(kubectl get hr tenant-root -n tenant-root -o yaml | grep 'host:' | awk '{print $2}') | ||
kubectl patch configmap -n cozy-system cozystack --type merge -p "{\"data\":{\"root-host\":\"$host\"}}" | ||
|
||
# Write version to cozystack-version config | ||
kubectl create configmap -n cozy-system cozystack-version --from-literal=version=8 --dry-run=client -o yaml | kubectl apply -f- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling for configuration lookups
The template assumes the ConfigMap and Namespace exist and contain the required data. Consider adding validation to handle missing configurations gracefully.
Add error handling:
📝 Committable suggestion
🧰 Tools
🪛 yamllint
[error] 1-1: syntax error: expected the node content, but found '-'
(syntax)