This project demonstrates a complete Keycloak setup with LDAP and Kerberos integration for protecting a web application.
The demo includes:
- Keycloak 23.0 - Identity and Access Management
- PostgreSQL - Keycloak's database
- OpenLDAP - LDAP directory server with test users
- Kerberos KDC - Kerberos authentication server
- Simple Web App - Node.js application protected by Keycloak
- Docker and Docker Compose
- curl and jq (for setup script)
- Start all services:
docker-compose up -d-
Wait for all services to start (this may take 1-2 minutes)
-
Run the Keycloak configuration script:
./setup-keycloak.sh-
Keycloak Admin Console: http://localhost:8080
- Username:
admin - Password:
admin
- Username:
-
Demo Web Application: http://localhost:3000
All test users are available in both LDAP and Kerberos:
| Username | Password | Full Name | |
|---|---|---|---|
| jdoe | password123 | John Doe | [email protected] |
| asmith | password123 | Alice Smith | [email protected] |
| bjones | password123 | Bob Jones | [email protected] |
- Go to http://localhost:3000
- Click "Access Protected Resource"
- You'll be redirected to Keycloak login
- Log in with one of the test users (e.g.,
jdoe/password123) - You should see the protected page with user information from LDAP
- Access Keycloak Admin Console
- Navigate to Realm Settings > User Federation
- You should see the configured LDAP provider
- Click Synchronize all users to sync LDAP users
- Go to Users to see the imported LDAP users
The Kerberos setup includes:
- Realm:
EXAMPLE.COM - KDC:
kerberos.example.com - Service Principal:
HTTP/[email protected]
Kerberos principals created:
[email protected][email protected][email protected]HTTP/[email protected](for Keycloak)
- Connection URL: ldap://ldap:389
- Base DN: dc=example,dc=com
- Users DN: ou=users,dc=example,dc=com
- Bind DN: cn=admin,dc=example,dc=com
- Bind Password: admin
- Realm: EXAMPLE.COM
- KDC: kerberos.example.com
- Admin Principal: admin/[email protected]
- Keycloak Service: HTTP/[email protected]
- Realm Name: demo
- Client ID: webapp
- Client Secret: webapp-secret
Check service logs:
docker-compose logs [service-name]- Check LDAP service is running:
docker-compose ps ldap-
Manually sync LDAP users in Keycloak Admin Console
-
Test LDAP connection:
docker exec keycloak-ldap ldapsearch -x -b "dc=example,dc=com" -D "cn=admin,dc=example,dc=com" -w admin- Check Kerberos service:
docker-compose logs kerberos- Verify keytab was created:
docker exec keycloak-kerberos ls -la /var/lib/krb5kdc/keycloak.keytabdocker-compose downTo remove all data:
docker-compose down -v.
├── docker-compose.yml # Main orchestration file
├── setup-keycloak.sh # Keycloak configuration script
├── ldap/
│ └── ldif/
│ └── users.ldif # LDAP test users
├── kerberos/
│ ├── Dockerfile # Kerberos KDC image
│ ├── krb5.conf # Kerberos client config
│ ├── kdc.conf # KDC configuration
│ └── setup-kerberos.sh # Kerberos initialization
└── webapp/
├── Dockerfile # Web app image
├── package.json # Node.js dependencies
└── server.js # Express application