Waldur Keycloak mapper
Custom Keycloak OIDC protocol mappers that integrate with Waldur so OIDC tokens reflect Waldur permissions, offering access, and per-offering identities. The build produces a single shaded JAR that operators drop into Keycloak's providers directory; Keycloak picks it up via SPI on next start.
What's in the box
| Display name in Keycloak | Purpose |
|---|---|
Waldur preferred username mapper |
Adds the per-offering preferred username from Waldur as a custom claim. |
Waldur offering access mapper |
Checks per-user offering access in Waldur and mutates Keycloak group/role membership accordingly. |
Waldur MinIO mapper |
Adds a comma-separated list of customer or project UUIDs as a claim, intended for MinIO policy mapping. |
Waldur resource roles mapper |
Adds group names for the user's Waldur resource and resource-project roles to a list claim, intended for Rancher. |
All four mappers register under the standard Token mapper category in the Keycloak admin UI (Clients → your client → Client scopes → Mappers).
Mappers
Waldur preferred username mapper
Resolves a user's preferred username for a specific Waldur offering and emits it as an OIDC claim on the ID token, access token, and userinfo response.
Configuration
| Parameter | Description |
|---|---|
| Waldur API URL | Base URL with trailing slash, e.g. https://waldur.example.com/api/. |
| Offering UUID | UUID of the Waldur offering to look up the username in. |
| API Token | Waldur API token (sent as Authorization: Token <token>). |
| TLS Validation | When off, disables both hostname and certificate-chain verification. |
| Claim Name | OIDC claim name to write the username into. |
Waldur offering access mapper
On every token issuance, asks Waldur whether the user has access to the configured offering and reconciles Keycloak state to match: joins/leaves a configured group and grants/revokes a configured role.
Heads up — side effects. This mapper mutates Keycloak user-group and user-role state during token issuance. That's unusual for an OIDC mapper. Be deliberate about which clients trigger it and how often tokens are minted.
Configuration
| Parameter | Description |
|---|---|
| Waldur API URL | Base URL with trailing slash. |
| Offering UUID | UUID of the offering to check access against. |
| API Token | Waldur API token. |
| Username Source | id (Keycloak user ID) or username. |
| Group name | Group to add/remove the user from. The mapper resolves it as /<name>; nested groups are not supported. |
| Add to group | If off, group membership is not touched. |
| Role name | Realm role to grant/revoke. |
| Assign role | If off, role assignment is not touched. |
| Claim Name | OIDC claim name to write group info into (optional). |
TLS validation is always strict for this mapper — there is no toggle.
Waldur MinIO mapper
Aggregates the user's Waldur permissions at customer or project scope and emits the matching scope UUIDs as a comma-separated string under a single claim. MinIO can then map that claim to its policy engine.
Configuration
| Parameter | Description |
|---|---|
| Waldur API URL | Base URL with trailing slash. |
| API Token | Waldur API token. |
| Permission Scope | customer or project. |
| TLS Validation | When off, disables both hostname and certificate-chain verification. |
| Username Source | id (Keycloak user ID) or username. |
| Claim Name | OIDC claim name to write the UUID list into (e.g. policy). |
Example claim payload. For a user who is owner in customers C1, C2 (with Permission Scope = customer and Claim Name = policy):
1 2 3 | |
Waldur resource roles mapper
At token time, asks Waldur which resource (cluster) and resource-project roles the user holds in one or more offerings, renders each into a group name, and merges the names into a list claim on the ID token, access token, and userinfo response. Nothing in Keycloak is mutated: the groups exist only in the issued tokens.
The user is identified by civil number, taken only from the userId of their federated identity link for the configured, trusted identity provider (TARA by default). A user without that link gets no Waldur groups and no request is sent (logged at DEBUG). The username is never used: it can be set outside the trusted provider, so treating it as a civil number would let anyone with a matching username inherit someone else's roles.
For each offering it calls
1 2 | |
and concatenates the results. resource entries are rendered with the cluster group template, resource_project entries with the project group template.
Configuration
| Parameter | Config key | Default | Description |
|---|---|---|---|
| Waldur API URL | url.waldur.api.value |
Base URL with trailing slash. | |
| Waldur Offering UUIDs | uuids.waldur.offerings.value |
Comma-separated; each offering is queried and the groups concatenated. | |
| Token environment variable | token.waldur.env.value |
WALDUR_MAPPER_TOKEN |
Name of the environment variable of the Keycloak process holding the Waldur API token. Must start with WALDUR_. |
| TLS validation enabled | tls.waldur.validate |
on | When off, disables both hostname and certificate-chain verification. Refused unless insecure connections are allowed. |
| Identity provider alias | idp.alias.value |
TARA |
Identity provider whose federated identity link holds the civil number. |
| Project group template | template.waldur.project.group |
c_${cluster_id}_${rp_uuid}_${role_name} |
Group name for a resource-project role. |
| Cluster group template | template.waldur.cluster.group |
c_${cluster_id}_${resource_uuid}_cluster_${role_name} |
Group name for a resource (cluster) role. |
| Fail on non-login error | waldur.fail.on.refresh.error |
on | See Failure semantics below. The key keeps its old name for compatibility. |
| Cache max age (seconds) | waldur.cache.max.age.seconds |
0 (disabled) |
Keep the last successful answer per user this long and serve it while Waldur is unreachable. See Last-known answer cache. |
| When Waldur refuses the mapper | waldur.on.refused |
fail_closed |
fail_closed or freeze. See When Waldur refuses the mapper below. |
| Allow insecure Waldur connection (development only) | waldur.allow.insecure.connection |
off | Allows an http:// API URL or TLS validation turned off. Without it either is a configuration error. |
| Token Claim Name | claim.name |
roles |
Claim to merge the group names into. |
| Add to ID token / access token / userinfo / … | standard | Standard Keycloak include-in-token switches. |
The token is never stored in the mapper configuration. It is read from the environment variable named above at token time, so set it on the Keycloak process (e.g. WALDUR_MAPPER_TOKEN in the container environment). Only names starting with WALDUR_ are accepted, so a mapper configuration cannot point at another secret of the Keycloak process; any other name is a configuration error and no request is sent. An unset variable is a configuration error too.
Transport. The API URL must use https:// with TLS validation on. An http:// URL or validation turned off is a configuration error, and no request is sent, unless Allow insecure Waldur connection (development only) is on. A configuration error fails closed: see Failure semantics.
Templates use Python string.Template syntax and render byte-identically to the rancher-kc-crd site agent's group_name_template and cluster_group_name_template; keep the two in sync. Variables:
| Variable | Value |
|---|---|
${cluster_id} |
resource_backend_id (the Rancher cluster ID). |
${resource_uuid} |
resource_uuid (the Waldur resource, i.e. the cluster), 32 lower-case hex characters. |
${rp_uuid} |
resource_project_uuid, 32 hex characters. |
${rp_uuid_short} |
First 8 hex characters of rp_uuid. |
${role_name} |
Waldur role name, case preserved (no lowercasing, as in the agent). |
An entry is skipped when a variable its template uses is empty (e.g. a cluster with no backend ID yet), when the template uses a variable the agent knows but this endpoint does not return (${customer_slug}, ${project_slug}, ${resource_slug}, ${project_name}), or when the name would exceed Keycloak's 255-character group-name limit.
Rancher. Rancher's Keycloak OIDC provider turns every entry of a top-level roles claim (in the ID token, access token, or userinfo, with userinfo winning) into a keycloakoidc_group://<name> principal. Keep the claim name roles and enable the mapper for the ID token, access token, and userinfo. Existing values of the claim are kept; Waldur groups are appended and duplicates removed. When the lookup succeeds with no roles, the claim is still written (possibly as an empty list), so a user who lost every role loses the groups too.
Failure semantics. A 5xx or other unexpected answer, a timeout (2 s connect, 5 s request), a connection error, or a non-list body is an outage; an unknown civil number ([]) is not an error. A 401, 403 or 404 is a refusal and follows When Waldur refuses the mapper below (with freeze, it is handled as an outage too).
A configuration error (token variable unset or without the WALDUR_ prefix, API URL or offering UUIDs missing or invalid, insecure transport without the development switch) always fails closed, whatever When Waldur refuses the mapper says: no request is sent, an ERROR is logged, and every request gets the claim without Waldur groups, with no 503 and no cached groups. It will not heal by itself, so it must not hide behind cached access while revokes stop working.
Outages are handled as follows: Error messages and logs never contain the request URL, since it carries the civil number; it is masked (EE38…01) where it appears.
- If the last-known answer cache is on and holds an entry for the user, its groups are served instead for every kind of request, and nothing fails (see below).
- Otherwise, with Fail on non-login error on, every request except the interactive login fails with HTTP 503
temporarily_unavailable:refresh_tokengrants, userinfo calls (…/protocol/openid-connect/userinfo, GET or POST), and any other grant or unrecognised request. Only anauthorization_codegrant, or a token issued directly from the browser flow (authorization endpoint orlogin-actions), counts as login. Rancher refetches groups either through a refresh grant or, while its stored access token is still valid, by calling userinfo with it alone; userinfo claims override the token's, so answering userinfo without the Waldur groups would drop the user's access. When the request fails instead, Rancher keeps the last-known groups. - In every other case (the interactive login, or the switch off) the mapper logs a warning and adds no Waldur groups; the rest of the token is issued normally.
When Waldur refuses the mapper. A 401, 403 or 404 means Waldur rejects the mapper itself rather than being down: the mapper token expired or its user was deactivated, the offering does not expose civil_number, or the offering UUID is wrong. Waldur will not recover from this on its own, so the choice is between keeping access and keeping revokes working:
| Value | Behaviour | Trade-off |
|---|---|---|
fail_closed (default) |
Log an ERROR and add no Waldur groups on every request, ignoring the cache. The claim is written without them. | Rancher removes Waldur-granted access at the next refresh, so everyone loses it until the mapper is fixed, but a revoke can never be held open by a broken token. |
freeze |
Handle it like an outage: non-login requests fail with 503 and cached groups are served. | Users keep their last-known access, but no change made in Waldur, revokes included, takes effect until the mapper is fixed. Logged only as a failed lookup, so watch the logs. |
Last-known answer cache. With Cache max age (seconds) above 0, every successful Waldur answer is kept per realm, user and mapper (key waldur-resource-roles:<realmId>:<userId>:<mapperId>, value: the group list and the time of the answer) with a lifespan of the max age. An empty answer is stored too, so a revoke followed by an outage does not bring access back. To avoid a write per token, an entry is rewritten only when the groups changed or it is older than a quarter of the max age. When Waldur cannot be asked and an entry exists, its groups are served and an INFO line records the masked civil number and the entry's age.
The entry lives in Keycloak's single-use object store (session.singleUseObjects()), not in a user attribute. A user attribute may be editable through the account console, where editing it would grant access, and an identity provider with FORCE sync can wipe it. The store is not user-editable, expires entries natively, and is shared across Keycloak nodes. The cost is that it is lost when every Keycloak node restarts at once.
Trade-off during an outage: a role revoked within the last max age before the outage keeps working until the entry expires, and access granted during the outage is not visible until Waldur answers again. Choose the max age as the longest window of stale access you accept.
The lookup runs once per Keycloak request and is cached on the session, so the ID token, access token, and userinfo of one request share one Waldur call per offering. Each call logs one INFO line with the offering, the masked civil number (EE38…01), the HTTP status, and the group count.
Building from source
Prerequisites
- JDK 17 (the project compiles to
--release 17). - Maven 3.6+.
- Docker — only needed for integration tests (
mvn verify).
Build
1 2 3 | |
The shaded JAR lands at target/waldur-keycloak-mapper-<version>.jar. Locally, <version> falls back to the <revision> property in pom.xml (currently 1.4.0); CI overrides it via -Drevision=<tag>.
Tests
- Unit tests under
src/test/java/...— verify URL construction and special-character encoding. - Integration test (
KeycloakProviderIT) — boots a Keycloak container with the freshly-built JAR mounted as a provider and asserts that all four mappers register. Auto-skips when Docker isn't available. The image registry can be overridden with-Ddocker.registry.prefix=(default mirrors viaregistry.hpc.ut.ee/mirror/).
Installation in Keycloak
-
Grab the JAR from the GitHub releases page (or build it yourself).
-
Drop it into Keycloak's providers directory. For a Docker-based deployment:
1 2 3 4 5 6 7 8 | |
The leading ./ matters — without it Docker Compose treats the entry as a named volume rather than a bind mount.
-
Restart Keycloak so the SPI loader picks up the new provider.
-
In the admin console, configure the mappers under Clients → your client → Client scopes → scope → Mappers → Add mapper → By configuration. Pick one of the display names listed at the top of this README.
Compatibility
| Mapper version | Keycloak | Java |
|---|---|---|
| 1.4.x | 26.x | 17 |
Older mapper versions targeted earlier Keycloak releases; check the release notes if you need to pin to an older line.
Releasing
Releases are developer-driven, not CI-automated:
1 2 | |
License
MIT — Copyright (c) 2025-2026 OpenNode OÜ.