GOV RBAC · Role-based access control for UK Government
Identity and access,
built for government.
Audited by default.
A role-based access control platform across four services, with Keycloak IAM, OIDC sign-in and permissions embedded in signed tokens, all behind a GOV.UK Design System interface.
The product
Five tasks, one consistent service.
Government-grade sign-in, out of the box.
Authentication uses the OIDC Authorization Code flow with PKCE via Keycloak. Tokens never reach the browser, and sessions are regenerated on every successful sign-in to prevent session fixation.
- +Access, ID and refresh tokens stored server-side only
- +Sign-in rate-limited to 20 requests per 15 minutes per IP
- +Locked accounts are stopped at the door, before entering the app
Every user, every status, one search away.
Administrators search and list users with a live activity status. A daily scheduler marks accounts dormant after 60 days, so stale access is flagged without anyone having to remember.
- +Active and inactive status driven by a daily inactivity scheduler
- +Create user appears only for administrators
- +One template serves every permission tier
Account controls that adapt to who's looking.
The profile shows personal details, roles and account controls. Reset password and Lock account render only for users with the right permissions, with no separate admin pages to maintain.
- +Actions rendered conditionally against the signed-in user's roles
- +Password reset issues a four-word passphrase, shown once and never stored
- +Admin unlock clears Keycloak state and failed-attempt counts together
Role changes you confirm before they land.
Roles are changed in two steps: a selection form, then a confirmation page showing the before-and-after difference. On save, the full capability set is resolved and written into the user's next token.
- +Two-step confirmation with a before-and-after view
- +Role inheritance graph resolved to a complete capability set
- +Capabilities synced to Keycloak and embedded in the next JWT
A complete history, kept by the database itself.
Every change to an account or role assignment is captured by PostgreSQL versioning triggers into mirrored history tables. There is no application-level audit code to forget or bypass.
- +Each row versioned with a validity window before it changes
- +Role grants and revocations shown with who made them
- +Structured logging with correlation IDs across services
Screens show test data. All names and email addresses are fictional.
Features
Engineered for consistency and control.
User creation saga
A distributed transaction across the user service, Keycloak and access control. If a later step fails, a compensation call rolls back the Keycloak account, keeping every system consistent without two-phase commit.
JWT capability embedding
Capabilities are written as Keycloak user attributes and embedded in signed tokens by protocol mappers. Downstream services read them straight from the JWT, with an HTTP fallback for older tokens.
Account lifecycle
A daily scheduler deactivates dormant accounts. An hourly job mirrors Keycloak brute-force locks into access control, and admin unlock resets everything atomically.
Temporal audit trail
Versioning triggers copy each modified row to a history table with a validity range. Modifier names are resolved across schemas by UUID.
Layered security
Server-side sessions with httpOnly, secure cookies; CSRF synchronizer tokens; Helmet headers with a strict CSP and no unsafe-inline; sign-in rate limiting; session regeneration on OIDC callback.
Permission-driven UI
Route-level checks in middleware, and Nunjucks templates that render each action only for users who can perform it. One template per page serves every tier.
Architecture
Four services. One source of identity.
All four services share one PostgreSQL instance, split across two schemas. Identity is correlated by a shared system user ID, and no foreign key crosses a schema boundary.
GOV.UK interface. Owns the session, CSRF, OIDC callback and token refresh.
Identity, profile, account lifecycle, schedulers and saga orchestration.
Roles and permissions, capability graph traversal, JWT attribute sync.
Keycloak Admin API proxy: users, attributes and protocol mappers.
Key flows
- FLOW 01User creation saga
The user service saves the record, asks the Keycloak manager to create the account, then initialises access control. If access control fails, the Keycloak account is deleted before the database transaction rolls back.
UI → UMS [DB insert] → KM [Keycloak create] → ACM [AC insert]ACM fail → KM [Keycloak rollback] → UMS [DB rollback] - FLOW 02JWT capability embedding
On a role change, access control walks the inheritance graph and writes the resolved capabilities to Keycloak. Protocol mappers then embed them in every subsequent token, so no lookup is needed per request.
Role change → ACM [graph traversal] → KM [write attributes] → KeycloakNext token: capabilities: ["Create users", …] as a signed claim - FLOW 03Sign-in and account guard
After the OIDC token exchange, the UI fetches the user record. A locked account has its session destroyed and is redirected to an account-locked page. Otherwise the session is regenerated and the last sign-in date is stamped.
Documentation
Every decision, written down.
The repository includes an application guide covering every feature, flow and architectural decision, from the data model and saga pattern to JWT embedding, session security and GOV.UK component usage.
Saga orchestration, Keycloak compensation, inheritance graph, two-step confirmation
Daily scheduler, 60-day threshold, activity flag, sign-in date stamping
Passphrase generation, brute-force sync, hourly lock scheduler, manual unlock
Temporal tables, versioning triggers, structured logging, correlation IDs
PostgreSQL schemas, entity relationships, cross-schema identity, saga diagram
OIDC PKCE flow, JWT embedding, CSP headers, CSRF, method-level authorisation