SSO / Keycloak Setup
The ferrite platform supports single sign-on via Keycloak OIDC. The server handles JWT validation natively -- no reverse proxy auth is needed.
Overview
- Run a Keycloak instance
- Create a realm, client, and roles
- Set environment variables on the ferrite-server
- The dashboard auto-detects OIDC mode and shows an SSO login button
Server configuration
Set these environment variables (in .env or your deployment config):
bash
KEYCLOAK_URL=https://keycloak.example.com
KEYCLOAK_REALM=ferrite
KEYCLOAK_CLIENT_ID=ferrite-dashboardThe server auto-detects Keycloak mode when all three variables are set. Without them, it falls back to Basic auth.
Keycloak configuration
Create a realm
- Log in to the Keycloak admin console
- Create a new realm called
ferrite
Create a client
- In the
ferriterealm, go to Clients and create a new client:- Client ID:
ferrite-dashboard - Client type: OpenID Connect
- Root URL:
https://dashboard.example.com
- Client ID:
- Configure the client:
- Valid redirect URIs:
https://dashboard.example.com/* - Web origins:
https://dashboard.example.com - Client authentication: Off (public client for SPA)
- Valid redirect URIs:
Create roles
Create these realm roles for role-based access control:
| Role | Permissions |
|---|---|
ferrite-admin | Full access: read, write, delete, admin paths |
ferrite-provisioner | Read + create/update devices and groups |
| (no role) | Viewer: read-only access |
Assign roles to users in the Keycloak admin console.
Create users
Create users in the ferrite realm and assign them the appropriate roles.
How it works
- The dashboard calls
GET /auth/modeon startup and detectskeycloakmode - User clicks "Sign in with SSO" -- the dashboard redirects to Keycloak's authorization endpoint with PKCE
- After authentication, Keycloak redirects back with an authorization code
- The dashboard exchanges the code for tokens via the Keycloak token endpoint
- The access token (JWT) is stored in
sessionStorageand sent asAuthorization: Bearer <token>on every API call - The server validates the JWT using cached JWKS keys (refreshed every 5 minutes), falling back to the userinfo endpoint if JWKS validation fails
- Roles are extracted from the
realm_access.rolesJWT claim
Device authentication
For device-to-server authentication (chunk upload), use API keys rather than OIDC:
bash
# Server-side
INGEST_API_KEY=your-secret-device-key
# Device-side (in firmware or gateway config)
X-API-Key: your-secret-device-keyThe /ingest/elf endpoint additionally accepts user auth (Bearer or Basic) for manual ELF uploads.