Skip to content

Commit 81bed17

Browse files
committed
add keycloak
1 parent 8d5bbf0 commit 81bed17

File tree

4 files changed

+111
-1
lines changed

4 files changed

+111
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ A [proxy](https://en.wikipedia.org/wiki/Proxy_server) is a server application th
120120

121121
- [Authelia](examples/authelia) - Authelia is an open-source authentication and authorization server providing two-factor authentication and single sign-on (SSO) for your applications via a web portal. It acts as a companion for reverse proxies by allowing, denying, or redirecting requests. Recommended to combine with [Traefik](examples/traefik).
122122
- [Authentik](examples/authentik) - Authentik is an open-source Identity Provider focused on flexibility and versatility.
123-
- [Keycloak](https://github.com/keycloak/keycloak-containers/tree/main/docker-compose-examples) - Keycloak is an open-source Identity and Access Management (IAM) solution for modern applications and services.
123+
- [Keycloak](examples/keycloak) - Keycloak is an open-source Identity and Access Management (IAM) solution for modern applications and services.
124124
- [lldap](examples/lldap) - lldap is a lightweight authentication server that provides an opinionated, simplified LDAP interface for authentication. It integrates with many backends, from KeyCloak to Authelia to Nextcloud and more.
125125

126126
### Large Language Models & AI

examples/keycloak/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# References
2+
3+
- https://github.com/keycloak/keycloak
4+
- https://www.keycloak.org/getting-started/getting-started-docker
5+
6+
# Notes
7+
8+
````
9+
# copy example env file
10+
cp env.example .env
11+
12+
# adjust env to your needs
13+
# adjust the compose.yml to your needs
14+
nano .env
15+
nano docker-compose.yml
16+
17+
# create docker networks
18+
docker network create proxy
19+
docker network create keycloak-internal
20+
21+
# spawn the stack
22+
docker compose up -d
23+
````

examples/keycloak/docker-compose.yml

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
version: '3.7'
2+
3+
services:
4+
postgres:
5+
image: postgres:16-alpine
6+
container_name: keycloak-db
7+
restart: always
8+
expose:
9+
- 5432
10+
volumes:
11+
- ${DOCKER_VOLUME_STORAGE:-/mnt/docker-volumes}/keycloak/database:/var/lib/postgresql/data
12+
environment:
13+
POSTGRES_DB: ${POSTGRES_DB}
14+
POSTGRES_USER: ${POSTGRES_USER}
15+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
16+
healthcheck:
17+
test: [ "CMD", "pg_isready", "-q", "-d", "${KEYCLOAK_DB_NAME}", "-U", "${KEYCLOAK_DB_USER}" ]
18+
interval: 10s
19+
timeout: 5s
20+
retries: 3
21+
start_period: 60s
22+
networks:
23+
- keycloak-internal
24+
25+
keycloak:
26+
image: quay.io/keycloak/keycloak:25.0
27+
container_name: keycloak-app
28+
command: start
29+
environment:
30+
KC_HOSTNAME: ${KEYCLOAK_HOSTNAME}
31+
KEYCLOAK_ADMIN: ${KEYCLOAK_ADMIN}
32+
KEYCLOAK_ADMIN_PASSWORD: ${KEYCLOAK_ADMIN_PASSWORD}
33+
KC_DB: postgres
34+
KC_DB_URL: jdbc:postgresql://postgres/${POSTGRES_DB}
35+
KC_DB_USERNAME: ${POSTGRES_USER}
36+
KC_DB_PASSWORD: ${POSTGRES_PASSWORD}
37+
KC_PROXY_HEADERS: 'xforwarded'
38+
KC_HTTP_ENABLED: true
39+
KC_HEALTH_ENABLED: true
40+
PROXY_ADDRESS_FORWARDING: 'true'
41+
healthcheck:
42+
test:
43+
- "CMD-SHELL"
44+
- |
45+
exec 3<>/dev/tcp/localhost/9000 &&
46+
echo -e 'GET /health/ready HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n' >&3 &&
47+
cat <&3 | tee /tmp/healthcheck.log | grep -q '200 OK'
48+
interval: 10s
49+
timeout: 5s
50+
retries: 3
51+
start_period: 90s
52+
ports:
53+
- 8080:8080
54+
expose:
55+
- 8080 # web ui http
56+
- 9000 # health endpoint
57+
restart: always
58+
depends_on:
59+
postgres:
60+
condition: service_healthy
61+
networks:
62+
- keycloak-internal
63+
# - proxy
64+
#labels:
65+
# - traefik.enable=true
66+
# - traefik.docker.network=proxy
67+
# - traefik.http.routers.keycloak.rule=Host(`keycloak.example.com`)
68+
# - traefik.http.services.keycloak.loadbalancer.server.port=8080
69+
# # Optional part for traefik middlewares
70+
# - traefik.http.routers.keycloak.middlewares=local-ipwhitelist@file
71+
72+
networks:
73+
keycloak-internal:
74+
internal: true
75+
#proxy:
76+
# external: true

examples/keycloak/env.example

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# define FQDN hostname
2+
KEYCLOAK_HOSTNAME=keycloak.example.com
3+
4+
# define login credentials
5+
KEYCLOAK_ADMIN=admin
6+
KEYCLOAK_ADMIN_PASSWORD=password
7+
8+
# define database credentials
9+
POSTGRES_DB=keycloak_db
10+
POSTGRES_USER=keycloak_db_user
11+
POSTGRES_PASSWORD=keycloak_db_user_password

0 commit comments

Comments
 (0)