files-idp: the SHARED OAuth2 secret is root-owned, so kanidm-provision cannot read it through basicSecretFile — the post-start dies Permission denied and takes kanidm.service (and the switch) with it #1095

Closed
opened 2026-09-01 02:45:22 +00:00 by ben · 0 comments
Owner

Failure

Drive 20260901T005009Z (target device) red at deploy-takeover after 26 green legs — the same leg as 20260831T202009Z, one rung deeper. #1088's declarative flip WORKED: kanidm-provision created the client, replaced its origins, and read back its basic secret (PATCH /v1/oauth2/nextcloud → 200, GET /v1/oauth2/nextcloud/_basic_secret → 200). It then died imposing the shared value:

kanidm-provision post-start:     Updating /v1/oauth2/nextcloud oauth2_rs_origin_landing
kanidm-provision post-start: Error:
   0: failed to read "/run/secrets/vars/files-oidc-secret/secret"
   1: Permission denied (os error 13)
   Location: src/client.rs:409
systemd[1]: kanidm.service: Control process exited, code=exited, status=1/FAILURE
systemd[1]: Failed to start kanidm identity management daemon.

Read live off the gateway (170.64.217.106, journalctl -u kanidm.service). Note the blast radius grew: the provisioning runs as kanidm.service's post-start, so its failure fails kanidm itself, and files-idp-client.service then fails downstream on a dead IdP (Failed to start Provision the files OAuth2 client…, retrying to its budget). Switch exit 4, masked_exit detector correct as always.

Diagnosis

internal/clan/files_idp_gateway.go:158 declares the shared generator with no owner:

renderFilesOIDCSecretGenerator(&b, "")   // → files.secret = { };  → clan default root:root 0400

That was correct while the gateway's reader was a root-run oneshot (secret="$(cat …)"). #1088 changed the reader: basicSecretFile is read by kanidm-provision, running as the non-root kanidm user. Root-owned 0400 is unreadable to it.

The precedent is one file over and already carries the rule. The gate client's own pre-shared secret, internal/clan/vmguest.go:570-575:

clan.core.vars.generators.gate-oidc = {
  # kanidm reads it as the non-root kanidm user (basicSecretFile); the control-
  # plane unit runs as root and reads it regardless.
  files.secret = { owner = "kanidm"; group = "kanidm"; mode = "0400"; };

Same reader, same mechanism, ownership already stated. The files client just never inherited it — the ownership argument was chosen for the OLD reader and not revisited when the reader changed.

Why no test caught it: the render tests pin the generator's presence and share = true, never its ownership; and ownership is a runtime property no eval can see — nix eval renders files.secret = { } perfectly happily. This class only shows on a live deploy.

Fix — landed

renderFilesOIDCSecretGenerator(&b, "kanidm") on the gateway side, with the reasoning recorded at the call site. Ownership is per-machine: the device declares the same generator (share = true shares the VALUE, not the file mode) and keeps its own owner — idss-idp co-hosted, root on the member device, where no kanidm user exists and a kanidm owner would fail the chown (the mirror of #1029).

Red-before-green: the render test now pins files.secret = { owner = "kanidm"; group = "kanidm"; mode = "0400"; }; and fails against the previous render; full internal/clan suite green.

Filed and fixed in the same motion by the watching session under ADR 0174 (a two-way-door render change with an in-repo precedent, revertible) rather than routed to the swarm, because the drive executor was already re-firing and each cycle costs a ~60-minute gateway-image rebuild before it would have re-hit this same line.

## Failure Drive `20260901T005009Z` (target `device`) red at `deploy-takeover` after 26 green legs — the same leg as `20260831T202009Z`, one rung deeper. #1088's declarative flip WORKED: kanidm-provision created the client, replaced its origins, and read back its basic secret (`PATCH /v1/oauth2/nextcloud` → 200, `GET /v1/oauth2/nextcloud/_basic_secret` → 200). It then died imposing the shared value: ``` kanidm-provision post-start: Updating /v1/oauth2/nextcloud oauth2_rs_origin_landing kanidm-provision post-start: Error: 0: failed to read "/run/secrets/vars/files-oidc-secret/secret" 1: Permission denied (os error 13) Location: src/client.rs:409 systemd[1]: kanidm.service: Control process exited, code=exited, status=1/FAILURE systemd[1]: Failed to start kanidm identity management daemon. ``` Read live off the gateway (`170.64.217.106`, `journalctl -u kanidm.service`). Note the blast radius grew: the provisioning runs as **kanidm.service's post-start**, so its failure fails *kanidm itself*, and `files-idp-client.service` then fails downstream on a dead IdP (`Failed to start Provision the files OAuth2 client…`, retrying to its budget). Switch exit 4, `masked_exit` detector correct as always. ## Diagnosis `internal/clan/files_idp_gateway.go:158` declares the shared generator with **no owner**: ```go renderFilesOIDCSecretGenerator(&b, "") // → files.secret = { }; → clan default root:root 0400 ``` That was correct while the gateway's reader was a root-run oneshot (`secret="$(cat …)"`). #1088 changed the reader: `basicSecretFile` is read by **kanidm-provision, running as the non-root `kanidm` user**. Root-owned 0400 is unreadable to it. The precedent is one file over and already carries the rule. The gate client's own pre-shared secret, `internal/clan/vmguest.go:570-575`: ```nix clan.core.vars.generators.gate-oidc = { # kanidm reads it as the non-root kanidm user (basicSecretFile); the control- # plane unit runs as root and reads it regardless. files.secret = { owner = "kanidm"; group = "kanidm"; mode = "0400"; }; ``` Same reader, same mechanism, ownership already stated. The files client just never inherited it — the ownership argument was chosen for the OLD reader and not revisited when the reader changed. **Why no test caught it:** the render tests pin the generator's presence and `share = true`, never its ownership; and ownership is a *runtime* property no eval can see — `nix eval` renders `files.secret = { }` perfectly happily. This class only shows on a live deploy. ## Fix — landed `renderFilesOIDCSecretGenerator(&b, "kanidm")` on the gateway side, with the reasoning recorded at the call site. Ownership is **per-machine**: the device declares the same generator (`share = true` shares the VALUE, not the file mode) and keeps its own owner — idss-idp co-hosted, root on the member device, where no kanidm user exists and a kanidm owner would fail the chown (the mirror of #1029). Red-before-green: the render test now pins `files.secret = { owner = "kanidm"; group = "kanidm"; mode = "0400"; };` and fails against the previous render; full `internal/clan` suite green. Filed and fixed in the same motion by the watching session under ADR 0174 (a two-way-door render change with an in-repo precedent, revertible) rather than routed to the swarm, because the drive executor was already re-firing and each cycle costs a ~60-minute gateway-image rebuild before it would have re-hit this same line.
ben closed this issue 2026-09-01 02:46:27 +00:00
Sign in to join this conversation.
No milestone
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
Matou/idss#1095
No description provided.