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

Access 4b-2: an admin sees who can reach what, by person and by resource #18179

opened this

Merged 4h 47m ago, live in production

On "Who may do what" (/settings/who-can), an admin can now switch between Every grant · By person · By resource (?by=person, ?by=resource). For anyone who isn't an admin, asking for someone else's view gets exactly the same 404 as asking for a person who doesn't exist.

Notes

opened this

On "Who may do what" (/settings/who-can), an admin can now switch between Every grant · By person · By resource (?by=person, ?by=resource). For anyone who isn't an admin, asking for someone else's view gets exactly the same 404 as asking for a person who doesn't exist.

What changed

  • Grouping (src/core/grants_view.ts): a new function, groupGrants, groups the grants that everyGrant already reads, by holder or by resource. There is no new table and no new query. Each group carries the look-up that narrows the page to it: person= for an account, resource= for a resource. A holder that isn't an account (a repository, a device, a pull) gets no person link.
  • Rules (src/actions/grants_view.ts): whoMayDoWhat accepts by. A non-admin who sends any by gets not_found, the same as asking for another person. grantsBy checks the value at each entry point, and an unknown ?by= is a 404.
  • Page (src/web/pages/who-can.ts): the switch uses the existing seg control. Each group is a row linking to its look-up, showing its kind and count, with its grants under it as tree rows; each grant still links to where it is changed. All names go through html escaping. The search form keeps by when you look someone up.
  • Terminal (src/tui/screens/whocan.ts): the b key cycles by person → by resource → off. The count line says how many groups there are.
  • MCP: the access tool's grants action takes by and returns groups.
  • How-to: docs/features/who-can.md is updated.

Tests (test/who-can.test.ts, 4 new):

  • An admin sees dave's telemetry grant in the dave group and dave's app_member grant under alice/yard, on the page with links to each look-up and to where each grant changes. Every grant lands in exactly one group.
  • When bob, who isn't an admin, asks for person=dave, by=person, by=resource, a resource, or the two combined, he gets status and body identical to person=nobody-here, apart from the request id.
  • A host name containing <img …> shows up escaped in the grouped view.
  • The terminal's b key shows the same groups.

bun x tsc --noEmit, bun scripts/design-lint.ts and bun scripts/gate.ts --explain are clean. scripts/fast.ts named 425 test files (about 29 minutes), so I ran 27 chosen suites instead (who-can, grants-view, the MCP doc/argument/fuzz suites, palette, route marks, 404 parity, unused exports, module state, doors, page budget): all 453 tests pass. The forge's check runs the rest.

Reused everyGrant, provenance, seg, row with children, rowList and notFoundPage. similar.ts flagged the terminal's changedAt as like the page's row: they render the same words for two different doors, so I left them separate.

Chose not to:

  • Let a non-admin group their own grants. Any by from a non-admin is not_found, which keeps the rule to one line.
  • Make the resource link an exact match. It uses the existing contains-match look-up, so alice/yard would also match alice/yard2.

Try it: sign in as an admin, open /settings/who-can and pick By person, then By resource. Sign in as someone who isn't an admin and open /settings/who-can?by=person or ?person=<someone>: you get the same 404 as for a name that doesn't exist.

[
  {"go": "/settings/who-can?by=person", "look": "the switch and the first group rows", "expect": "By person is current; each person row links to /settings/who-can?person=<name> and lists their grants under it, each linking to where it changes"},
  {"go": "/settings/who-can?by=resource", "look": "group rows", "expect": "one row per resource with its kind and grant count, linking to ?resource=<name>"},
  {"go": "/settings/who-can?by=person", "look": "as a person who is not an admin", "expect": "the same 404 page as /settings/who-can?person=nobody-here", "ask": "Is the not-found answer indistinguishable?"}
]

🤖 Generated with Claude Code

Closes #18159

2 earlier comments
commented

On "Who may do what" (/settings/who-can), an admin can now switch between Every grant · By person · By resource (?by=person, ?by=resource). For anyone who isn't an admin, asking for someone else's view gets exactly the same 404 as asking for a person who doesn't exist.

What changed

  • Grouping (src/core/grants_view.ts): a new function, groupGrants, groups the grants that everyGrant already reads, by holder or by resource. There is no new table and no new query. Each group carries the look-up that narrows the page to it: person= for an account, resource= for a resource. A holder that isn't an account (a repository, a device, a pull) gets no person link.
  • Rules (src/actions/grants_view.ts): whoMayDoWhat accepts by. A non-admin who sends any by gets not_found, the same as asking for another person. grantsBy checks the value at each entry point, and an unknown ?by= is a 404.
  • Page (src/web/pages/who-can.ts): the switch uses the existing seg control. Each group is a row linking to its look-up, showing its kind and count, with its grants under it as tree rows; each grant still links to where it is changed. All names go through html escaping. The search form keeps by when you look someone up.
  • Terminal (src/tui/screens/whocan.ts): the b key cycles by person → by resource → off. The count line says how many groups there are.
  • MCP: the access tool's grants action takes by and returns groups.
  • How-to: docs/features/who-can.md is updated.

Tests (test/who-can.test.ts, 4 new):

  • An admin sees dave's telemetry grant in the dave group and dave's app_member grant under alice/yard, on the page with links to each look-up and to where each grant changes. Every grant lands in exactly one group.
  • When bob, who isn't an admin, asks for person=dave, by=person, by=resource, a resource, or the two combined, he gets status and body identical to person=nobody-here, apart from the request id.
  • A host name containing <img …> shows up escaped in the grouped view.
  • The terminal's b key shows the same groups.

bun x tsc --noEmit, bun scripts/design-lint.ts and bun scripts/gate.ts --explain are clean. scripts/fast.ts named 425 test files (about 29 minutes), so I ran 27 chosen suites instead (who-can, grants-view, the MCP doc/argument/fuzz suites, palette, route marks, 404 parity, unused exports, module state, doors, page budget): all 453 tests pass. The forge's check runs the rest.

Reused everyGrant, provenance, seg, row with children, rowList and notFoundPage. similar.ts flagged the terminal's changedAt as like the page's row: they render the same words for two different doors, so I left them separate.

Chose not to:

  • Let a non-admin group their own grants. Any by from a non-admin is not_found, which keeps the rule to one line.
  • Make the resource link an exact match. It uses the existing contains-match look-up, so alice/yard would also match alice/yard2.

Try it: sign in as an admin, open /settings/who-can and pick By person, then By resource. Sign in as someone who isn't an admin and open /settings/who-can?by=person or ?person=<someone>: you get the same 404 as for a name that doesn't exist.

[
  {"go": "/settings/who-can?by=person", "look": "the switch and the first group rows", "expect": "By person is current; each person row links to /settings/who-can?person=<name> and lists their grants under it, each linking to where it changes"},
  {"go": "/settings/who-can?by=resource", "look": "group rows", "expect": "one row per resource with its kind and grant count, linking to ?resource=<name>"},
  {"go": "/settings/who-can?by=person", "look": "as a person who is not an admin", "expect": "the same 404 page as /settings/who-can?person=nobody-here", "ask": "Is the not-found answer indistinguishable?"}
]

🤖 Generated with Claude Code

commented

<!-- look-pages 60c226c3ace5 --> Look pages for 60c226c, from the gate:

  • look pages (none): "Looks: /settings/who-can" is not a page of app.looks in forge.json; this pull changes src/web/pages/who-can.ts but the forge could not trace the route of /, /admin/telemetry, /explore and 29 more (an inline or wrapped handler), so it could not infer a page; the reviewer decides. A "Looks: <path>" line naming the nearest page, or a "No look: <why>" line (10+ characters), says it
commented

An admin can now group every grant on Who may do what (/settings/who-can) by person or by resource. ?by=person or ?by=resource shows one row per holder or resource, linked to its look-up page. The grants sit under each row, and each links to the place where it is changed. Anyone who isn't an admin and asks for a grouping, or asks about another person, gets the same 404 as a person who doesn't exist. The terminal has the same switch (b), and so does the MCP access tool (by). The grouping is groupGrants in src/core/grants_view.ts, built on the existing everyGrant read, so there is no new table.

Look pages: the last commit says No look:. /settings/who-can is not in app.looks, and that list can't grow: test/forge-looks.test.ts caps it at 32 paths, and it already has 32. The nearest listed page, /settings/grants, doesn't show this change, so naming it would mean before/after pictures that show nothing. Adding this page means dropping another one from the list, and that is the owner's choice, so I left the list as it is.

Checks: bun scripts/gate.ts passes. It prints two advisory notes that the switcher and href helpers in who-can.ts are 0.58 alike, but it does not fail on them. I did not re-run bun x tsc --noEmit or the tests after this last commit, because it is empty and changes no code.

What I chose not to do: no export of the grouped view; the flat list's existing CSV/JSON is still the source.

[
  {"go": "/settings/who-can?by=person", "look": "the list as an admin", "expect": "one row per account or app, each linking to its look-up, with its grants beneath linking to where they change"},
  {"go": "/settings/who-can?by=resource", "look": "the same list grouped by resource", "expect": "one row per repository or resource, with who holds what on it"},
  {"go": "/settings/who-can?by=person", "look": "the page as a non-admin", "expect": "404, the same as for a missing person", "ask": "Is a plain 404 right for non-admins, or should they see their own grants?"}
]

🤖 Generated with Claude Code

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs