Keycload infra-as-code setup
Find a file
2026-11-17 17:48:35 +11:00
.kiro/steering Change CRLF to LF 2026-11-05 14:56:16 +11:00
.vscode Colours update 2026-11-04 23:06:59 +11:00
.gitattributes Create gitattributes 2026-11-05 14:55:33 +11:00
.gitignore Functional realm with a functional vaultwarden 2025-09-04 21:21:12 +10:00
.terraform.lock.hcl Create a client for Aurral 2026-11-05 14:51:29 +11:00
backend.tf Move state to S3 2026-02-13 14:31:38 +11:00
backup-roles-groups.tf Add client for Bacularis 2026-11-12 06:49:34 +11:00
client-argocd-roles-groups.tf Connect ArgoCD via OIDC 2026-05-20 09:11:48 +10:00
client-argocd.tf Change secret name for argocd clientid 2026-05-20 21:03:07 +10:00
client-aurral-groups.tf Create a client for Aurral 2026-11-05 14:51:29 +11:00
client-aurral.tf Create a client for Aurral 2026-11-05 14:51:29 +11:00
client-bacularis.tf Add client for Bacularis 2026-11-12 06:49:34 +11:00
client-forgejo-roles-groups.tf Add Forgejo client 2026-04-25 13:20:08 +10:00
client-forgejo.tf Rename secret keys for Forgejo, application requirements 2026-04-25 13:24:02 +10:00
client-immich-roles-groups.tf Add immich client 2026-09-03 14:32:56 +10:00
client-immich.tf Add immich client 2026-09-03 14:32:56 +10:00
client-mealie-roles-groups.tf Add Mealie client 2026-05-10 13:15:39 +10:00
client-mealie.tf Add Mealie client 2026-05-10 13:15:39 +10:00
client-ocis-roles-groups.tf add offline access for owncloud 2026-07-23 22:55:12 +10:00
client-ocis.tf Add client for OCIS android 2026-07-24 06:38:52 +10:00
client-paperless-roles-groups.tf Add Paperless-ngx 2026-07-28 18:37:41 +10:00
client-paperless.tf Add Paperless-ngx 2026-07-28 18:37:41 +10:00
client-proxmox-users-groups.tf Add OCIS client, fix the proxmoxbs groups issue 2026-07-23 15:59:22 +10:00
client-proxmox.tf Move to the new cluster 2025-12-02 20:04:26 +11:00
client-proxmoxbs-roles.tf Add OCIS client, fix the proxmoxbs groups issue 2026-07-23 15:59:22 +10:00
client-proxmoxbs.tf Simplify proxmoxbs config 2026-05-14 10:47:17 +10:00
client-searxng-roles.tf Add searxng 2026-01-01 21:01:11 +11:00
client-searxng.tf Increase session timeouts on searxng 2026-02-14 07:57:33 +11:00
client-trilium-access.tf Add Trilium client 2026-11-17 17:44:37 +11:00
client-trilium.tf Add root location for redirects in Trilium client 2026-11-17 17:48:35 +11:00
client-vault-roles.tf Config Hashicorp Vault 2025-10-08 20:34:20 +11:00
client-vault.tf Config Hashicorp Vault 2025-10-08 20:34:20 +11:00
client-welcome-roles.tf Add Welcome Page client 2025-09-28 17:58:17 +10:00
client-welcome.tf Tighten Homepage redirects 2026-11-04 22:52:27 +11:00
members.tf Add Trilium client 2026-11-17 17:44:37 +11:00
prod.tfvars Move to the new cluster 2025-12-02 20:04:26 +11:00
providers.tf Move to the new cluster 2025-12-02 20:04:26 +11:00
README.md Add root location for redirects in Trilium client 2026-11-17 17:48:35 +11:00
realm_cosmos.tf Add searxng 2026-01-01 21:01:11 +11:00
realm_master.tf Configure email settings on the master realm 2025-12-03 09:27:02 +11:00
users.tf Remove Vaultwarden client 2026-07-23 16:21:21 +10:00
variables.tf Functional realm with a functional vaultwarden 2025-09-04 21:21:12 +10:00
versions.tf Add immich client 2026-09-03 14:32:56 +10:00

Keycloak setup guide

Create a client in the Master realm of Keycloak

  1. Open the Master Realm and create a new client called terraform-super
  2. Enable Client Authentication
  3. Disable Standard Flow and Direct access grants
  4. Enable Service Account Roles
  5. In the Service Account Roles for the client add the admin role to the client

Configure Aurral SSO

Before planning or applying, create the Vault KV v2 secret at secret/kubernetes/transfer/aurral/creds with OIDC_CLIENT_ID and OIDC_CLIENT_SECRET keys matching Aurral's OIDC configuration. The same secret also holds LASTFM_API_KEY and LASTFM_API_SECRET for Aurral; these can reuse Navidrome's Last.fm keys. This repository reads only the OIDC keys to configure Keycloak; the Last.fm keys are consumed by the Aurral deployment.

The Aurral client is created in the Cosmos realm and uses the exact redirect URI https://aurral.livewire.cc/sso/callback. It requires PKCE with S256, following the repository's client convention.

The default aurral-groups scope adds a groups claim containing full group paths to ID and access tokens. The groups /Aurral/Aurral-Admins and /Aurral/Aurral-Users both include Alex and Ami. Manage their memberships in members.tf and configure Aurral to recognize these group paths.

Configure backup administration and Bacularis SSO

The Cosmos group /Backup Admins includes Alex (alexv) and Jane (ami). It grants the existing proxmoxbs-admin client role for PBS. PBS must map that role to its own backup permissions; Keycloak membership alone does not configure PBS ACLs. The existing Mox-Admins role assignments are preserved.

The Bacularis client reads its client-id and client-secret from the Vault KV v2 secret at common/keycloak/bacularis. Create this secret before planning or applying; use bacularis as the client ID and a generated client secret. Keep the secret in Vault and copy it into the manually deployed Bacularis identity provider configuration.

In Bacularis, open Security > Authentication > Identity providers and create an OpenID Connect provider with identifier keycloak:

Setting Value
Discovery endpoint https://auth.livewire.cc/realms/cosmos/.well-known/openid-configuration
Client ID / secret client-id / client-secret from common/keycloak/bacularis
Redirect URI https://concordia.cosmi.co.in:9097/web/oidc/keycloak/redirect
Post logout redirect URI https://concordia.cosmi.co.in:9097/web/login/
Scope openid profile email
PKCE Enabled, S256
User attribute source ID token
Username / long name / email attributes preferred_username / name / email
Role attribute groups

Use discovery and token signature validation. The client has a default bacularis-groups scope that includes full group paths in ID tokens, access tokens, and UserInfo responses. Its backchannel logout URL is https://concordia.cosmi.co.in:9097/web/oidc/keycloak/logout.

Assign the identity provider to a Bacularis organization and provision or create both users in that organization. In Security > Roles > Role mapping, map the IAM group /Backup Admins to Bacularis's administrator role, then select Identity Provider as the role source and attach that mapping to the provider. Configure the organization's API hosts and Bacula resource permissions as needed. Log out and back in to pick up changed mappings. Role mapping requires Bacularis 6.0.0 or later; older versions need local Bacularis role assignments.

See the official OpenID Connect guide and role mapping guide.

Configure Trilium SSO

The confidential Cosmos client trilium uses authorization code flow with PKCE S256, callback https://notes.livewire.cc/callback, and post-logout redirect https://notes.livewire.cc/ (with /login also allowed). Direct grants, implicit flow, and service accounts are disabled. Its default scopes provide profile and email claims.

Before planning a new installation, create the Vault KV v2 entry at mount secret, path kubernetes/productivity/trilium-oauth2, with keys TRILIUM_OAUTH_CLIENT_ID (trilium) and TRILIUM_OAUTH_CLIENT_SECRET (a generated secret of at least 32 characters). The same entry supplies the Trilium deployment through Vault Secrets Operator; do not copy the secret into Git or command-line arguments. The initial credentials have been provisioned for this installation.

Trilium has a dedicated trilium-browser authentication flow. A required login subflow accepts an existing SSO cookie or a username/password login, including OTP for users who have it configured. A subsequent conditional subflow denies users without the realm role trilium-access. This placement ensures the access check also runs after an SSO cookie login. Only this client overrides the browser flow; the realm's default flow remains in use by other clients.

The role is granted by Trilium-Users, whose exhaustive membership in members.tf includes only keycloak_user.user_alexv. Do not add this role to realm default roles or shared groups: Trilium is a single-user application.

After reviewing and applying the Terraform plan, commit/push the Trilium values and VaultStaticSecret in magi-deployments, then sync its Argo CD Application. The operator refreshes credentials every 300 seconds and restarts Trilium on changes. When rotating the shared secret in Vault, also apply Terraform to update Keycloak before relying on the new credential.

The owner must finish enrollment in Trilium: sign in with the local password, open Options > Password & Auth, choose OpenID Connect provider, and select Connect account, authenticating as alexv. Trilium binds the provider subject identifier to the instance; supplying environment variables alone does not complete enrollment. Test login and logout through https://notes.livewire.cc.