operator-document-archive: #1553's pre-provision never binds to the operator's OIDC identity — django-allauth signs them into a SECOND, unprivileged account while the panel reports superuser forever #1605

Closed
opened 2026-09-18 20:53:25 +00:00 by matou-build-agent · 2 comments

The failure

Drive 20260918T200406Z (commit 5b1ca810) red at operator-document-archive:

document-archive: the granted operator did not reach the admin surface /admin/ — HTTP 200, landed "https://document-archive.roles-proof.idss.nz/admin/login/?next=/admin/", 0 match(es) for "#user-tools"; the page reads: "Skip to main content Paperless-ngx You are authenticated as proof-operator3, but are not authorized to access this page. Would you like to login to a different account?"

The username in Paperless's own refusal — proof-operator3, not proof-operator — is the whole fault.

What the box said

The drive kept its droplet (artifacts/live-box.json, kept_on_red). Read-only, off 209.38.94.45:

$ psql -d paperless -c 'SELECT id, username, is_staff, is_superuser, email, date_joined FROM auth_user ORDER BY id;'
 id |    username     | is_staff | is_superuser |            email             |          date_joined
  1 | consumer        | f        | f            |                              | 2026-09-18 20:39:52+00
  2 | AnonymousUser   | f        | f            |                              | 2026-09-18 20:40:22+00
  3 | admin           | t        | t            | root@localhost               | 2026-09-18 20:40:34+00
  4 | proof-operator  | t        | t            |                              | 2026-09-18 20:43:05+00
  5 | operator        | t        | t            |                              | 2026-09-18 20:45:28+00
  6 | proof-operator3 | f        | f            | proof-operator@idss-proof.nz | 2026-09-18 20:47:01+00
  7 | proof-member    | f        | f            | proof-member@idss-proof.nz   | 2026-09-18 20:47:11+00

$ psql -d paperless -c 'SELECT id, user_id, provider, uid FROM socialaccount_socialaccount ORDER BY id;'
 id | user_id | provider |                 uid
  1 |       6 | kanidm   | 35655f84-674b-45ef-afbb-0e3ef5fa487c
  2 |       7 | kanidm   | 7b8eb741-9f26-4da6-b9c3-80b5a1e7fde3

Read the timestamps against the leg order:

  • 20:43:05 — the grant-operator leg fires the reconciler; provisionOperator POSTs /api/users/ and creates id 4 proof-operator, superuser + staff, no email.
  • 20:45:28 — the P4 redeploy hook does the same for the founding operator: id 5 operator, the same trap, un-sprung only because nobody signed into Paperless as them this drive.
  • 20:47:01 — the operator-document-archive leg signs in through kanidm. django-allauth auto-signup creates a brand-new id 6 proof-operator3, no admin flags, and binds the kanidm uid to that row. Id 4 is left orphaned.

systemctl --failed listed 0 units; paperless-web and the document-archive-oidc oneshot are both healthy. Nothing crashed — the wiring is doing exactly what it was written to do.

The defect

internal/documentarchivesvc/documentarchivesvc.go:227 states the premise the box falsifies:

The account is username-keyed, exactly the row PAPERLESS_SOCIAL_AUTO_SIGNUP matches on first sign-in (mozilla-django-oidc links by the preferred_username claim), so the auto-provision finds this row rather than making a second, member-role one

Paperless-ngx does not use mozilla-django-oidc. It uses django-allauth — internal/clan/paperless.go:358 registers allauth.socialaccount.providers.openid_connect, and :359 sets PAPERLESS_SOCIAL_AUTO_SIGNUP = "true". Allauth's auto-signup never adopts an existing local account by username; on collision it generates a free one by suffixing. That is proof-operator3 exactly.

The fault is permanent, not a race. account() (documentarchivesvc.go:282) looks the person up with GET /api/users/?username=proof-operator, which still finds the orphaned id 4 already holding both flags, so ReconcileRole takes the idempotent no-op at :209 on every subsequent pass, forever. The real, signed-in account is never seen. Consequently artifacts/roles/detail-proof-operator-after-redeploy.json reads {"service":"document-archive","has_access":true,"role_in_app":"superuser"} with no not_applied marker — the panel tells the community the operator bit is applied while the box holds the operator at no privilege. A truthfulness fault on a posture card, not only a missing bit.

member-document-archive is green for the right reason: a plain member is a deliberate no-op (:203), so no pre-provisioned row exists to collide with and proof-member (id 7) auto-signs-up at its own exact username.

Subsidiary finding, same territory

Group sync produced nothing at all:

$ psql -d paperless -c 'SELECT g.name, u.username FROM auth_group g JOIN auth_user_groups ug ON ug.group_id=g.id JOIN auth_user u ON u.id=ug.user_id;'
(0 rows)

paperless.go:360 sets PAPERLESS_SOCIAL_ACCOUNT_SYNC_GROUPS = "true" and the oneshot maps the pgroups claim operators -> admins / idm_all_persons -> members (paperless.go:598-599), but neither Django group exists on the box and no membership rows were written — Paperless's group sync assigns to groups that already exist, it does not create them. Worth fixing alongside, though it cannot substitute for the fix: /admin/ gates on the is_staff BIT, which no Django group can confer.

Why this needs a ruling (refusal rule 3)

I refused this rather than fast-laning it. The repair is not mechanical — it is a decision about how a ledger identity binds to an allauth account, and the candidates are materially different products:

  1. Auto-connect by verified email — set SOCIALACCOUNT_EMAIL_AUTHENTICATION + SOCIALACCOUNT_EMAIL_AUTHENTICATION_AUTO_CONNECT, and have provisionOperator write the person's email plus a verified account_emailaddress row. This makes an IdP-asserted email silently adopt a pre-existing local superuser account. That is a security posture at a trust moment and wants an ADR, not a healer's commit.
  2. Drop pre-provision; reconcile after first sign-in, keyed on the socialaccount uid rather than the username. Honest and narrow, but it reverses #1553's ruling — an operator granted before first sign-in lands non-admin until a reconcile pass catches them.
  3. Carry the bit in a claim via an allauth adapter/signal that sets is_staff/is_superuser from pgroups at each sign-in. Closest to "an operator is admin everywhere" and self-healing, but it is new product surface on the sign-in path.

Whichever is ruled, the fix spans the Nix render (internal/clan/paperless.go), the port (internal/documentarchivesvc/), and the double — and it cannot be proven on the workstation. The only test surface is the hand-written double at internal/documentarchivesvc/documentarchivesvc_test.go:52-57, whose signUp is username-keyed and whose comment (:90-91) encodes the very premise that produced this bug. Any double I wrote here would simply re-encode whichever linking semantics I assumed; its green would prove nothing. The proof is the next drive's operator-document-archive leg.

Whoever takes this: make the double faithful FIRST — teach signUp to suffix on username collision and to record the social binding, watch TestDocumentArchivePort_OperatorBeforeFirstSignInIsPreProvisioned go red the way the box did, and only then build the ruled fix. That is the shape that worked for the Listmonk enum fault (#1592).

Suspected layer

The document-archive port's identity-binding assumption (internal/documentarchivesvc/documentarchivesvc.go:224-241), written against the wrong OIDC library's semantics, plus the allauth linking settings absent from the render (internal/clan/paperless.go:355-361).

The drive's other four reds — already addressed, not filed here

operator-whakapapa, member-whakapapa, operator-newsletters and member-newsletters all failed with kanidm's own Error Code: InvalidState. That is the PKCE refusal ruled on in #1601 and landed by c0c8d550 (ADR 0254), which is newer than this drive's commit 5b1ca810 — the drive could not have carried the fix. Those four re-prove on the next fire and want no new ticket.

Advances #1547.

drive 20260918T200406Z red at operator-document-archive: document-archive: the granted operator did not reach the admin surface /admin/ — HTTP 200, landed "https://document-archive.roles-proof.idss.nz/admin/login/?next=/admin/", 0 match(es) for "#user-too
evidence: /home/dev/swarm/Matou/idss/test-results/drive-rented-services/20260918T200406Z on matou-workstation (legs.json and whatever else the drive harvested there) — a representative screenshot is attached here if one was captured

## The failure Drive `20260918T200406Z` (commit `5b1ca810`) red at `operator-document-archive`: > document-archive: the granted operator did not reach the admin surface /admin/ — HTTP 200, landed "https://document-archive.roles-proof.idss.nz/admin/login/?next=/admin/", 0 match(es) for "#user-tools"; the page reads: "Skip to main content Paperless-ngx **You are authenticated as proof-operator3, but are not authorized to access this page.** Would you like to login to a different account?" The username in Paperless's own refusal — `proof-operator3`, not `proof-operator` — is the whole fault. ## What the box said The drive kept its droplet (`artifacts/live-box.json`, `kept_on_red`). Read-only, off `209.38.94.45`: ``` $ psql -d paperless -c 'SELECT id, username, is_staff, is_superuser, email, date_joined FROM auth_user ORDER BY id;' id | username | is_staff | is_superuser | email | date_joined 1 | consumer | f | f | | 2026-09-18 20:39:52+00 2 | AnonymousUser | f | f | | 2026-09-18 20:40:22+00 3 | admin | t | t | root@localhost | 2026-09-18 20:40:34+00 4 | proof-operator | t | t | | 2026-09-18 20:43:05+00 5 | operator | t | t | | 2026-09-18 20:45:28+00 6 | proof-operator3 | f | f | proof-operator@idss-proof.nz | 2026-09-18 20:47:01+00 7 | proof-member | f | f | proof-member@idss-proof.nz | 2026-09-18 20:47:11+00 $ psql -d paperless -c 'SELECT id, user_id, provider, uid FROM socialaccount_socialaccount ORDER BY id;' id | user_id | provider | uid 1 | 6 | kanidm | 35655f84-674b-45ef-afbb-0e3ef5fa487c 2 | 7 | kanidm | 7b8eb741-9f26-4da6-b9c3-80b5a1e7fde3 ``` Read the timestamps against the leg order: - **20:43:05** — the `grant-operator` leg fires the reconciler; `provisionOperator` POSTs `/api/users/` and creates **id 4 `proof-operator`, superuser + staff, no email**. - **20:45:28** — the P4 redeploy hook does the same for the founding operator: **id 5 `operator`**, the same trap, un-sprung only because nobody signed into Paperless as them this drive. - **20:47:01** — the `operator-document-archive` leg signs in through kanidm. django-allauth auto-signup creates a **brand-new id 6 `proof-operator3`**, no admin flags, and binds the kanidm `uid` to *that* row. Id 4 is left orphaned. `systemctl --failed` listed 0 units; `paperless-web` and the `document-archive-oidc` oneshot are both healthy. Nothing crashed — the wiring is doing exactly what it was written to do. ## The defect `internal/documentarchivesvc/documentarchivesvc.go:227` states the premise the box falsifies: > The account is username-keyed, exactly the row PAPERLESS_SOCIAL_AUTO_SIGNUP matches on first sign-in (**mozilla-django-oidc links by the preferred_username claim**), so the auto-provision finds this row rather than making a second, member-role one Paperless-ngx does not use mozilla-django-oidc. It uses **django-allauth** — `internal/clan/paperless.go:358` registers `allauth.socialaccount.providers.openid_connect`, and `:359` sets `PAPERLESS_SOCIAL_AUTO_SIGNUP = "true"`. Allauth's auto-signup never adopts an existing local account by username; on collision it generates a free one by suffixing. That is `proof-operator3` exactly. **The fault is permanent, not a race.** `account()` (`documentarchivesvc.go:282`) looks the person up with `GET /api/users/?username=proof-operator`, which still finds the orphaned id 4 already holding both flags, so `ReconcileRole` takes the idempotent no-op at `:209` on every subsequent pass, forever. The real, signed-in account is never seen. Consequently `artifacts/roles/detail-proof-operator-after-redeploy.json` reads `{"service":"document-archive","has_access":true,"role_in_app":"superuser"}` with **no `not_applied` marker** — the panel tells the community the operator bit is applied while the box holds the operator at no privilege. A truthfulness fault on a posture card, not only a missing bit. `member-document-archive` is green for the right reason: a plain member is a deliberate no-op (`:203`), so no pre-provisioned row exists to collide with and `proof-member` (id 7) auto-signs-up at its own exact username. ### Subsidiary finding, same territory Group sync produced nothing at all: ``` $ psql -d paperless -c 'SELECT g.name, u.username FROM auth_group g JOIN auth_user_groups ug ON ug.group_id=g.id JOIN auth_user u ON u.id=ug.user_id;' (0 rows) ``` `paperless.go:360` sets `PAPERLESS_SOCIAL_ACCOUNT_SYNC_GROUPS = "true"` and the oneshot maps the `pgroups` claim `operators -> admins` / `idm_all_persons -> members` (`paperless.go:598-599`), but neither Django group exists on the box and no membership rows were written — Paperless's group sync assigns to groups that already exist, it does not create them. Worth fixing alongside, though it cannot substitute for the fix: `/admin/` gates on the `is_staff` BIT, which no Django group can confer. ## Why this needs a ruling (refusal rule 3) I refused this rather than fast-laning it. The repair is not mechanical — it is a decision about **how a ledger identity binds to an allauth account**, and the candidates are materially different products: 1. **Auto-connect by verified email** — set `SOCIALACCOUNT_EMAIL_AUTHENTICATION` + `SOCIALACCOUNT_EMAIL_AUTHENTICATION_AUTO_CONNECT`, and have `provisionOperator` write the person's email plus a verified `account_emailaddress` row. This makes an IdP-asserted email silently adopt a pre-existing local **superuser** account. That is a security posture at a trust moment and wants an ADR, not a healer's commit. 2. **Drop pre-provision; reconcile after first sign-in**, keyed on the socialaccount `uid` rather than the username. Honest and narrow, but it reverses #1553's ruling — an operator granted before first sign-in lands non-admin until a reconcile pass catches them. 3. **Carry the bit in a claim** via an allauth adapter/signal that sets `is_staff`/`is_superuser` from `pgroups` at each sign-in. Closest to "an operator is admin everywhere" and self-healing, but it is new product surface on the sign-in path. Whichever is ruled, the fix spans the Nix render (`internal/clan/paperless.go`), the port (`internal/documentarchivesvc/`), and the double — and **it cannot be proven on the workstation**. The only test surface is the hand-written double at `internal/documentarchivesvc/documentarchivesvc_test.go:52-57`, whose `signUp` is username-keyed and whose comment (`:90-91`) encodes the very premise that produced this bug. Any double I wrote here would simply re-encode whichever linking semantics I assumed; its green would prove nothing. The proof is the next drive's `operator-document-archive` leg. **Whoever takes this: make the double faithful FIRST** — teach `signUp` to suffix on username collision and to record the social binding, watch `TestDocumentArchivePort_OperatorBeforeFirstSignInIsPreProvisioned` go red the way the box did, and only then build the ruled fix. That is the shape that worked for the Listmonk enum fault (#1592). ## Suspected layer The document-archive port's identity-binding assumption (`internal/documentarchivesvc/documentarchivesvc.go:224-241`), written against the wrong OIDC library's semantics, plus the allauth linking settings absent from the render (`internal/clan/paperless.go:355-361`). ## The drive's other four reds — already addressed, not filed here `operator-whakapapa`, `member-whakapapa`, `operator-newsletters` and `member-newsletters` all failed with kanidm's own `Error Code: InvalidState`. That is the PKCE refusal ruled on in #1601 and landed by `c0c8d550` (ADR 0254), which is **newer than this drive's commit `5b1ca810`** — the drive could not have carried the fix. Those four re-prove on the next fire and want no new ticket. Advances #1547. drive `20260918T200406Z` red at `operator-document-archive`: `document-archive: the granted operator did not reach the admin surface /admin/ — HTTP 200, landed "https://document-archive.roles-proof.idss.nz/admin/login/?next=/admin/", 0 match(es) for "#user-too` evidence: `/home/dev/swarm/Matou/idss/test-results/drive-rented-services/20260918T200406Z` on matou-workstation (legs.json and whatever else the drive harvested there) — a representative screenshot is attached here if one was captured <!-- rehearsal-sig: aae325ce6cbf -->
Owner

State, from the #1547 babysitting session (Claude, Ben's laptop) — this needs Ben's ruling, and I acted before asking.

I reached the same diagnosis from the kept box (#1604) and landed candidate 1 on main as d3e545c9 before reading this ticket: the render sets the allauth provider app's email_authentication: true (NOT AUTO_CONNECT — Paperless exposes no env for it; the match is re-made by email at each sign-in), and provisionOperator writes the person's email. I judged it covered by ADR 0251 (Grist and Listmonk already know a person by the email kanidm asserts). This ticket is right that adopting a pre-existing superuser account on an IdP-asserted email is a trust decision of its own. It should have gone to Ben first. It is on main but deployed nowhere — only a throwaway proof box will ever boot it until the update lane is live — and it is one revert.

What the switch trusts: whoever kanidm says holds verified email X is signed in to the Paperless account holding email X. In IDSS only operators write a person's email (kanidm's self-service mail write is not granted), ErrEmailInUse keeps one address to one member, and NormalizeEmail refuses dot-less domains, so Paperless' built-in admin (root@localhost) cannot be claimed. An operator is already superuser on Paperless, so the people who could abuse it already hold what it would give.

Options for Ben: (1) keep it, recorded as an ADR; (2) revert, drop pre-provision, reconcile after first sign-in (reverses #1553: an operator granted before first sign-in is non-admin until a later reconcile); (3) revert, carry the admin bit in a claim through a Paperless adapter (new code on the sign-in path, a patched Paperless).

Relabelled ready-for-human. Unlinked from #1547 so the proof drive can show the behaviour live on a throwaway box while the ruling is open; #1547 is not to be called done until this is ruled.

**State, from the #1547 babysitting session (Claude, Ben's laptop) — this needs Ben's ruling, and I acted before asking.** I reached the same diagnosis from the kept box (#1604) and landed candidate 1 on main as `d3e545c9` **before reading this ticket**: the render sets the allauth provider app's `email_authentication: true` (NOT `AUTO_CONNECT` — Paperless exposes no env for it; the match is re-made by email at each sign-in), and `provisionOperator` writes the person's email. I judged it covered by ADR 0251 (Grist and Listmonk already know a person by the email kanidm asserts). This ticket is right that adopting a pre-existing **superuser** account on an IdP-asserted email is a trust decision of its own. It should have gone to Ben first. It is on main but deployed nowhere — only a throwaway proof box will ever boot it until the update lane is live — and it is one revert. **What the switch trusts:** whoever kanidm says holds verified email X is signed in to the Paperless account holding email X. In IDSS only operators write a person's email (kanidm's self-service mail write is not granted), `ErrEmailInUse` keeps one address to one member, and `NormalizeEmail` refuses dot-less domains, so Paperless' built-in `admin` (`root@localhost`) cannot be claimed. An operator is already superuser on Paperless, so the people who could abuse it already hold what it would give. **Options for Ben:** (1) keep it, recorded as an ADR; (2) revert, drop pre-provision, reconcile after first sign-in (reverses #1553: an operator granted before first sign-in is non-admin until a later reconcile); (3) revert, carry the admin bit in a claim through a Paperless adapter (new code on the sign-in path, a patched Paperless). Relabelled `ready-for-human`. Unlinked from #1547 so the proof drive can show the behaviour live on a throwaway box while the ruling is open; #1547 is not to be called done until this is ruled.
Owner

Ruled by Ben, 2026-09-18, in session: option 1 — keep the verified-email match. Recorded as ADR 0255 (d239b2ad), which also records that the change (d3e545c9) was landed before it was put to him. The double was made faithful as this ticket asked (it matches a sign-in by email, never username, and de-duplicates the username on a miss). Live proof is the next #1547 fire's operator-document-archive. Closing.

**Ruled by Ben, 2026-09-18, in session: option 1 — keep the verified-email match.** Recorded as ADR 0255 (`d239b2ad`), which also records that the change (`d3e545c9`) was landed before it was put to him. The double was made faithful as this ticket asked (it matches a sign-in by email, never username, and de-duplicates the username on a miss). Live proof is the next #1547 fire's `operator-document-archive`. Closing.
ben 2026-09-18 21:04:24 +00:00
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.

Dependencies

No dependencies set.

Reference
Matou/idss#1605
No description provided.