init: 아르고cd, vault 기반 인프라 설계
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"realm": "project-auth",
|
||||
"enabled": true,
|
||||
"displayName": "Project Auth",
|
||||
"sslRequired": "NONE",
|
||||
"registrationAllowed": false,
|
||||
"loginWithEmailAllowed": true,
|
||||
"duplicateEmailsAllowed": false,
|
||||
"resetPasswordAllowed": true,
|
||||
"clients": [
|
||||
{
|
||||
"clientId": "project-auth-server",
|
||||
"name": "project-auth-server",
|
||||
"enabled": true,
|
||||
"protocol": "openid-connect",
|
||||
"publicClient": false,
|
||||
"standardFlowEnabled": true,
|
||||
"directAccessGrantsEnabled": false,
|
||||
"serviceAccountsEnabled": false
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
psql -v ON_ERROR_STOP=1 --username "${POSTGRES_USER}" --dbname "${POSTGRES_DB}" <<-EOSQL
|
||||
CREATE USER ${AUTH_DB_USER} WITH PASSWORD '${AUTH_DB_PASSWORD}';
|
||||
CREATE DATABASE ${AUTH_DB_NAME} OWNER ${AUTH_DB_USER};
|
||||
|
||||
CREATE USER ${KEYCLOAK_DB_USER} WITH PASSWORD '${KEYCLOAK_DB_PASSWORD}';
|
||||
CREATE DATABASE ${KEYCLOAK_DB_NAME} OWNER ${KEYCLOAK_DB_USER};
|
||||
EOSQL
|
||||
@@ -0,0 +1,70 @@
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: keycloak-client-sync
|
||||
annotations:
|
||||
argocd.argoproj.io/sync-wave: "4"
|
||||
spec:
|
||||
backoffLimit: 5
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: keycloak-client-sync
|
||||
spec:
|
||||
serviceAccountName: keycloak-client-sync
|
||||
restartPolicy: OnFailure
|
||||
containers:
|
||||
- name: keycloak-client-sync
|
||||
image: quay.io/keycloak/keycloak:26.5.5
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- |
|
||||
set -eu
|
||||
|
||||
until /opt/keycloak/bin/kcadm.sh config credentials \
|
||||
--server http://keycloak.platform.svc.cluster.local \
|
||||
--realm master \
|
||||
--user "$KC_BOOTSTRAP_ADMIN_USERNAME" \
|
||||
--password "$KC_BOOTSTRAP_ADMIN_PASSWORD" >/dev/null 2>&1; do
|
||||
sleep 5
|
||||
done
|
||||
|
||||
CLIENT_UUID=$(/opt/keycloak/bin/kcadm.sh get clients \
|
||||
-r project-auth \
|
||||
-q clientId="$KEYCLOAK_CLIENT_ID" | sed -n 's/.*"id" : "\([^"]*\)".*/\1/p' | head -n 1)
|
||||
|
||||
test -n "$CLIENT_UUID"
|
||||
|
||||
/opt/keycloak/bin/kcadm.sh update "clients/${CLIENT_UUID}" \
|
||||
-r project-auth \
|
||||
-s "secret=$KEYCLOAK_CLIENT_SECRET" \
|
||||
-s "baseUrl=$AUTH_SERVER_BASE_URL" \
|
||||
-s 'redirectUris=["'"$AUTH_SERVER_BASE_URL"'/login/oauth2/code/keycloak-google","'"$AUTH_SERVER_BASE_URL"'/login/oauth2/code/keycloak-github"]' \
|
||||
-s 'webOrigins=["'"$AUTH_SERVER_BASE_URL"'"]'
|
||||
env:
|
||||
- name: KC_BOOTSTRAP_ADMIN_USERNAME
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: platform-config
|
||||
key: KEYCLOAK_BOOTSTRAP_ADMIN_USERNAME
|
||||
- name: KC_BOOTSTRAP_ADMIN_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: keycloak-bootstrap-admin
|
||||
key: KEYCLOAK_BOOTSTRAP_ADMIN_PASSWORD
|
||||
- name: KEYCLOAK_CLIENT_ID
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: platform-config
|
||||
key: KEYCLOAK_CLIENT_ID
|
||||
- name: KEYCLOAK_CLIENT_SECRET
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: keycloak-client-auth-server
|
||||
key: KEYCLOAK_CLIENT_SECRET
|
||||
- name: AUTH_SERVER_BASE_URL
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: platform-config
|
||||
key: AUTH_SERVER_BASE_URL
|
||||
@@ -0,0 +1,5 @@
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: keycloak-client-sync
|
||||
automountServiceAccountToken: false
|
||||
@@ -0,0 +1,104 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: keycloak
|
||||
annotations:
|
||||
argocd.argoproj.io/sync-wave: "3"
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: keycloak
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: keycloak
|
||||
spec:
|
||||
serviceAccountName: keycloak
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
seccompProfile:
|
||||
type: RuntimeDefault
|
||||
containers:
|
||||
- name: keycloak
|
||||
image: quay.io/keycloak/keycloak:26.5.5
|
||||
args:
|
||||
- start-dev
|
||||
- --import-realm
|
||||
- --http-port=8080
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
name: http
|
||||
- containerPort: 9000
|
||||
name: management
|
||||
env:
|
||||
- name: KC_DB
|
||||
value: postgres
|
||||
- name: KC_DB_URL
|
||||
value: jdbc:postgresql://postgres.platform.svc.cluster.local:5432/keycloak
|
||||
- name: KC_DB_USERNAME
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: platform-config
|
||||
key: KEYCLOAK_DB_USER
|
||||
- name: KC_DB_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: postgres-keycloak-credentials
|
||||
key: KEYCLOAK_DB_PASSWORD
|
||||
- name: KC_HEALTH_ENABLED
|
||||
value: "true"
|
||||
- name: KC_BOOTSTRAP_ADMIN_USERNAME
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: platform-config
|
||||
key: KEYCLOAK_BOOTSTRAP_ADMIN_USERNAME
|
||||
- name: KC_BOOTSTRAP_ADMIN_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: keycloak-bootstrap-admin
|
||||
key: KEYCLOAK_BOOTSTRAP_ADMIN_PASSWORD
|
||||
volumeMounts:
|
||||
- name: keycloak-realm-import
|
||||
mountPath: /opt/keycloak/data/import/project-auth-realm.json
|
||||
subPath: project-auth-realm.json
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /health/ready
|
||||
port: management
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 10
|
||||
timeoutSeconds: 3
|
||||
failureThreshold: 6
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /health/live
|
||||
port: management
|
||||
initialDelaySeconds: 60
|
||||
periodSeconds: 15
|
||||
timeoutSeconds: 3
|
||||
failureThreshold: 6
|
||||
startupProbe:
|
||||
httpGet:
|
||||
path: /health/ready
|
||||
port: management
|
||||
initialDelaySeconds: 20
|
||||
periodSeconds: 10
|
||||
timeoutSeconds: 3
|
||||
failureThreshold: 30
|
||||
resources:
|
||||
requests:
|
||||
cpu: 250m
|
||||
memory: 768Mi
|
||||
limits:
|
||||
cpu: 1000m
|
||||
memory: 1536Mi
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
capabilities:
|
||||
drop:
|
||||
- ALL
|
||||
volumes:
|
||||
- name: keycloak-realm-import
|
||||
configMap:
|
||||
name: keycloak-realm-import
|
||||
@@ -0,0 +1,12 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: keycloak
|
||||
spec:
|
||||
selector:
|
||||
app: keycloak
|
||||
ports:
|
||||
- name: http
|
||||
port: 80
|
||||
targetPort: 8080
|
||||
type: ClusterIP
|
||||
@@ -0,0 +1,5 @@
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: keycloak
|
||||
automountServiceAccountToken: false
|
||||
@@ -0,0 +1,22 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
|
||||
resources:
|
||||
- postgres-serviceaccount.yaml
|
||||
- keycloak-serviceaccount.yaml
|
||||
- keycloak-client-sync-serviceaccount.yaml
|
||||
- postgres-service.yaml
|
||||
- postgres-statefulset.yaml
|
||||
- keycloak-service.yaml
|
||||
- keycloak-deployment.yaml
|
||||
- keycloak-client-sync-job.yaml
|
||||
generatorOptions:
|
||||
disableNameSuffixHash: true
|
||||
|
||||
configMapGenerator:
|
||||
- name: postgres-init-script
|
||||
files:
|
||||
- files/postgres/01-init-project-auth-databases.sh
|
||||
- name: keycloak-realm-import
|
||||
files:
|
||||
- files/keycloak/project-auth-realm.json
|
||||
@@ -0,0 +1,13 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: postgres
|
||||
spec:
|
||||
clusterIP: None
|
||||
selector:
|
||||
app: postgres
|
||||
ports:
|
||||
- name: postgres
|
||||
port: 5432
|
||||
targetPort: 5432
|
||||
type: ClusterIP
|
||||
@@ -0,0 +1,5 @@
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: postgres
|
||||
automountServiceAccountToken: false
|
||||
@@ -0,0 +1,126 @@
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: postgres
|
||||
annotations:
|
||||
argocd.argoproj.io/sync-wave: "2"
|
||||
spec:
|
||||
serviceName: postgres
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: postgres
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: postgres
|
||||
spec:
|
||||
serviceAccountName: postgres
|
||||
securityContext:
|
||||
fsGroup: 999
|
||||
seccompProfile:
|
||||
type: RuntimeDefault
|
||||
containers:
|
||||
- name: postgres
|
||||
image: postgres:16-alpine
|
||||
ports:
|
||||
- containerPort: 5432
|
||||
name: postgres
|
||||
env:
|
||||
- name: PGDATA
|
||||
value: /var/lib/postgresql/data/pgdata
|
||||
- name: POSTGRES_USER
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: platform-config
|
||||
key: POSTGRES_SUPERUSER
|
||||
- name: POSTGRES_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: postgres-superuser-credentials
|
||||
key: POSTGRES_SUPERUSER_PASSWORD
|
||||
- name: POSTGRES_DB
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: platform-config
|
||||
key: POSTGRES_DEFAULT_DB
|
||||
- name: AUTH_DB_NAME
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: platform-config
|
||||
key: AUTH_DB_NAME
|
||||
- name: AUTH_DB_USER
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: platform-config
|
||||
key: AUTH_DB_USER
|
||||
- name: AUTH_DB_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: postgres-auth-server-credentials
|
||||
key: AUTH_DB_PASSWORD
|
||||
- name: KEYCLOAK_DB_NAME
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: platform-config
|
||||
key: KEYCLOAK_DB_NAME
|
||||
- name: KEYCLOAK_DB_USER
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: platform-config
|
||||
key: KEYCLOAK_DB_USER
|
||||
- name: KEYCLOAK_DB_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: postgres-keycloak-credentials
|
||||
key: KEYCLOAK_DB_PASSWORD
|
||||
securityContext:
|
||||
volumeMounts:
|
||||
- name: postgres-data
|
||||
mountPath: /var/lib/postgresql/data
|
||||
- name: postgres-init-script
|
||||
mountPath: /docker-entrypoint-initdb.d/01-init-project-auth-databases.sh
|
||||
subPath: 01-init-project-auth-databases.sh
|
||||
- name: postgres-run
|
||||
mountPath: /var/run/postgresql
|
||||
readinessProbe:
|
||||
exec:
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB"
|
||||
initialDelaySeconds: 10
|
||||
periodSeconds: 10
|
||||
timeoutSeconds: 3
|
||||
livenessProbe:
|
||||
exec:
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB"
|
||||
initialDelaySeconds: 20
|
||||
periodSeconds: 15
|
||||
timeoutSeconds: 3
|
||||
resources:
|
||||
requests:
|
||||
cpu: 250m
|
||||
memory: 512Mi
|
||||
limits:
|
||||
cpu: 1000m
|
||||
memory: 1024Mi
|
||||
volumes:
|
||||
- name: postgres-init-script
|
||||
configMap:
|
||||
name: postgres-init-script
|
||||
defaultMode: 0555
|
||||
- name: postgres-run
|
||||
emptyDir: {}
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: postgres-data
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 5Gi
|
||||
Reference in New Issue
Block a user