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

Report key: an admin makes, rotates and revokes it through the JSON API, in the settings page's words #18289

opened this

Merged 4h 46m ago, live in production

An admin can now make, rotate and revoke a repository's report key through the JSON API, in the same words as the settings page and the terminal. POST /api/v1/repos/:owner/:name/report-key makes the key, or rotates an existing one. It answers {key, line, shown:"once"} with 201.

Notes

opened this

An admin can now make, rotate and revoke a repository's report key through the JSON API, in the same words as the settings page and the terminal.

  • POST /api/v1/repos/:owner/:name/report-key makes the key, or rotates an existing one. It answers {key, line, shown:"once"} with 201.
  • DELETE on the same path revokes the key and answers {revoked, line}.
  • GET answers {made, line} and never the key.
  • Non-admins and anonymous callers get the exact 404 body a missing repository gets, on all three verbs. This is checked before the token scope.
  • Mutations need an admin-scope token or a same-origin session.
  • Responses are no-store, and the key is never logged.

The route is in the new src/http/api/report_key.ts, registered right after crashReportRoutes. It calls makeKey, revokeKey and keyLine from src/actions/report_key.ts, and adds no table or grant.

Two things I touched beyond your list:

  • src/http/lazy_lists.ts: I regenerated it with bun scripts/lazy-lists.ts, not by hand. The new route is a 404 no_route without that, and test/boot-lazy.test.ts would fail on a stale list. Three lines were added.
  • The API contract: I added three entries under src/contract/openapi/routes/ and a report-key tag. The contract tests require every route to be listed.

Tests: a new test in test/crash-report-key.test.ts makes a key through the API and files a report with it (202). It rotates so the old key gets 404, then revokes so the new key gets 404. It also checks that a non-admin and an anonymous caller get an identical 404 on all three verbs. It uses its own repository because the report rate limit is counted per repository and address. The contract, lazy-boot, route-mark, doorless and crash-report suites pass, and tsc is clean. I did not run the full suite.

Not done:

  • No new terminal or page code. Both already do this, so the commit says No door:.
  • No rate limit on the key route. I added none.
  • docs/features/crash-reports.md now describes the API.

To try it: curl -X POST -H "authorization: Bearer $ADMIN_TOKEN" $FORGE_URL/api/v1/repos/<owner>/<name>/report-key. Then send the returned key as X-Report-Key to that repository's crash-reports.

I did not use bun scripts/similar.ts. The route is thin and I reused the existing actions and the crash door's 404 wording.

Closes #18286

5 earlier comments
commented

An admin can now make, rotate and revoke a repository's report key through the JSON API, in the same words as the settings page and the terminal.

  • POST /api/v1/repos/:owner/:name/report-key makes the key, or rotates an existing one. It answers {key, line, shown:"once"} with 201.
  • DELETE on the same path revokes the key and answers {revoked, line}.
  • GET answers {made, line} and never the key.
  • Non-admins and anonymous callers get the exact 404 body a missing repository gets, on all three verbs. This is checked before the token scope.
  • Mutations need an admin-scope token or a same-origin session.
  • Responses are no-store, and the key is never logged.

The route is in the new src/http/api/report_key.ts, registered right after crashReportRoutes. It calls makeKey, revokeKey and keyLine from src/actions/report_key.ts, and adds no table or grant.

Two things I touched beyond your list:

  • src/http/lazy_lists.ts: I regenerated it with bun scripts/lazy-lists.ts, not by hand. The new route is a 404 no_route without that, and test/boot-lazy.test.ts would fail on a stale list. Three lines were added.
  • The API contract: I added three entries under src/contract/openapi/routes/ and a report-key tag. The contract tests require every route to be listed.

Tests: a new test in test/crash-report-key.test.ts makes a key through the API and files a report with it (202). It rotates so the old key gets 404, then revokes so the new key gets 404. It also checks that a non-admin and an anonymous caller get an identical 404 on all three verbs. It uses its own repository because the report rate limit is counted per repository and address. The contract, lazy-boot, route-mark, doorless and crash-report suites pass, and tsc is clean. I did not run the full suite.

Not done:

  • No new terminal or page code. Both already do this, so the commit says No door:.
  • No rate limit on the key route. I added none.
  • docs/features/crash-reports.md now describes the API.

To try it: curl -X POST -H "authorization: Bearer $ADMIN_TOKEN" $FORGE_URL/api/v1/repos/<owner>/<name>/report-key. Then send the returned key as X-Report-Key to that repository's crash-reports.

I did not use bun scripts/similar.ts. The route is thin and I reused the existing actions and the crash door's 404 wording.

commented

I merged main into the branch and pushed it. The pull should merge cleanly now. The crash-report, report-key, contract and lazy-boot tests and tsc pass; I did not run the full suite.

Main had already added POST and DELETE on /api/v1/repos/:owner/:name/report-key in #18277, inside src/http/api/crash_reports.ts, with an rw token and its own contract entries. So I kept main's version of those and dropped my duplicate route file, src/http/api/report_key.ts.

What this pull now adds on top of main:

  • GET: GET /api/v1/repos/:owner/:name/report-key answers {made, line}: when the key was made, or null, and the settings page's words about it. It never returns the key. It needs only an ro token, and anyone who isn't the repository's admin gets 404, signed in or not.
  • Contract and docs: a contract entry for GET and a line in docs/features/crash-reports.md. lazy_lists.ts is regenerated, not hand-edited.
  • Test: an API test in test/crash-report-key.test.ts covers make, file a report (202), rotate, revoke, GET never showing the key, and the identical 404 for a non-admin.

Anonymous callers: on POST and DELETE, main answers 401 before the 404, because it checks the token scope first. That differs from the issue's "identical 404 for anyone else". A signed-in non-admin still gets the identical 404. I left main's behaviour alone and the test asserts the 401 for those two verbs.

commented

I regenerated the OpenAPI route index with bun scripts/openapi-routes.ts and pushed it. The new GET export for the report key was sitting out of its sorted place, and that was the one failing test.

test/openapi-routes.test.ts and the contract tests pass locally. I did not run the full suite. The forge's check will run it on this push.

commented

An admin can now read, make, rotate and revoke a repository's report key through the JSON API (#18286). This push fixes the check that failed three times.

The failure. GET /api/v1/repos/:owner/:name/report-key answers 200 without a session phase. test/route-timing-coverage.test.ts refuses that unless UNTIMED names the route. I added it there with a reason: one indexed read, no page to phase. That was the only change in this push.

What the GET returns. The route is in src/http/api/crash_reports.ts. For an admin it returns when the key was made and the settings page's key line, never the key itself. Anyone else gets a 404. POST makes or rotates the key and shows it once. DELETE revokes it. All three use the settings page's wording.

The other gates.

  • bun scripts/gate.ts --explain is all ok, including both doors, name-the-issue, dead code and the untimed-job check.
  • tsc --noEmit is clean.
  • 51 tests pass across route-timing-coverage, crash-report-key, unused-exports, job-slices and hollow.
  • I did not run the full suite; the forge runs it on the push.

Not done. I added no terminal screen for the key. The gate's both-doors rule passed on the existing commits, so I left that as it was.

To try it.

  1. With an admin token, POST /api/v1/repos/<owner>/<name>/report-key returns the key once, with status 201.
  2. Send that key as X-Report-Key to crash-reports.
  3. GET the same path to see when it was made.
  4. DELETE it to revoke.

🤖 Generated with Claude Code

commented

The report-key POST and DELETE now answer an anonymous caller with the same 404 as a missing repository. I pushed that fix, but I did not change the OpenAPI role as asked.

  • 404 before the scope check: reportKeyWrite in src/http/api/crash_reports.ts now finds the repository and runs canAdmin first. A missing repository, no signed-in user or a non-admin gets the 404, and only then does requireScope(ctx, "rw") run. test/crash-report-key.test.ts now loops GET, POST and DELETE with the non-admin cookie and with no cookie, expects the identical 404 body each time, and the carve-out comment is gone.
  • Why the role stays member: Role is anonymous | member | admin, and the shared.ts doc says admin means a site admin only. The route is open to the repository's admin, who need not be a site admin, so admin would be wrong. The POST and DELETE entries also carry member, not an admin role. I kept member and added "(repository admin)" to the GET summary so the OpenAPI page says who may call it. If you want a different value there, say which.
  • src/http/lazy_lists.ts: the one added line is unavoidable. Without it the route is a 404 and the boot-lazy test fails.

Checks:

  • The key tests, test/report-key-api.test.ts and the route-timing coverage test pass: 17 tests.
  • tsc --noEmit is clean.
  • The gate passes, with its comment rewrap committed.
  • I did not run the full suite; the forge's check does that on push.
  • I did not run scripts/design-lint.ts: I touched no pages.

To try it: curl -X POST $FORGE_URL/api/v1/repos/<owner>/<name>/report-key with no credentials returns the same 404 as a repository that does not exist.

🤖 Generated with Claude Code

commented

An admin makes, rotates, revokes and reads a repository's report key through the JSON API, in the settings page's words. The previous check failed on the refuses entries of POST and DELETE; I fixed those and pushed.

  • What broke the check: the POST and DELETE OpenAPI entries still declared refuses: [401, 404]. After the earlier fix, a caller with no session is answered 404 before the scope check, so 401 is never sent. Both entries now declare refuses: [404].
  • What changed earlier on the branch: POST and DELETE look up the repository and run the admin check first. A missing repository, no session and a non-admin all get the identical 404; the token-scope check runs only after that. GET is admin-only, never returns the key, and is sent no-store. The test covers GET, POST and DELETE with a non-admin cookie and with no cookie, and expects the same 404 body each time.
  • Checks run: bun test test/openapi-errors.test.ts passes, 5 tests. bun x tsc --noEmit is clean and the gate passes.
  • A flake: one run of test/openapi-errors.test.ts failed on its first try here and passed on rerun, so I take it for a timing flake. I could not reproduce the template test ("plan carries the template only when it is not blank") either; it failed once in a glob run over test/template, but test/spawn-template-api.test.ts passed twice when run alone. It touches nothing this pull changes, but I haven't ruled out a real flake.
  • role: the three report-key OpenAPI entries keep role: "member". admin there means a site admin, and the repository's admin need not be one. The GET summary says "repository admin".
  • src/http/lazy_lists.ts: one line was added to it, which the issue asked me not to touch. Without it the route answers 404 and the boot-lazy test fails.
  • Left out: no UI changes and no change to who may file reports with a key.

To try it, make a key with an admin token:

curl -X POST -H "authorization: Bearer $TOKEN" $FORGE_URL/api/v1/repos/<owner>/<name>/report-key

It answers 201 with {key, message}. Send that key as X-Report-Key to the repository's crash-reports. The same call with no credentials, or as a non-admin, returns the 404 of a repository that does not exist.

🤖 Generated with Claude Code

Sign in to join this conversation.

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

Keyboard shortcuts

Docs