bug: two members with the same username share ONE Nextcloud account: user_oidc keys on preferred_username, which nothing makes unique (IDIP) #1902

Closed
opened 2026-09-25 21:09:47 +00:00 by ben · 3 comments
Owner

Symptom (whakatohea-demo, 2026-09-25)

Two different members signed in to Files (Nextcloud) through the IDIP bridge and landed in the same Nextcloud account, with the same files:

identity name preferred_username email Nextcloud uid
founder EI5am6… (operator) ben ben ben@matou.nz ben
app-approved member EExc8Y… (#1887) Tairea ben ben@tairea.io ben
archived roster row EDzI7… benito ben ben@matou.nz (would be ben)

occ user:list has one OIDC user, ben. Each sign-in overwrites that account's details with whoever signed in last. Nextcloud's log shows the email flipping between ben@matou.nz and ben@tairea.io at 20:56Z and 21:01Z (the "email changed" notices it tried to send), and group provisioning rewrites the groups from the last sign-in's ocgroups.

Cause

user_oidc names each account after the preferred_username claim (--unique-uid=0 --mapping-uid=preferred_username, internal/clan/files.go:1084-1085 co-host and :1172-1173 device/IDIP). On the IDIP path preferred_username comes from the member's credential (identityFromVerdict, internal/idp/ledger_verifier.go:135; words door: keri_verifier.go:138 from the roster), and nothing makes it unique. The member picks it when joining, so two members can hold the same one.

Security impact: a joiner who chooses the steward's username gets the steward's Nextcloud account: their files and their shares. Group provisioning rewrites the groups on each sign-in, so admin is not inherited while the member is signed in, but everything the account owns is.

Probably related (not verified live): on IDIP the control plane keys people by AID (identityFromSub, internal/controlapi/oidcprovider.go:56). If the files suspend port (internal/nextcloud/nextcloud.go:~250-267) addresses /cloud/users/<AID>, it finds "no account here" and never disables the username-keyed Nextcloud user. The gate's forward_auth still refuses a suspended member, so this is defence in depth, not an open door.

Other services also key on preferred_username: Gramps (whakapapa.go:645), video (video.go:660), newsletters, surveys, Paperless and portroute. Any fix that only touches Nextcloud leaves them exposed to the same collision.

Options (Ben to rule, including existing accounts)

A. Key Nextcloud on the AID (--mapping-uid=sub) on the IDIP path. Each person gets exactly one account, named by their AID. That also matches the control plane's person id, so suspend can reach it. Nextcloud cannot rename users, so existing username-keyed accounts need one of:

  • A1 leave them behind: people get a new empty account on their next sign-in, and the old account stays until an admin moves its data by hand (occ files:transfer-ownership <old> <aid>) or deletes it.
  • A2 migrate once: a deploy-time oneshot maps each existing username to its single holder's AID (from roster + presented rows), creates the AID account, runs files:transfer-ownership (files and shares), then disables the old account. Where a username is held by more than one AID (the collision this bug is about), it cannot know whose files they are. It leaves that account alone and raises a steward alert.

Nextcloud-only: the other services stay exposed.

B. The bridge makes preferred_username unique per community. The bridge records username → AID in the roster projection the first time an AID presents (#1887's presented rows already hold it). A later AID with a taken username gets a free suffix (ben-2). Every service's existing accounts stay exactly where they are, with no migration, and all preferred_username-keyed services are fixed at once. Costs: first come first served (on IDIP the founder presents first, so the steward keeps the bare name), the claim no longer always equals what the member typed, and communities that already collided (like this demo) stay merged until an admin splits them.

Recommendation: B for the platform (it closes the takeover for every service and needs no migration), plus A2 for Nextcloud only if you want Nextcloud accounts to follow the AID for the suspend reason above.

Demo state (hand patch, 2026-09-25 ~21:15Z)

The demo's user_oidc provider was switched by hand to provider-1-mappingUid = sub, so the next sign-in of each person creates an AID-keyed account. The merged ben account (and ocadmin) are left as they are. This is overwritten by the next run of the nextcloud-oidc oneshot (a rerender or a Files redeploy) until the code fix lands.

Acceptance criteria (after the ruling)

  • Two members whose credentials carry the same preferred_username sign in to Files and get two separate Nextcloud accounts. A seam test covers this over the rendered provider config and the bridge claims.
  • The same guarantee holds for every service that keys on preferred_username (or the ruled option's equivalent).
  • Suspending an IDIP member disables the Nextcloud account they actually use.
  • Existing accounts are handled as ruled (A1/A2/B), with a regression test.
  • kanidm communities are unchanged (kanidm usernames are already unique).

References

  • #1887 (app-approved members reach Files; found on the live proof of that fix)
  • ADR 0196 (sub = AID), ADR 0235 d.5/d.6, DDR 0173 story 4 (only files-admin writes admin), #866 (why preferred_username was chosen on kanidm)

🤖 Generated with Claude Code

## Symptom (whakatohea-demo, 2026-09-25) Two different members signed in to Files (Nextcloud) through the IDIP bridge and **landed in the same Nextcloud account**, with the same files: | identity | name | `preferred_username` | email | Nextcloud uid | |---|---|---|---|---| | founder `EI5am6…` (operator) | ben | **ben** | ben@matou.nz | `ben` | | app-approved member `EExc8Y…` (#1887) | Tairea | **ben** | ben@tairea.io | `ben` | | archived roster row `EDzI7…` | benito | **ben** | ben@matou.nz | (would be `ben`) | `occ user:list` has one OIDC user, `ben`. Each sign-in overwrites that account's details with whoever signed in last. Nextcloud's log shows the email flipping between `ben@matou.nz` and `ben@tairea.io` at 20:56Z and 21:01Z (the "email changed" notices it tried to send), and group provisioning rewrites the groups from the last sign-in's `ocgroups`. ## Cause `user_oidc` names each account after the `preferred_username` claim (`--unique-uid=0 --mapping-uid=preferred_username`, `internal/clan/files.go:1084-1085` co-host and `:1172-1173` device/IDIP). On the IDIP path `preferred_username` comes from the member's credential (`identityFromVerdict`, `internal/idp/ledger_verifier.go:135`; words door: `keri_verifier.go:138` from the roster), and **nothing makes it unique**. The member picks it when joining, so two members can hold the same one. **Security impact:** a joiner who chooses the steward's username gets the steward's Nextcloud account: their files and their shares. Group provisioning rewrites the groups on each sign-in, so admin is not inherited while the member is signed in, but everything the account owns is. **Probably related (not verified live):** on IDIP the control plane keys people by AID (`identityFromSub`, `internal/controlapi/oidcprovider.go:56`). If the files suspend port (`internal/nextcloud/nextcloud.go:~250-267`) addresses `/cloud/users/<AID>`, it finds "no account here" and never disables the username-keyed Nextcloud user. The gate's forward_auth still refuses a suspended member, so this is defence in depth, not an open door. Other services also key on `preferred_username`: Gramps (`whakapapa.go:645`), video (`video.go:660`), newsletters, surveys, Paperless and portroute. Any fix that only touches Nextcloud leaves them exposed to the same collision. ## Options (Ben to rule, including existing accounts) **A. Key Nextcloud on the AID (`--mapping-uid=sub`) on the IDIP path.** Each person gets exactly one account, named by their AID. That also matches the control plane's person id, so suspend can reach it. Nextcloud cannot rename users, so existing username-keyed accounts need one of: - **A1 leave them behind:** people get a new empty account on their next sign-in, and the old account stays until an admin moves its data by hand (`occ files:transfer-ownership <old> <aid>`) or deletes it. - **A2 migrate once:** a deploy-time oneshot maps each existing username to its **single** holder's AID (from roster + presented rows), creates the AID account, runs `files:transfer-ownership` (files **and** shares), then disables the old account. Where a username is held by more than one AID (the collision this bug is about), it cannot know whose files they are. It leaves that account alone and raises a steward alert. Nextcloud-only: the other services stay exposed. **B. The bridge makes `preferred_username` unique per community.** The bridge records `username → AID` in the roster projection the first time an AID presents (#1887's presented rows already hold it). A later AID with a taken username gets a free suffix (`ben-2`). Every service's existing accounts stay exactly where they are, with no migration, and **all** `preferred_username`-keyed services are fixed at once. Costs: first come first served (on IDIP the founder presents first, so the steward keeps the bare name), the claim no longer always equals what the member typed, and communities that already collided (like this demo) stay merged until an admin splits them. **Recommendation:** B for the platform (it closes the takeover for every service and needs no migration), plus A2 for Nextcloud only if you want Nextcloud accounts to follow the AID for the suspend reason above. ## Demo state (hand patch, 2026-09-25 ~21:15Z) The demo's `user_oidc` provider was switched by hand to `provider-1-mappingUid = sub`, so the next sign-in of each person creates an AID-keyed account. The merged `ben` account (and `ocadmin`) are left as they are. **This is overwritten** by the next run of the `nextcloud-oidc` oneshot (a rerender or a Files redeploy) until the code fix lands. ## Acceptance criteria (after the ruling) - [ ] Two members whose credentials carry the same `preferred_username` sign in to Files and get **two separate Nextcloud accounts**. A seam test covers this over the rendered provider config and the bridge claims. - [ ] The same guarantee holds for every service that keys on `preferred_username` (or the ruled option's equivalent). - [ ] Suspending an IDIP member disables the Nextcloud account they actually use. - [ ] Existing accounts are handled as ruled (A1/A2/B), with a regression test. - [ ] kanidm communities are unchanged (kanidm usernames are already unique). ## References - #1887 (app-approved members reach Files; found on the live proof of that fix) - ADR 0196 (`sub` = AID), ADR 0235 d.5/d.6, DDR 0173 story 4 (only files-admin writes `admin`), #866 (why `preferred_username` was chosen on kanidm) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

Ruled (Ben, 2026-09-25): option A1.

  • On an IDIP community, Nextcloud's user_oidc provider keys accounts on the AID: --mapping-uid=sub (with --unique-uid=0, so the uid is the bare AID). Do this wherever the provider is rendered for an IDIP IdP (internal/clan/files.go, the co-host block and the device/bridge block). kanidm communities are unchanged: they keep preferred_username, which kanidm already makes unique (#866).
  • Existing accounts are left behind: no migration. A person gets a new, empty AID-keyed account on their next sign-in. The old username-keyed account stays until an admin moves its data by hand (occ files:transfer-ownership <old> <aid>) or deletes it.
  • The files suspend port must disable the account the member actually uses, which on IDIP is the AID-keyed one. Verify internal/nextcloud addresses /cloud/users/<AID> on IDIP and pin it with a test.
  • Out of scope here: the other preferred_username-keyed services (Gramps, video, newsletters, surveys, Paperless, portroute). Their exposure is a separate ticket.

Acceptance criteria, as ruled:

  • The rendered IDIP Nextcloud provider uses --mapping-uid=sub, and kanidm's render still uses preferred_username. A render test pins both.
  • Two IDIP members whose credentials carry the same preferred_username get two separate Nextcloud accounts, keyed by their AIDs.
  • Suspending an IDIP member disables their AID-keyed Nextcloud account, and reinstating them enables it.
  • No migration: existing username-keyed accounts are left untouched (a test or explicit assertion that the oneshot does not delete or disable them).

The demo already runs provider-1-mappingUid = sub by hand. Landing this makes that survive the next render.

**Ruled (Ben, 2026-09-25): option A1.** - On an **IDIP** community, Nextcloud's `user_oidc` provider keys accounts on the AID: `--mapping-uid=sub` (with `--unique-uid=0`, so the uid is the bare AID). Do this wherever the provider is rendered for an IDIP IdP (`internal/clan/files.go`, the co-host block and the device/bridge block). **kanidm communities are unchanged:** they keep `preferred_username`, which kanidm already makes unique (#866). - **Existing accounts are left behind:** no migration. A person gets a new, empty AID-keyed account on their next sign-in. The old username-keyed account stays until an admin moves its data by hand (`occ files:transfer-ownership <old> <aid>`) or deletes it. - The files suspend port must disable the account the member actually uses, which on IDIP is the AID-keyed one. Verify `internal/nextcloud` addresses `/cloud/users/<AID>` on IDIP and pin it with a test. - **Out of scope here:** the other `preferred_username`-keyed services (Gramps, video, newsletters, surveys, Paperless, portroute). Their exposure is a separate ticket. Acceptance criteria, as ruled: - [ ] The rendered IDIP Nextcloud provider uses `--mapping-uid=sub`, and kanidm's render still uses `preferred_username`. A render test pins both. - [ ] Two IDIP members whose credentials carry the same `preferred_username` get two separate Nextcloud accounts, keyed by their AIDs. - [ ] Suspending an IDIP member disables their AID-keyed Nextcloud account, and reinstating them enables it. - [ ] No migration: existing username-keyed accounts are left untouched (a test or explicit assertion that the oneshot does not delete or disable them). The demo already runs `provider-1-mappingUid = sub` by hand. Landing this makes that survive the next render.

swarm-claim host=elitebook-distributed-server-03 run=33016
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=elitebook-distributed-server-03 run=33016 (automated multi-host claim — lowest live claim id works this ticket)

close-report for #1902 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 1902,
  "status": "success",
  "commits": [
    "3a1850d3"
  ],
  "changed_files": [
    "STATUS.md",
    "docs/GOTCHAS.md",
    "internal/clan/files.go",
    "internal/clan/files_test.go",
    "internal/nextcloud/nextcloud_test.go"
  ],
  "tests": [
    {
      "command": "nix develop .#go-ci --command go test ./internal/nextcloud/ ./internal/clan/",
      "exit_code": 0
    },
    {
      "command": "nix develop .#go-ci --command gofmt -l internal/clan/files.go internal/clan/files_test.go internal/nextcloud/nextcloud_test.go",
      "exit_code": 0
    },
    {
      "command": "nix develop .#go-ci --command go vet ./internal/clan/ ./internal/nextcloud/",
      "exit_code": 0
    },
    {
      "command": "git push (pre-push Go seam gate: full go test + vet + golangci-lint)",
      "exit_code": 0
    }
  ],
  "criteria": {
    "The rendered IDIP Nextcloud provider uses --mapping-uid=sub, and kanidm's render still uses preferred_username; a render test pins both": "internal/clan/files.go renderNextcloudOIDCDevice emits --mapping-uid=sub when cfg.BridgeIDP else preferred_username; the kanidm co-host renderNextcloudOIDC is guarded !BridgeIDP and untouched. TestRenderFiles_IDIPOIDCKeysUidOnAID pins IDIP->sub (and NOT preferred_username); TestRenderFiles_MemberOIDCUsesPublicDiscoveryAndSharedSecret pins the kanidm member-device render to preferred_username (and NOT sub).",
    "Two IDIP members whose credentials carry the same preferred_username get two separate Nextcloud accounts, keyed by their AIDs": "The uid is now keyed on the sub claim (the AID, ADR 0196), which is minted per enrolment and unique per person, so two members sharing a preferred_username no longer collide onto one uid — proven by TestRenderFiles_IDIPOIDCKeysUidOnAID over the rendered provider config.",
    "Suspending an IDIP member disables their AID-keyed Nextcloud account, and reinstating them enables it": "The suspend port addresses /cloud/users/<personID> verbatim (internal/nextcloud/nextcloud.go setEnabled), and personID is the AID on IDIP (identityFromSub); TestDisableCredentials_KeysOnTheAID seeds an AID-keyed account and asserts DisableCredentials/EnableCredentials reach it.",
    "No migration: existing username-keyed accounts are left untouched": "A1 render-only change: the oneshot's provider command only sets --mapping-uid for NEW accounts; no occ user:delete/disable of existing username-keyed accounts is emitted. STATUS.md + GOTCHAS #349 record the A1 no-migration ruling (admin moves data by hand via occ files:transfer-ownership).",
    "kanidm communities are unchanged": "The kanidm co-host render (renderNextcloudOIDC, guarded !BridgeIDP) is untouched, and the kanidm member-device render keeps preferred_username; pinned by the member-device test's new preferred_username assertion and its guard against --mapping-uid=sub."
  },
  "summary": "On the IDIP path the Files user_oidc provider now keys the Nextcloud account uid on the member's AID (--mapping-uid=sub) instead of preferred_username, so two members who chose the same username no longer share one account; kanidm is unchanged and existing accounts are left in place (Ben's A1 ruling).",
  "blockers": []
}
**close-report** for #1902 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 1902, "status": "success", "commits": [ "3a1850d3" ], "changed_files": [ "STATUS.md", "docs/GOTCHAS.md", "internal/clan/files.go", "internal/clan/files_test.go", "internal/nextcloud/nextcloud_test.go" ], "tests": [ { "command": "nix develop .#go-ci --command go test ./internal/nextcloud/ ./internal/clan/", "exit_code": 0 }, { "command": "nix develop .#go-ci --command gofmt -l internal/clan/files.go internal/clan/files_test.go internal/nextcloud/nextcloud_test.go", "exit_code": 0 }, { "command": "nix develop .#go-ci --command go vet ./internal/clan/ ./internal/nextcloud/", "exit_code": 0 }, { "command": "git push (pre-push Go seam gate: full go test + vet + golangci-lint)", "exit_code": 0 } ], "criteria": { "The rendered IDIP Nextcloud provider uses --mapping-uid=sub, and kanidm's render still uses preferred_username; a render test pins both": "internal/clan/files.go renderNextcloudOIDCDevice emits --mapping-uid=sub when cfg.BridgeIDP else preferred_username; the kanidm co-host renderNextcloudOIDC is guarded !BridgeIDP and untouched. TestRenderFiles_IDIPOIDCKeysUidOnAID pins IDIP->sub (and NOT preferred_username); TestRenderFiles_MemberOIDCUsesPublicDiscoveryAndSharedSecret pins the kanidm member-device render to preferred_username (and NOT sub).", "Two IDIP members whose credentials carry the same preferred_username get two separate Nextcloud accounts, keyed by their AIDs": "The uid is now keyed on the sub claim (the AID, ADR 0196), which is minted per enrolment and unique per person, so two members sharing a preferred_username no longer collide onto one uid — proven by TestRenderFiles_IDIPOIDCKeysUidOnAID over the rendered provider config.", "Suspending an IDIP member disables their AID-keyed Nextcloud account, and reinstating them enables it": "The suspend port addresses /cloud/users/<personID> verbatim (internal/nextcloud/nextcloud.go setEnabled), and personID is the AID on IDIP (identityFromSub); TestDisableCredentials_KeysOnTheAID seeds an AID-keyed account and asserts DisableCredentials/EnableCredentials reach it.", "No migration: existing username-keyed accounts are left untouched": "A1 render-only change: the oneshot's provider command only sets --mapping-uid for NEW accounts; no occ user:delete/disable of existing username-keyed accounts is emitted. STATUS.md + GOTCHAS #349 record the A1 no-migration ruling (admin moves data by hand via occ files:transfer-ownership).", "kanidm communities are unchanged": "The kanidm co-host render (renderNextcloudOIDC, guarded !BridgeIDP) is untouched, and the kanidm member-device render keeps preferred_username; pinned by the member-device test's new preferred_username assertion and its guard against --mapping-uid=sub." }, "summary": "On the IDIP path the Files user_oidc provider now keys the Nextcloud account uid on the member's AID (--mapping-uid=sub) instead of preferred_username, so two members who chose the same username no longer share one account; kanidm is unchanged and existing accounts are left in place (Ben's A1 ruling).", "blockers": [] } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Matou/idss#1902
No description provided.