← All articles
SECURITY Keycloak: Enterprise Identity Management for Your Ho... 2026-02-09 · keycloak · sso · identity

Keycloak: Enterprise Identity Management for Your Homelab

Security 2026-02-09 keycloak sso identity authentication oidc saml security

You've got Nextcloud, Gitea, Grafana, Jellyfin, and a dozen other self-hosted services. Each one has its own user database, its own login page, and its own password. You're either reusing the same password everywhere (bad) or maintaining a spreadsheet of per-service credentials (also bad).

Keycloak is an open source identity and access management platform. It gives you one login for all your services — real single sign-on (SSO) with industry-standard protocols.

What Keycloak Does

Keycloak vs. Authelia vs. Authentik

Feature Keycloak Authelia Authentik
Primary purpose Full IAM platform Auth proxy/portal IAM + auth proxy
Protocol support OIDC, SAML, OAuth Forward auth only OIDC, SAML, proxy
User management Full admin console File/LDAP-based Full admin console
Identity federation Yes (LDAP, SAML, OIDC) LDAP only Yes (LDAP, SAML, OIDC)
MFA options TOTP, WebAuthn, custom TOTP, WebAuthn, Duo TOTP, WebAuthn, SMS
Resource usage ~500 MB-1 GB RAM ~30 MB RAM ~300 MB RAM
Complexity High Low Medium
Best for Full enterprise IAM Simple proxy auth Middle ground

Choose Keycloak if you need SAML support, identity federation, or fine-grained authorization. Choose Authelia if you just need a login portal in front of your reverse proxy. Choose Authentik if you want a middle ground.

Setup with Docker

services:
  keycloak:
    image: quay.io/keycloak/keycloak:latest
    restart: unless-stopped
    command: start
    environment:
      KC_DB: postgres
      KC_DB_URL: jdbc:postgresql://keycloak-db:5432/keycloak
      KC_DB_USERNAME: keycloak
      KC_DB_PASSWORD: changeme
      KC_HOSTNAME: auth.yourdomain.com
      KC_PROXY_HEADERS: xforwarded
      KEYCLOAK_ADMIN: admin
      KEYCLOAK_ADMIN_PASSWORD: changeme
    ports:
      - 8080:8080
    depends_on:
      keycloak-db:
        condition: service_healthy

  keycloak-db:
    image: postgres:16-alpine
    restart: unless-stopped
    volumes:
      - keycloak_db:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: keycloak
      POSTGRES_USER: keycloak
      POSTGRES_PASSWORD: changeme
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U keycloak"]
      interval: 10s
      timeout: 5s
      retries: 5

volumes:
  keycloak_db:

For production, always run behind a reverse proxy with TLS. Keycloak requires HTTPS for most features (it will warn you otherwise).

Reverse Proxy (Caddy)

auth.yourdomain.com {
    reverse_proxy keycloak:8080
}

Initial Configuration

1. Create a Realm

Realms are isolated tenants in Keycloak. The master realm is for admin — create a new realm for your services.

  1. Log in to https://auth.yourdomain.com/admin
  2. Click the realm dropdown → Create realm
  3. Name it homelab (or whatever you prefer)

2. Create Users

In your new realm:

  1. Users → Add user
  2. Set username, email, first/last name
  3. Credentials tab → Set a password
  4. Required actions → Optionally force password change on first login

3. Create Groups and Roles

Organize users by function:

Assign roles to groups, then add users to groups. This scales much better than per-user role assignment.

Connecting Services

OpenID Connect (OIDC)

Most modern self-hosted apps support OIDC. The setup pattern is the same everywhere:

In Keycloak:

  1. Go to your realm → Clients → Create client
  2. Client type: OpenID Connect
  3. Client ID: grafana (or whatever service)
  4. Set Valid redirect URIs: https://grafana.yourdomain.com/login/generic_oauth
  5. Copy the Client Secret from the Credentials tab

In the service, configure:

Example: Grafana

# grafana.ini
[auth.generic_oauth]
enabled = true
name = Keycloak
allow_sign_up = true
client_id = grafana
client_secret = your-client-secret
scopes = openid profile email
auth_url = https://auth.yourdomain.com/realms/homelab/protocol/openid-connect/auth
token_url = https://auth.yourdomain.com/realms/homelab/protocol/openid-connect/token
api_url = https://auth.yourdomain.com/realms/homelab/protocol/openid-connect/userinfo
role_attribute_path = contains(realm_access.roles[*], 'admin') && 'Admin' || 'Viewer'

Example: Nextcloud

Install the "Social Login" or "OpenID Connect" app in Nextcloud, then configure:

Example: Gitea

# app.ini
[oauth2]
ENABLED = true

# Then add via Gitea admin UI:
# Authentication Sources → Add OAuth2 Provider
# Provider: OpenID Connect
# Client ID: gitea
# Client Secret: your-secret
# OpenID Connect Auto Discovery URL:
#   https://auth.yourdomain.com/realms/homelab/.well-known/openid-configuration

Services with Good OIDC Support

These self-hosted apps work well with Keycloak out of the box:

SAML for Legacy Apps

Some enterprise tools only support SAML. Keycloak handles both:

  1. Clients → Create client
  2. Client type: SAML
  3. Set the Master SAML Processing URL to the app's ACS endpoint
  4. Download the SAML metadata XML from Keycloak and import it into the app

SAML is more complex than OIDC — prefer OIDC whenever the app supports it.

Identity Federation

Connect external identity sources so users can log in with existing credentials:

GitHub Login

  1. Identity Providers → Add provider → GitHub
  2. Create an OAuth App in GitHub → get Client ID and Secret
  3. Users can now "Log in with GitHub" on your Keycloak login page

LDAP / Active Directory

  1. User Federation → Add provider → LDAP
  2. Configure connection URL, bind DN, user/group search bases
  3. Keycloak syncs users from LDAP and authenticates against it

This is powerful for mixed environments — your family logs in with local Keycloak accounts while your work apps authenticate against Active Directory.

Multi-Factor Authentication

Enable MFA in your realm:

  1. Authentication → Flows
  2. Edit the browser flow to require OTP
  3. Or use Required Actions to prompt users to set up TOTP on next login

Keycloak supports:

Theming

Keycloak's default login page looks corporate. Customize it:

  1. Create a theme directory: themes/homelab/login/
  2. Override templates and CSS
  3. Mount it into the container: -v ./themes:/opt/keycloak/themes
  4. Set the realm's login theme to homelab

Or use community themes like Keywind for a modern look.

Common Pitfalls

The Bottom Line

Keycloak is the gold standard for self-hosted identity management. It's what enterprises use, and it's available to your homelab for free. The initial setup is more involved than simpler options like Authelia, but the payoff is real SSO across all your services, identity federation, and enterprise-grade security features.

If you're running more than five services with their own login pages, centralizing authentication with Keycloak will save you time, improve security, and eliminate password fatigue.