Public: anyone can read this; the crew can change it.

Roles, part 3c: a token a member mints carries scopes only over that member's own repositories and apps #2401

Parked opened this
Closed without merging

A token minted by a non-admin person now reaches only that person's own repositories and apps, and can't carry the admin scope. An admin's minting is unchanged. The type check is clean and the new test file passes.

Notes

stopped parked by the crew deploy b2d7105

opened this

A token minted by a non-admin person now reaches only that person's own repositories and apps, and can't carry the admin scope. An admin's minting is unchanged. The type check is clean and the new test file passes. I also ran the roles, tokens, schema-additive, API, auth, MCP, proposal-token-doors and account suites, and all passed. I did not run the whole suite.

What changed

  • Flag on the token: a new migration adds token.own_only (ALTER TABLE … ADD COLUMN with a default of 0, so it is additive). createToken in src/actions/users.ts sets it for any non-admin human account. Tokens minted before this keep what they could reach.
  • Refusal at minting: asking for admin as a non-admin person returns too_wide.
    • On POST /api/v1/tokens that is a 403 with the line "a token you mint reaches only your own repositories and apps: choose read or read and write".
    • On /settings/tokens the same line shows as a flash. The form no longer offers the admin option to non-admins.
  • Refusal at use: src/http/own_gate.ts runs after the proposal gate on each request. For a flagged token, a git path (/:owner/:name.git/…) or an API path (/api/v1/repos/:owner/:name/…) under another account returns 403. Paths that name no repository pass as before.
  • Docs: docs/ROLES.md has a short "Tokens" section.
  • Tests: test/token-own-only.test.ts covers:
    • A member's token works on their own repository.
    • The same token gets 403 on another account's repository, over the API and over git.
    • The admin scope is refused on the API and the page.
    • An admin's admin token still reaches every repository.
    • How ownerNamed reads a path.

What I chose not to do

  • Roles: guests are treated like members here, since they can't own anything anyway. Agents and organizations are untouched.
  • Org-owned repositories: a member's token is refused on them, even where the member could write through a team. "Own" means the member's own account.
  • Other-account lookups: /api/v1/users/:username/repos and /api/v1/orgs/… name no repository, so they still pass the gate. Those routes act as the member and expose nothing new.
  • Per-repository or per-app scopes: I did not add scopes tied to a single repository or app. Scopes stay ro, rw and admin.

To try it: as a non-admin, curl -X POST $URL/api/v1/tokens -d '{"username":…,"password":…,"scope":"rw"}'. Use the token on /api/v1/repos/<you>/<repo> (200) and on /api/v1/repos/<other>/<repo> (403). Asking for "scope":"admin" gets the 403 above.

🤖 Generated with Claude Code

Closes #2386

commented

A token minted by a non-admin person now reaches only that person's own repositories and apps, and can't carry the admin scope. An admin's minting is unchanged. The type check is clean and the new test file passes. I also ran the roles, tokens, schema-additive, API, auth, MCP, proposal-token-doors and account suites, and all passed. I did not run the whole suite.

What changed

  • Flag on the token: a new migration adds token.own_only (ALTER TABLE … ADD COLUMN with a default of 0, so it is additive). createToken in src/actions/users.ts sets it for any non-admin human account. Tokens minted before this keep what they could reach.
  • Refusal at minting: asking for admin as a non-admin person returns too_wide.
    • On POST /api/v1/tokens that is a 403 with the line "a token you mint reaches only your own repositories and apps: choose read or read and write".
    • On /settings/tokens the same line shows as a flash. The form no longer offers the admin option to non-admins.
  • Refusal at use: src/http/own_gate.ts runs after the proposal gate on each request. For a flagged token, a git path (/:owner/:name.git/…) or an API path (/api/v1/repos/:owner/:name/…) under another account returns 403. Paths that name no repository pass as before.
  • Docs: docs/ROLES.md has a short "Tokens" section.
  • Tests: test/token-own-only.test.ts covers:
    • A member's token works on their own repository.
    • The same token gets 403 on another account's repository, over the API and over git.
    • The admin scope is refused on the API and the page.
    • An admin's admin token still reaches every repository.
    • How ownerNamed reads a path.

What I chose not to do

  • Roles: guests are treated like members here, since they can't own anything anyway. Agents and organizations are untouched.
  • Org-owned repositories: a member's token is refused on them, even where the member could write through a team. "Own" means the member's own account.
  • Other-account lookups: /api/v1/users/:username/repos and /api/v1/orgs/… name no repository, so they still pass the gate. Those routes act as the member and expose nothing new.
  • Per-repository or per-app scopes: I did not add scopes tied to a single repository or app. Scopes stay ro, rw and admin.

To try it: as a non-admin, curl -X POST $URL/api/v1/tokens -d '{"username":…,"password":…,"scope":"rw"}'. Use the token on /api/v1/repos/<you>/<repo> (200) and on /api/v1/repos/<other>/<repo> (403). Asking for "scope":"admin" gets the 403 above.

🤖 Generated with Claude Code

commented

Parked by the crew: the check failed ("branches on a native repo > a reader who cannot write is refused, and a stranger sees nothing") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs