Problem
Currently, users must be created manually in Keycloak through the UI or API. In a Kubernetes environment, it would be more cloud-native to declaratively define users through Helm values, ConfigMaps, or CRDs.
Current State
Users must be created by:
- Logging into Keycloak admin console
- Manually creating users through the UI
- Or using Keycloak API/CLI after deployment
This doesn't follow Kubernetes declarative principles where infrastructure should be defined as code.
Expected Behavior
Users should be definable in a cloud-native way:
- Through Helm values during installation
- Via ConfigMaps that can be updated
- Using Kubernetes CRDs for full GitOps compatibility
Reference: opencloud-compose Pattern
The opencloud-compose repository includes pre-defined users in config/keycloak/opencloud-realm-autoprovisioning.dist.json:
{
"users": [{
"username": "admin",
"firstName": "Admin",
"email": "admin@example.org",
"emailVerified": true,
"enabled": true,
"credentials": [{
"type": "password",
"value": "admin"
}],
"realmRoles": ["opencloudAdmin", "default-roles-opencloud"],
"groups": ["/users"]
}]
}
However, this uses hardcoded passwords, which is insecure for production.
Proposed Solution
Option 1: Helm Values (Simplest)
keycloak:
users:
- username: admin
email: admin@example.com
# Password from existing secret
passwordSecret:
name: admin-credentials
key: password
roles:
- opencloudAdmin
groups:
- /users
- username: john
email: john@example.com
passwordSecret:
name: john-credentials
key: password
groups:
- /users
- /developers
Option 2: ConfigMap-based (More Flexible)
apiVersion: v1
kind: ConfigMap
metadata:
name: opencloud-users
labels:
app.kubernetes.io/component: keycloak-users
data:
users.yaml: |
users:
- username: admin
email: admin@example.com
passwordSecretRef: admin-credentials
roles: [opencloudAdmin]
groups: [/users]
Option 3: CRDs (Most Cloud-Native)
apiVersion: opencloud.eu/v1
kind: KeycloakUser
metadata:
name: admin
spec:
username: admin
email: admin@example.com
passwordSecretRef:
name: admin-credentials
key: password
roles:
- opencloudAdmin
groups:
- /users
Implementation Details
- Passwords: Always reference Kubernetes secrets, never hardcode
- Realm Import: Extend the existing realm import to include users
- Updates: Support updating users after initial deployment
- Validation: Validate user definitions before applying
The implementation could use Keycloak's Admin API or realm import functionality, similar to how opencloud-compose handles it but with Kubernetes-native secret management.
Benefits
- GitOps Compatible: Users defined as code
- Secure: Passwords in Kubernetes secrets
- Auditable: User changes tracked in git
- Repeatable: Same users across environments
- Cloud-Native: Follows Kubernetes patterns
Use Cases
- Development: Quickly spin up environments with test users
- CI/CD: Automated testing with predefined users
- Production: Declarative user management with proper secrets
Related Issues
Security Considerations
- Passwords must be stored in Kubernetes secrets
- Initial passwords should be marked for mandatory change
- Consider integration with external secret managers (Vault, etc.)
- Support for OIDC/SAML federation for production users
Problem
Currently, users must be created manually in Keycloak through the UI or API. In a Kubernetes environment, it would be more cloud-native to declaratively define users through Helm values, ConfigMaps, or CRDs.
Current State
Users must be created by:
This doesn't follow Kubernetes declarative principles where infrastructure should be defined as code.
Expected Behavior
Users should be definable in a cloud-native way:
Reference: opencloud-compose Pattern
The opencloud-compose repository includes pre-defined users in
config/keycloak/opencloud-realm-autoprovisioning.dist.json:{ "users": [{ "username": "admin", "firstName": "Admin", "email": "admin@example.org", "emailVerified": true, "enabled": true, "credentials": [{ "type": "password", "value": "admin" }], "realmRoles": ["opencloudAdmin", "default-roles-opencloud"], "groups": ["/users"] }] }However, this uses hardcoded passwords, which is insecure for production.
Proposed Solution
Option 1: Helm Values (Simplest)
Option 2: ConfigMap-based (More Flexible)
Option 3: CRDs (Most Cloud-Native)
Implementation Details
The implementation could use Keycloak's Admin API or realm import functionality, similar to how opencloud-compose handles it but with Kubernetes-native secret management.
Benefits
Use Cases
Related Issues
Security Considerations