mirror of
https://github.com/outbackdingo/cozystack.git
synced 2026-01-27 10:18:39 +00:00
add keycloak (#475)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Integrated Keycloak service into deployment configurations across multiple files, enhancing user authentication capabilities. - Introduced a new Helm chart for Keycloak, facilitating easier deployment and management. - Added Kubernetes Ingress and Service resources for Keycloak to manage external access and internal service routing. - Configured a PostgreSQL cluster specifically for Keycloak, ensuring data persistence. - **Bug Fixes** - Updated versioning in the installer script to ensure compatibility with the latest configurations. - **Documentation** - Added detailed configuration options for Keycloak deployment, including resource limits and ingress settings. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -174,3 +174,9 @@ releases:
|
||||
namespace: cozy-external-secrets-operator
|
||||
optional: true
|
||||
dependsOn: [cilium]
|
||||
|
||||
- name: keycloak
|
||||
releaseName: keycloak
|
||||
chart: cozy-keycloak
|
||||
namespace: cozy-keycloak
|
||||
dependsOn: [postgres-operator]
|
||||
|
||||
@@ -124,3 +124,9 @@ releases:
|
||||
namespace: cozy-external-secrets-operator
|
||||
optional: true
|
||||
dependsOn: []
|
||||
|
||||
- name: keycloak
|
||||
releaseName: keycloak
|
||||
chart: cozy-keycloak
|
||||
namespace: cozy-keycloak
|
||||
dependsOn: [postgres-operator]
|
||||
|
||||
@@ -249,3 +249,9 @@ releases:
|
||||
namespace: cozy-external-secrets-operator
|
||||
optional: true
|
||||
dependsOn: [cilium,kubeovn]
|
||||
|
||||
- name: keycloak
|
||||
releaseName: keycloak
|
||||
chart: cozy-keycloak
|
||||
namespace: cozy-keycloak
|
||||
dependsOn: [postgres-operator]
|
||||
|
||||
@@ -19,7 +19,7 @@ releases:
|
||||
chart: cozy-cert-manager-crds
|
||||
namespace: cozy-cert-manager
|
||||
dependsOn: []
|
||||
|
||||
|
||||
- name: cozystack-api
|
||||
releaseName: cozystack-api
|
||||
chart: cozy-cozystack-api
|
||||
@@ -145,3 +145,9 @@ releases:
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
- name: keycloak
|
||||
releaseName: keycloak
|
||||
chart: cozy-keycloak
|
||||
namespace: cozy-keycloak
|
||||
dependsOn: [postgres-operator]
|
||||
|
||||
3
packages/system/keycloak/Chart.yaml
Normal file
3
packages/system/keycloak/Chart.yaml
Normal file
@@ -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
|
||||
12
packages/system/keycloak/templates/db.yaml
Normal file
12
packages/system/keycloak/templates/db.yaml
Normal file
@@ -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"
|
||||
36
packages/system/keycloak/templates/ingress.yaml
Normal file
36
packages/system/keycloak/templates/ingress.yaml
Normal file
@@ -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
|
||||
{{- 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
|
||||
9
packages/system/keycloak/templates/service-headless.yaml
Normal file
9
packages/system/keycloak/templates/service-headless.yaml
Normal file
@@ -0,0 +1,9 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: keycloak-headless
|
||||
spec:
|
||||
type: ClusterIP
|
||||
clusterIP: None
|
||||
selector:
|
||||
app: keycloak-ha
|
||||
12
packages/system/keycloak/templates/service.yaml
Normal file
12
packages/system/keycloak/templates/service.yaml
Normal file
@@ -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
|
||||
135
packages/system/keycloak/templates/sts.yaml
Normal file
135
packages/system/keycloak/templates/sts.yaml
Normal file
@@ -0,0 +1,135 @@
|
||||
{{- $cozyConfig := lookup "v1" "ConfigMap" "cozy-system" "cozystack" }}
|
||||
{{- $host := index $cozyConfig.data "root-host" }}
|
||||
{{- $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
|
||||
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
|
||||
{{- 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 }}
|
||||
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
|
||||
terminationGracePeriodSeconds: 60
|
||||
14
packages/system/keycloak/values.yaml
Normal file
14
packages/system/keycloak/values.yaml
Normal file
@@ -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"
|
||||
resources:
|
||||
limits:
|
||||
memory: 1500Mi
|
||||
requests:
|
||||
memory: 500Mi
|
||||
cpu: 100m
|
||||
@@ -3,7 +3,7 @@ set -o pipefail
|
||||
set -e
|
||||
|
||||
BUNDLE=$(set -x; kubectl get configmap -n cozy-system cozystack -o 'go-template={{index .data "bundle-name"}}')
|
||||
VERSION=7
|
||||
VERSION=8
|
||||
|
||||
run_migrations() {
|
||||
if ! kubectl get configmap -n cozy-system cozystack-version; then
|
||||
|
||||
9
scripts/migrations/7
Normal file
9
scripts/migrations/7
Normal file
@@ -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-
|
||||
Reference in New Issue
Block a user