KeyCloak Administration
Overview
Provides systematic KeyCloak administration guidance covering installation, configuration, realm management, security hardening, and operational best practices. Supports both standalone and clustered deployments for secure, scalable identity and access management (IAM) solutions.
Quick Start Guide
Choose your task and load the appropriate reference:
- New Installation → Continue to Installation & Setup
- Realm & User Management → Load realm-management.md
- Client Configuration → Load client-configuration.md
- Authentication & SSO → Load authentication-sso.md
- Authorization & RBAC → Load authorization-rbac.md
- User Federation (LDAP/AD) → Load user-federation.md
- Security Hardening → Load security-hardening.md
- High Availability & Scaling → Load ha-scalability.md
- Troubleshooting → Load troubleshooting.md
- Integration Examples → Load integration-examples.md
Installation & Setup
Deployment Options
1. Standalone Mode (Development/Testing)
# Download and start KeyCloak
wget https://github.com/keycloak/keycloak/releases/download/[VERSION]/keycloak-[VERSION].tar.gz
tar -xvzf keycloak-[VERSION].tar.gz
cd keycloak-[VERSION]
bin/kc.sh start-dev
# Access: http://localhost:8080
# Create initial admin user on first access
2. Production Mode with Database
# Configure and build
bin/kc.sh build --db=postgres
# Set environment variables
export KC_DB=postgres
export KC_DB_URL=jdbc:postgresql://localhost/keycloak
export KC_DB_USERNAME=keycloak
export KC_DB_PASSWORD=password
export KC_HOSTNAME=keycloak.example.com
# Start production mode
bin/kc.sh start --optimized
3. Docker Deployment
docker run -d \
--name keycloak \
-p 8080:8080 \
-e KEYCLOAK_ADMIN=admin \
-e KEYCLOAK_ADMIN_PASSWORD=admin \
quay.io/keycloak/keycloak:latest \
start-dev
4. Kubernetes - Use KeyCloak Operator or Helm charts
Initial Configuration Steps
- Admin Account: Create on first access with strong password (12+ chars)
- Hostname: Configure
KC_HOSTNAME for production
- SSL/TLS: Set up certificates (required for production)
- Database: Configure PostgreSQL connection
- Email: Configure SMTP for notifications
# Email settings
KC_SMTP_HOST=smtp.example.com
KC_SMTP_PORT=587
KC_SMTP_FROM=noreply@example.com
KC_SMTP_STARTTLS=true
Core Concepts
Realms
- Master realm: Administrative realm (don't use for apps)
- Application realms: Separate realms per app/environment
- Create: Admin Console → Create Realm
Users & Groups
- Users: Individual accounts with credentials
- Groups: Organize users hierarchically
- Attributes: Custom key-value pairs
- Federation: Sync from LDAP/AD (see user-federation.md)
Clients
- OIDC clients: Modern OAuth 2.0/OIDC applications
- SAML clients: Legacy enterprise applications
- Types: Confidential (server-side) or Public (SPA/mobile)
- Details: See client-configuration.md
Roles & Permissions
- Realm roles: Global across all clients
- Client roles: Specific to one client
- Composite roles: Inherit multiple roles
- Details: See authorization-rbac.md
Common Tasks
Configure SSO for Applications
Create OIDC client for your application
Set redirect URIs (exact URLs, no wildcards)
Configure client type:
- Confidential: Server-side apps (need client secret)
- Public: SPAs/mobile apps (use PKCE)
Obtain configuration from realm endpoint:
https://keycloak.example.com/realms/{realm}/.well-known/openid-configuration
Integrate with your app (see integration-examples.md)
Enable Multi-Factor Authentication
- Authentication → Flows
- Duplicate Browser flow
- Add OTP or WebAuthn authenticator
- Set as Required or Conditional
- Bind to realm
- Users configure MFA on next login
Details: See authentication-sso.md
Connect to LDAP/Active Directory
- User Federation → Add LDAP Provider
- Configure connection (URL, bind DN, credentials)
- Set search base:
ou=users,dc=example,dc=com
- Configure mappers for attributes
- Test connection and sync users
Details: See user-federation.md
Secure Production Deployment
Essential security measures:
- SSL/TLS: Required for all production traffic
- Password policy: 12+ chars, complexity requirements
- Brute force protection: Enable with lockout
- Token lifespans: Short access tokens (5-15 min)
- Admin MFA: Enable for all admin accounts
- Event logging: Monitor authentication events
Complete checklist: See security-hardening.md
Set Up High Availability
- Shared database: PostgreSQL/MySQL for all nodes
- Distributed caching: Configure Infinispan
- Load balancer: HAProxy/NGINX with sticky sessions
- Health checks: Use
/health/ready and /health/live
- Monitoring: Prometheus metrics at
/metrics
Details: See ha-scalability.md
Troubleshooting Quick Reference
Users Can't Login
- Check user enabled status
- Verify redirect URIs match exactly
- Review required actions
- Check Events → Login Events
Token Validation Fails
- Verify realm public key
- Check token expiration
- Validate issuer URL
- Confirm audience claim
LDAP Sync Issues
- Test LDAP connection
- Verify bind credentials
- Check user DN path
- Run manual sync
Full troubleshooting guide: See troubleshooting.md
Essential Commands
# Start modes
bin/kc.sh start-dev # Development
bin/kc.sh start --optimized # Production
# Build for database
bin/kc.sh build --db=postgres
# Export/Import realm
bin/kc.sh export --dir /backup --realm my-realm
bin/kc.sh import --dir /backup
# Admin CLI
bin/kcadm.sh config credentials --server http://localhost:8080 --realm master --user admin
bin/kcadm.sh create realms -s realm=my-realm -s enabled=true
bin/kcadm.sh create users -r my-realm -s username=john -s enabled=true
bin/kcadm.sh set-password -r my-realm --username john --new-password secret
Best Practices Summary
Architecture
- Separate realms per application/environment
- Use groups for structure, roles for permissions
- Plan token lifespans based on security needs
- Enable session replication in clusters
Security
- Always use SSL/TLS in production
- Enable MFA for privileged accounts
- Implement brute force protection
- Regular security audits
- Principle of least privilege
Operations
- Automate backups and test restores
- Monitor metrics and set alerts
- Document configurations
- Regular updates and patching
- Capacity planning
Development
- Use PKCE for public clients
- Implement proper token refresh
- Handle token expiration gracefully
- Validate tokens correctly
- Use appropriate grant types
Reference Documentation
For detailed guidance, load the appropriate reference file:
- realm-management.md - Realm configuration, users, groups
- client-configuration.md - OIDC/SAML clients, scopes, mappers
- authentication-sso.md - Auth flows, MFA, social login, IdP
- authorization-rbac.md - Roles, permissions, fine-grained auth
- user-federation.md - LDAP/AD integration, custom providers
- security-hardening.md - Security policies, monitoring, auditing
- ha-scalability.md - Clustering, performance, backup, DR
- troubleshooting.md - Common issues, logging, diagnostics
- integration-examples.md - Spring Boot, Node.js, React, Python, Docker, K8s
Additional Resources
1---
2name: keycloak-administration
3description: Provides comprehensive KeyCloak administration guidance including realm management, user/group administration, client configuration, authentication flows, identity brokering, authorization policies, security hardening, and troubleshooting. Covers SSO configuration, SAML/OIDC setup, role-based access control (RBAC), user federation (LDAP/AD), social login integration, multi-factor authentication (MFA), and high availability deployments. Use when configuring KeyCloak, setting up SSO, managing realms and clients, troubleshooting authentication issues, implementing RBAC, or when users mention "KeyCloak", "SSO", "OIDC", "SAML", "identity provider", "IAM", "authentication flow", "user federation", "realm configuration", or "access management".
4metadata:
5 source: https://skillmd.com/skills/aibot88/keycloak-administration
6---
7
8# KeyCloak Administration
9
10## Overview
11
12Provides systematic KeyCloak administration guidance covering installation, configuration, realm management, security hardening, and operational best practices. Supports both standalone and clustered deployments for secure, scalable identity and access management (IAM) solutions.
13
14## Quick Start Guide
15
16Choose your task and load the appropriate reference:
17
181. **New Installation** → Continue to Installation & Setup
192. **Realm & User Management** → Load [realm-management.md](references/realm-management.md)
203. **Client Configuration** → Load [client-configuration.md](references/client-configuration.md)
214. **Authentication & SSO** → Load [authentication-sso.md](references/authentication-sso.md)
225. **Authorization & RBAC** → Load [authorization-rbac.md](references/authorization-rbac.md)
236. **User Federation (LDAP/AD)** → Load [user-federation.md](references/user-federation.md)
247. **Security Hardening** → Load [security-hardening.md](references/security-hardening.md)
258. **High Availability & Scaling** → Load [ha-scalability.md](references/ha-scalability.md)
269. **Troubleshooting** → Load [troubleshooting.md](references/troubleshooting.md)
2710. **Integration Examples** → Load [integration-examples.md](references/integration-examples.md)
28
29## Installation & Setup
30
31## Deployment Options
32
33**1. Standalone Mode (Development/Testing)**
34
35```bash
36# Download and start KeyCloak
37wget https://github.com/keycloak/keycloak/releases/download/[VERSION]/keycloak-[VERSION].tar.gz
38tar -xvzf keycloak-[VERSION].tar.gz
39cd keycloak-[VERSION]
40bin/kc.sh start-dev
41
42# Access: http://localhost:8080
43# Create initial admin user on first access
44```
45
46**2. Production Mode with Database**
47
48```bash
49# Configure and build
50bin/kc.sh build --db=postgres
51
52# Set environment variables
53export KC_DB=postgres
54export KC_DB_URL=jdbc:postgresql://localhost/keycloak
55export KC_DB_USERNAME=keycloak
56export KC_DB_PASSWORD=password
57export KC_HOSTNAME=keycloak.example.com
58
59# Start production mode
60bin/kc.sh start --optimized
61```
62
63**3. Docker Deployment**
64
65```bash
66docker run -d \
67 --name keycloak \
68 -p 8080:8080 \
69 -e KEYCLOAK_ADMIN=admin \
70 -e KEYCLOAK_ADMIN_PASSWORD=admin \
71 quay.io/keycloak/keycloak:latest \
72 start-dev
73```
74
75**4. Kubernetes** - Use KeyCloak Operator or Helm charts
76
77### Initial Configuration Steps
78
791. **Admin Account**: Create on first access with strong password (12+ chars)
802. **Hostname**: Configure `KC_HOSTNAME` for production
813. **SSL/TLS**: Set up certificates (required for production)
824. **Database**: Configure PostgreSQL connection
835. **Email**: Configure SMTP for notifications
84
85```properties
86# Email settings
87KC_SMTP_HOST=smtp.example.com
88KC_SMTP_PORT=587
89KC_SMTP_FROM=noreply@example.com
90KC_SMTP_STARTTLS=true
91```
92
93## Core Concepts
94
95### Realms
96
97- **Master realm**: Administrative realm (don't use for apps)
98- **Application realms**: Separate realms per app/environment
99- Create: Admin Console → Create Realm
100
101### Users & Groups
102
103- **Users**: Individual accounts with credentials
104- **Groups**: Organize users hierarchically
105- **Attributes**: Custom key-value pairs
106- **Federation**: Sync from LDAP/AD (see [user-federation.md](references/user-federation.md))
107
108### Clients
109
110- **OIDC clients**: Modern OAuth 2.0/OIDC applications
111- **SAML clients**: Legacy enterprise applications
112- **Types**: Confidential (server-side) or Public (SPA/mobile)
113- Details: See [client-configuration.md](references/client-configuration.md)
114
115### Roles & Permissions
116
117- **Realm roles**: Global across all clients
118- **Client roles**: Specific to one client
119- **Composite roles**: Inherit multiple roles
120- Details: See [authorization-rbac.md](references/authorization-rbac.md)
121
122## Common Tasks
123
124### Configure SSO for Applications
125
1261. **Create OIDC client** for your application
1272. **Set redirect URIs** (exact URLs, no wildcards)
1283. **Configure client type**:
129 - Confidential: Server-side apps (need client secret)
130 - Public: SPAs/mobile apps (use PKCE)
1314. **Obtain configuration** from realm endpoint:
132
133 ```
134 https://keycloak.example.com/realms/{realm}/.well-known/openid-configuration
135 ```
136
1375. **Integrate** with your app (see [integration-examples.md](references/integration-examples.md))
138
139### Enable Multi-Factor Authentication
140
1411. Authentication → Flows
1422. Duplicate Browser flow
1433. Add OTP or WebAuthn authenticator
1444. Set as Required or Conditional
1455. Bind to realm
1466. Users configure MFA on next login
147
148Details: See [authentication-sso.md](references/authentication-sso.md)
149
150### Connect to LDAP/Active Directory
151
1521. User Federation → Add LDAP Provider
1532. Configure connection (URL, bind DN, credentials)
1543. Set search base: `ou=users,dc=example,dc=com`
1554. Configure mappers for attributes
1565. Test connection and sync users
157
158Details: See [user-federation.md](references/user-federation.md)
159
160### Secure Production Deployment
161
162Essential security measures:
163
164- **SSL/TLS**: Required for all production traffic
165- **Password policy**: 12+ chars, complexity requirements
166- **Brute force protection**: Enable with lockout
167- **Token lifespans**: Short access tokens (5-15 min)
168- **Admin MFA**: Enable for all admin accounts
169- **Event logging**: Monitor authentication events
170
171Complete checklist: See [security-hardening.md](references/security-hardening.md)
172
173### Set Up High Availability
174
1751. **Shared database**: PostgreSQL/MySQL for all nodes
1762. **Distributed caching**: Configure Infinispan
1773. **Load balancer**: HAProxy/NGINX with sticky sessions
1784. **Health checks**: Use `/health/ready` and `/health/live`
1795. **Monitoring**: Prometheus metrics at `/metrics`
180
181Details: See [ha-scalability.md](references/ha-scalability.md)
182
183## Troubleshooting Quick Reference
184
185### Users Can't Login
186
187- Check user enabled status
188- Verify redirect URIs match exactly
189- Review required actions
190- Check Events → Login Events
191
192### Token Validation Fails
193
194- Verify realm public key
195- Check token expiration
196- Validate issuer URL
197- Confirm audience claim
198
199### LDAP Sync Issues
200
201- Test LDAP connection
202- Verify bind credentials
203- Check user DN path
204- Run manual sync
205
206Full troubleshooting guide: See [troubleshooting.md](references/troubleshooting.md)
207
208## Essential Commands
209
210```bash
211# Start modes
212bin/kc.sh start-dev # Development
213bin/kc.sh start --optimized # Production
214
215# Build for database
216bin/kc.sh build --db=postgres
217
218# Export/Import realm
219bin/kc.sh export --dir /backup --realm my-realm
220bin/kc.sh import --dir /backup
221
222# Admin CLI
223bin/kcadm.sh config credentials --server http://localhost:8080 --realm master --user admin
224bin/kcadm.sh create realms -s realm=my-realm -s enabled=true
225bin/kcadm.sh create users -r my-realm -s username=john -s enabled=true
226bin/kcadm.sh set-password -r my-realm --username john --new-password secret
227```
228
229## Best Practices Summary
230
231### Architecture
232
233- Separate realms per application/environment
234- Use groups for structure, roles for permissions
235- Plan token lifespans based on security needs
236- Enable session replication in clusters
237
238### Security
239
240- Always use SSL/TLS in production
241- Enable MFA for privileged accounts
242- Implement brute force protection
243- Regular security audits
244- Principle of least privilege
245
246### Operations
247
248- Automate backups and test restores
249- Monitor metrics and set alerts
250- Document configurations
251- Regular updates and patching
252- Capacity planning
253
254### Development
255
256- Use PKCE for public clients
257- Implement proper token refresh
258- Handle token expiration gracefully
259- Validate tokens correctly
260- Use appropriate grant types
261
262## Reference Documentation
263
264For detailed guidance, load the appropriate reference file:
265
266- **[realm-management.md](references/realm-management.md)** - Realm configuration, users, groups
267- **[client-configuration.md](references/client-configuration.md)** - OIDC/SAML clients, scopes, mappers
268- **[authentication-sso.md](references/authentication-sso.md)** - Auth flows, MFA, social login, IdP
269- **[authorization-rbac.md](references/authorization-rbac.md)** - Roles, permissions, fine-grained auth
270- **[user-federation.md](references/user-federation.md)** - LDAP/AD integration, custom providers
271- **[security-hardening.md](references/security-hardening.md)** - Security policies, monitoring, auditing
272- **[ha-scalability.md](references/ha-scalability.md)** - Clustering, performance, backup, DR
273- **[troubleshooting.md](references/troubleshooting.md)** - Common issues, logging, diagnostics
274- **[integration-examples.md](references/integration-examples.md)** - Spring Boot, Node.js, React, Python, Docker, K8s
275
276## Additional Resources
277
278- Official documentation: <https://www.keycloak.org/documentation>
279- Admin CLI reference for automation
280- Client adapter docs for frameworks
281- Community forums for support