Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

πŸ“ Writes provider-specific auth guides

Alicia Sykesfbe470bf1615
diff --git a/docs/authentication/authelia-oidc.md b/docs/authentication/authelia-oidc.md
new file mode 100644
index 00000000..5cce3079
--- /dev/null
+++ b/docs/authentication/authelia-oidc.md
@@ -0,0 +1,452 @@
+# Authelia Authentication for Dashy
+
+Dashy supports using [Authelia](https://www.authelia.com/) as its OIDC provider.
+
+[Authelia](https://www.authelia.com/) is an [open source](https://github.com/authelia/authelia) authentication and authorization server for self-hosted services. It speaks OIDC, supports MFA, and is configured via a single YAML file. Users live in a flat file, LDAP, or your own SQL store. It's a popular pairing with reverse proxies for forward-auth across many apps, and the same instance can act as your Dashy OIDC provider.
+
+### Contents
+
+- [1. Deploy Authelia](#1-deploy-authelia)
+- [2. Configure Authelia](#2-configure-authelia)
+ - [Generate secrets and keys](#generate-secrets-and-keys)
+ - [Users database](#users-database)
+ - [Main configuration](#main-configuration)
+- [3. Enabling Authelia in Dashy](#3-enabling-authelia-in-dashy)
+- [4. Groups and Visibility](#4-groups-and-visibility)
+- [Troubleshooting](#troubleshooting-common-authelia-issues)
+- [How it Works](#how-it-works)
+ - [Client side](#client-side)
+ - [Server side](#server-side)
+ - [Visual Overview](#visual-overview)
+
+## 1. Deploy Authelia
+
+Authelia v4.38+ requires HTTPS for the session cookie URLs. In production, terminate TLS at a reverse proxy on a real domain. For local testing the example below uses a self-signed cert and `lvh.me`, a wildcard DNS name that resolves to `127.0.0.1` everywhere, so no /etc/hosts edits are needed.
+
+<details>
+ <summary>Example <code>docker-compose.yml</code></summary>
+
+```yaml
+name: dashy-authelia
+
+services:
+ authelia:
+ image: authelia/authelia:4.38
+ restart: unless-stopped
+ ports:
+ - "9091:9091"
+ volumes:
+ - ./config:/config
+ environment:
+ TZ: UTC
+ healthcheck:
+ test: ["CMD-SHELL", "wget --no-check-certificate -qO- https://127.0.0.1:9091/api/health >/dev/null 2>&1"]
+ start_period: 20s
+ interval: 10s
+ timeout: 5s
+ retries: 10
+```
+
+</details>
+
+The `config/` directory holds Authelia's `configuration.yml`, the user database, the OIDC signing key, and (for local testing) the TLS cert. Generate them in step 2.
+
+---
+
+## 2. Configure Authelia
+
+### Generate secrets and keys
+
+Authelia needs four secrets: a session secret, a storage encryption key, an OIDC HMAC secret, and an RSA private key for signing id_tokens. For local testing also generate a self-signed TLS cert.
+
+```bash
+mkdir -p config
+SESSION_SECRET=$(openssl rand -hex 64)
+STORAGE_KEY=$(openssl rand -hex 32)
+HMAC_SECRET=$(openssl rand -hex 64)
+
+openssl genrsa -out config/oidc-private.pem 2048
+
+# Local testing only. In production use a real cert from your reverse proxy.
+openssl req -x509 -newkey rsa:2048 -nodes \
+ -keyout config/tls.key -out config/tls.crt \
+ -days 365 -subj "/CN=authelia.lvh.me" \
+ -addext "subjectAltName=DNS:authelia.lvh.me,DNS:*.lvh.me"
+```
+
+Keep the three shell variables around: you'll paste them into `configuration.yml` below.
+
+### Users database
+
+Hash a password with Authelia's CLI:
+
+```bash
+docker run --rm authelia/authelia:4.38 \
+ authelia crypto hash generate argon2 --password 'YourPasswordHere'
+```
+
+Copy the `Digest:` value into `config/users_database.yml`:
+
+```yaml
+users:
+ authelia-admin:
+ disabled: false
+ displayname: "Authelia Admin"
+ password: "$argon2id$v=19$m=65536,t=3,p=4$..."
+ groups:
+ - admins
+ authelia-user:
+ disabled: false
+ displayname: "Authelia User"
+ password: "$argon2id$v=19$m=65536,t=3,p=4$..."
+ groups:
+ - users
+```
+
+The `admins` group name is what Dashy's `adminGroup` will match.
+
+### Main configuration
+
+`config/configuration.yml`:
+
+```yaml
+theme: light
+server:
+ address: 'tcp://:9091'
+ tls:
+ certificate: /config/tls.crt
+ key: /config/tls.key
+log:
+ level: info
+totp:
+ issuer: authelia.lvh.me
+authentication_backend:
+ password_reset:
+ disable: true
+ file:
+ path: /config/users_database.yml
+ password:
+ algorithm: argon2id
+access_control:
+ default_policy: one_factor
+session:
+ secret: <SESSION_SECRET>
+ cookies:
+ - domain: 'lvh.me'
+ authelia_url: 'https://authelia.lvh.me:9091'
+regulation:
+ max_retries: 3
+ find_time: 2m
+ ban_time: 5m
+storage:
+ encryption_key: <STORAGE_KEY>
+ local:
+ path: /config/db.sqlite3
+notifier:
+ filesystem:
+ filename: /config/notifications.txt
+identity_providers:
+ oidc:
+ hmac_secret: <HMAC_SECRET>
+ cors:
+ endpoints:
+ - authorization
+ - token
+ - revocation
+ - introspection
+ - userinfo
+ allowed_origins:
+ - http://localhost:4000
+ jwks:
+ - key_id: dashy
+ algorithm: RS256
+ use: sig
+ key: |
+ -----BEGIN PRIVATE KEY-----
+ (contents of config/oidc-private.pem)
+ -----END PRIVATE KEY-----
+ clients:
+ - client_id: dashy
+ client_name: Dashy
+ public: true
+ authorization_policy: one_factor
+ require_pkce: true
+ pkce_challenge_method: S256
+ redirect_uris:
+ - http://localhost:4000
+ - http://localhost:4000/
+ scopes:
+ - openid
+ - profile
+ - email
+ - groups
+ userinfo_signed_response_alg: none
+```
+
+Key things to note:
+
+- `public: true` and `require_pkce: true` are required: Dashy is a SPA, so it must be a public client with PKCE
+- Register the redirect URI both with and without a trailing slash, since browsers may strip or add one
+- The `groups` scope is required for the `adminGroup` check
+- `userinfo_signed_response_alg: none` keeps the userinfo response as JSON, which is what `oidc-client-ts` (Dashy's OIDC client) expects
+- The `cors` block is required: Dashy is a SPA and makes cross-origin calls from the browser to Authelia's token and userinfo endpoints, and without these origins allow-listed the browser blocks the token exchange after login. `allowed_origins` must list Dashy's exact origin (scheme + host + port)
+
+For production, swap `server.tls` out for a reverse proxy doing HTTPS, change `session.cookies` to your real domain (e.g. `domain: example.com`, `authelia_url: https://auth.example.com`), and pick a real user backend (LDAP or SQL).
+
+Bring Authelia up:
+
+```bash
+docker compose up -d
+```
+
+Once it's healthy, `https://authelia.lvh.me:9091/.well-known/openid-configuration` should return JSON with `issuer: https://authelia.lvh.me:9091`. That issuer URL is what Dashy needs.
+
+### Summary
+
+Authelia is now configured with an OIDC client for Dashy.
+
+---
+
+## 3. Enabling Authelia in Dashy
+
+In `/user-data/conf.yml`:
+
+```yaml
+appConfig:
+ ...
+ disableConfigurationForNonAdmin: true
+ auth:
+ enableOidc: true
+ oidc:
+ clientId: dashy
+ endpoint: https://authelia.lvh.me:9091
+ adminGroup: admins
+ scope: openid profile email groups
+```
+
+Where:
+- `disableConfigurationForNonAdmin` - Prevent read/write config access to non-admin users
+- `auth.enableOidc` - Set the auth mode to OIDC
+- `clientId` - Must match the `client_id` field of the Authelia client
+- `endpoint` - The Authelia base URL (the OIDC issuer). Dashy appends `/.well-known/openid-configuration` itself
+- `adminGroup` - Name of the Authelia group that grants admin in Dashy
+- `scope` - Must include `groups` for the `adminGroup` check to work
+
+Restart Dashy for these changes to take effect.
+
+If Authelia uses a self-signed cert, Dashy's server has to trust it before it can fetch the discovery doc or JWKS. Start Dashy with `NODE_EXTRA_CA_CERTS=/path/to/tls.crt`, or mount your CA bundle into the Dashy container and point that env var at it. With a real cert this isn't needed. Your browser also needs to trust the cert (visit `https://authelia.lvh.me:9091` once and accept the warning, or import the cert into the browser's trust store).
+
+Everything should now be fully configured and working πŸŽ‰
+When you load Dashy, you'll be redirected to Authelia's login page. After signing in, you'll land back on Dashy's homepage with full access, and all of Dashy's client, server and asset endpoints will be locked behind authentication.
+
+---
+
+## 4. Groups and Visibility
+
+Once group membership is in the id_token, you can use it to hide or show pages, sections and items. The property name is `hideForKeycloakUsers` / `showForKeycloakUsers` (the name is historical; it works for any OIDC provider, including Authelia).
+
+To make an Admin section visible only to members of `admins`:
+
+```yaml
+displayData:
+ showForKeycloakUsers:
+ groups:
+ - admins
+```
+
+Both `showForKeycloakUsers` and `hideForKeycloakUsers` accept lists of `groups` and `roles`. If a user matches an entry they're allowed or excluded as defined.
+
+```yaml
+sections:
+ - name: Internal Tools
+ displayData:
+ showForKeycloakUsers:
+ groups: ['admins']
+ hideForKeycloakUsers:
+ groups: ['users']
+ items:
+ - title: Hidden from interns
+ displayData:
+ hideForKeycloakUsers:
+ groups: ['interns']
+```
+
+---
+
+## Troubleshooting common Authelia Issues
+
+#### Config validation fails on session cookies
+Problem: Authelia refuses to start, complaining `option 'authelia_url' does not have a secure scheme` or `option 'domain' is not a valid cookie domain`.<br>
+Solution: v4.38+ requires HTTPS for `authelia_url` and a cookie domain with at least one period. Use a real domain (`example.com`, `auth.example.com`) or `lvh.me` for local testing, and enable TLS either on Authelia or in front of it.
+
+#### Dashy server can't fetch Authelia's discovery doc
+Problem: Dashy server logs show TLS errors (`self-signed certificate`, `UNABLE_TO_VERIFY_LEAF_SIGNATURE`) when fetching `.well-known/openid-configuration` or the JWKS.<br>
+Solution: Authelia is on a self-signed cert. Start Dashy with `NODE_EXTRA_CA_CERTS=/path/to/tls.crt`, or use a real certificate. The signing cert for OIDC tokens is separate from the TLS cert: it's the TLS cert that needs to be trusted by Node.
+
+#### "Critical Configuration Load Error" with a CORS message on first load
+Problem: Browser shows `Cross-Origin Request Blocked ... at https://authelia.lvh.me:9091/.well-known/openid-configuration. (Reason: CORS request did not succeed). Status code: (null)` before any redirect to Authelia, and Dashy renders a Critical Configuration Load Error.<br>
+Solution: Misleading error: this is the self-signed cert, not CORS. When the browser sees an untrusted HTTPS cert during a JS fetch it blocks the request silently with no chance for you to click through. Open `https://authelia.lvh.me:9091` directly in the same browser, click through the warning, then reload Dashy. For a less hacky setup, use [mkcert](https://github.com/FiloSottile/mkcert) to generate a locally-trusted cert, or terminate TLS at a reverse proxy with a real Let's Encrypt cert.
+
+#### CORS error on the token endpoint after login
+Problem: Login at Authelia succeeds, but the redirect back to Dashy fails with a CORS error on a POST to `/api/oidc/token`.<br>
+Solution: Authelia's CORS allow-list doesn't include Dashy's origin. Add the `identity_providers.oidc.cors` block from step 2 with `token` (and ideally `authorization`, `userinfo`, `revocation`, `introspection`) under `endpoints`, and Dashy's origin under `allowed_origins`. Restart Authelia.
+
+#### Redirect loop after login
+Problem: Browser bounces between Dashy and Authelia repeatedly.<br>
+Solution: `endpoint` in `conf.yml` probably includes `.well-known/openid-configuration`. Drop everything from `.well-known` onwards; Dashy appends it itself.
+
+#### invalid_request: redirect URI mismatch
+Problem: Authelia returns `invalid_request` saying the redirect URI is not registered.<br>
+Solution: Authelia matches redirect URIs exactly. Register both the bare URL and the trailing-slash variant (`http://localhost:4000` and `http://localhost:4000/`) on the client.
+
+#### Logged in but config saves return 403
+Problem: User authenticates fine, but saving the dashboard returns 403.<br>
+Solution: The id_token isn't carrying the group claim. Paste the token (from localStorage, key `ID_TOKEN`) into [jwt.io](https://jwt.io) and look for `groups`. If it's missing, the client's `scopes` list doesn't include `groups`. If the claim is there but the user isn't in it, add them to the `admins` group in `users_database.yml` (or whatever backend you're using) and restart Authelia.
+
+#### Issuer mismatch behind a reverse proxy
+Problem: Server logs show `unexpected "iss" claim value`. The browser reaches Authelia at `https://auth.example.com` but Authelia advertises a different issuer.<br>
+Solution: Make sure your reverse proxy forwards `X-Forwarded-Proto: https` and `X-Forwarded-Host`, and that `session.cookies[].authelia_url` matches the public URL exactly.
+
+#### Locked out after a few wrong passwords
+Problem: Login fails with "User has been banned" even with the correct password.<br>
+Solution: The `regulation` block bans an account after `max_retries` failed attempts within `find_time`. Default ban is 5 minutes. Wait it out or `docker compose restart authelia` to clear the in-memory ban.
+
+#### Two-factor prompt appears unexpectedly
+Problem: After password entry Authelia asks for a TOTP code or other 2FA, but you wanted password-only for Dashy.<br>
+Solution: `access_control.default_policy` is set to `two_factor`. Change it to `one_factor`, or add a specific rule with `policy: one_factor` matching the Dashy redirect.
+
+#### Username claim is a UUID, not the username
+Problem: Dashy logs show users with random-looking subject IDs.<br>
+Solution: Authelia's `sub` claim is an opaque UUID per user. Dashy's OIDC client falls through `preferred_username`, `email`, then `sub`, so as long as the `profile` and `email` scopes are requested the username should be human-readable. Confirm both scopes are in the client's `scopes` list.
+
+#### Token expired / clock skew
+Problem: 401s with `"exp" claim timestamp check failed` or `"iat" claim timestamp check failed`, even just after login.<br>
+Solution: Dashy allows 30 seconds of drift. Sync clocks on both hosts with NTP. Container clocks follow their host, so it's almost always the host that's drifted.
+
+#### Numeric Client ID truncated
+Problem: Audience mismatch when `clientId` in `conf.yml` is a long numeric string.<br>
+Solution: Wrap numeric Client IDs in quotes (e.g. `clientId: "12345678901234567"`). Without quotes YAML parses the value as a JS number and loses precision past around 15 digits.
+
+#### Dashy server can't reach Authelia
+Problem: Auth'd API calls return 401 and Dashy logs show fetch errors for `.well-known/openid-configuration`.<br>
+Solution: `endpoint` must be reachable from inside the Dashy container, not just from the browser. If both run in Docker, put them on the same network. Test with `docker exec <dashy-container> wget -qO- "$ENDPOINT/.well-known/openid-configuration"`.
+
+#### Config change to auth.oidc not picked up
+Problem: Updated `clientId`, `endpoint`, `adminGroup` or `scope` in `conf.yml`, but Dashy still uses the old values.<br>
+Solution: The server reads the auth config only at boot. Restart the Dashy container after any change to fields under `auth.oidc`.
+
+---
+
+## How it Works
+
+If you're a developer or contributor looking to understand or make changes to Dashy's OIDC implementation, the following outlines how it's wired together.
+
+The same OIDC pipeline backs Authelia, Authentik, Keycloak, and any other generic OIDC provider. The only Authelia-specific code is your configuration; everything else is shared.
+
+### Client side
+
+Boot starts in [`src/main.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/main.js). After the initial `/conf.yml` fetch parses the auth block, `isOidcEnabled()` decides whether to lazily import [`oidc-client-ts`](https://github.com/authts/oidc-client-ts) and call `initOidcAuth()`.
+
+[`src/utils/auth/OidcAuth.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/auth/OidcAuth.js) wraps `oidc-client-ts`. On load it inspects the URL: if it sees a `?code=` callback it runs `userManager.signinCallback()` to exchange the code (and PKCE verifier) for tokens, persists the user info, and hard-redirects to `/`. Otherwise it calls `userManager.getUser()`; if there's no usable session it falls through to `userManager.signinRedirect()` to send the browser to Authelia. A short-lived `sessionStorage` guard prevents the redirect loop that would otherwise occur if the IdP returns without a usable user.
+
+`persistUserInfo()` writes the raw `id_token`, the user's `groups` and `roles`, a derived `isAdmin` flag, and a username (falling back through `preferred_username`, `email`, and `sub`) to localStorage. The keys (`ID_TOKEN`, `KEYCLOAK_INFO`, `USERNAME`, `ISADMIN`) live in [`src/utils/config/defaults.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/config/defaults.js); the `KEYCLOAK_INFO` name is historical and reused for all OIDC providers, including Authelia.
+
+[`src/utils/auth/getApiAuthHeader.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/auth/getApiAuthHeader.js) builds the Authorization header for every internal API call. It does a client-side `exp` check and returns `null` for missing or expired tokens, so the next request triggers a fresh login rather than a 401.
+
+[`src/utils/IsVisibleToUser.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/IsVisibleToUser.js) reads `KEYCLOAK_INFO` when evaluating `showForKeycloakUsers` and `hideForKeycloakUsers` rules.
+
+### Server side
+
+[`services/auth-oidc.js`](https://github.com/lissy93/dashy/blob/4.1.5/services/auth-oidc.js) contains the entire server-side auth surface, in five small pieces:
+
+- `loadOidcSettings()` reads `auth.oidc` (or `auth.keycloak`) at boot and returns a normalised `{ issuer, clientId, adminGroup, adminRole }`. For generic OIDC providers the `issuer` is whatever you set as `endpoint` in `conf.yml`, verbatim
+- `createOidcMiddleware()` returns a Connect middleware. Permissive on no-token requests so the SPA can bootstrap; otherwise it verifies the Bearer token against the issuer's JWKS using [`jose`](https://github.com/panva/jose). Checks cover signature, issuer (against the canonical value from the discovery doc), audience (must equal `clientId`), and expiry, with a 30-second clock-skew tolerance. Sets `req.auth = { user, isAdmin, claims }` on success, `401` on failure
+- `getIssuerContext()` lazily fetches `.well-known/openid-configuration` on first use and wraps `jwks_uri` in `createRemoteJWKSet`, which handles JWKS caching and on-demand key rotation. The result is memoised per-issuer for the life of the process
+- `deriveIsAdmin()` checks the token's `groups` claim against `adminGroup`, and the `realm_access.roles` / `resource_access.<clientId>.roles` arrays against `adminRole`. Authelia only emits `groups`, so the group path is what's used in practice
+- `maybeBootstrapConfig()` is the stripped-response helper. When auth is configured, guest access is off, and an unauthenticated request hits the root `/conf.yml`, it returns a minimal copy with only `appConfig.auth`, `appConfig.enableServiceWorker`, and a `pageInfo.title` of `Login | <your title>`. Sections, items, hostnames and any other secrets never leave the server
+
+[`services/app.js`](https://github.com/lissy93/dashy/blob/4.1.5/services/app.js) wires it all together. The middleware mounts as `protectConfig` in front of every YAML route and config-mutating route. The `/*.yml` handler sets `Cache-Control: private, no-store` and `Vary: Authorization` whenever auth is configured (so intermediate caches can never mix auth states), then calls `maybeBootstrapConfig`; a stripped result is sent as-is, otherwise `res.sendFile` serves the full file. `POST /config-manager/save` is additionally guarded by `requireAdmin`, which returns `401` if `req.auth` is unset and `403` if `req.auth.isAdmin` is false.
+
+### Visual Overview
+
+<details>
+
+<summary>End-to-end authentication flow</summary>
+
+```mermaid
+sequenceDiagram
+ autonumber
+ actor User
+ participant Browser as Browser (Dashy SPA)
+ participant Dashy as Dashy Server
+ participant Auth as Authelia
+
+ Note over Browser,Dashy: 1. Bootstrap (no token yet)
+ User->>Browser: Open Dashy
+ Browser->>Dashy: GET /conf.yml
+ Dashy-->>Browser: 200 stripped conf<br/>(auth block + minimal pageInfo)
+ Browser->>Browser: Parse auth.oidc
+
+ Note over Browser,Auth: 2. OIDC login (Authorization Code + PKCE)
+ Browser->>Auth: 302 /api/oidc/authorization<br/>client_id, code_challenge, redirect_uri
+ User->>Auth: Submit credentials
+ Auth-->>Browser: 302 back with ?code=AUTH_CODE
+ Browser->>Auth: POST /api/oidc/token<br/>(code + code_verifier)
+ Auth-->>Browser: id_token + access_token
+ Browser->>Browser: Store tokens in localStorage<br/>hard reload to /
+
+ Note over Browser,Dashy: 3. Authenticated read
+ Browser->>Dashy: GET /conf.yml<br/>Authorization: Bearer id_token
+ Dashy->>Auth: Fetch discovery + JWKS<br/>(lazy on first call, then cached)
+ Auth-->>Dashy: openid-configuration + JWKS
+ Dashy->>Dashy: Verify signature / issuer / audience / expiry
+ Dashy-->>Browser: 200 full conf.yml
+
+ Note over Browser,Dashy: 4. Write request (admin only)
+ Browser->>Dashy: POST /config-manager/save<br/>Authorization: Bearer id_token
+ Dashy->>Dashy: Verify token, derive isAdmin from<br/>adminGroup claim
+ alt isAdmin
+ Dashy-->>Browser: 200 saved
+ else not admin
+ Dashy-->>Browser: 403 Forbidden
+ end
+```
+
+</details>
+
+
+<details>
+
+<summary>Server-side request handling</summary>
+
+```mermaid
+flowchart TD
+ Req([Incoming request to Dashy server])
+ Req --> Bearer{Authorization:<br/>Bearer present?}
+
+ Bearer -- No --> NoAuth[req.auth unset<br/>pass through]:::neutral
+ Bearer -- Yes --> Verify[/Verify JWT against cached JWKS:<br/>signature Β· issuer Β· audience Β· expiry/]
+ Verify --> Valid{Valid?}
+ Valid -- No --> R401Bad[/401 Unauthorized/]:::err
+ Valid -- Yes --> SetAuth[req.auth = user + isAdmin<br/>derived from claims]:::ok
+
+ NoAuth --> Route{Endpoint}
+ SetAuth --> Route
+
+ Route -- "GET /conf.yml" --> ConfGate{req.auth?}
+ ConfGate -- No --> Strip[/200 stripped conf<br/>auth + minimal pageInfo/]:::ok
+ ConfGate -- Yes --> Full[/200 full conf.yml/]:::ok
+
+ Route -- "POST /config-manager/save" --> SaveGate{req.auth<br/>and isAdmin?}
+ SaveGate -- No req.auth --> R401Save[/401 Unauthorized/]:::err
+ SaveGate -- Not admin --> R403[/403 Forbidden/]:::err
+ SaveGate -- Admin --> Saved[/200 saved/]:::ok
+
+ classDef ok fill:#bbf7d0,stroke:#16a34a,color:#14532d
+ classDef err fill:#fecaca,stroke:#dc2626,color:#7f1d1d
+ classDef neutral fill:#dbeafe,stroke:#2563eb,color:#1e3a8a
+```
+
+</details>
diff --git a/docs/authentication/authentik.md b/docs/authentication/authentik.md
new file mode 100644
index 00000000..8d5cdaf4
--- /dev/null
+++ b/docs/authentication/authentik.md
@@ -0,0 +1,422 @@
+# Authentik Authentication for Dashy
+
+Dashy supports using [Authentik](https://goauthentik.io/) as its OIDC provider.
+
+[Authentik](https://goauthentik.io/) is an [open source](https://github.com/goauthentik/authentik) identity provider that speaks OIDC, OAuth 2.0, SAML 2.0 and LDAP. It runs in Docker, has a polished admin UI, and supports MFA, social login, and per-application group policies, which makes it a good fit for self-hosted setups where you want a single login across many services.
+
+### Contents
+
+- [1. Deploy Authentik](#1-deploy-authentik)
+- [2. Configure Authentik](#2-configure-authentik)
+ - [Create the groups scope](#create-the-groups-scope)
+ - [Create the OIDC provider](#create-the-oidc-provider)
+ - [Create the application](#create-the-application)
+ - [Create the admin group](#create-the-admin-group)
+ - [Create test users](#create-test-users)
+- [3. Enabling Authentik in Dashy](#3-enabling-authentik-in-dashy)
+- [4. Groups and Visibility](#4-groups-and-visibility)
+- [Troubleshooting](#troubleshooting-common-authentik-issues)
+- [How it Works](#how-it-works)
+ - [Client side](#client-side)
+ - [Server side](#server-side)
+ - [Visual Overview](#visual-overview)
+
+## 1. Deploy Authentik
+
+If you've not already done so, spin up an Authentik instance, following the [official docs](https://docs.goauthentik.io/docs/install-config/install/docker-compose). The compose file below is a minimal local setup.
+
+A `.env` file alongside the compose file (generate fresh secrets with `openssl rand -hex 32`):
+
+```env
+AUTHENTIK_TAG=2024.12
+PG_PASS=replace-me-with-random-hex
+AUTHENTIK_SECRET_KEY=replace-me-with-random-hex
+AUTHENTIK_BOOTSTRAP_PASSWORD=change-me-now
+AUTHENTIK_BOOTSTRAP_TOKEN=replace-me-with-random-hex
+```
+
+<details>
+ <summary>Example <code>docker-compose.yml</code></summary>
+
+```yaml
+name: authentik
+
+services:
+ postgresql:
+ image: docker.io/library/postgres:16-alpine
+ restart: unless-stopped
+ healthcheck:
+ test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"]
+ start_period: 20s
+ interval: 10s
+ retries: 5
+ timeout: 5s
+ volumes:
+ - ./data/postgres:/var/lib/postgresql/data
+ environment:
+ POSTGRES_PASSWORD: ${PG_PASS}
+ POSTGRES_USER: authentik
+ POSTGRES_DB: authentik
+
+ redis:
+ image: docker.io/library/redis:7-alpine
+ command: --save 60 1 --loglevel warning
+ restart: unless-stopped
+ healthcheck:
+ test: ["CMD-SHELL", "redis-cli ping | grep PONG"]
+ start_period: 20s
+ interval: 10s
+ retries: 5
+ timeout: 3s
+ volumes:
+ - ./data/redis:/data
+
+ server:
+ image: ghcr.io/goauthentik/server:${AUTHENTIK_TAG}
+ restart: unless-stopped
+ command: server
+ environment: &authentik-env
+ AUTHENTIK_REDIS__HOST: redis
+ AUTHENTIK_POSTGRESQL__HOST: postgresql
+ AUTHENTIK_POSTGRESQL__USER: authentik
+ AUTHENTIK_POSTGRESQL__NAME: authentik
+ AUTHENTIK_POSTGRESQL__PASSWORD: ${PG_PASS}
+ AUTHENTIK_SECRET_KEY: ${AUTHENTIK_SECRET_KEY}
+ AUTHENTIK_BOOTSTRAP_PASSWORD: ${AUTHENTIK_BOOTSTRAP_PASSWORD}
+ AUTHENTIK_BOOTSTRAP_TOKEN: ${AUTHENTIK_BOOTSTRAP_TOKEN}
+ AUTHENTIK_BOOTSTRAP_EMAIL: ${AUTHENTIK_BOOTSTRAP_EMAIL}
+ AUTHENTIK_ERROR_REPORTING__ENABLED: "false"
+ ports:
+ - "9000:9000"
+ - "9443:9443"
+ depends_on:
+ postgresql: {condition: service_healthy}
+ redis: {condition: service_healthy}
+
+ worker:
+ image: ghcr.io/goauthentik/server:${AUTHENTIK_TAG}
+ restart: unless-stopped
+ command: worker
+ environment: *authentik-env
+ depends_on:
+ postgresql: {condition: service_healthy}
+ redis: {condition: service_healthy}
+```
+
+</details>
+
+Bring it up:
+
+```bash
+docker compose up -d
+```
+
+First boot runs database migrations and takes a minute or two. Once the `server` container is healthy, open `http://localhost:9000` and sign in as `akadmin` with the bootstrap password.
+
+---
+
+## 2. Configure Authentik
+
+### Create the groups scope
+
+Authentik doesn't expose group membership in the id_token by default. Dashy needs it for the `adminGroup` check and for the `showForKeycloakUsers` / `hideForKeycloakUsers` visibility rules.
+
+1. Go to **Customisation > Property Mappings**
+2. Click **Create > Scope Mapping**
+3. Set **Name** to `groups`
+4. Set **Scope name** to `groups`
+5. Set **Expression** to:
+
+```python
+return {"groups": [g.name for g in request.user.ak_groups.all()]}
+```
+
+6. Click **Finish**
+
+### Create the OIDC provider
+
+1. Go to **Applications > Providers**
+2. Click **Create**, pick **OAuth2/OpenID Provider**, click **Next**
+3. Set **Name** to `Dashy`
+4. Set **Authorization flow** to `default-provider-authorization-implicit-consent` (use `default-provider-authorization-explicit-consent` if you want users to confirm sign-in each time)
+5. Set **Invalidation flow** to `default-provider-invalidation-flow` (required on Authentik 2023.10 and newer)
+6. Under **Protocol settings**:
+ - **Client type**: `Public`
+ - **Client ID**: `dashy`, or leave the auto-generated value and copy it for later
+ - **Redirect URIs** with matching mode `Strict`, one URL per line. Register both the bare URL and the trailing-slash version:
+ - `https://dashy.example.com`
+ - `https://dashy.example.com/`
+ - **Signing Key**: the built-in `authentik Self-signed Certificate` is fine
+7. Expand **Advanced protocol settings**:
+ - Add `openid`, `profile`, `email`, and the `groups` scope you just created to **Scopes**
+ - Turn **Include claims in id_token** on
+8. Click **Finish**
+
+### Create the application
+
+1. Go to **Applications > Applications**
+2. Click **Create**
+3. Set **Name** to `Dashy`
+4. Set **Slug** to `dashy` (this becomes part of the issuer URL: `<host>/application/o/<slug>/`)
+5. Set **Provider** to the `Dashy` provider you just made
+6. Click **Create**
+
+Now open the `Dashy` provider again (**Applications > Providers > Dashy**) and copy the **OpenID Configuration Issuer URL** shown on the page (e.g. `https://auth.example.com/application/o/dashy/`). The provider only displays a valid URL once it's bound to an application. You'll need this for Dashy's `endpoint` setting later.
+
+### Create the admin group
+
+1. Go to **Directory > Groups**
+2. Click **Create**
+3. Set **Name** to `dashy-admins`
+4. Click **Create**
+5. Open the new group, click **Users**, and add any users who should have admin rights in Dashy
+
+### Create test users
+
+If you want separate accounts beyond `akadmin`:
+
+1. Go to **Directory > Users**
+2. Click **Create**, fill in **Username**, **Name** and **Email**, click **Create**
+3. On the new user's page, click **Set password**, set a password, click **Update**
+4. Add the user to `dashy-admins` for admin access, or leave them out for a non-admin
+
+### Summary
+
+Authentik should now be configured, and ready to go!
+
+---
+
+## 3. Enabling Authentik in Dashy
+
+Finally, you need to tell Dashy to use Authentik. This goes in the `appConfig.auth` section of your main `/user-data/conf.yml`.
+
+```yaml
+appConfig:
+ ...
+ disableConfigurationForNonAdmin: true
+ auth:
+ enableOidc: true
+ oidc:
+ clientId: dashy
+ endpoint: https://auth.example.com/application/o/dashy/
+ adminGroup: dashy-admins
+ scope: openid profile email groups
+```
+
+Where:
+- `disableConfigurationForNonAdmin` - Prevent read/write config access to non-admin users
+- `auth.enableOidc` - Set the auth mode to OIDC
+- `clientId` - The Client ID from the Authentik provider (exact, case-sensitive)
+- `endpoint` - The OpenID Configuration Issuer URL from the provider page. Use the bare issuer, not the discovery URL; Dashy appends `/.well-known/openid-configuration` itself
+- `adminGroup` - Name of the Authentik group that grants admin in Dashy (matches the `dashy-admins` group above)
+- `scope` - Space-separated list of scopes to request. Must include `groups` when `adminGroup` is set, otherwise the id_token won't carry the claim
+
+Restart Dashy for these changes to take effect.
+
+If Authentik runs on a different host or behind a reverse proxy, make sure `endpoint` is reachable from inside the Dashy container, and that the issuer URL the provider advertises matches `endpoint` exactly.
+
+Everything should now be fully configured and working πŸŽ‰
+When you load Dashy, you'll be redirected to Authentik's login page. After signing in you will land back on Dashy's homepage with full access, and all of Dashy's client, server and asset endpoints will be locked behind authentication.
+
+---
+
+## 4. Groups and Visibility
+
+Once group membership is in the id_token, you can use it to hide or show pages, sections and items in Dashy. The property name is `hideForKeycloakUsers` / `showForKeycloakUsers` (the name is historical; it works for any OIDC provider, including Authentik).
+
+To make an Admin section visible only to members of `dashy-admins`:
+
+```yaml
+displayData:
+ showForKeycloakUsers:
+ groups:
+ - dashy-admins
+```
+
+Both `showForKeycloakUsers` and `hideForKeycloakUsers` accept lists of `groups` and `roles`. If a user matches an entry they're allowed or excluded as defined.
+
+```yaml
+sections:
+ - name: Internal Tools
+ displayData:
+ showForKeycloakUsers:
+ groups: ['dashy-admins']
+ hideForKeycloakUsers:
+ groups: ['guests']
+ items:
+ - title: Hidden from interns
+ displayData:
+ hideForKeycloakUsers:
+ groups: ['interns']
+```
+
+---
+
+## Troubleshooting common Authentik Issues
+
+#### Migrations still running on first boot
+Problem: Authentik returns 502 or never reaches the login page right after `docker compose up`.<br>
+Solution: First boot runs database migrations and can take a minute or two. Tail the logs with `docker compose logs -f server` and wait for the `uvicorn` startup line before opening the UI.
+
+#### Redirect loop after login
+Problem: Browser bounces between Dashy and Authentik repeatedly.<br>
+Solution: `endpoint` in `conf.yml` probably includes `.well-known/openid-configuration`. Drop everything from `.well-known` onwards; Dashy appends it itself.
+
+#### invalid_redirect_uri
+Problem: Authentik shows "invalid redirect URI" after submitting credentials.<br>
+Solution: The URL Dashy is being served from doesn't exactly match what's registered on the provider. Register both the bare URL and the trailing-slash variant (e.g. `https://dashy.example.com` and `https://dashy.example.com/`), keep matching mode on `Strict`, and make sure the scheme matches (`http` vs `https`).
+
+#### Logged in but config saves return 403
+Problem: User authenticates fine, but saving the dashboard returns 403.<br>
+Solution: The id_token isn't carrying the group claim. Paste the token (from localStorage, key `ID_TOKEN`) into [jwt.io](https://jwt.io) and look for `groups`. If it's missing, the `groups` scope mapping isn't attached to the provider's **Scopes** or **Include claims in id_token** is off. If the claim is there but the user isn't in it, add them to the `dashy-admins` group.
+
+#### Issuer mismatch behind a reverse proxy
+Problem: Server logs show `unexpected "iss" claim value`. The browser reaches Authentik over HTTPS, but Authentik advertises an HTTP issuer in its discovery document.<br>
+Solution: Set `AUTHENTIK_LISTEN__TRUSTED_PROXY_CIDRS` on the Authentik server and worker containers to include your proxy's IP range (e.g. `172.16.0.0/12` for default Docker bridges), and make sure the proxy forwards `X-Forwarded-Proto: https`. Once Authentik trusts the proxy, its discovery document will advertise the public HTTPS URL.
+
+#### Audience mismatch on token verification
+Problem: Server logs show `unexpected "aud" claim value`. Every auth'd API call returns 401.<br>
+Solution: `clientId` in `conf.yml` must exactly match the provider's **Client ID** field. If you let Authentik auto-generate one, copy the exact value (including case) from the provider page.
+
+#### Self-signed Authentik certificate rejected
+Problem: Dashy server logs show TLS errors (`self-signed certificate`, `UNABLE_TO_VERIFY_LEAF_SIGNATURE`) when fetching the discovery doc or JWKS.<br>
+Solution: Use a real certificate on the Authentik HTTPS endpoint (Let's Encrypt or your homelab CA), or mount your CA bundle into the Dashy container and set `NODE_EXTRA_CA_CERTS=/path/to/ca.pem`. Authentik's built-in `authentik Self-signed Certificate` is only used to sign tokens; the TLS cert is whatever's terminating HTTPS in front of Authentik.
+
+#### "OIDC signinCallback returned no user"
+Problem: Login submits, Authentik redirects back, then Dashy shows the error toast `OIDC signinCallback returned no user`.<br>
+Solution: The id_token came back without a usable username claim. Confirm `profile` and `email` are in the provider's **Scopes**, that **Include claims in id_token** is on, and that the user has an email or username set in Authentik.
+
+#### Logout stuck on a consent screen
+Problem: Clicking Logout sends the user to Authentik's end-session endpoint, which prompts for confirmation and never returns.<br>
+Solution: This is the default behaviour of `default-provider-invalidation-flow`. To skip the prompt, change the provider's **Invalidation flow** to one without a consent stage, or accept the extra click.
+
+#### Token expired / clock skew
+Problem: 401s with `"exp" claim timestamp check failed` or `"iat" claim timestamp check failed`, even just after login.<br>
+Solution: Dashy allows 30 seconds of drift. Sync clocks on both hosts with NTP. Container clocks follow their host, so it's almost always the host that's drifted.
+
+#### Numeric Client ID truncated
+Problem: Audience mismatch when `clientId` in `conf.yml` is a long numeric string.<br>
+Solution: Wrap numeric Client IDs in quotes (e.g. `clientId: "12345678901234567"`). Without quotes YAML parses the value as a JS number and loses precision past around 15 digits.
+
+#### Dashy server can't reach Authentik
+Problem: Auth'd API calls return 401 and Dashy logs show fetch errors for `.well-known/openid-configuration`.<br>
+Solution: `endpoint` must be reachable from inside the Dashy container, not just from the browser. If both run in Docker, put them on the same network. Test with `docker exec <dashy-container> wget -qO- "$ENDPOINT/.well-known/openid-configuration"`.
+
+#### Config change to auth.oidc not picked up
+Problem: Updated `clientId`, `endpoint`, `adminGroup` or `scope` in `conf.yml`, but Dashy still uses the old values.<br>
+Solution: The server reads the auth config only at boot. Restart the Dashy container after any change to fields under `auth.oidc`.
+
+---
+
+## How it Works
+
+If you're a developer or contributor looking to understand or make changes to Dashy's OIDC implementation, the following outlines how it's wired together.
+
+The same OIDC pipeline backs Authentik, Keycloak, and any other generic OIDC provider. The only Authentik-specific code is your configuration; everything else is shared.
+
+### Client side
+
+Boot starts in [`src/main.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/main.js). After the initial `/conf.yml` fetch parses the auth block, `isOidcEnabled()` decides whether to lazily import [`oidc-client-ts`](https://github.com/authts/oidc-client-ts) and call `initOidcAuth()`.
+
+[`src/utils/auth/OidcAuth.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/auth/OidcAuth.js) wraps `oidc-client-ts`. On load it inspects the URL: if it sees a `?code=` callback it runs `userManager.signinCallback()` to exchange the code (and PKCE verifier) for tokens, persists the user info, and hard-redirects to `/`. Otherwise it calls `userManager.getUser()`; if there's no usable session it falls through to `userManager.signinRedirect()` to send the browser to Authentik. A short-lived `sessionStorage` guard prevents the redirect loop that would otherwise occur if the IdP returns without a usable user.
+
+`persistUserInfo()` writes the raw `id_token`, the user's `groups` and `roles`, a derived `isAdmin` flag, and a username (falling back through `preferred_username`, `email`, and `sub`) to localStorage. The keys (`ID_TOKEN`, `KEYCLOAK_INFO`, `USERNAME`, `ISADMIN`) live in [`src/utils/config/defaults.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/config/defaults.js); the `KEYCLOAK_INFO` name is historical and reused for all OIDC providers, including Authentik.
+
+[`src/utils/auth/getApiAuthHeader.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/auth/getApiAuthHeader.js) builds the Authorization header for every internal API call. It does a client-side `exp` check and returns `null` for missing or expired tokens, so the next request triggers a fresh login rather than a 401.
+
+[`src/utils/IsVisibleToUser.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/IsVisibleToUser.js) reads `KEYCLOAK_INFO` when evaluating `showForKeycloakUsers` and `hideForKeycloakUsers` rules.
+
+### Server side
+
+[`services/auth-oidc.js`](https://github.com/lissy93/dashy/blob/4.1.5/services/auth-oidc.js) contains the entire server-side auth surface, in five small pieces:
+
+- `loadOidcSettings()` reads `auth.oidc` (or `auth.keycloak`) at boot and returns a normalised `{ issuer, clientId, adminGroup, adminRole }`. For generic OIDC providers the `issuer` is whatever you set as `endpoint` in `conf.yml`, verbatim
+- `createOidcMiddleware()` returns a Connect middleware. Permissive on no-token requests so the SPA can bootstrap; otherwise it verifies the Bearer token against the issuer's JWKS using [`jose`](https://github.com/panva/jose). Checks cover signature, issuer (against the canonical value from the discovery doc), audience (must equal `clientId`), and expiry, with a 30-second clock-skew tolerance. Sets `req.auth = { user, isAdmin, claims }` on success, `401` on failure
+- `getIssuerContext()` lazily fetches `.well-known/openid-configuration` on first use and wraps `jwks_uri` in `createRemoteJWKSet`, which handles JWKS caching and on-demand key rotation. The result is memoised per-issuer for the life of the process
+- `deriveIsAdmin()` checks the token's `groups` claim against `adminGroup`, and the `realm_access.roles` / `resource_access.<clientId>.roles` arrays against `adminRole`. Authentik only emits `groups`, so the group path is what's used in practice
+- `maybeBootstrapConfig()` is the stripped-response helper. When auth is configured, guest access is off, and an unauthenticated request hits the root `/conf.yml`, it returns a minimal copy with only `appConfig.auth`, `appConfig.enableServiceWorker`, and a `pageInfo.title` of `Login | <your title>`. Sections, items, hostnames and any other secrets never leave the server
+
+[`services/app.js`](https://github.com/lissy93/dashy/blob/4.1.5/services/app.js) wires it all together. The middleware mounts as `protectConfig` in front of every YAML route and config-mutating route. The `/*.yml` handler sets `Cache-Control: private, no-store` and `Vary: Authorization` whenever auth is configured (so intermediate caches can never mix auth states), then calls `maybeBootstrapConfig`; a stripped result is sent as-is, otherwise `res.sendFile` serves the full file. `POST /config-manager/save` is additionally guarded by `requireAdmin`, which returns `401` if `req.auth` is unset and `403` if `req.auth.isAdmin` is false.
+
+### Visual Overview
+
+<details>
+
+<summary>End-to-end authentication flow</summary>
+
+```mermaid
+sequenceDiagram
+ autonumber
+ actor User
+ participant Browser as Browser (Dashy SPA)
+ participant Dashy as Dashy Server
+ participant AK as Authentik
+
+ Note over Browser,Dashy: 1. Bootstrap (no token yet)
+ User->>Browser: Open Dashy
+ Browser->>Dashy: GET /conf.yml
+ Dashy-->>Browser: 200 stripped conf<br/>(auth block + minimal pageInfo)
+ Browser->>Browser: Parse auth.oidc
+
+ Note over Browser,AK: 2. OIDC login (Authorization Code + PKCE)
+ Browser->>AK: 302 /application/o/authorize/<br/>client_id, code_challenge, redirect_uri
+ User->>AK: Submit credentials
+ AK-->>Browser: 302 back with ?code=AUTH_CODE
+ Browser->>AK: POST /application/o/token/<br/>(code + code_verifier)
+ AK-->>Browser: id_token + access_token
+ Browser->>Browser: Store tokens in localStorage<br/>hard reload to /
+
+ Note over Browser,Dashy: 3. Authenticated read
+ Browser->>Dashy: GET /conf.yml<br/>Authorization: Bearer id_token
+ Dashy->>AK: Fetch discovery + JWKS<br/>(lazy on first call, then cached)
+ AK-->>Dashy: openid-configuration + JWKS
+ Dashy->>Dashy: Verify signature / issuer / audience / expiry
+ Dashy-->>Browser: 200 full conf.yml
+
+ Note over Browser,Dashy: 4. Write request (admin only)
+ Browser->>Dashy: POST /config-manager/save<br/>Authorization: Bearer id_token
+ Dashy->>Dashy: Verify token, derive isAdmin from<br/>adminGroup claim
+ alt isAdmin
+ Dashy-->>Browser: 200 saved
+ else not admin
+ Dashy-->>Browser: 403 Forbidden
+ end
+```
+
+</details>
+
+
+<details>
+
+<summary>Server-side request handling</summary>
+
+```mermaid
+flowchart TD
+ Req([Incoming request to Dashy server])
+ Req --> Bearer{Authorization:<br/>Bearer present?}
+
+ Bearer -- No --> NoAuth[req.auth unset<br/>pass through]:::neutral
+ Bearer -- Yes --> Verify[/Verify JWT against cached JWKS:<br/>signature Β· issuer Β· audience Β· expiry/]
+ Verify --> Valid{Valid?}
+ Valid -- No --> R401Bad[/401 Unauthorized/]:::err
+ Valid -- Yes --> SetAuth[req.auth = user + isAdmin<br/>derived from claims]:::ok
+
+ NoAuth --> Route{Endpoint}
+ SetAuth --> Route
+
+ Route -- "GET /conf.yml" --> ConfGate{req.auth?}
+ ConfGate -- No --> Strip[/200 stripped conf<br/>auth + minimal pageInfo/]:::ok
+ ConfGate -- Yes --> Full[/200 full conf.yml/]:::ok
+
+ Route -- "POST /config-manager/save" --> SaveGate{req.auth<br/>and isAdmin?}
+ SaveGate -- No req.auth --> R401Save[/401 Unauthorized/]:::err
+ SaveGate -- Not admin --> R403[/403 Forbidden/]:::err
+ SaveGate -- Admin --> Saved[/200 saved/]:::ok
+
+ classDef ok fill:#bbf7d0,stroke:#16a34a,color:#14532d
+ classDef err fill:#fecaca,stroke:#dc2626,color:#7f1d1d
+ classDef neutral fill:#dbeafe,stroke:#2563eb,color:#1e3a8a
+```
+
+</details>
diff --git a/docs/authentication/cloudflare-tunnel.md b/docs/authentication/cloudflare-tunnel.md
new file mode 100644
index 00000000..3a5986e9
--- /dev/null
+++ b/docs/authentication/cloudflare-tunnel.md
@@ -0,0 +1,290 @@
+# Cloudflare Tunnel + Access for Dashy
+
+Dashy works well behind [Cloudflare Tunnel](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/) with [Cloudflare Access](https://developers.cloudflare.com/cloudflare-one/policies/access/) doing auth at the edge. This is one of the most common ways to expose a homelab dashboard to the public internet without opening any inbound ports, without managing TLS, and without standing up your own identity provider.
+
+The flow: Cloudflare authenticates the user (via Google, GitHub, email OTP, etc.) at the edge, signs an identity into request headers, and forwards the request to a `cloudflared` daemon you run on your network. `cloudflared` proxies to Dashy. Dashy reads the email from the header and matches the user against its config.
+
+### Contents
+
+- [1. How it fits together](#1-how-it-fits-together)
+- [2. Create the tunnel in Cloudflare](#2-create-the-tunnel-in-cloudflare)
+- [3. Run cloudflared](#3-run-cloudflared)
+- [4. Add a Cloudflare Access policy](#4-add-a-cloudflare-access-policy)
+- [5. Configure Dashy](#5-configure-dashy)
+- [6. Best practices](#6-best-practices)
+- [Troubleshooting](#troubleshooting-common-cloudflare-tunnel-issues)
+- [How it Works](#how-it-works)
+
+## 1. How it fits together
+
+Three Cloudflare pieces, plus Dashy on your side:
+- Cloudflare Tunnel exposes Dashy to the public internet over an outbound-only connection. No port forwarding, no inbound firewall rules
+- Cloudflare Access sits in front of the tunnel and enforces an identity policy. Anyone reaching the tunnel has already authenticated to Cloudflare
+- `cloudflared` is the daemon you run alongside Dashy. It dials out to Cloudflare and forwards authenticated requests to Dashy's local port
+- Dashy's header auth reads the email Cloudflare sets in `Cf-Access-Authenticated-User-Email` and matches it to a user
+
+```mermaid
+architecture-beta
+ group cloudflare(cloud)[Cloudflare]
+ group homelab(server)[Your network]
+
+ service user(internet)[User]
+ service access(cloud)[Access policy] in cloudflare
+ service tunnel(server)[cloudflared] in homelab
+ service dashy(server)[Dashy] in homelab
+
+ user:R --> L:access
+ access:R --> L:tunnel
+ tunnel:R --> L:dashy
+```
+
+
+You need:
+- A Cloudflare account
+- A domain on Cloudflare (any TLD, free plan is fine)
+- Docker (or any way to run `cloudflared`)
+- Free tier covers up to 50 Access users
+
+## 2. Create the tunnel in Cloudflare
+
+Cloudflare's dashboard handles most of this.
+
+1. Go to [Zero Trust dashboard](https://one.dash.cloudflare.com)
+2. Open **Networks > Tunnels**
+3. Click **Create a tunnel**
+4. Pick **Cloudflared** as the connector, click **Next**
+5. Name it (e.g. `homelab`), click **Save tunnel**
+6. Copy the **tunnel token** shown on the install screen. You'll paste this into Docker compose in the next step. Keep it secret, it grants tunnel access
+7. Click **Next** without installing the package on the host (Docker is easier)
+8. Add a **Public hostname**:
+ - **Subdomain**: e.g. `dashy`
+ - **Domain**: your Cloudflare domain
+ - **Type**: `HTTP`
+ - **URL**: `dashy:8080` (the in-network service name + port Dashy listens on)
+9. Click **Save**
+
+Cloudflare now routes `https://dashy.example.com` through the tunnel to your `cloudflared` daemon, which forwards to `dashy:8080` on whatever Docker network they share.
+
+## 3. Run cloudflared
+
+A minimal compose with Dashy + `cloudflared` together:
+
+<details>
+ <summary>Example <code>docker-compose.yml</code></summary>
+
+```yaml
+name: dashy-cfaccess
+
+services:
+ cloudflared:
+ image: cloudflare/cloudflared:latest
+ restart: unless-stopped
+ command: tunnel --no-autoupdate run
+ environment:
+ TUNNEL_TOKEN: ${CLOUDFLARE_TUNNEL_TOKEN}
+ depends_on:
+ dashy:
+ condition: service_healthy
+
+ dashy:
+ image: lissy93/dashy:4.1.5
+ restart: unless-stopped
+ environment:
+ NODE_ENV: production
+ HOST: 0.0.0.0
+ PORT: 8080
+ volumes:
+ - ./user-data:/app/user-data
+ healthcheck:
+ test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/healthz >/dev/null 2>&1"]
+ interval: 10s
+ timeout: 5s
+ retries: 10
+ start_period: 30s
+```
+
+</details>
+
+Set the token via env or a `.env` file alongside the compose:
+
+```env
+CLOUDFLARE_TUNNEL_TOKEN=eyJhIjoiMDF...rest-of-token
+```
+
+Bring it up:
+
+```bash
+docker compose up -d
+```
+
+Notice what's not in the compose: Dashy has no `ports:` mapping. It's only reachable from inside the Docker network, which means only `cloudflared` can talk to it. That's the first half of the security model.
+
+## 4. Add a Cloudflare Access policy
+
+Without Access, the tunnel is open to anyone who knows the URL. Add a policy so Cloudflare enforces auth at the edge.
+
+1. In Zero Trust, open **Access > Applications**
+2. Click **Add an application**
+3. Choose **Self-hosted**
+4. Set **Application name** to `Dashy`
+5. Set **Session duration** to whatever feels right (e.g. 24 hours)
+6. Under **Application domain**, pick the subdomain and domain you used in step 2 (`dashy.example.com`)
+7. Click **Next**
+8. Add a policy:
+ - **Policy name**: `Trusted users`
+ - **Action**: `Allow`
+ - **Include**: `Emails ending in @example.com`, or `Emails` with specific addresses, or `Everyone` for open access
+9. Optionally add a second policy for admins with stricter rules
+10. Click **Next** and **Add application**
+
+Cloudflare now bounces anyone visiting `https://dashy.example.com` to its login page first, only forwarding the request after auth.
+
+## 5. Configure Dashy
+
+In `/user-data/conf.yml`:
+
+```yaml
+appConfig:
+ ...
+ disableConfigurationForNonAdmin: true
+ auth:
+ enableHeaderAuth: true
+ users:
+ hash: "0000000000000000000000000000000000000000000000000000000000000000"
+ type: admin
+ hash: "0000000000000000000000000000000000000000000000000000000000000000"
+ type: normal
+ headerAuth:
+ userHeader: Cf-Access-Authenticated-User-Email
+ proxyWhitelist:
+ - 172.18.0.2
+```
+
+Where:
+- `enableHeaderAuth` - Turns on header auth mode
+- `users` - Required. The email the proxy sends must match `user` here for the user to be admitted. The `type` field controls admin status in Dashy
+- `hash` - Required by Dashy's user schema even though the password is never checked under header auth. Quote it to stop YAML parsing the all-zero placeholder as the number 0
+- `userHeader` - The header Cloudflare Access sets after a user authenticates. Matches case-insensitively
+- `proxyWhitelist` - Required. The IP `cloudflared` connects from. Find it with `docker compose exec dashy getent hosts cloudflared` or check `docker network inspect`. This is the single biggest control: requests from any other IP get 401 before headers are even read
+
+Restart Dashy after editing.
+
+Open `https://dashy.example.com`. Cloudflare bounces you to its login page, you authenticate, and you land on the Dashy dashboard auto-logged-in as that email.
+
+## 6. Best practices
+
+- Don't bind Dashy's port to the host. Only `cloudflared` should reach it, which is the case if you leave the `ports:` block out of the dashy service
+- Treat the tunnel token as a credential. Anyone with it can connect a `cloudflared` to your tunnel and impersonate it
+- Set `proxyWhitelist` to the smallest possible set of IPs. For Docker compose that's typically just the one `cloudflared` container address
+- Pin `cloudflared` to a version tag in production rather than `:latest`. Cloudflare updates the daemon often
+- Configure Access policies before public release. A tunnel without an Access policy is wide open
+- Use Access groups in the dashboard for "who is an admin" rather than relying solely on Dashy's `type: admin`, so identity changes don't require redeploying Dashy
+- For machine-to-machine access (CI, healthchecks, monitoring), use Access [Service Tokens](https://developers.cloudflare.com/cloudflare-one/identity/service-tokens/) and a separate bypass policy keyed on the token. Don't try to share user credentials
+- If Dashy and `cloudflared` aren't on the same Docker network, force them on one with an explicit `networks:` block
+
+## Troubleshooting common Cloudflare Tunnel issues
+
+#### 401 Unauthorized from Dashy after the Cloudflare login screen
+Problem: You authenticate at Cloudflare, get redirected to Dashy, but see "Unauthorized - not from trusted proxy".<br>
+Solution: `proxyWhitelist` doesn't include `cloudflared`'s container IP. Run `docker compose exec dashy getent hosts cloudflared` to find it, paste that IP into `proxyWhitelist`, restart Dashy.
+
+#### "Unauthorized - missing user header"
+Problem: Server logs show that header auth ran but the user header was empty.<br>
+Solution: The request reached Dashy from a trusted IP but without `Cf-Access-Authenticated-User-Email`. This usually means the tunnel doesn't have an Access policy in front of it, so traffic is reaching Dashy unauthenticated. Open the Access application in Zero Trust and confirm there's at least one policy attached.
+
+#### User logs in but admin features stay locked
+Problem: You authenticate, the dashboard renders, but Save Config and other admin actions are disabled.<br>
+Solution: The email Cloudflare sends must exactly match a `users[].user` entry with `type: admin`. Check the JWT in `Cf-Access-Jwt-Assertion` (decode at [jwt.io](https://jwt.io)) to see the actual email Cloudflare is sending. Often a personal Google account vs work account mismatch.
+
+#### Loop or repeated redirects to the Cloudflare login page
+Problem: Each refresh bounces back through Cloudflare's login.<br>
+Solution: Session cookies are being blocked or stripped. Check that the tunnel's public hostname uses HTTPS (it does by default), that no upstream proxy strips third-party cookies, and that the Access application's session duration is non-zero.
+
+#### "Critical Configuration Load Error" on first load
+Problem: SPA errors out before showing the dashboard.<br>
+Solution: Usually a CORS or network reachability issue, but for Cloudflare Tunnel this is most often a `cloudflared` to `dashy` networking problem inside Docker. `docker compose logs cloudflared` will show connection attempts. Confirm both services are on the same Docker network and that the tunnel's public hostname URL matches the service name and port (e.g. `dashy:8080`, not `localhost:8080`).
+
+#### cloudflared can't connect to the tunnel
+Problem: `cloudflared` keeps logging connection errors.<br>
+Solution: Check the token. Tokens are tunnel-specific, and rotating one in the dashboard invalidates the previous one. If you recreated the tunnel, paste the new token into `.env` and restart.
+
+#### Schema warning "hash must be string" on Dashy startup
+Problem: Dashy logs warn about user hashes not being strings.<br>
+Solution: YAML parsed an all-zeros (or all-digit) hash as a number. Wrap the value in quotes: `hash: "0000..."` rather than `hash: 0000...`.
+
+#### Want to bypass Cloudflare Access for automation
+Problem: A monitoring or CI agent needs to hit `/healthz` or scrape Dashy, but Cloudflare Access blocks it.<br>
+Solution: In the Access application, add a Service Token, then create a Bypass policy keyed on that token. The agent sends `Cf-Access-Client-Id` and `Cf-Access-Client-Secret` headers to authenticate as a machine. Don't share user logins.
+
+---
+
+## How it Works
+
+### Server side
+
+When Dashy has `enableHeaderAuth: true`, [`services/app.js`](https://github.com/lissy93/dashy/blob/4.1.5/services/app.js) installs a small middleware in front of every API and asset route. The middleware does two things per request:
+
+- Check `req.socket.remoteAddress` against `proxyWhitelist`. If the source IP isn't in the list, return 401 immediately. The header is never even inspected
+- Read the header named by `userHeader` (case-insensitive). If empty, return 401. Otherwise set `req.auth = { user: <email> }` and let the request through
+
+The IP check is the security boundary. Cloudflare adds `Cf-Access-Authenticated-User-Email` only after a successful Access policy match, and `cloudflared` is the only thing that can talk to Dashy (no exposed port). So the only way that header can be set on a request reaching Dashy is via the Cloudflare to cloudflared to dashy path, after a real Cloudflare Access authentication.
+
+The SPA fetches `/get-user` once on load, which returns whatever email the server saw. The client-side code in [`src/utils/auth/HeaderAuth.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/auth/HeaderAuth.js) matches that email against the configured `users[]` to determine `type: admin` vs `normal`, then sets the session cookie. The route guard in [`src/router.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/router.js) skips its usual `/login` bounce when `enableHeaderAuth` is on, since the SPA can't tell "not logged in" from "header auth still resolving" and the server is authoritative anyway.
+
+#### Server-side auth middleware
+
+```mermaid
+flowchart LR
+ Req([Request reaches Dashy]) --> IP{Source IP in<br/>proxyWhitelist?}
+ IP -- No --> R401a[/401 Unauthorized<br/>not from trusted proxy/]:::err
+ IP -- Yes --> Hdr{User header<br/>present?}
+ Hdr -- No --> R401b[/401 Unauthorized<br/>missing user header/]:::err
+ Hdr -- Yes --> Pass[/Set req.auth = email<br/>continue to route handler/]:::ok
+
+ classDef ok fill:#bbf7d0,stroke:#16a34a,color:#14532d
+ classDef err fill:#fecaca,stroke:#dc2626,color:#7f1d1d
+```
+
+
+<details>
+
+<summary>End-to-end authentication flow</summary>
+
+```mermaid
+sequenceDiagram
+ autonumber
+ actor User
+ participant Browser as Browser
+ participant CF as Cloudflare Edge
+ participant Tunnel as cloudflared (your network)
+ participant Dashy as Dashy
+
+ Note over User,CF: 1. First visit
+ User->>Browser: Open https://dashy.example.com
+ Browser->>CF: GET /
+ CF->>CF: No Access session cookie
+
+ Note over CF,User: 2. Access auth at the edge
+ CF-->>Browser: 302 to Access login
+ User->>CF: Authenticate (Google / GitHub / OTP / etc)
+ CF->>CF: Check Access policy
+ CF-->>Browser: 302 back to /, sets CF_Authorization cookie
+
+ Note over Browser,Dashy: 3. Authenticated request reaches Dashy
+ Browser->>CF: GET / (with CF_Authorization)
+ CF->>Tunnel: Forward, add headers:<br/>Cf-Access-Authenticated-User-Email<br/>Cf-Access-Jwt-Assertion
+ Tunnel->>Dashy: Proxy to dashy:8080
+ Dashy->>Dashy: Check req.socket.remoteAddress in proxyWhitelist<br/>Read user header, set req.auth
+ Dashy-->>Tunnel: 200 + SPA
+ Tunnel-->>CF: 200
+ CF-->>Browser: 200
+
+ Note over Browser,Dashy: 4. SPA auto-login
+ Browser->>Dashy: GET /get-user
+ Dashy-->>Browser: { user: "[email protected]" }
+ Browser->>Browser: Match email to users[], set cookie,<br/>render dashboard with right admin level
+```
+
+</details>
diff --git a/docs/authentication/keycloak.md b/docs/authentication/keycloak.md
new file mode 100644
index 00000000..30bc0e24
--- /dev/null
+++ b/docs/authentication/keycloak.md
@@ -0,0 +1,479 @@
+# Keycloak Authentication for Dashy
+
+Dashy supports using a [Keycloak](https://www.keycloak.org/) (V17+) authentication server.
+
+[Keycloak](https://www.keycloak.org/about.html) is a Java-based [open source](https://github.com/keycloak/keycloak), high-performance, secure authentication system, supported by [RedHat](https://www.redhat.com/en). It can be deployed with Docker, and enables you to secure multiple self-hosted applications with single-sign-on using standard protocols (OpenID Connect, OAuth 2.0, SAML 2.0 and social login).
+
+### Contents
+
+- [1. Deploy Keycloak](#1-deploy-keycloak)
+- [2. Configure Keycloak](#2-configure-keycloak)
+- [3. Enabling Keycloak in Dashy](#3-enabling-keycloak-in-dashy)
+- [4. Groups and Roles](#4-groups-and-roles)
+- [Troubleshooting](#troubleshooting-common-keycloak-issues)
+- [How it Works](#how-it-works)
+
+## 1. Deploy Keycloak
+
+If you've not already done so, spin up a Keycloak instance.
+You can do this by following the [Keycloak Docs](https://www.keycloak.org/guides.html#getting-started), or use the following Docker examples:
+
+```bash
+docker run -d \
+ -p 9100:8080 \
+ --name keycloak \
+ -e KEYCLOAK_ADMIN=kc-admin \
+ -e KEYCLOAK_ADMIN_PASSWORD=KeycloakAdmin2026! \
+ quay.io/keycloak/keycloak:25.0 start-dev
+```
+
+<details>
+ <summary>Example <code>docker-compose.yml</code></summary>
+
+```env
+KEYCLOAK_ADMIN=kc-admin
+KEYCLOAK_ADMIN_PASSWORD=KeycloakAdmin2026!
+```
+
+```yaml
+name: dashy-keycloak
+services:
+ keycloak:
+ image: quay.io/keycloak/keycloak:25.0
+ command:
+ - start-dev
+ - --http-port=9100
+ - --hostname-strict=false
+ - --health-enabled=true
+ restart: unless-stopped
+ ports:
+ - "9100:9100"
+ - "4000:8080"
+ volumes:
+ - keycloak-data:/opt/keycloak/data
+ environment:
+ KEYCLOAK_ADMIN: ${KEYCLOAK_ADMIN}
+ KEYCLOAK_ADMIN_PASSWORD: ${KEYCLOAK_ADMIN_PASSWORD}
+ KC_HTTP_ENABLED: "true"
+ KC_HOSTNAME_STRICT: "false"
+ KC_HEALTH_ENABLED: "true"
+ healthcheck:
+ test: ["CMD-SHELL", "timeout 2 bash -c '</dev/tcp/127.0.0.1/9100'"]
+ start_period: 30s
+ interval: 10s
+ timeout: 5s
+ retries: 15
+
+ dashy:
+ image: lissy93/dashy:4.1.0
+ network_mode: service:keycloak
+ restart: unless-stopped
+ depends_on:
+ keycloak:
+ condition: service_healthy
+ environment:
+ NODE_ENV: production
+ HOST: 0.0.0.0
+ PORT: 8080
+ volumes:
+ - ./user-data:/app/user-data
+ healthcheck:
+ test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/healthz >/dev/null 2>&1"]
+ start_period: 30s
+ interval: 10s
+ timeout: 5s
+ retries: 15
+
+volumes:
+ keycloak-data:
+```
+
+</details>
+
+You should now be able to access the Keycloak web interface at `http://127.0.0.1:9100`, log in with your admin credentials above, and create a new password when prompted.
+
+---
+
+## 2. Configure Keycloak
+
+### Create the Keycloak realm
+1. Open `http://localhost:9100`.
+2. Click **Administration Console**.
+3. Log in as `kc-admin`.
+4. Open the realm selector in the top-left.
+5. Click **Create realm**.
+6. Set **Realm name** to `dashy`.
+7. Click **Create**.
+
+### Allow Dashy's local origin
+1. In the `dashy` realm, open **Realm settings**.
+2. Open **Security defenses**.
+3. Open **Headers**.
+4. Clear **X-Frame-Options**.
+5. Set **Content-Security-Policy** to:
+
+```text
+frame-src 'self' http://localhost:4000 http://127.0.0.1:4000; frame-ancestors 'self' http://localhost:4000 http://127.0.0.1:4000; object-src 'none';
+```
+
+6. Click **Save**.
+
+### Create the Dashy client
+1. In the `dashy` realm, open **Clients**.
+2. Click **Create client**.
+3. Set **Client type** to `OpenID Connect`.
+4. Set **Client ID** to `dashy`.
+5. Click **Next**.
+6. Turn **Client authentication** off. Dashy is a SPA using PKCE, so it must be a public client.
+7. Leave **Standard flow** on.
+8. Leave **Direct access grants** on or off; Dashy does not require it.
+9. Click **Next**.
+10. Set **Valid redirect URIs** to:
+ - `http://localhost:4000/*`
+ - `http://127.0.0.1:4000/*`
+11. Set **Valid post logout redirect URIs** to:
+ - `http://localhost:4000/*`
+ - `http://127.0.0.1:4000/*`
+12. Set **Web origins** to:
+ - `http://localhost:4000`
+ - `http://127.0.0.1:4000`
+13. Click **Save**.
+
+
+### Add the realm-role mapper
+
+Dashy uses `adminRole: dashy-admin` in `user-data/conf.yml`. For server-side admin checks to work, Keycloak must include realm roles in the ID token
+
+1. Open **Clients**
+2. Click the `dashy` client
+3. Open **Client scopes**
+4. Click the dedicated scope row, usually named `dashy-dedicated`
+5. Click **Add mapper**
+6. Click **By configuration**
+7. Select **User Realm Role**
+8. Set **Name** to `dashy-realm-roles`
+9. Set **Token Claim Name** to `realm_access.roles`
+10. Turn **Multivalued** on
+11. Turn **Add to ID token** on
+12. Turn **Add to access token** on
+13. Turn **Add to userinfo** on
+14. Click **Save**
+
+### Create the Dashy admin role
+1. In the `dashy` realm, open **Realm roles**
+2. Click **Create role**
+3. Set **Role name** to `dashy-admin`
+4. Click **Save**
+
+### (Alternative) Use a group for admin
+
+To grant admin via group membership instead of a realm role, add a second mapper of type *Group Membership* with claim name `groups`, create the group under *Groups*, assign your admin users to it, then set `adminGroup: <group-name>` (in place of `adminRole`) in your Dashy config later.
+
+### Create test users
+
+Create an admin user:
+1. Open **Users**
+2. Click **Add user**
+3. Set **Username** to `keycloak-admin`
+4. Set **Email verified** to on
+5. Set **First name** to `Keycloak`
+6. Set **Last name** to `Admin`
+7. Click **Create**
+8. Open the **Credentials** tab
+9. Click **Set password**
+10. Set a password, turn **Temporary** off, and save it
+11. Open the **Role mapping** tab
+12. Click **Assign role**
+13. Filter by realm roles, select `dashy-admin`, and assign it
+
+Create a normal user:
+1. Open **Users**
+2. Click **Add user**
+3. Set **Username** to `keycloak-user`
+4. Set **Email verified** to on
+5. Set **First name** to `Keycloak`
+6. Set **Last name** to `User`
+7. Click **Create**
+8. Open the **Credentials** tab
+9. Set a non-temporary password
+10. Do not assign `dashy-admin`
+
+### Summary
+
+Keycloak should now be configured, and ready to go!
+
+The Keycloak UI is not super intuitive, so if you're struggling to find where to configure any of the above options, below is a full start-to-end walkthrough video:
+
+https://github.com/user-attachments/assets/12b6a596-1ec6-453a-9ff7-d4e2c3aa69f7
+
+If you need to, you can make a backup of your Keycloak config, with their built-in backup tool. Something like:
+
+```bash
+docker compose run --rm --no-deps \
+ -v ./backup:/backup \
+ keycloak export \
+ --realm dashy \
+ --dir /backup \
+ --users realm_file \
+ --optimized
+```
+
+Here's an example of a configured [`dashy-realm.json`](https://github.com/user-attachments/files/27861822/dashy-realm.json) backup.
+
+---
+
+## 3. Enabling Keycloak in Dashy
+
+Finally, you need to tell Dashy to use the new Keycloak setup, and only allow access from authorized Keycloak users. This is done in the `appConfig.auth` section of your main `/user-data/conf.yml` file.
+
+As an example, you can view this [`conf.yml`](https://github.com/user-attachments/files/27861628/conf.yml), which is fully-configured with Keycloak auth using the info from the above steps.
+
+```yaml
+appConfig:
+ ...
+ disableConfigurationForNonAdmin: true
+ auth:
+ enableKeycloak: true
+ keycloak:
+ serverUrl: http://localhost:9100
+ realm: dashy
+ clientId: dashy
+ adminRole: dashy-admin
+```
+
+Where:
+- `disableConfigurationForNonAdmin` - Prevent read/write config access to non-admin Keycloak users
+- `auth.enableKeycloak` - Set the auth mode to Keycloak
+- `serverUrl` - The host (no paths) to your Keycloak instance, accessible from the Dashy container
+- `realm` - The name (case sensitive) of the Keycloak realm to use
+- `clientId` - Client ID that you created for Dashy
+- `adminRole` - The role name that grants admin
+- `adminGroup` - (Alternative to `adminRole`) Group name that grants admin
+- `idpHint` - (Optional) Alias of an external IdP federated through Keycloak; skips the Keycloak login page and redirects straight to that provider
+
+Note that a restart is required for these changes to take effect.
+
+If Keycloak runs on a different host or behind a reverse proxy, make sure `serverUrl` is reachable from inside the Dashy container, and that the realm's redirect URIs and Web Origins match Dashy's public URL.
+
+Everything should now be fully configured and working πŸŽ‰<br>
+Now, when you load Dashy, you'll be redirected to your Keycloak login page, after logging in you will then land back on Dashy's homepage with full access! All Dashy's client, server and asset endpoints will be blocked, and return a 403 until you are authenticated.
+
+---
+
+## 4. Groups and Roles
+
+Keycloak allows you to assign users roles and groups. Dashy supports using these roles, to configure who can access various sections or items in Dashy's frontend.
+
+For example, to make any given section only visible to admins, simply add the following to the section's `displayData` section:
+
+```yaml
+displayData:
+ showForKeycloakUsers:
+ roles:
+ - dashy-admin # ID of the admin role you created earlier
+```
+
+Keycloak server administration and configuration is a deep topic; please refer to the [server admin guide](https://www.keycloak.org/docs/latest/server_admin/index.html#assigning-permissions-and-access-using-roles-and-groups) to see details about creating and assigning roles and groups.
+
+Once you have groups or roles assigned to users you can configure access under each section or item `displayData.showForKeycloakUser` and `displayData.hideForKeycloakUser`.
+
+Both show and hide configurations accept a list of `groups` and `roles` that limit access. If a users data matches one or more items in these lists they will be allowed or excluded as defined.
+
+```yaml
+sections:
+ - name: DeveloperResources
+ displayData:
+ showForKeycloakUsers:
+ roles: ['canViewDevResources']
+ hideForKeycloakUsers:
+ groups: ['ProductTeam']
+ items:
+ - title: Not Visible for developers
+ displayData:
+ hideForKeycloakUsers:
+ groups: ['DevelopmentTeam']
+```
+
+---
+
+## Troubleshooting common Keycloak Issues
+
+#### Client Authentication Issue
+Problem: Redirect loop, if client authentication is enabled.<br>
+Solution: Switch off "Client authentication" in the dashy client's "Advanced" settings.
+
+#### Double URL
+Problem: If you get redirected to "https://dashy.my.domain/#iss=https://keycloak.my.domain/realms/dashy"<br>
+Solution: Turn on "Exclude Issuer From Authentication Response" in the dashy client's "Advanced" -> "OpenID Connect Compatibility Modes".
+
+#### Problems with multiple Dashy Pages
+Problem: Refreshing or logging out of dashy results in an "invalid_redirect_uri" error.<br>
+Solution: In the dashy client's "Access settings", set "Root URL" to https://dashy.my.domain/, and make sure the valid redirect URIs end in /*.
+
+#### 403 on login-status-iframe.html/init
+Problem: Browser console shows a 403 from Keycloak when the SPA loads.<br>
+Solution: Open the dashy client's "Web origins" and remove any trailing `/*`. Web Origins must be bare origins (e.g. http://localhost:4000), not http://localhost:4000/*.
+
+#### CSP error for /3p-cookies/step1.html or "Authentication failed (Keycloak)"
+Problem: The hidden Keycloak iframe is blocked by frame-ancestors.<br>
+Solution: In the dashy realm (not master), open Realm settings -> Security defenses -> Headers. Clear X-Frame-Options and set the Content-Security-Policy as described earlier in this section.
+
+#### Dashy server can't reach Keycloak
+Problem: SPA loads fine but every authenticated API call returns 401, and the Dashy server logs show `[auth-oidc] token verification failed` or fetch errors for `.well-known/openid-configuration`.<br>
+Solution: `serverUrl` must be reachable from inside the Dashy container, not just from the browser. In Docker, put both services on the same network and use the service name (e.g. `http://keycloak:8080`). Test with `docker exec <dashy-container> wget -qO- "$SERVER_URL/realms/dashy/.well-known/openid-configuration"`.
+
+#### Logged in but config saves return 403
+Problem: User authenticates fine, but saving the dashboard returns 403.<br>
+Solution: The id_token doesn't carry the admin claim. Confirm the *Add to ID token* toggle on the Step 2 mapper is on. Paste the token (from localStorage, key `ID_TOKEN`) into [jwt.io](https://jwt.io) and look for `realm_access.roles` (or `groups` if you're using `adminGroup`).
+
+#### Issuer mismatch behind a reverse proxy
+Problem: Server logs show `unexpected "iss" claim value`. The browser reaches Keycloak over HTTPS but Keycloak advertises an HTTP issuer in its discovery document.<br>
+Solution: Set `KC_HOSTNAME=<public-host>` on Keycloak so the issuer matches the public URL, and ensure your reverse proxy forwards `X-Forwarded-Proto: https`.
+
+#### Audience mismatch on token verification
+Problem: Server logs show `unexpected "aud" claim value`. Every auth'd API call returns 401.<br>
+Solution: `clientId` in `conf.yml` must exactly match the Keycloak client's Client ID. Check for trailing whitespace, case mismatches, or accidentally using the client's internal UUID instead of the Client ID string.
+
+#### Self-signed Keycloak certificate rejected
+Problem: Dashy server logs show TLS errors (`self-signed certificate`, `UNABLE_TO_VERIFY_LEAF_SIGNATURE`) when fetching JWKS or discovery.<br>
+Solution: Use a real certificate on Keycloak (Let's Encrypt, or your homelab CA), or mount your CA bundle into the Dashy container and set `NODE_EXTRA_CA_CERTS=/path/to/ca.pem`.
+
+#### Token expired / clock skew
+Problem: 401s with `"exp" claim timestamp check failed` or `"iat" claim timestamp check failed`, even just after login.<br>
+Solution: Dashy allows 30 seconds of drift. Sync clocks on both hosts with NTP. Container clocks follow their host, so it's almost always the host that's drifted.
+
+#### Mixed content blocked by the browser
+Problem: Dashy served over HTTPS, Keycloak over HTTP. The browser blocks the token or JWKS endpoint with a mixed-content error.<br>
+Solution: Terminate both behind HTTPS. For local testing, use HTTP on both, but never mix schemes in the same flow.
+
+#### Numeric Client ID truncated
+Problem: Token verification fails with audience mismatch when `clientId` in `conf.yml` is a long numeric string.<br>
+Solution: Wrap numeric Client IDs in quotes (e.g. `clientId: "12345678901234567"`). Without quotes YAML parses the value as a JS number and loses precision past about 15 digits.
+
+#### Logout lands on a broken page
+Problem: Clicking Logout in Dashy ends on a Keycloak error or 404 instead of returning to Dashy.<br>
+Solution: Add Dashy's URL to **Valid post logout redirect URIs** on the `dashy` client. Keycloak v18+ requires registered, exact-match post-logout URIs.
+
+#### check-sso hangs in strict browsers
+Problem: First load spins indefinitely. Browser console reports blocked third-party cookies. Common in Safari, Brave, or Firefox with strict tracking protection.<br>
+Solution: Serve Dashy and Keycloak under the same registrable domain (e.g. `dashy.example.com` and `auth.example.com`) so the session cookie is first-party.
+
+#### Config change to auth.keycloak not picked up
+Problem: Updated `serverUrl`, `realm`, `clientId`, `adminRole`, or `adminGroup` in `conf.yml`, but Dashy still authenticates against the old values.<br>
+Solution: The server reads the auth config only at boot. Restart the Dashy container after any change to fields under `auth.keycloak`.
+
+---
+
+## How it Works
+
+If you're a developer or contributor looking to understand or make changes to Dashy's Keycloak implementation, the following outlines how it's wired together.
+
+The same OIDC pipeline backs both Keycloak and generic OIDC providers. The only Keycloak-specific code is the SPA adapter, which uses `keycloak-js` so it can take advantage of `check-sso` and silent token renewal.
+
+### Client side
+
+Boot starts in [`src/main.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/main.js). After the initial `/conf.yml` fetch parses the auth block, `isKeycloakEnabled()` decides whether to lazily import `keycloak-js` and call `initKeycloakAuth()`.
+
+[`src/utils/auth/KeycloakAuth.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/auth/KeycloakAuth.js) wraps the adapter. On load it calls `keycloakClient.init({ onLoad: 'check-sso', responseMode: 'query' })`. If a Keycloak session already exists the user is silently authenticated; otherwise the SPA redirects to the login page with PKCE. On return, `storeKeycloakInfo()` persists the raw `id_token`, the user's `groups` and `roles`, `preferred_username`, and a derived `isAdmin` flag to localStorage, then hard-redirects to `/` so the SPA boots a second time with the Bearer token in place.
+
+[`src/utils/auth/getApiAuthHeader.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/auth/getApiAuthHeader.js) builds the Authorization header for every internal API call. It does a client-side `exp` check and returns `null` for missing or expired tokens, so the next request triggers a fresh login rather than a 401.
+
+The localStorage keys (`ID_TOKEN`, `KEYCLOAK_INFO`, `USERNAME`, `ISADMIN`) live in [`src/utils/config/defaults.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/config/defaults.js). [`src/utils/IsVisibleToUser.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/IsVisibleToUser.js) reads `KEYCLOAK_INFO` when evaluating `showForKeycloakUsers` and `hideForKeycloakUsers` rules.
+
+### Server side
+
+[`services/auth-oidc.js`](https://github.com/lissy93/dashy/blob/4.1.5/services/auth-oidc.js) contains the entire server-side auth surface, in five small pieces:
+
+- `loadOidcSettings()` reads `auth.keycloak` (or `auth.oidc`) at boot and returns a normalised `{ issuer, clientId, adminGroup, adminRole }`. For Keycloak the issuer is `<serverUrl>/realms/<realm>`.
+- `createOidcMiddleware()` returns a Connect middleware. Permissive on no-token requests so the SPA can bootstrap; otherwise it verifies the Bearer token against the realm's JWKS using [`jose`](https://github.com/panva/jose). Checks cover signature, issuer (against the canonical value from the discovery doc), audience (must equal `clientId`), and expiry, with a 30-second clock-skew tolerance. Sets `req.auth = { user, isAdmin, claims }` on success, `401` on failure.
+- `getIssuerContext()` lazily fetches `.well-known/openid-configuration` on first use and wraps `jwks_uri` in `createRemoteJWKSet`, which handles JWKS caching and on-demand key rotation. The result is memoised per-issuer for the life of the process.
+- `deriveIsAdmin()` checks the token's `groups` claim against `adminGroup`, and the union of `realm_access.roles` and `resource_access.<clientId>.roles` against `adminRole`. Either match returns true.
+- `maybeBootstrapConfig()` is the stripped-response helper. When auth is configured, guest access is off, and an unauthenticated request hits the root `/conf.yml`, it returns a minimal copy with only `appConfig.auth`, `appConfig.enableServiceWorker`, and a `pageInfo.title` of `Login | <your title>`. Sections, items, hostnames and any other secrets never leave the server.
+
+[`services/app.js`](https://github.com/lissy93/dashy/blob/4.1.5/services/app.js) wires it all together. The middleware mounts as `protectConfig` in front of every YAML route and config-mutating route. The `/*.yml` handler sets `Cache-Control: private, no-store` and `Vary: Authorization` whenever auth is configured (so intermediate caches can never mix auth states), then calls `maybeBootstrapConfig`; a stripped result is sent as-is, otherwise `res.sendFile` serves the full file. `POST /config-manager/save` is additionally guarded by `requireAdmin`, which returns `401` if `req.auth` is unset and `403` if `req.auth.isAdmin` is false.
+
+### Why the mapper matters
+
+The server's admin check reads from the `id_token` only. Keycloak's default mapper adds realm roles to the access token but not the id token, so without the Step 2 *Add to ID token* toggle, `realm_access.roles` is absent and every user is treated as non-admin. The same applies to `groups` if you use `adminGroup` instead. This is the single most common cause of "logged in fine, but can't save changes".
+
+### Visual Overview
+
+<details>
+
+<summary>End-to-end authentication flow</summary>
+
+```mermaid
+sequenceDiagram
+ autonumber
+ actor User
+ participant Browser as Browser (Dashy SPA)
+ participant Dashy as Dashy Server
+ participant KC as Keycloak
+
+ Note over Browser,Dashy: 1. Bootstrap (no token yet)
+ User->>Browser: Open Dashy
+ Browser->>Dashy: GET /conf.yml
+ Dashy-->>Browser: 200 stripped conf<br/>(auth block + minimal pageInfo)
+ Browser->>Browser: Parse auth.keycloak
+
+ Note over Browser,KC: 2. OIDC login (Authorization Code + PKCE)
+ Browser->>KC: 302 /realms/dashy/protocol/openid-connect/auth<br/>client_id, code_challenge, redirect_uri
+ User->>KC: Submit credentials
+ KC-->>Browser: 302 back with ?code=AUTH_CODE
+ Browser->>KC: POST /token (code + code_verifier)
+ KC-->>Browser: id_token + access_token + refresh_token
+ Browser->>Browser: Store tokens in localStorage
+
+ Note over Browser,Dashy: 3. Authenticated read
+ Browser->>Dashy: GET /conf.yml<br/>Authorization: Bearer id_token
+ Dashy->>KC: Fetch discovery + JWKS<br/>(lazy on first call, then cached)
+ KC-->>Dashy: openid-configuration + JWKS
+ Dashy->>Dashy: Verify signature / issuer / audience / expiry
+ Dashy-->>Browser: 200 full conf.yml
+
+ Note over Browser,Dashy: 4. Write request (admin only)
+ Browser->>Dashy: POST /config-manager/save<br/>Authorization: Bearer id_token
+ Dashy->>Dashy: Verify token, derive isAdmin from<br/>adminRole / adminGroup claims
+ alt isAdmin
+ Dashy-->>Browser: 200 saved
+ else not admin
+ Dashy-->>Browser: 403 Forbidden
+ end
+```
+
+</details>
+
+
+<details>
+
+<summary>Server-side request handling</summary>
+
+```mermaid
+flowchart TD
+ Req([Incoming request to Dashy server])
+ Req --> Bearer{Authorization:<br/>Bearer present?}
+
+ Bearer -- No --> NoAuth[req.auth unset<br/>pass through]:::neutral
+ Bearer -- Yes --> Verify[/Verify JWT against cached JWKS:<br/>signature Β· issuer Β· audience Β· expiry/]
+ Verify --> Valid{Valid?}
+ Valid -- No --> R401Bad[/401 Unauthorized/]:::err
+ Valid -- Yes --> SetAuth[req.auth = user + isAdmin<br/>derived from claims]:::ok
+
+ NoAuth --> Route{Endpoint}
+ SetAuth --> Route
+
+ Route -- "GET /conf.yml" --> ConfGate{req.auth?}
+ ConfGate -- No --> Strip[/200 stripped conf<br/>auth + minimal pageInfo/]:::ok
+ ConfGate -- Yes --> Full[/200 full conf.yml/]:::ok
+
+ Route -- "POST /config-manager/save" --> SaveGate{req.auth<br/>and isAdmin?}
+ SaveGate -- No req.auth --> R401Save[/401 Unauthorized/]:::err
+ SaveGate -- Not admin --> R403[/403 Forbidden/]:::err
+ SaveGate -- Admin --> Saved[/200 saved/]:::ok
+
+ classDef ok fill:#bbf7d0,stroke:#16a34a,color:#14532d
+ classDef err fill:#fecaca,stroke:#dc2626,color:#7f1d1d
+ classDef neutral fill:#dbeafe,stroke:#2563eb,color:#1e3a8a
+```
+
+</details>
diff --git a/docs/authentication/pocketid.md b/docs/authentication/pocketid.md
new file mode 100644
index 00000000..71950433
--- /dev/null
+++ b/docs/authentication/pocketid.md
@@ -0,0 +1,370 @@
+# Pocket ID Authentication for Dashy
+
+Dashy supports using [Pocket ID](https://pocket-id.org/) as its OIDC provider.
+
+[Pocket ID](https://pocket-id.org/) is a small [open source](https://github.com/pocket-id/pocket-id) identity provider built around passkeys. It's a single Go binary backed by SQLite (or Postgres if you want), no password storage, no email server needed for basic use. Popular in homelab setups where you want SSO across a handful of services without running Authentik or Keycloak.
+
+### Contents
+
+- [1. Deploy Pocket ID](#1-deploy-pocket-id)
+- [2. Configure Pocket ID](#2-configure-pocket-id)
+ - [First-time admin setup](#first-time-admin-setup)
+ - [Create the OIDC client](#create-the-oidc-client)
+ - [Create the admin group](#create-the-admin-group)
+ - [Create test users](#create-test-users)
+- [3. Enabling Pocket ID in Dashy](#3-enabling-pocket-id-in-dashy)
+- [4. Groups and Visibility](#4-groups-and-visibility)
+- [Troubleshooting](#troubleshooting-common-pocket-id-issues)
+- [How it Works](#how-it-works)
+ - [Client side](#client-side)
+ - [Server side](#server-side)
+ - [Visual Overview](#visual-overview)
+
+## 1. Deploy Pocket ID
+
+A minimal compose:
+
+<details>
+ <summary>Example <code>docker-compose.yml</code></summary>
+
+```yaml
+name: dashy-pocketid
+
+services:
+ pocket-id:
+ image: ghcr.io/pocket-id/pocket-id:v2.7.0
+ restart: unless-stopped
+ ports:
+ - "1411:1411"
+ environment:
+ APP_URL: http://localhost:1411
+ TRUST_PROXY: "false"
+ DB_PROVIDER: sqlite
+ DB_CONNECTION_STRING: /data/pocket-id.db
+ ENCRYPTION_KEY: "local-dev-key-32-bytes-padding!!"
+ volumes:
+ - ./data:/data
+ healthcheck:
+ test: ["CMD", "wget", "-qO-", "http://127.0.0.1:1411/healthz"]
+ interval: 10s
+ timeout: 5s
+ retries: 10
+ start_period: 30s
+```
+
+</details>
+
+A few things worth understanding before you start:
+
+- `APP_URL` is the URL the browser uses to reach Pocket ID. It must match exactly, since Pocket ID puts that value in the OIDC issuer, in cookie domains, and in the WebAuthn relying party
+- `ENCRYPTION_KEY` is required and must be at least 16 bytes. Generate a real one with `openssl rand -hex 32` for production; the example above is for local testing only
+- Pocket ID is passkey-only by default. Passkeys (WebAuthn) require a secure context, which means either HTTPS, or a literal `localhost` host. `pocketid.lvh.me` and similar lookalikes don't qualify, only the exact string `localhost`. For production use HTTPS with a real domain; for local testing stick to `http://localhost`
+
+For production:
+
+- Put Pocket ID behind a reverse proxy with HTTPS on a real domain
+- Set `APP_URL: https://auth.example.com`
+- Set `TRUST_PROXY: "true"` so it honours forwarded headers
+- Use a 32-byte random `ENCRYPTION_KEY`
+- Consider swapping `DB_PROVIDER` to `postgres` for redundancy
+
+Bring Pocket ID up:
+
+```bash
+docker compose up -d pocket-id
+```
+
+Wait for it to be healthy (`curl -sf http://localhost:1411/healthz`), then continue.
+
+---
+
+## 2. Configure Pocket ID
+
+### First-time admin setup
+
+There's no env-var bootstrap. You create the first admin through the UI, or via SQLite if you want to script it.
+
+Through the UI:
+
+1. Open `http://localhost:1411` in a browser
+2. The setup wizard prompts for a first admin (username, email, name)
+3. After creating the user, register a passkey when prompted
+
+If you can't easily register a passkey (no compatible device, or running headless), insert the admin user via SQLite and then use the CLI to get a one-time login URL:
+
+```bash
+docker compose exec pocket-id sh -c '
+ apk add --no-cache sqlite >/dev/null 2>&1
+ sqlite3 /data/pocket-id.db "
+ INSERT INTO users (id, created_at, updated_at, username, email, first_name, last_name, display_name, is_admin, email_verified)
+ VALUES (\"admin-uuid-001\", datetime(\"now\"), datetime(\"now\"), \"pocketid-admin\", \"[email protected]\", \"Pocket ID\", \"Admin\", \"Admin\", 1, 1);
+ "
+'
+
+docker compose exec pocket-id /app/pocket-id one-time-access-token pocketid-admin
+```
+
+The CLI prints a URL like `http://localhost:1411/lc/<token>`. Open it in a browser to log in. The token is single-use and expires in 1 hour. Once signed in, register a passkey under **Settings > Passkeys** so you don't need to keep generating OTA tokens.
+
+### Create the OIDC client
+
+1. Open **Admin > OIDC Clients**
+2. Click **Add OIDC Client**
+3. Set **Name** to `Dashy`
+4. Set **Callback URLs** to both:
+ - `http://localhost:4000`
+ - `http://localhost:4000/`
+5. Set **Logout Callback URLs** to `http://localhost:4000`
+6. Turn **Public Client** on
+7. Turn **PKCE** on
+8. Click **Save**
+
+Pocket ID generates a client ID (a UUID, e.g. `268a3701-e9ec-41f6-bad5-87c78ce87c94`). Copy it; you'll need it for Dashy's config.
+
+### Create the admin group
+
+1. Open **Admin > User Groups**
+2. Click **Add Group**
+3. Set **Name** to `Dashy admins` (or anything you like)
+4. Set **Friendly name** to `admins` (this is what Pocket ID emits in the OIDC `groups` claim, and what Dashy matches against)
+5. Click **Save**
+
+### Create test users
+
+1. Open **Admin > Users**
+2. Click **Add User**
+3. Fill in **Username**, **Email**, **First Name**, **Last Name**
+4. Save, then optionally open the user and assign them to the `admins` group via the **Groups** tab
+5. Either share the OTA URL (via the CLI command above) with the user, or have them set up a passkey on first sign-in
+
+### Summary
+
+Pocket ID should now have an OIDC client, an admin group, and at least one admin user in that group.
+
+---
+
+## 3. Enabling Pocket ID in Dashy
+
+In `/user-data/conf.yml`:
+
+```yaml
+appConfig:
+ ...
+ disableConfigurationForNonAdmin: true
+ auth:
+ enableOidc: true
+ oidc:
+ clientId: 268a3701-e9ec-41f6-bad5-87c78ce87c94
+ endpoint: http://localhost:1411
+ adminGroup: admins
+ scope: openid profile email groups
+```
+
+Where:
+- `disableConfigurationForNonAdmin` - Prevent read/write config access to non-admin users
+- `auth.enableOidc` - Set the auth mode to OIDC
+- `clientId` - The client ID from Pocket ID. It's a UUID, so no YAML quoting needed
+- `endpoint` - Pocket ID's `APP_URL`. Must match exactly. Dashy appends `/.well-known/openid-configuration` itself
+- `adminGroup` - The group's **friendly name** (not the display name) that grants admin in Dashy
+- `scope` - `groups` is needed for the `adminGroup` check. Pocket ID emits the claim by default when the scope is requested
+
+Restart Dashy after editing.
+
+If Pocket ID runs behind a reverse proxy, make sure `endpoint` and `APP_URL` agree, and that Dashy can reach `endpoint` from its container. With both services in Docker, you can either put them on the same network and use the service name, or use the host's exposed port.
+
+Everything should now be fully configured and working πŸŽ‰
+When you load Dashy, you'll be redirected to Pocket ID's sign-in page. Authenticate with your passkey (or paste a one-time code), and you'll land back on Dashy with full access. All of Dashy's client, server and asset endpoints will be locked behind authentication.
+
+---
+
+## 4. Groups and Visibility
+
+Once the `groups` claim is in the id_token, you can use it to hide or show pages, sections and items. The property name is `hideForKeycloakUsers` / `showForKeycloakUsers` (the name is historical; it works for any OIDC provider, including Pocket ID).
+
+To make an Admin section visible only to members of `admins`:
+
+```yaml
+displayData:
+ showForKeycloakUsers:
+ groups:
+ - admins
+```
+
+Both `showForKeycloakUsers` and `hideForKeycloakUsers` accept lists of `groups` and `roles`. If a user matches an entry they're allowed or excluded as defined.
+
+```yaml
+sections:
+ - name: Internal Tools
+ displayData:
+ showForKeycloakUsers:
+ groups: ['admins']
+ hideForKeycloakUsers:
+ groups: ['guests']
+ items:
+ - title: Hidden from interns
+ displayData:
+ hideForKeycloakUsers:
+ groups: ['interns']
+```
+
+---
+
+## Troubleshooting common Pocket ID issues
+
+#### Pocket ID won't start, "ENCRYPTION_KEY must be at least 16 bytes long"
+Problem: Container restarts on boot, logs show the encryption key error.<br>
+Solution: Set `ENCRYPTION_KEY` to a string of 16 characters or more. For production generate a real random one (`openssl rand -hex 32` gives you 64 hex chars).
+
+#### "WebAuthn is not supported in this browser"
+Problem: Browser console shows the WebAuthn error and passkey registration or login fails.<br>
+Solution: WebAuthn needs a secure context. Browsers grant this for HTTPS, or for the literal hostname `localhost`. `pocketid.lvh.me`, `127.0.0.1`, or anything else over HTTP won't qualify. For local testing, set `APP_URL: http://localhost:1411` and access Pocket ID via `http://localhost:1411`. For production, terminate HTTPS in front of Pocket ID.
+
+#### "Cookie 'session' has been rejected because a non-HTTPS cookie can't be set as 'secure'"
+Problem: Browser refuses to store Pocket ID's session cookie, so login appears to succeed but the next request comes back as not signed in.<br>
+Solution: Same root cause as the WebAuthn one. Pocket ID always sets cookies with the `Secure` flag, which browsers will only accept on HTTPS or on `localhost`. Switch to `http://localhost` or use HTTPS.
+
+#### One-time access token returns "Token is invalid or expired"
+Problem: The CLI gave you a URL, but visiting it returns the invalid/expired error.<br>
+Solution: OTA tokens are single-use and expire after 1 hour. If you've already used the URL or it's stale, generate a fresh one: `docker compose exec pocket-id /app/pocket-id one-time-access-token <username>`. The earlier "Cookie rejected as Secure" issue can also cause this to look like a token problem because the session cookie from the OTA exchange never persisted.
+
+#### Logged in but config saves return 403
+Problem: User authenticates fine, but saving the dashboard returns 403.<br>
+Solution: The `groups` claim isn't matching. Two things to check. First, that `adminGroup` in `conf.yml` equals the group's **friendly name**, not the display name. Second, that the user is actually in the group via **Admin > Users > [user] > Groups**. You can decode the id_token at [jwt.io](https://jwt.io) (take it from localStorage, key `ID_TOKEN`) to see what's in the claim.
+
+#### Redirect URI mismatch
+Problem: Pocket ID returns an `invalid_request` for the redirect URI on the authorize step.<br>
+Solution: Pocket ID matches callback URLs exactly. Register both the bare URL and the trailing-slash variant (`http://localhost:4000` and `http://localhost:4000/`) on the OIDC client, and make sure the scheme matches what Dashy is actually served on.
+
+#### Dashy server can't reach Pocket ID
+Problem: Auth'd API calls return 401 and Dashy logs show fetch errors for `.well-known/openid-configuration`.<br>
+Solution: `endpoint` must be reachable from inside the Dashy container. If both run in Docker, share a network and use service names, or use `network_mode: service:pocket-id` (then `localhost` inside Dashy resolves to Pocket ID). Test with `docker exec <dashy-container> wget -qO- "$ENDPOINT/.well-known/openid-configuration"`.
+
+#### Issuer mismatch on token verification
+Problem: Dashy server logs show `unexpected "iss" claim value`. The token's `iss` claim doesn't match Dashy's `endpoint`.<br>
+Solution: Pocket ID puts `APP_URL` straight into the issuer. Make sure `APP_URL`, `endpoint` in Dashy's `conf.yml`, and the URL the browser uses are all the same string (same scheme, host, and port).
+
+#### First admin can't sign in, no setup page appears
+Problem: Visiting Pocket ID just shows a login form, no setup wizard.<br>
+Solution: A previous Pocket ID instance may have created users in the database. Either log in as one of those users, or wipe `data/` and start fresh: `docker compose down && rm -rf data && docker compose up -d`. (The `data` dir is owned by the container user, so you may need sudo or use a throwaway container to clean up.)
+
+#### Token expired / clock skew
+Problem: 401s with `"exp" claim timestamp check failed`, even just after login.<br>
+Solution: Dashy allows 30 seconds of drift. Sync clocks (NTP) on both hosts. Container clocks follow their host, so it's almost always the host that's drifted.
+
+#### Config change to auth.oidc not picked up
+Problem: Updated `clientId`, `endpoint`, `adminGroup` or `scope` in `conf.yml`, but Dashy still uses the old values.<br>
+Solution: The server reads the auth config only at boot. Restart the Dashy container after any change to fields under `auth.oidc`.
+
+---
+
+## How it Works
+
+If you're a developer or contributor looking to understand or make changes to Dashy's OIDC implementation, the following outlines how it's wired together.
+
+The same OIDC pipeline backs Pocket ID, Authelia, Authentik, Keycloak, Zitadel, and any other generic OIDC provider. The only Pocket ID specific quirk is that it's passkey-first; everything on the Dashy side is shared.
+
+### Client side
+
+Boot starts in [`src/main.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/main.js). After the initial `/conf.yml` fetch parses the auth block, `isOidcEnabled()` decides whether to lazily import [`oidc-client-ts`](https://github.com/authts/oidc-client-ts) and call `initOidcAuth()`.
+
+[`src/utils/auth/OidcAuth.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/auth/OidcAuth.js) wraps `oidc-client-ts`. On load it inspects the URL: if it sees a `?code=` callback it runs `userManager.signinCallback()` to exchange the code (and PKCE verifier) for tokens, persists the user info, and hard-redirects to `/`. Otherwise it calls `userManager.getUser()`; if there's no usable session it falls through to `userManager.signinRedirect()` to send the browser to Pocket ID. A short-lived `sessionStorage` guard prevents the redirect loop that would otherwise occur if the IdP returns without a usable user.
+
+`persistUserInfo()` writes the raw `id_token`, the user's `groups` and `roles`, a derived `isAdmin` flag, and a username (falling back through `preferred_username`, `email`, and `sub`) to localStorage. The keys (`ID_TOKEN`, `KEYCLOAK_INFO`, `USERNAME`, `ISADMIN`) live in [`src/utils/config/defaults.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/config/defaults.js); the `KEYCLOAK_INFO` name is historical and reused for all OIDC providers, including Pocket ID.
+
+[`src/utils/auth/getApiAuthHeader.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/auth/getApiAuthHeader.js) builds the Authorization header for every internal API call. It does a client-side `exp` check and returns `null` for missing or expired tokens, so the next request triggers a fresh login rather than a 401.
+
+[`src/utils/IsVisibleToUser.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/IsVisibleToUser.js) reads `KEYCLOAK_INFO` when evaluating `showForKeycloakUsers` and `hideForKeycloakUsers` rules.
+
+### Server side
+
+[`services/auth-oidc.js`](https://github.com/lissy93/dashy/blob/4.1.5/services/auth-oidc.js) contains the entire server-side auth surface, in five small pieces:
+
+- `loadOidcSettings()` reads `auth.oidc` (or `auth.keycloak`) at boot and returns a normalised `{ issuer, clientId, adminGroup, adminRole }`. For generic OIDC providers the `issuer` is whatever you set as `endpoint` in `conf.yml`, verbatim
+- `createOidcMiddleware()` returns a Connect middleware. Permissive on no-token requests so the SPA can bootstrap; otherwise it verifies the Bearer token against the issuer's JWKS using [`jose`](https://github.com/panva/jose). Checks cover signature, issuer (against the canonical value from the discovery doc), audience (must equal `clientId`), and expiry, with a 30-second clock-skew tolerance. Sets `req.auth = { user, isAdmin, claims }` on success, `401` on failure
+- `getIssuerContext()` lazily fetches `.well-known/openid-configuration` on first use and wraps `jwks_uri` in `createRemoteJWKSet`, which handles JWKS caching and on-demand key rotation. The result is memoised per-issuer for the life of the process
+- `deriveIsAdmin()` checks the token's `groups` claim against `adminGroup`, and the `realm_access.roles` / `resource_access.<clientId>.roles` arrays against `adminRole`. Pocket ID emits `groups` natively, so the group path is what's used in practice
+- `maybeBootstrapConfig()` is the stripped-response helper. When auth is configured, guest access is off, and an unauthenticated request hits the root `/conf.yml`, it returns a minimal copy with only `appConfig.auth`, `appConfig.enableServiceWorker`, and a `pageInfo.title` of `Login | <your title>`. Sections, items, hostnames and any other secrets never leave the server
+
+[`services/app.js`](https://github.com/lissy93/dashy/blob/4.1.5/services/app.js) wires it all together. The middleware mounts as `protectConfig` in front of every YAML route and config-mutating route. The `/*.yml` handler sets `Cache-Control: private, no-store` and `Vary: Authorization` whenever auth is configured (so intermediate caches can never mix auth states), then calls `maybeBootstrapConfig`; a stripped result is sent as-is, otherwise `res.sendFile` serves the full file. `POST /config-manager/save` is additionally guarded by `requireAdmin`, which returns `401` if `req.auth` is unset and `403` if `req.auth.isAdmin` is false.
+
+### Visual Overview
+
+<details>
+
+<summary>End-to-end authentication flow</summary>
+
+```mermaid
+sequenceDiagram
+ autonumber
+ actor User
+ participant Browser as Browser (Dashy SPA)
+ participant Dashy as Dashy Server
+ participant P as Pocket ID
+
+ Note over Browser,Dashy: 1. Bootstrap (no token yet)
+ User->>Browser: Open Dashy
+ Browser->>Dashy: GET /conf.yml
+ Dashy-->>Browser: 200 stripped conf<br/>(auth block + minimal pageInfo)
+ Browser->>Browser: Parse auth.oidc
+
+ Note over Browser,P: 2. OIDC login (Authorization Code + PKCE)
+ Browser->>P: 302 /authorize<br/>client_id, code_challenge, redirect_uri
+ User->>P: Authenticate (passkey or one-time code)
+ P-->>Browser: 302 back with ?code=AUTH_CODE
+ Browser->>P: POST /api/oidc/token<br/>(code + code_verifier)
+ P-->>Browser: id_token + access_token<br/>(groups claim from user's groups)
+ Browser->>Browser: Store tokens in localStorage<br/>hard reload to /
+
+ Note over Browser,Dashy: 3. Authenticated read
+ Browser->>Dashy: GET /conf.yml<br/>Authorization: Bearer id_token
+ Dashy->>P: Fetch discovery + JWKS<br/>(lazy on first call, then cached)
+ P-->>Dashy: openid-configuration + JWKS
+ Dashy->>Dashy: Verify signature / issuer / audience / expiry
+ Dashy-->>Browser: 200 full conf.yml
+
+ Note over Browser,Dashy: 4. Write request (admin only)
+ Browser->>Dashy: POST /config-manager/save<br/>Authorization: Bearer id_token
+ Dashy->>Dashy: Verify token, derive isAdmin from<br/>adminGroup claim
+ alt isAdmin
+ Dashy-->>Browser: 200 saved
+ else not admin
+ Dashy-->>Browser: 403 Forbidden
+ end
+```
+
+</details>
+
+
+<details>
+
+<summary>Server-side request handling</summary>
+
+```mermaid
+flowchart TD
+ Req([Incoming request to Dashy server])
+ Req --> Bearer{Authorization:<br/>Bearer present?}
+
+ Bearer -- No --> NoAuth[req.auth unset<br/>pass through]:::neutral
+ Bearer -- Yes --> Verify[/Verify JWT against cached JWKS:<br/>signature Β· issuer Β· audience Β· expiry/]
+ Verify --> Valid{Valid?}
+ Valid -- No --> R401Bad[/401 Unauthorized/]:::err
+ Valid -- Yes --> SetAuth[req.auth = user + isAdmin<br/>derived from claims]:::ok
+
+ NoAuth --> Route{Endpoint}
+ SetAuth --> Route
+
+ Route -- "GET /conf.yml" --> ConfGate{req.auth?}
+ ConfGate -- No --> Strip[/200 stripped conf<br/>auth + minimal pageInfo/]:::ok
+ ConfGate -- Yes --> Full[/200 full conf.yml/]:::ok
+
+ Route -- "POST /config-manager/save" --> SaveGate{req.auth<br/>and isAdmin?}
+ SaveGate -- No req.auth --> R401Save[/401 Unauthorized/]:::err
+ SaveGate -- Not admin --> R403[/403 Forbidden/]:::err
+ SaveGate -- Admin --> Saved[/200 saved/]:::ok
+
+ classDef ok fill:#bbf7d0,stroke:#16a34a,color:#14532d
+ classDef err fill:#fecaca,stroke:#dc2626,color:#7f1d1d
+ classDef neutral fill:#dbeafe,stroke:#2563eb,color:#1e3a8a
+```
+
+</details>
diff --git a/docs/authentication/tailscale.md b/docs/authentication/tailscale.md
new file mode 100644
index 00000000..772e95d1
--- /dev/null
+++ b/docs/authentication/tailscale.md
@@ -0,0 +1,338 @@
+# Tailscale (and Headscale) for Dashy
+
+[Tailscale](https://tailscale.com/) is a popular way to put Dashy on a private network you can reach from your phone, laptop, or any other device you've added to your tailnet, without exposing it to the public internet. With Tailscale Serve in front, requests reaching Dashy already carry the user's identity in HTTP headers, which plugs straight into Dashy's header auth for auto-login.
+
+[Headscale](https://github.com/juanfont/headscale) is a self-hosted control plane that speaks the same protocol. Everything in this guide works with both. There's a short section near the end on what changes when you swap Tailscale's coordination server for your own Headscale instance.
+
+### Contents
+
+- [How it fits together](#how-it-fits-together)
+- [Prepare Tailscale](#prepare-tailscale)
+- [Run Tailscale + Dashy together](#run-tailscale--dashy-together)
+- [Configure Dashy](#configure-dashy)
+- [Funnel for public access](#funnel-for-public-access-optional)
+- [Using Headscale instead](#using-headscale-instead)
+- [Best practices](#best-practices)
+- [Troubleshooting](#troubleshooting-common-tailscale-issues)
+- [How it Works](#how-it-works)
+
+## How it fits together
+
+```mermaid
+architecture-beta
+ group homelab(server)[Your network]
+
+ service user(internet)[User device on tailnet]
+ service ts(server)[tailscaled] in homelab
+ service dashy(server)[Dashy] in homelab
+
+ user:R --> L:ts
+ ts:R --> L:dashy
+```
+
+The pieces:
+
+- `tailscaled` runs alongside Dashy, joins your tailnet, and obtains a free HTTPS cert for your tailnet hostname
+- Tailscale Serve terminates HTTPS and reverse-proxies to Dashy, adding `Tailscale-User-Login`, `Tailscale-User-Name`, and `Tailscale-User-Profile-Pic` headers describing the authenticated tailnet user
+- Dashy's header auth reads `Tailscale-User-Login` and matches it to a configured user
+- Traffic between user devices and your host runs over WireGuard, peer-to-peer where possible. Tailscale's control plane only mediates key exchange and routing, not the data itself
+
+You need:
+
+- A Tailscale account (free plan covers 100 devices and 3 users)
+- An auth key, generated in the admin console
+- Docker
+- MagicDNS and HTTPS certificates both enabled in your tailnet settings (both on by default)
+
+## Prepare Tailscale
+
+1. Sign in to [the Tailscale admin console](https://login.tailscale.com/admin)
+2. Open **DNS** and confirm **MagicDNS** is on, and **HTTPS Certificates** is on. Both are required for Tailscale Serve
+3. Open **Settings > Keys > Generate auth key**
+4. Pick **Reusable: no**, **Ephemeral: no**, **Pre-approved: yes**, optionally tag with `tag:container`
+5. Copy the key (`tskey-auth-...`). You'll paste it into a `.env` next to the compose file
+
+Note your tailnet's domain (something like `tail123abc.ts.net`). Your Dashy host will get a hostname under it once the container starts, e.g. `dashy.tail123abc.ts.net`.
+
+## Run Tailscale + Dashy together
+
+The Tailscale container shares its network namespace with Dashy, so the daemon listens on the tailnet and proxies to `127.0.0.1:8080` (Dashy in the same namespace).
+
+<details>
+ <summary>Example <code>docker-compose.yml</code></summary>
+
+```yaml
+name: dashy-tailscale
+
+services:
+ tailscale:
+ image: tailscale/tailscale:latest
+ hostname: dashy
+ restart: unless-stopped
+ environment:
+ TS_AUTHKEY: ${TS_AUTHKEY}?ephemeral=false
+ TS_STATE_DIR: /var/lib/tailscale
+ TS_SERVE_CONFIG: /config/serve.json
+ TS_USERSPACE: "false"
+ TS_EXTRA_ARGS: --advertise-tags=tag:container
+ volumes:
+ - ./ts-state:/var/lib/tailscale
+ - ./ts-config:/config
+ - /dev/net/tun:/dev/net/tun
+ cap_add:
+ - net_admin
+ - sys_module
+
+ dashy:
+ image: lissy93/dashy:4.1.5
+ restart: unless-stopped
+ network_mode: service:tailscale
+ environment:
+ NODE_ENV: production
+ HOST: 0.0.0.0
+ PORT: 8080
+ volumes:
+ - ./user-data:/app/user-data
+ depends_on:
+ tailscale:
+ condition: service_started
+ healthcheck:
+ test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/healthz >/dev/null 2>&1"]
+ interval: 10s
+ timeout: 5s
+ retries: 10
+ start_period: 30s
+```
+
+</details>
+
+`.env` next to the compose:
+
+```env
+TS_AUTHKEY=tskey-auth-xxx...
+```
+
+Then `ts-config/serve.json`:
+
+```json
+{
+ "TCP": {
+ "443": { "HTTPS": true }
+ },
+ "Web": {
+ "${TS_CERT_DOMAIN}:443": {
+ "Handlers": {
+ "/": { "Proxy": "http://127.0.0.1:8080" }
+ }
+ }
+ }
+}
+```
+
+`${TS_CERT_DOMAIN}` is substituted by the Tailscale container at runtime with the hostname it gets in your tailnet (e.g. `dashy.tail123abc.ts.net`).
+
+Bring it up:
+
+```bash
+docker compose up -d
+```
+
+The first run takes ~30 seconds while Tailscale joins the tailnet and provisions an HTTPS cert. After that, your tailnet name shows up in the admin console under **Machines**, and the URL becomes reachable from any device on the tailnet.
+
+Notice what's not in the compose: Dashy has no `ports:` mapping. It's only reachable through Tailscale, never directly.
+
+## Configure Dashy
+
+In `/user-data/conf.yml`:
+
+```yaml
+appConfig:
+ ...
+ disableConfigurationForNonAdmin: true
+ auth:
+ enableHeaderAuth: true
+ users:
+ hash: "0000000000000000000000000000000000000000000000000000000000000000"
+ type: admin
+ hash: "0000000000000000000000000000000000000000000000000000000000000000"
+ type: normal
+ headerAuth:
+ userHeader: Tailscale-User-Login
+ proxyWhitelist:
+ - 127.0.0.1
+```
+
+Where:
+- `enableHeaderAuth` - Turns on header auth mode
+- `users` - The email Tailscale sends in `Tailscale-User-Login` must match `user` here. `type` controls admin status in Dashy
+- `hash` - Required by Dashy's user schema even though the password is never checked under header auth. Quote it so YAML doesn't parse an all-zero placeholder as the number 0
+- `userHeader` - The header `tailscale serve` sets on every proxied request, containing the tailnet user's login (typically email)
+- `proxyWhitelist` - Just `127.0.0.1` because `tailscaled` and Dashy share a network namespace, so requests appear to come from localhost
+
+Restart Dashy after editing.
+
+Open `https://dashy.<your-tailnet>.ts.net` from any device on your tailnet. You'll land on the dashboard with the right admin level for your email. No login prompt.
+
+## Funnel for public access (optional)
+
+[Tailscale Funnel](https://tailscale.com/kb/1223/funnel) exposes a tailnet service to the public internet through Tailscale's edge. It uses the same daemon and config, you just flip a switch in `serve.json`:
+
+```json
+{
+ "TCP": {
+ "443": { "HTTPS": true }
+ },
+ "Web": {
+ "${TS_CERT_DOMAIN}:443": {
+ "Handlers": {
+ "/": { "Proxy": "http://127.0.0.1:8080" }
+ }
+ }
+ },
+ "AllowFunnel": {
+ "${TS_CERT_DOMAIN}:443": true
+ }
+}
+```
+
+You also need to enable Funnel under **Settings > Funnel** in the admin console and add your node to the allow-list.
+
+**Important caveat on auth:** Funnel requests come from the public internet, where the caller isn't a tailnet member. Tailscale doesn't inject identity headers on Funnel traffic, only on Serve traffic from authenticated tailnet peers. Header auth in Dashy would 401 every public visitor.
+
+For a publicly-exposed Dashy via Funnel, you have two options:
+
+- Use Dashy's [built-in HTTP auth](https://github.com/lissy93/dashy/blob/4.1.5/docs/authentication.md#http-auth) (`ENABLE_HTTP_AUTH=true` with users in `conf.yml`) so the browser prompts for credentials
+- Front Funnel with another auth layer, or just don't expose via Funnel and stick to Serve plus the Tailscale apps on the user's devices
+
+For a "Funnel only allows my tailnet users in, but they show up as authenticated" effect, use Serve, not Funnel. Funnel is for "I want anyone on the internet to reach this".
+
+## Using Headscale instead
+
+[Headscale](https://github.com/juanfont/headscale) is a self-hosted reimplementation of Tailscale's coordination server, compatible with the official Tailscale clients. Run your own and you don't depend on Tailscale's cloud for control-plane traffic.
+
+For Dashy, everything in this guide applies unchanged. The only differences are:
+
+- Point the `tailscaled` daemon at your Headscale server via the `TS_EXTRA_ARGS` env var:
+ ```yaml
+ TS_EXTRA_ARGS: --login-server=https://headscale.example.com --advertise-tags=tag:container
+ ```
+- Generate auth keys on the Headscale server (`headscale preauthkeys create --user <user>`) instead of the Tailscale admin console
+- ACLs are defined in Headscale's policy file rather than the Tailscale admin UI
+- MagicDNS HTTPS certificates require Headscale β‰₯0.23. Older versions don't auto-provision certs, so you'd need to terminate TLS yourself with a reverse proxy. Funnel is also Headscale β‰₯0.23
+
+The `serve.json` shape, the Dashy header-auth config, and the identity headers (`Tailscale-User-Login` etc.) are identical. Headscale uses the same protocol, so the client behaves the same way.
+
+## Best practices
+
+- Don't bind Dashy's port to the host. Only `tailscaled` should reach it, which is the case if you leave `ports:` off the dashy service and use `network_mode: service:tailscale`
+- Treat the auth key as a credential. Tag it (`tag:container`) and rotate it periodically. Prefer non-ephemeral keys for the Dashy node so it survives restarts
+- Use Tailscale ACLs to limit who in your tailnet can reach the Dashy node, especially for shared organisations. Configure under **Access controls** in the admin console
+- Pin `tailscale/tailscale` to a version tag in production rather than `:latest`. The Docker image follows the daemon's release cadence
+- Match Dashy's `users[]` to actual tailnet emails. Every tailnet member who should reach Dashy needs an entry. Promote to admin by setting `type: admin`
+- For self-hosting purists, Headscale removes the dependency on Tailscale's coordination server. Otherwise prefer the hosted plan, the free tier is generous and the engineering team owns reliability for you
+
+## Troubleshooting common Tailscale issues
+
+#### Container starts but no machine appears in the Tailscale admin console
+Problem: `docker compose logs tailscale` shows the daemon running but it never registers.<br>
+Solution: The auth key is wrong, expired, or the wrong type. Generate a fresh **Reusable: No, Ephemeral: No, Pre-approved: Yes** key and update `.env`. Auth keys are single-use unless marked reusable.
+
+#### "no HTTPS server configured for ${TS_CERT_DOMAIN}"
+Problem: Serve config references the env-substituted hostname but Tailscale didn't substitute it.<br>
+Solution: Older `tailscale/tailscale` images didn't expand `${TS_CERT_DOMAIN}` in `serve.json`. Update to a recent image (`v1.66+` or `latest`), or hardcode your tailnet hostname in `serve.json` (`dashy.tail123abc.ts.net:443`).
+
+#### HTTPS cert never issued
+Problem: Browser shows a TLS error visiting the tailnet URL.<br>
+Solution: HTTPS certificates aren't enabled for your tailnet. Open **DNS** in the admin console and turn on both **MagicDNS** and **HTTPS Certificates**. Cert issuance takes about a minute after `serve.json` is applied.
+
+#### "401 Unauthorized - not from trusted proxy" from Dashy
+Problem: Reaches Dashy but the header auth middleware rejects it.<br>
+Solution: `tailscaled` and Dashy must share a network namespace via `network_mode: service:tailscale` for the source IP to be `127.0.0.1`. If they're on different networks, the source IP will be the Tailscale container's IP instead. Update `proxyWhitelist` accordingly, or fix the compose to share the namespace.
+
+#### "401 Unauthorized - missing user header"
+Problem: Source IP check passes, but `Tailscale-User-Login` isn't present.<br>
+Solution: The request didn't come through `tailscale serve` (maybe Funnel, maybe a direct hit on the tailnet IP without going via Serve). Confirm `serve.json` is loaded by running `docker compose exec tailscale tailscale serve status` and re-issuing the request through the HTTPS URL.
+
+#### Logged in but admin features stay locked
+Problem: Authenticates fine, but admin actions return 403.<br>
+Solution: The email in `Tailscale-User-Login` doesn't exactly match a `users[].user` with `type: admin`. Run `docker compose exec tailscale tailscale whois <your-tailnet-ip>` to see what login Tailscale will pass through.
+
+#### Funnel users see 401
+Problem: You enabled `AllowFunnel`, but visitors from outside the tailnet get 401.<br>
+Solution: Expected. Funnel traffic doesn't carry tailnet identity, so header auth has nothing to match. Either drop header auth and use built-in HTTP auth for Funnel-exposed Dashy, or only use Funnel for fully-public read access (no auth, guest mode).
+
+#### Tailscale container exits with "cannot allocate memory" or DEVICE_RESET
+Problem: Crash loop on a low-memory host.<br>
+Solution: Either bump memory, or set `TS_USERSPACE: "true"` to use the userspace WireGuard implementation (slower but no kernel module dependency). Remove the `/dev/net/tun` volume mount and the `net_admin` and `sys_module` capabilities when in userspace mode.
+
+#### MagicDNS hostname doesn't resolve from the device I'm using
+Problem: Other tailnet devices can't reach the Dashy URL even though the machine shows up in the admin console.<br>
+Solution: Confirm MagicDNS is on globally (admin console **DNS**) and on the client (`tailscale netcheck` and the Tailscale app's settings). On Linux clients add `--accept-dns=true` to `tailscale up`. Older Linux setups sometimes need `nameserver 100.100.100.100` in `/etc/resolv.conf`.
+
+#### Headscale setup, certs not issued automatically
+Problem: Using Headscale, the tailnet hostname works but HTTPS isn't auto-provisioned.<br>
+Solution: Headscale's auto-cert support requires version 0.23 or newer. Either upgrade Headscale, or run your own reverse proxy with HTTPS (Caddy, Traefik) in front of the Tailscale daemon and route to it as you would any other internal service.
+
+#### Config change to auth.headerAuth not picked up
+Problem: Updated `userHeader`, `proxyWhitelist`, or `users` in `conf.yml`, but Dashy still uses the old values.<br>
+Solution: The server reads the auth config only at boot. Restart the Dashy container after any change.
+
+---
+
+## How it Works
+
+### Server side
+
+`tailscaled` runs WireGuard for the data plane and a small HTTPS server in the same container for Tailscale Serve. When a tailnet peer hits `https://dashy.<tailnet>.ts.net`, the request is delivered over WireGuard directly to your host. `tailscaled` terminates TLS using the cert it auto-provisioned, then makes an internal HTTP request to `http://127.0.0.1:8080` (Dashy in the same namespace), adding three headers:
+
+- `Tailscale-User-Login` - the user's tailnet login, typically their email
+- `Tailscale-User-Name` - the display name
+- `Tailscale-User-Profile-Pic` - a URL to their avatar
+
+Dashy's [header auth middleware](https://github.com/lissy93/dashy/blob/4.1.5/services/app.js) checks `req.socket.remoteAddress` against `proxyWhitelist` (which is `127.0.0.1` because of the shared namespace), reads `Tailscale-User-Login`, and sets `req.auth = { user: <email> }`. The SPA's `HeaderAuth.js` then fetches `/get-user`, matches the email to `users[]`, and sets the session cookie. Same code path as the Cloudflare Tunnel guide, just a different proxy and a different header name.
+
+Identity flows from the user's tailnet membership all the way to Dashy's role-based UI without the user ever entering a password.
+
+```mermaid
+flowchart LR
+ Req([Request reaches Dashy]) --> IP{Source IP in<br/>proxyWhitelist?}
+ IP -- No --> R401a[/401 Unauthorized<br/>not from trusted proxy/]:::err
+ IP -- Yes --> Hdr{Tailscale-User-Login<br/>present?}
+ Hdr -- No --> R401b[/401 Unauthorized<br/>missing user header/]:::err
+ Hdr -- Yes --> Pass[/Set req.auth = email<br/>continue to route handler/]:::ok
+
+ classDef ok fill:#bbf7d0,stroke:#16a34a,color:#14532d
+ classDef err fill:#fecaca,stroke:#dc2626,color:#7f1d1d
+```
+
+<details>
+
+<summary>End-to-end authentication flow</summary>
+
+```mermaid
+sequenceDiagram
+ autonumber
+ actor User
+ participant Device as User device (on tailnet)
+ participant TS as tailscaled (your host)
+ participant Dashy as Dashy
+
+ Note over Device,TS: WireGuard tunnel established earlier<br/>(out of band, peer-to-peer)
+
+ User->>Device: Open https://dashy.tail123.ts.net
+ Device->>TS: HTTPS request over WireGuard
+ TS->>TS: Terminate TLS<br/>look up tailnet identity of peer
+ TS->>Dashy: HTTP to 127.0.0.1:8080<br/>+ Tailscale-User-Login: [email protected]<br/>+ Tailscale-User-Name<br/>+ Tailscale-User-Profile-Pic
+ Dashy->>Dashy: Check req.socket.remoteAddress in proxyWhitelist (127.0.0.1)<br/>Read user header, set req.auth
+ Dashy-->>TS: 200 + SPA
+ TS-->>Device: 200 (HTTPS)
+
+ Note over Device,Dashy: SPA auto-login
+ Device->>Dashy: GET /get-user
+ Dashy-->>Device: { user: "[email protected]" }
+ Device->>Device: Match email to users[], set cookie,<br/>render dashboard with right admin level
+```
+
+</details>
diff --git a/docs/authentication/zitadel.md b/docs/authentication/zitadel.md
new file mode 100644
index 00000000..061b146a
--- /dev/null
+++ b/docs/authentication/zitadel.md
@@ -0,0 +1,449 @@
+# Zitadel Authentication for Dashy
+
+Dashy supports using [Zitadel](https://zitadel.com/) as its OIDC provider.
+
+[Zitadel](https://zitadel.com/) is an [open source](https://github.com/zitadel/zitadel) identity and access platform written in Go and backed by Postgres or CockroachDB. It speaks OIDC, OAuth 2.0, and SAML, supports MFA, social login, and per-project role management. The free self-hosted edition is fully featured; there's also a managed cloud option.
+
+> [!IMPORTANT]
+> This guide targets Zitadel **v3.4.x**. Zitadel v4 removed the embedded-JS Actions API used to translate Zitadel's role claim format into a `groups` claim Dashy understands. The same flow on v4 needs a sidecar webhook target; see the v4 note in the Action step.
+
+### Contents
+
+- [1. Deploy Zitadel](#1-deploy-zitadel)
+- [2. Configure Zitadel](#2-configure-zitadel)
+ - [Create the project](#create-the-project)
+ - [Create the OIDC application](#create-the-oidc-application)
+ - [Create the admin role](#create-the-admin-role)
+ - [Grant the role to a user](#grant-the-role-to-a-user)
+ - [Map roles to a groups claim](#map-roles-to-a-groups-claim)
+ - [Create test users](#create-test-users)
+- [3. Enabling Zitadel in Dashy](#3-enabling-zitadel-in-dashy)
+- [4. Groups and Visibility](#4-groups-and-visibility)
+- [Troubleshooting](#troubleshooting-common-zitadel-issues)
+- [How it Works](#how-it-works)
+ - [Client side](#client-side)
+ - [Server side](#server-side)
+ - [Visual Overview](#visual-overview)
+
+## 1. Deploy Zitadel
+
+Zitadel needs a Postgres backend. The compose below brings up both, with the admin user pre-created via env, and a machine user PAT written to disk for programmatic setup.
+
+<details>
+ <summary>Example <code>docker-compose.yml</code></summary>
+
+```yaml
+name: dashy-zitadel
+
+services:
+ postgres:
+ image: postgres:16-alpine
+ restart: unless-stopped
+ environment:
+ POSTGRES_USER: postgres
+ POSTGRES_PASSWORD: postgres
+ POSTGRES_DB: zitadel
+ healthcheck:
+ test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"]
+ interval: 5s
+ timeout: 5s
+ retries: 10
+ start_period: 10s
+ volumes:
+ - ./data/postgres:/var/lib/postgresql/data
+
+ zitadel:
+ image: ghcr.io/zitadel/zitadel:v3.4.10
+ restart: unless-stopped
+ command: 'start-from-init --masterkey "MasterkeyNeedsToHave32Characters" --tlsMode disabled'
+ ports:
+ - "8080:8080"
+ environment:
+ ZITADEL_EXTERNALDOMAIN: zitadel.lvh.me
+ ZITADEL_EXTERNALPORT: 8080
+ ZITADEL_EXTERNALSECURE: "false"
+ ZITADEL_PORT: 8080
+ ZITADEL_TLS_ENABLED: "false"
+ ZITADEL_DATABASE_POSTGRES_HOST: postgres
+ ZITADEL_DATABASE_POSTGRES_PORT: 5432
+ ZITADEL_DATABASE_POSTGRES_DATABASE: zitadel
+ ZITADEL_DATABASE_POSTGRES_USER_USERNAME: postgres
+ ZITADEL_DATABASE_POSTGRES_USER_PASSWORD: postgres
+ ZITADEL_DATABASE_POSTGRES_USER_SSL_MODE: disable
+ ZITADEL_DATABASE_POSTGRES_ADMIN_USERNAME: postgres
+ ZITADEL_DATABASE_POSTGRES_ADMIN_PASSWORD: postgres
+ ZITADEL_DATABASE_POSTGRES_ADMIN_SSL_MODE: disable
+ ZITADEL_FIRSTINSTANCE_ORG_NAME: Dashy
+ ZITADEL_FIRSTINSTANCE_ORG_HUMAN_USERNAME: zitadel-admin
+ ZITADEL_FIRSTINSTANCE_ORG_HUMAN_PASSWORD: AdminPass2026!
+ ZITADEL_FIRSTINSTANCE_ORG_HUMAN_PASSWORDCHANGEREQUIRED: "false"
+ ZITADEL_FIRSTINSTANCE_ORG_HUMAN_EMAIL_ADDRESS: [email protected]
+ ZITADEL_FIRSTINSTANCE_ORG_HUMAN_EMAIL_VERIFIED: "true"
+ ZITADEL_FIRSTINSTANCE_ORG_HUMAN_FIRSTNAME: Zitadel
+ ZITADEL_FIRSTINSTANCE_ORG_HUMAN_LASTNAME: Admin
+ depends_on:
+ postgres:
+ condition: service_healthy
+```
+
+</details>
+
+The Zitadel external domain (`zitadel.lvh.me` above) must resolve to the host Zitadel listens on. `lvh.me` and its subdomains resolve to `127.0.0.1` everywhere, so no /etc/hosts edits needed locally.
+
+For production:
+
+- Drop `--tlsMode disabled` and `ZITADEL_EXTERNALSECURE: "false"`
+- Put Zitadel behind a reverse proxy on a real domain with HTTPS
+- Use a strong masterkey (32 characters, generated fresh: `openssl rand -hex 16`)
+- Use a real Postgres password and a dedicated database user, not the `postgres` superuser
+
+Bring it up:
+
+```bash
+docker compose up -d
+```
+
+First boot runs the database migrations and creates the org, admin user, and a machine user. Once Zitadel is healthy (`curl -sf http://localhost:8080/debug/ready`), open `http://zitadel.lvh.me:8080/ui/console` and sign in as `zitadel-admin` with the bootstrap password.
+
+---
+
+## 2. Configure Zitadel
+
+Steps below are the manual UI walkthrough. There's also a Management API for scripted setup; an example bootstrap script is at [`alicia-notes/zitadel/configure.sh`](https://github.com/lissy93/dashy/blob/4.1.5/alicia-notes/zitadel/configure.sh) in the source repo.
+
+### Create the project
+
+1. Open the console at `http://zitadel.lvh.me:8080/ui/console`
+2. Sign in as `zitadel-admin`
+3. Go to **Projects**
+4. Click **Create New Project**
+5. Set **Name** to `Dashy`, click **Continue**
+
+### Create the OIDC application
+
+1. Open the `Dashy` project
+2. Under **Applications**, click **New**
+3. Set **Name** to `Dashy`, **Type** to `User Agent`, click **Continue**
+4. Set **Authentication Method** to `PKCE`, click **Continue**
+5. Set **Redirect URIs** to both:
+ - `http://localhost:4000`
+ - `http://localhost:4000/`
+6. Set **Post Logout URIs** to `http://localhost:4000`, click **Continue**
+7. Review and click **Create**
+
+After creation, open the application and:
+
+1. Open **Configuration** (or **Settings**)
+2. Turn **Development Mode** on (required for http redirect URIs during local testing; turn it off in production)
+3. Turn **ID Token Role Assertion** on so project roles appear in the id_token
+4. Turn **ID Token Userinfo Assertion** on (optional but useful for debugging)
+5. Click **Save**
+
+Copy the **Client ID** shown on the application page. It's a long numeric string; you'll need it for Dashy's config.
+
+### Create the admin role
+
+1. In the `Dashy` project, open **Roles**
+2. Click **New**
+3. Set **Key** to `admins`
+4. Set **Display Name** to `Dashy admins`
+5. Set **Group** to `admins` (this name is also what Dashy's `adminGroup` will match)
+6. Click **Save**
+
+### Grant the role to a user
+
+1. Open the `zitadel-admin` user (under **Users**)
+2. Open the **Authorizations** tab
+3. Click **New**
+4. Pick the `Dashy` project
+5. Select the `admins` role
+6. Click **Save**
+
+### Map roles to a groups claim
+
+By default Zitadel emits roles in a nested `urn:zitadel:iam:org:project:roles` claim. Dashy looks for a flat `groups` array, so an Action is needed to translate.
+
+1. Open your org's settings (top-right menu, **Organisation Settings**), then **Actions**
+2. Click **New**
+3. Set **Name** to `addGroupsClaim`
+4. Paste this script:
+
+```javascript
+function addGroupsClaim(ctx, api) {
+ if (ctx.v1 && ctx.v1.user && ctx.v1.user.grants && ctx.v1.user.grants.grants) {
+ var groups = [];
+ for (var i = 0; i < ctx.v1.user.grants.grants.length; i++) {
+ var g = ctx.v1.user.grants.grants[i];
+ if (g.roles) {
+ for (var j = 0; j < g.roles.length; j++) {
+ if (groups.indexOf(g.roles[j]) === -1) groups.push(g.roles[j]);
+ }
+ }
+ }
+ api.v1.claims.setClaim('groups', groups);
+ }
+}
+```
+
+5. Set **Allowed To Fail** to true (so a bug here doesn't block login entirely)
+6. Click **Save**
+
+Now bind it to the token flow:
+
+1. Still in **Actions**, open **Flows**
+2. Open **Complement Token**
+3. For both **Pre Userinfo Creation** and **Pre Access Token Creation**, click **Add** and select `addGroupsClaim`
+4. Click **Save**
+
+> [!NOTE]
+> On Zitadel v4 the embedded-JS Actions feature is gone. The same translation needs an Actions v2 target (a small HTTP webhook your Zitadel instance can call). The shape of the script is roughly the same; only the deployment changes. See the [Zitadel v4 Actions docs](https://zitadel.com/docs/concepts/features/actions_v2) for the webhook flow.
+
+### Create test users
+
+If you want users beyond `zitadel-admin`:
+
+1. Go to **Users**, click **New**
+2. Fill in **Username** (e.g. `zitadel-user`), **First Name**, **Last Name**, **Email**, click **Continue**
+3. Set an initial password and turn off **Password Change Required**
+4. Optionally grant the user the `admins` role via **Authorizations** if they should have admin access in Dashy
+
+### Summary
+
+Zitadel should now have a project, an OIDC application, a role, the role granted to your admin user, and an Action that exposes roles as a `groups` claim.
+
+---
+
+## 3. Enabling Zitadel in Dashy
+
+In `/user-data/conf.yml`:
+
+```yaml
+appConfig:
+ ...
+ disableConfigurationForNonAdmin: true
+ auth:
+ enableOidc: true
+ oidc:
+ clientId: "1234567890123456789"
+ endpoint: http://zitadel.lvh.me:8080
+ adminGroup: admins
+ scope: openid profile email
+```
+
+Where:
+- `disableConfigurationForNonAdmin` - Prevent read/write config access to non-admin users
+- `auth.enableOidc` - Set the auth mode to OIDC
+- `clientId` - The Client ID from Zitadel. **Wrap it in quotes**: Zitadel client IDs are 19-digit numeric strings, which YAML parses as a JS number and loses precision on
+- `endpoint` - The Zitadel base URL, which is also its issuer. Dashy appends `/.well-known/openid-configuration` itself
+- `adminGroup` - Name of the role that grants admin in Dashy (matches the `admins` role above)
+- `scope` - Standard OIDC scopes. Zitadel doesn't need a custom `groups` scope; the Action puts the claim in the token regardless of scope
+
+Restart Dashy for these changes to take effect.
+
+If Zitadel runs on a different host or behind a reverse proxy, make sure `endpoint` is reachable from inside the Dashy container, and that the issuer Zitadel advertises matches `endpoint` exactly.
+
+Everything should now be fully configured and working πŸŽ‰
+When you load Dashy, you'll be redirected to Zitadel's login page. After signing in, you'll land back on Dashy's homepage with full access, and all of Dashy's client, server and asset endpoints will be locked behind authentication.
+
+---
+
+## 4. Groups and Visibility
+
+Once the Action puts roles in the id_token's `groups` claim, you can use them to hide or show pages, sections and items. The property name is `hideForKeycloakUsers` / `showForKeycloakUsers` (the name is historical; it works for any OIDC provider, including Zitadel).
+
+To make an Admin section visible only to members of `admins`:
+
+```yaml
+displayData:
+ showForKeycloakUsers:
+ groups:
+ - admins
+```
+
+Both `showForKeycloakUsers` and `hideForKeycloakUsers` accept lists of `groups` and `roles`. If a user matches an entry they're allowed or excluded as defined.
+
+```yaml
+sections:
+ - name: Internal Tools
+ displayData:
+ showForKeycloakUsers:
+ groups: ['admins']
+ hideForKeycloakUsers:
+ groups: ['guests']
+ items:
+ - title: Hidden from interns
+ displayData:
+ hideForKeycloakUsers:
+ groups: ['interns']
+```
+
+---
+
+## Troubleshooting common Zitadel Issues
+
+#### Numeric Client ID truncated
+Problem: Login redirects to Zitadel with the error "client not found" or similar, even though the Client ID looks right.<br>
+Solution: Zitadel Client IDs are long numeric strings. Without quotes around the value in `conf.yml`, YAML parses it as a JS number and loses precision past around 15 digits, so the actual value Dashy sends is wrong. Wrap it in quotes: `clientId: "373607668411072515"`.
+
+#### Logged in but config saves return 403
+Problem: User authenticates fine, but saving the dashboard returns 403.<br>
+Solution: The `groups` claim isn't in the id_token. Paste the token (from localStorage, key `ID_TOKEN`) into [jwt.io](https://jwt.io). If `groups` is missing, the Action either isn't bound to the right triggers, or the user has no project role grants. Check **Actions > Flows > Complement Token** has `addGroupsClaim` on both Pre Userinfo Creation and Pre Access Token Creation, and that the user has been granted the `admins` role under their **Authorizations** tab.
+
+#### Development Mode disabled with http redirect URIs
+Problem: Zitadel returns `invalid_redirect_uri` for `http://localhost:4000` on the authorize step.<br>
+Solution: Zitadel only accepts http redirect URIs when the OIDC application has **Development Mode** turned on. Open the application's **Configuration** tab and enable it. For production, use HTTPS for both Zitadel and Dashy and leave Development Mode off.
+
+#### "Invalid issuer" on token verification
+Problem: Dashy server logs show `unexpected "iss" claim value`. The browser reaches Zitadel at one URL but the issuer in the id_token is different.<br>
+Solution: Zitadel's issuer is built from `ZITADEL_EXTERNALDOMAIN`, `ZITADEL_EXTERNALPORT`, and `ZITADEL_EXTERNALSECURE`. Set these to match the public URL exactly. Behind a reverse proxy, make sure the proxy forwards `X-Forwarded-Proto: https` and `X-Forwarded-Host`.
+
+#### Token endpoint CORS blocked
+Problem: Browser shows `Cross-Origin Request Blocked` on a POST to `/oauth/v2/token`.<br>
+Solution: This usually means **Development Mode** is off on the OIDC application and Zitadel isn't auto-allowing your local origin. Turn it on for local testing. In production, Zitadel allows origins listed in the registered redirect URIs automatically.
+
+#### Action script never fires
+Problem: The Action exists but no `groups` claim appears in the token.<br>
+Solution: The Action needs to be bound to a flow. Open **Actions > Flows > Complement Token** and confirm `addGroupsClaim` is in both **Pre Userinfo Creation** and **Pre Access Token Creation**. Also check the Action is in **State: Active** (not deactivated).
+
+#### Action exists but tokens have no groups, on Zitadel v4
+Problem: v1 Actions were deprecated in Zitadel v4 and no longer fire.<br>
+Solution: Either pin to Zitadel v3.4.x (last release line with v1 Actions), or migrate to [Actions v2](https://zitadel.com/docs/concepts/features/actions_v2) which uses HTTP webhook targets. Actions v2 needs an extra service to host the script, so it's a heavier setup.
+
+#### Zitadel UI loads but login fails with "instance not found"
+Problem: Visiting Zitadel via an unconfigured hostname returns "Instance not found" or similar.<br>
+Solution: Zitadel binds itself to one external domain at first init. Use `http://zitadel.lvh.me:8080` (or whatever `ZITADEL_EXTERNALDOMAIN` is set to), not `http://localhost:8080` or `http://127.0.0.1:8080`.
+
+#### Dashy server can't reach Zitadel
+Problem: Auth'd API calls return 401 and Dashy logs show fetch errors for `.well-known/openid-configuration`.<br>
+Solution: `endpoint` must be reachable from inside the Dashy container, not just from the browser. If both run in Docker, put them on the same network. Test with `docker exec <dashy-container> wget -qO- "$ENDPOINT/.well-known/openid-configuration"`.
+
+#### Subject claim is a UUID, not a username
+Problem: Dashy logs show users with random-looking subject IDs.<br>
+Solution: Zitadel's `sub` claim is an opaque per-user ID. Dashy's OIDC client falls through `preferred_username`, `email`, then `sub`, so as long as `profile` and `email` are in the scopes, the username will be human-readable. Make sure both are listed in `scope:` in your Dashy config.
+
+#### Token expired / clock skew
+Problem: 401s with `"exp" claim timestamp check failed` or `"iat" claim timestamp check failed`, even just after login.<br>
+Solution: Dashy allows 30 seconds of drift. Sync clocks on both hosts with NTP. Container clocks follow their host, so it's almost always the host that's drifted.
+
+#### Config change to auth.oidc not picked up
+Problem: Updated `clientId`, `endpoint`, `adminGroup` or `scope` in `conf.yml`, but Dashy still uses the old values.<br>
+Solution: The server reads the auth config only at boot. Restart the Dashy container after any change to fields under `auth.oidc`.
+
+#### Postgres fails to start
+Problem: Zitadel never reaches ready, Postgres container exits or healthcheck fails.<br>
+Solution: Often a stale `data/postgres` directory left over from a previous version. Either run `docker compose down -v` to drop the volume, or `rm -rf data/postgres` and start over. Also confirm the host port 5432 isn't already taken by another Postgres.
+
+---
+
+## How it Works
+
+If you're a developer or contributor looking to understand or make changes to Dashy's OIDC implementation, the following outlines how it's wired together.
+
+The same OIDC pipeline backs Zitadel, Authelia, Authentik, Keycloak, and any other generic OIDC provider. The only Zitadel-specific piece is the Action that maps project roles to the `groups` claim; everything on the Dashy side is shared.
+
+### Client side
+
+Boot starts in [`src/main.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/main.js). After the initial `/conf.yml` fetch parses the auth block, `isOidcEnabled()` decides whether to lazily import [`oidc-client-ts`](https://github.com/authts/oidc-client-ts) and call `initOidcAuth()`.
+
+[`src/utils/auth/OidcAuth.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/auth/OidcAuth.js) wraps `oidc-client-ts`. On load it inspects the URL: if it sees a `?code=` callback it runs `userManager.signinCallback()` to exchange the code (and PKCE verifier) for tokens, persists the user info, and hard-redirects to `/`. Otherwise it calls `userManager.getUser()`; if there's no usable session it falls through to `userManager.signinRedirect()` to send the browser to Zitadel. A short-lived `sessionStorage` guard prevents the redirect loop that would otherwise occur if the IdP returns without a usable user.
+
+`persistUserInfo()` writes the raw `id_token`, the user's `groups` and `roles`, a derived `isAdmin` flag, and a username (falling back through `preferred_username`, `email`, and `sub`) to localStorage. The keys (`ID_TOKEN`, `KEYCLOAK_INFO`, `USERNAME`, `ISADMIN`) live in [`src/utils/config/defaults.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/config/defaults.js); the `KEYCLOAK_INFO` name is historical and reused for all OIDC providers, including Zitadel.
+
+[`src/utils/auth/getApiAuthHeader.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/auth/getApiAuthHeader.js) builds the Authorization header for every internal API call. It does a client-side `exp` check and returns `null` for missing or expired tokens, so the next request triggers a fresh login rather than a 401.
+
+[`src/utils/IsVisibleToUser.js`](https://github.com/lissy93/dashy/blob/4.1.5/src/utils/IsVisibleToUser.js) reads `KEYCLOAK_INFO` when evaluating `showForKeycloakUsers` and `hideForKeycloakUsers` rules.
+
+### Server side
+
+[`services/auth-oidc.js`](https://github.com/lissy93/dashy/blob/4.1.5/services/auth-oidc.js) contains the entire server-side auth surface, in five small pieces:
+
+- `loadOidcSettings()` reads `auth.oidc` (or `auth.keycloak`) at boot and returns a normalised `{ issuer, clientId, adminGroup, adminRole }`. For generic OIDC providers the `issuer` is whatever you set as `endpoint` in `conf.yml`, verbatim
+- `createOidcMiddleware()` returns a Connect middleware. Permissive on no-token requests so the SPA can bootstrap; otherwise it verifies the Bearer token against the issuer's JWKS using [`jose`](https://github.com/panva/jose). Checks cover signature, issuer (against the canonical value from the discovery doc), audience (must equal `clientId`), and expiry, with a 30-second clock-skew tolerance. Sets `req.auth = { user, isAdmin, claims }` on success, `401` on failure
+- `getIssuerContext()` lazily fetches `.well-known/openid-configuration` on first use and wraps `jwks_uri` in `createRemoteJWKSet`, which handles JWKS caching and on-demand key rotation. The result is memoised per-issuer for the life of the process
+- `deriveIsAdmin()` checks the token's `groups` claim against `adminGroup`, and the `realm_access.roles` / `resource_access.<clientId>.roles` arrays against `adminRole`. Zitadel emits roles in a different format, which is why the Action maps them into a flat `groups` array for Dashy
+- `maybeBootstrapConfig()` is the stripped-response helper. When auth is configured, guest access is off, and an unauthenticated request hits the root `/conf.yml`, it returns a minimal copy with only `appConfig.auth`, `appConfig.enableServiceWorker`, and a `pageInfo.title` of `Login | <your title>`. Sections, items, hostnames and any other secrets never leave the server
+
+[`services/app.js`](https://github.com/lissy93/dashy/blob/4.1.5/services/app.js) wires it all together. The middleware mounts as `protectConfig` in front of every YAML route and config-mutating route. The `/*.yml` handler sets `Cache-Control: private, no-store` and `Vary: Authorization` whenever auth is configured (so intermediate caches can never mix auth states), then calls `maybeBootstrapConfig`; a stripped result is sent as-is, otherwise `res.sendFile` serves the full file. `POST /config-manager/save` is additionally guarded by `requireAdmin`, which returns `401` if `req.auth` is unset and `403` if `req.auth.isAdmin` is false.
+
+### Visual Overview
+
+<details>
+
+<summary>End-to-end authentication flow</summary>
+
+```mermaid
+sequenceDiagram
+ autonumber
+ actor User
+ participant Browser as Browser (Dashy SPA)
+ participant Dashy as Dashy Server
+ participant Z as Zitadel
+
+ Note over Browser,Dashy: 1. Bootstrap (no token yet)
+ User->>Browser: Open Dashy
+ Browser->>Dashy: GET /conf.yml
+ Dashy-->>Browser: 200 stripped conf<br/>(auth block + minimal pageInfo)
+ Browser->>Browser: Parse auth.oidc
+
+ Note over Browser,Z: 2. OIDC login (Authorization Code + PKCE)
+ Browser->>Z: 302 /oauth/v2/authorize<br/>client_id, code_challenge, redirect_uri
+ User->>Z: Submit credentials
+ Z-->>Browser: 302 back with ?code=AUTH_CODE
+ Browser->>Z: POST /oauth/v2/token<br/>(code + code_verifier)
+ Z->>Z: Action addGroupsClaim runs<br/>maps project roles to groups[]
+ Z-->>Browser: id_token + access_token<br/>(id_token includes groups claim)
+ Browser->>Browser: Store tokens in localStorage<br/>hard reload to /
+
+ Note over Browser,Dashy: 3. Authenticated read
+ Browser->>Dashy: GET /conf.yml<br/>Authorization: Bearer id_token
+ Dashy->>Z: Fetch discovery + JWKS<br/>(lazy on first call, then cached)
+ Z-->>Dashy: openid-configuration + JWKS
+ Dashy->>Dashy: Verify signature / issuer / audience / expiry
+ Dashy-->>Browser: 200 full conf.yml
+
+ Note over Browser,Dashy: 4. Write request (admin only)
+ Browser->>Dashy: POST /config-manager/save<br/>Authorization: Bearer id_token
+ Dashy->>Dashy: Verify token, derive isAdmin from<br/>adminGroup claim
+ alt isAdmin
+ Dashy-->>Browser: 200 saved
+ else not admin
+ Dashy-->>Browser: 403 Forbidden
+ end
+```
+
+</details>
+
+
+<details>
+
+<summary>Server-side request handling</summary>
+
+```mermaid
+flowchart TD
+ Req([Incoming request to Dashy server])
+ Req --> Bearer{Authorization:<br/>Bearer present?}
+
+ Bearer -- No --> NoAuth[req.auth unset<br/>pass through]:::neutral
+ Bearer -- Yes --> Verify[/Verify JWT against cached JWKS:<br/>signature Β· issuer Β· audience Β· expiry/]
+ Verify --> Valid{Valid?}
+ Valid -- No --> R401Bad[/401 Unauthorized/]:::err
+ Valid -- Yes --> SetAuth[req.auth = user + isAdmin<br/>derived from claims]:::ok
+
+ NoAuth --> Route{Endpoint}
+ SetAuth --> Route
+
+ Route -- "GET /conf.yml" --> ConfGate{req.auth?}
+ ConfGate -- No --> Strip[/200 stripped conf<br/>auth + minimal pageInfo/]:::ok
+ ConfGate -- Yes --> Full[/200 full conf.yml/]:::ok
+
+ Route -- "POST /config-manager/save" --> SaveGate{req.auth<br/>and isAdmin?}
+ SaveGate -- No req.auth --> R401Save[/401 Unauthorized/]:::err
+ SaveGate -- Not admin --> R403[/403 Forbidden/]:::err
+ SaveGate -- Admin --> Saved[/200 saved/]:::ok
+
+ classDef ok fill:#bbf7d0,stroke:#16a34a,color:#14532d
+ classDef err fill:#fecaca,stroke:#dc2626,color:#7f1d1d
+ classDef neutral fill:#dbeafe,stroke:#2563eb,color:#1e3a8a
+```
+
+</details>