Keycloak¶
keyclock is an open source identity and access management solution. It is a powerful tool for managing user authentication and authorization. It is a great tool for managing user authentication and authorization for your applications. It is a great tool for managing user authentication and authorization for your applications.
Getting Started¶
To get started with Keycloak, you can follow the official documentation. You can also check out the Keycloak GitHub repository for more information. You can also check out the Keycloak Docker Hub for more information. You can also check out the Keycloak Docker Compose for more information.
Keycloak Docker Compose¶
services:
keycloak:
image: quay.io/keycloak/keycloak:latest
container_name: homelab-keycloak
environment:
- KC_BOOTSTRAP_ADMIN_USERNAME=${KC_ADMIN_USER}
- KC_BOOTSTRAP_ADMIN_PASSWORD=${KC_ADMIN_PASSWORD}
- KC_DB=postgres
- KC_DB_URL=jdbc:postgresql://${POSTGRES_HOST}:6423/${POSTGRES_DB_NAME}
- KC_DB_USERNAME=${POSTGRES_DB_USER}
- KEYCLOAK_DB_USERNAME=${POSTGRES_DB_USER}
- KC_DB_PASSWORD=${POSTGRES_DB_PASSWORD}
## reading password from secret file or local file is not working needs to be investicated.
## - KC_DB_PASSWORD_FILE=${POSTGRES_DB_PASSWORD}
- KC_DB_SCHEMA=${KC_DB_SCHEMA:-public}
- KC_HEALTH_ENABLED=true
- KC_METRICS_ENABLED=true
- KC_TRANSACTION_XA_ENABLED=true
#- KC_HTTPS_KEY_STORE_FILE=/opt/keycloak/conf/keycloak.p12 # Path INSIDE the container where the keystore will be mounted
#- KC_HTTPS_KEY_STORE_PASSWORD=password # The password you set for the keystore
#- KC_HTTPS_KEY_STORE_TYPE=PKCS12 # Keystore type (use JKS if you created keycloak.jks)
#- KC_HOSTNAME_STRICT_HTTPS=false
#- KC_HOSTNAME_STRICT_HTTPS_ENABLED=false
#- KC_HOSTNAME=${KC_HOSTNAME}
- KC_HOSTNAME_STRICT=false
- KC_SMTP_SERVER_URL=${KC_SMTP_SERVER_URL}
- KC_SMTP_SERVER_PORT=${KC_SMTP_SERVER_PORT}
- KC_SMTP_SERVER_USER=${KC_SMTP_SERVER_USER}
- KC_SMTP_SERVER_PASSWORD=${KC_SMTP_SERVER_PASSWORD}
- KC_SMTP_FROM=${KC_SMTP_FROM}
- KC_SMTP_FROM_DISPLAY_NAME=${KC_SMTP_FROM_DISPLAY_NAME}
- KC_SMTP_AUTHENTICATION=${KC_SMTP_AUTHENTICATION}
- KC_SMTP_START_TLS=${KC_SMTP_START_TLS}
- KC_SMTP_SSL=${KC_SMTP_SSL}
ports:
- "${KEYCLOAK_PORT:-8880}:8080"
- "${KEYCLOAK_HTTPS_PORT:-8943}:8443"
- "${KEYCLOAK_MGMT_PORT:-9000}:9000"
restart: always
volumes:
- ./realms:/opt/keycloak/data/import:rw
- ${CONTAINER_DIR}/keycloack/data:/opt/keycloak/data
- ${PWD}/keycloak-certs/keycloak.p12:/opt/keycloak/conf/keycloak.p12:ro
user: "${UID}:${GID}"
networks:
- homelab-internal
command:
- start
- --import-realm
- --metrics-enabled=true
- --proxy-headers=xforwarded
- --http-enabled=true
labels:
- summary="rhlab keycloak"
- traefik.enable=true
- traefik.http.routers.keycloak.rule=Host(`rhlab-keycloak.htsvsystems.com`)
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health/ready"]
interval: 30s
timeout: 10s
retries: 5
start_period: 120s
secrets:
KC_DB_PASSWORD_HASH_FILE:
file: kc_db_hash_password.secret ## Create afile in ${PWD} with the file name kc_db_hash_password.secret and value of the db_user
networks:
homelab-internal:
name: homelab-internal
external: true
secrets:
KC_DB_PASSWORD_HASH_FILE:
file: ~/rhlab/secrets/kc_db_hash_password.secret ## Create afile in ${PWD} with the file name kc_db_hash_password.secret and value of the db_user