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