Skip to content

A sign-in token mints a namespace's admin token for the person who administers it - #187

Merged
zlareb1 merged 8 commits into
mainfrom
fix-sign-in-token-admin-mint
Nov 3, 2026
Merged

zlareb1 merged 8 commits into
mainfrom
fix-sign-in-token-admin-mint

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

A person who holds admin on a standard namespace can now mint a per-namespace admin token for it from the dashboard or service_accounts.create; a restricted namespace still caps the token at the sign-in role. Before, every such mint was refused with cannot delegate admin, because a sign-in token's flat writer role capped it.

Why

Every sign-in token carries roles: ["writer"] unless the person is a platform admin (server/auth/login.py, platform_roles). That is a platform role, not the person's role on any namespace: the gate (authz.check_authorized) admits a primary token to a namespace on the subject's grant alone, so the same session acts as admin wherever its grant says admin.

Delegation applied a different measure. _allowed_roles took the parent token's flat role as a ceiling and lowered the grant to it, so a child could never exceed writer from a sign-in token. The dashboard's token form offers the roles up to the person's grant and defaults to it, so for any namespace the person owns it asked for admin and the server answered 403. No one but a platform admin or the operator's loom mint-token could produce an admin token.

The fix makes delegation measure a primary token the way the gate does, for a per-namespace child: on a named, unrestricted namespace the child takes the subject's live grant. A flat child keeps the parent's role, because its one roles claim also answers ops that name no namespace, where the gate reads the flat role alone and a higher claim would admit an org-wide admin op the parent cannot run. A token minted from another token still stays inside that token's own claim, * keeps its cap, and a restricted namespace keeps the role from both token and grant, as _check_restricted requires.

Scope and risk

Touches one branch of server/auth/delegation.py::_allowed_roles and adds _primary. The request-time recheck is unchanged: a delegated token is still cut to its creator's live grant on every call, so a revoked or lowered grant ends the child's admin at once.

What widens: a primary token (sign-in, or loom mint-token with no creator) can now mint a per-namespace child at the subject's grant on a named namespace even when its flat role is lower. That is exactly what the parent can already do itself on that namespace. Off the namespace, a scoped token is gated on its best per-namespace role only for deployment-scoped ops, all of which require viewer, and for row-scoped ops, where memory.redact and blacklist.remove require admin: such a child passes that first gate where its sign-in parent is refused outright, and the handler's row_in_scope then bounds it to the creator's live grant on the row's namespace, so it still acts only where the person holds admin. Not widened: flat children, * requests, scoped or delegated parents, restricted namespaces, and a namespace without a grant (still refused).

Compatibility, rollout and rollback

  • Wire: no op or field changes. service_accounts.create and the Setup page accept an admin role where they refused it.
  • Operator steps: none.
  • Rollback: revert the commit. Admin tokens minted in between keep working only while the creator's grant says admin, as every delegated token does.

Tests

tests/unit/test_delegation.py:

  • test_a_sign_in_token_delegates_the_persons_grant_not_its_flat_role: a sign-in token with an admin grant mints a per-namespace admin child (named and bare); a delegated-list parent, a scoped parent and a restricted namespace are still refused. Fails on main at the mint, passes with the change.
  • test_a_flat_child_keeps_the_sign_in_tokens_role: a flat child stays writer and is refused ADMIN on a namespace-less op.
  • test_a_viewer_flat_parent_delegates_its_subjects_grant_per_namespace: a viewer primary token whose subject holds admin mints a per-namespace admin child; its flat child stays viewer.
  • test_an_unreadable_classification_keeps_the_token_role_cap: with the directory unreadable the mint keeps the old cap (fails closed).

Ran: ruff format --check, ruff check, mypy server/auth/delegation.py, scripts/gates/function_length_gate.py (baseline unchanged), tests/unit/test_delegation.py, tests/unit/test_me_setup_scoped_token.py, test_public_copy.py and test_doc_links.py (281 passed), tests/unit -k "deleg or grant or token or authz or service_account or setup" (2103 passed).

The refusal was observed on a running deployment from the dashboard's token form: the namespace owner, signed in, chose Admin for their own namespace and got 403 AUTH_INSUFFICIENT cannot delegate admin on <namespace>. The sign-in token's flat writer role is the only cap that path meets, since the owner's grant there is admin. A delegated writer token asking for an admin child on the same namespace gets the same refusal, and keeps getting it after this change.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. Checked: the gate's primary-token path in authz.check_authorized and _check_restricted, every ceiling_role caller, and the existing delegation matrix.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand: none affected.
  • A new migration is additive and numbered after the latest on main; no merged migration is edited. (none)
  • A behaviour change to any file a plugin ships bumps both plugin manifests' version. (no plugin file changed)
  • The frontend builds and its tests pass, if frontend/ changed. (unchanged)
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description.
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 8 commits November 3, 2026 07:28
…ministers it

Every sign-in token carries the flat role writer, a platform role, and
delegation capped a child at it, so no one but a platform admin could
mint an admin token, even for a namespace they hold admin on. The gate
admits a primary token on the subject's grant alone, so on a named,
unrestricted namespace the child now takes that grant. A token minted
from another token keeps its own claim as the cap, and a restricted
namespace keeps the role from both.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
…rent's role

A flat child's one role also answers ops that name no namespace, where the
gate reads the flat role alone, so it stays inside the parent's. Tests for
the flat child, a viewer primary parent and an unreadable classification.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
…goes

A delegated or per-namespace parent keeps its own role as the cap for a
scoped child too, which the tests now exercise. A primary flat token with
no role is a state no mint produces, and the gate admits such a token on
its grant alone, so the guard for it goes.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
…mment sits on its branch

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
@zlareb1
zlareb1 merged commit fef463e into main Nov 3, 2026
36 of 40 checks passed
@zlareb1
zlareb1 deleted the fix-sign-in-token-admin-mint branch November 3, 2026 11:24
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant