Keycloak key custody: app-owned spaces fail every write unless a Keycloak group of the same name exists #967

Closed
opened 2026-10-19 00:20:20 +00:00 by Cordy · 6 comments
Owner

Found in batch 3 (Task D, 2026-10-19). Pre-existing. Found in the test rig with the real Keycloak key client against a fake server; not yet confirmed live.

What happens: under Keycloak-profile key custody, a space's key lives as an attribute on the Keycloak group named after the space. An app-owned space (created in Cairn, not in the directory) has no such group unless one happens to exist, so every write to it fails with group "<name>" not found. The comment in cmd/cairnd/main.go says app-owned spaces work under every custody.

To do:

  1. Confirm live on cairn-enc (files.c0rdyceps.ch, Keycloak-profile custody): does creating an app-owned space and uploading into it work? Earlier live checks may have used IdP-managed spaces only.
  2. Decide where an app-owned space's key lives under Keycloak custody, for example a Cairn-managed group or another attribute holder. This changes custody, so it needs research and a decision.
  3. Fix the code comment either way.
Found in batch 3 (Task D, 2026-10-19). Pre-existing. Found in the test rig with the real Keycloak key client against a fake server; not yet confirmed live. **What happens:** under Keycloak-profile key custody, a space's key lives as an attribute on the Keycloak group named after the space. An app-owned space (created in Cairn, not in the directory) has no such group unless one happens to exist, so every write to it fails with `group "<name>" not found`. The comment in `cmd/cairnd/main.go` says app-owned spaces work under every custody. **To do:** 1. Confirm live on cairn-enc (files.c0rdyceps.ch, Keycloak-profile custody): does creating an app-owned space and uploading into it work? Earlier live checks may have used IdP-managed spaces only. 2. Decide where an app-owned space's key lives under Keycloak custody, for example a Cairn-managed group or another attribute holder. This changes custody, so it needs research and a decision. 3. Fix the code comment either way.
Author
Owner

#1002 research (2026-10-26), research-1002-1-cairn.md §1.5, adds the other half of this issue.

Wrong key holder. Under Keycloak custody, an app-owned space whose name equals any top-level Keycloak group (case-insensitive) stores its key on that unrelated group. Whoever can manage that group in Keycloak can read or delete the key, and deleting the group destroys the app space's key. INFERRED from keycloak_group.go:141; a test sketch is in the file.

Multi-instance. The keyset cache has no TTL (keycloak_group.go:70), so after a group is deleted and recreated, instances can disagree on which key a space uses (#742).

Recommended (stage 3 of #1002):

  • Find the key holder by the group id recorded in the space registry, never by name.
  • App spaces get a Cairn-owned holder.

To be designed together with #965.

#1002 research (2026-10-26), `research-1002-1-cairn.md` §1.5, adds the other half of this issue. **Wrong key holder.** Under Keycloak custody, an app-owned space whose name equals **any** top-level Keycloak group (case-insensitive) stores its key on that unrelated group. Whoever can manage that group in Keycloak can read or delete the key, and deleting the group destroys the app space's key. INFERRED from keycloak_group.go:141; a test sketch is in the file. **Multi-instance.** The keyset cache has no TTL (keycloak_group.go:70), so after a group is deleted and recreated, instances can disagree on which key a space uses (#742). **Recommended (stage 3 of #1002):** - Find the key holder by the group id recorded in the space registry, never by name. - App spaces get a Cairn-owned holder. To be designed together with #965.
Author
Owner

Decision (Nikola, 2026-10-26): keys by space id. Keys are found by space id and the recorded group id, never by name. App-owned spaces get a Cairn-owned key holder. Research and design come first, inside the #1002 stage 2+3 batch, together with #965.

**Decision (Nikola, 2026-10-26): keys by space id.** Keys are found by space id and the recorded group id, never by name. App-owned spaces get a Cairn-owned key holder. Research and design come first, inside the #1002 stage 2+3 batch, together with #965.
Author
Owner

Stage 3 research (2026-10-26, research-1002-5-keys.md; summary on #1002).

More ways a key can be read through Keycloak today (VERIFIED in Keycloak source):

  • Any credential with view-users or manage-users can read the key attribute, and so can a delegated viewer or manager of that one group.
  • The "User Attribute" token mapper falls back to group attributes, so a misconfigured mapper puts space keys into members' tokens.

Keycloak key creation can lose a key. It reads, then writes, with no version check (keycloak_group.go:150-196), so two instances creating a key at once can lose one.

Recommended: a Cairn-owned subgroup per space id under one parent group, found by Keycloak group id, with a pinned public key and a generation number. Decisions follow on #1002.

Stage 3 research (2026-10-26, `research-1002-5-keys.md`; summary on #1002). **More ways a key can be read through Keycloak today (VERIFIED in Keycloak source):** - Any credential with `view-users` or `manage-users` can read the key attribute, and so can a delegated viewer or manager of that one group. - The "User Attribute" token mapper falls back to group attributes, so a misconfigured mapper puts space keys into members' tokens. **Keycloak key creation can lose a key.** It reads, then writes, with no version check (keycloak_group.go:150-196), so two instances creating a key at once can lose one. **Recommended:** a Cairn-owned subgroup per space id under one parent group, found by Keycloak group id, with a pinned public key and a generation number. Decisions follow on #1002.
Author
Owner

Decision (Nikola, 2026-10-26):

  • Every space gets a Cairn-owned key holder: in Keycloak, a subgroup per space id under one parent, found by group id and hidden from all lists.
  • The public key is pinned, and a mismatch refuses writes.
  • Keys shared by name or held on the wrong group are flagged for rotation at migration.

Details are on #1002.

**Decision (Nikola, 2026-10-26):** - Every space gets a Cairn-owned key holder: in Keycloak, a subgroup per space id under one parent, found by group id and hidden from all lists. - The public key is pinned, and a mismatch refuses writes. - Keys shared by name or held on the wrong group are flagged for rotation at migration. Details are on #1002.
Author
Owner

Fixed in v0.6.358 (#1002 stage 3, PR #1017). Under Keycloak custody, a space's key now lives in a Cairn-made, marked group /cairn-keys/<space id>, created on the space's first upload. It no longer depends on a directory group with the space's name, so app-owned spaces work. The code comment and handbook are corrected.

Live so far: the move on files created and marked /cairn-keys and copied 4 keys, and Check keys passed. Still open: the live upload into an app-owned space on files (step 1 of this issue). I'm keeping this open until that is done; it is tracked in #1005 section G.

Fixed in v0.6.358 (#1002 stage 3, PR #1017). Under Keycloak custody, a space's key now lives in a Cairn-made, marked group `/cairn-keys/<space id>`, created on the space's first upload. It no longer depends on a directory group with the space's name, so app-owned spaces work. The code comment and handbook are corrected. Live so far: the move on files created and marked `/cairn-keys` and copied 4 keys, and Check keys passed. **Still open:** the live upload into an app-owned space on files (step 1 of this issue). I'm keeping this open until that is done; it is tracked in #1005 section G.
Author
Owner

Live check on files (Keycloak custody), 2026-10-26:

  • Created test space zz-967-test and uploaded hello-967.txt.
  • The first upload created the holder /cairn-keys/01a17a756d4f52d57ddf40d4f6fc29ca (createdBy: first-upload, generation 1, hybrid). The key state went from new to ok, and the file reads back.
  • The space's key no longer depends on a Keycloak group named after the space.

Limit: files runs IdP power mode. There, every new space is a directory space (Cairn creates the Keycloak group /zz-967-test), and the app-owned lifecycle is not wired (DELETE /api/v1/spaces/{name} answers 501). The literal case of this issue, an app-owned space under Keycloak custody, cannot occur on files as configured. It is covered by the K2/K3 tests against the Keycloak fake. The key path it would use (/cairn-keys/<id> on first upload) is the one verified live above.

The test space is still on files. Its cleanup is pending Nikola's decision, because it needs the Keycloak group /zz-967-test deleted.

Closing: points 1 to 3 are done as far as this setup allows.

**Live check on files (Keycloak custody), 2026-10-26:** - Created test space `zz-967-test` and uploaded `hello-967.txt`. - The first upload created the holder `/cairn-keys/01a17a756d4f52d57ddf40d4f6fc29ca` (`createdBy: first-upload`, generation 1, hybrid). The key state went from `new` to `ok`, and the file reads back. - The space's key no longer depends on a Keycloak group named after the space. **Limit:** files runs IdP power mode. There, every new space is a directory space (Cairn creates the Keycloak group `/zz-967-test`), and the app-owned lifecycle is not wired (`DELETE /api/v1/spaces/{name}` answers 501). The literal case of this issue, an app-owned space under Keycloak custody, cannot occur on files as configured. It is covered by the K2/K3 tests against the Keycloak fake. The key path it would use (`/cairn-keys/<id>` on first upload) is the one verified live above. The test space is still on files. Its cleanup is pending Nikola's decision, because it needs the Keycloak group `/zz-967-test` deleted. Closing: points 1 to 3 are done as far as this setup allows.
Cordy closed this issue 2026-10-26 23:06:02 +00:00
Sign in to join this conversation.
No labels
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Cordy/Cairn#967
No description provided.