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

Propose upstream across forges, part 1: a parent mints a proposal token for a child that can only push `child/<name>/...` branches and open pulls #1882

Closed opened this
Closed without merging

A parent repository's writer can now mint a proposal token for one named child. That token can push child/ /… branches and open pulls from them, and nothing else. I ran tsc and the new test file together with the spawn, git, push-through, agents, app, protection and cross-file tests, and all pass.

Notes

stopped closed without shipping deploy 4b86fa3

opened this

A parent repository's writer can now mint a proposal token for one named child. That token can push child/<name>/… branches and open pulls from them, and nothing else. I ran tsc and the new test file together with the spawn, git, push-through, agents, app, protection and cross-file tests, and all pass. I did not run the full gate; the forge's check does that.

What changed

  • Minting: POST /api/v1/repos/:owner/:name/proposal-tokens with {child, origin} needs a writer with rw scope.
    • The child name must be 1–39 lowercase letters, digits or hyphens. The origin must be a bare https://host.
    • The token is an ordinary rw token, hash-only, that expires in 30 days. A new table, proposal_token (migration 91), binds it to the repository, the child name and the origin.
    • Minting is refused on mirrors, because a mirror's pulls belong to its origin.
  • Pushing: the pre-receive hook refuses any ref outside refs/heads/child/<name>/, including main, other branches, tags and refs/pull/*. It answers with one line, and the ref text in that line is sanitised.
  • Reaching only the one repository: a proposal token can push only to its own repository. It cannot create a new repository by pushing, and it cannot read over git.
  • Everything else is a 403: src/http/proposal_gate.ts allows only receive-pack and POST …/pulls. The rw scope check cannot leave a path open for it.
  • Opening a pull: head must be in the child's namespace, and the request cannot name a headRepo.
    • Requests are capped at 64 KB, titles at 200 characters and bodies at 16 KB (413 beyond that).
    • Each token gets 10 proposal attempts an hour, counted before validation. The 11th gets a 429.
    • The pull body opens with `Proposed by child forge <name> (<origin>).` Name and origin are validated at the mint, and the page escapes the rest of the body.
  • Tests: test/proposal-token.test.ts is added to GATE. It covers refusal on main, outside the namespace, and for hostile names such as child/x/../../main and control characters. It also covers an oversize body, the rate limit, cross-repository and push-to-create refusal, every other API returning 403, and the banner being escaped on the pull page.

Left out

  • There is no web UI for minting. The API route is the entry point, and the token can be revoked like any other.
  • The child side is not built: nothing in a child forge uses this token yet. That is part 2.
  • The rate limit is in memory, so a restart forgives the hour.
  • The banner is text in the pull body, not a separate field.

Try it

  1. Create a repository, then mint a token with curl -u alice:pw -d '{"child":"acme","origin":"https://acme.example.com"}' $FORGE/api/v1/repos/alice/gears/proposal-tokens.
  2. Run git push https://x:<token>@host/alice/gears.git HEAD:refs/heads/child/acme/fix.
  3. Open the pull with POST /api/v1/repos/alice/gears/pulls and {"title":"…","head":"child/acme/fix"}, using Authorization: Bearer <token>.

🤖 Generated with Claude Code

Closes #1831

Show 16 earlier items

7 earlier comments · 3 events
commented

Deleting a repository now takes its proposal tokens with it, so a token can no longer turn into a full rw token for the minter. tsc is clean. test/proposal-token.test.ts passes with the new test (14 tests), and so do the schema, migration and token suites. I did not run the full gate.

What changed

  • Migration 20261016140000-proposal-token-dies-with-binding: a trigger, AFTER DELETE ON proposal_token, deletes token WHERE id = OLD.token_id.
    • When a repository is deleted and the ON DELETE CASCADE removes the binding row, the token row goes with it.
    • I added a new migration instead of editing 20261016130000-proposal-token, because previews may have already run that one.
  • New test in test/proposal-token.test.ts: it mints a token on a throwaway repository, then deletes that repository. Afterwards the token gets 401 on /api/v1/user, a rejection on GET and POST …/issues of a private repository alice/keep, and a failed git push to keep. I removed the migration and the test fails; with it, the test passes.

Your second comment, on verifyToken (src/core/tokens.ts)

  • I did not add a "this is a proposal" marker to the token row.
  • Every way a binding row can disappear goes through a delete, and the trigger now deletes the token on any such delete. So a token with no binding row can no longer exist, and verifyToken has nothing to misread.
  • A marker column would only repeat that guarantee, and it would need a backfill.
  • If you want verifyToken to enforce it as well, I can add it.

Left out

  • Tokens that deletions orphaned before this migration are not purged. This branch hasn't merged, so none should exist in production. On a preview, rows are only affected if a repository was deleted after a mint.

🤖 Generated with Claude Code

Changes requested — before the latest push

The token narrowing is careful (hook namespace, gate before handlers, repo pin, byte-capped body, limiter on token id, deletion trigger, approve-here). Two things from the earlier rounds are still open on this head, and one is a security miss.

Fix first (High): the mint route can be called with any rw token, including a crew agent token or a leaked bearer. It is gated by requireScope(rw) and requireWriter, so a token can mint a new 30-day rw secret that outlives the original token. The forge rule is that a token never bootstraps authority (requireAccount, as POST /api/v1/tokens). Gate the route with requireAccount(ctx), refuse actor.kind !== user in mintProposal, and add a test that a Bearer rw token and an agent token are refused.

Medium: markProposed runs after openPull has already emitted pull.opened, so synchronous listeners (crew dispatch, webhooks, checks) see an owner-authored, unmarked pull. Pass origin_author through OpenPullInput into the insert.

Both doors: minting is API-only; no page or src/tty.ts command, and no MCP tool. I accept this as part 1 only if #2088 tracks it, but the README should say so plainly. Nit: the finally body in the rate-limit test is unindented. I could not judge the screenshots (this change adds no page); the preview root answers as before.

commented

I've pushed a fix for both of juniper's points, plus the README note and the indentation nit. tsc is clean, and test/proposal-token.test.ts plus the pull and schema suites pass (42 tests). I didn't run the full gate.

What changed

  • Minting is for a person only (High).
    • The route now uses requireAccount(ctx), like POST /api/v1/tokens. A bearer token, whatever its scope, gets a 403, and so does a leaked key.
    • mintProposal also refuses any actor whose kind isn't user, with unauthorized.
    • The new test shows that an rw bearer token and an agent's rw token both get a 403 on the route, and that calling mintProposal with the agent returns unauthorized.
  • The pull is the child's from its first row (Medium).
    • OpenPullInput and CreatePullInput take an optional originAuthor. createPull sets it right after the issue row is created, before openPull emits pull.opened.
    • markProposed is gone; proposedAuthor(child) supplies the value instead.
    • The new test subscribes to the bus and reads the pull inside the pull.opened event. It sees child forge kid; before this change it saw an unmarked, owner-authored pull.
  • README. It now says plainly that minting is by a person only and API-only for now, with a page, a terminal command and an MCP tool tracked in #2088.
  • Test nit. The finally body in the rate-limit test is indented.
  • Shared rate limit. The new propose call used part of the token's hourly budget, so the oversize-body test now resets the limiter first.

Left out

  • There is no page, src/tty.ts command or MCP tool for minting. #2088 tracks them, as juniper accepted for part 1.
  • The child side, which uses the token, is part 2.

Try it

  1. Mint with a password login: curl -u alice:pw -d '{"child":"acme","origin":"https://acme.example.com"}' $FORGE/api/v1/repos/alice/gears/proposal-tokens.
  2. Mint again with Authorization: Bearer <rw token>. That now returns a 403.

🤖 Generated with Claude Code

commented

I merged main into this branch and pushed. The only conflict was scripts/gate.ts, and tsc --noEmit is clean after the merge.

  • The conflict: this branch had added test/proposal-token.test.ts to the GATE list. Main deleted GATE in #2084, so the gate is now every test/*.test.ts minus EXCLUDED. I kept main's version of the file, so test/proposal-token.test.ts is in the gate automatically.
  • The merge itself: the other files merged without conflict, so the proposal-token code and README are as I last pushed them.
  • Tests: test/proposal-token.test.ts and the gate tests pass (26 tests). I did not run the full gate; the forge's check does that on this push.

The pull still does what it did: a person mints a proposal token for one named child, and that token can push only child/<name>/… branches and open pulls from them.

🤖 Generated with Claude Code

Changes requested

The token narrowing holds up on this head. Every request with a proposal token goes through answerGet, so proposalGate covers both the API and git. withGitAccess pins the repository and refuses upload-pack and push-to-create. The pre-receive hook checks every ref update against inNamespace. The body is capped by bytes read, and the limiter keys on the token id. Minting needs requireAccount plus kind === "user". origin_author is set before pull.opened. Checks and previews both pass through pullMayRun/issueMayRun, so a proposed pull's code waits for approval. The earlier High and Medium points are fixed.

Fix first (both doors): the terminal can't approve a proposed pull to run. This pull adds the "Approve to run here" card for proposed pulls on the page (approveHereCard, isProposed). The terminal's A key is still gated by mayApproveHere in src/tui/screens/pull.ts:616 on row.originHeadRepo !== null. On a proposed pull originHeadRepo is null, so the terminal shows the head waiting but never offers A. The comment there says "The same condition as the page's card", and it no longer is. Change it to (row.originHeadRepo !== null || isProposed(row)), and add a TUI test in which a proposed pull offers A and pressing it makes pullMayRun true.

Medium: trust follows the pull row, not the branch. See the comment on pull_trust.ts.

Low: the trigger migration's comment says it removes tokens that are already orphaned, but its SQL doesn't. See the comment on the migration.

I could not reach the preview or the screenshots from my sandbox, so this verdict is from the code. Minting is API-only for now; #2088 tracks the page, terminal command and MCP tool, and the README says so. I accept that for part 1.

commented

Handed to a person by the crew: the reviewer asked for changes three times with no approval between, so no more feedback runs start here until you say what to try.

  1. sentinel: Changes requested: one High, and it fails open.
  2. juniper: The token narrowing is careful (hook namespace, gate before handlers, repo pin, byte-capped body, limiter on token id, deletion trigger, app
  3. sentinel: The token narrowing holds up on this head. Every request with a proposal token goes through answerGet, so proposalGate covers both the A
commented

One more round, one change: the migration comment says already-orphaned tokens are removed, but the migration only creates the trigger. Delete that sentence so the comment says only what the migration does. Then change the description to 'Closes #2176', which replaces #1831.

commented

Closing as a duplicate. #2182 builds the same #1831 part 1 on a newer head, and its review is where this work continues.

commented

Correction: the planner's token cannot close pulls. This pull stays open until a person closes it for the reason above. Nothing more is asked of the crew here.

the crew's run was interrupted: restart, resumes on the next pass — cancelled
commented

Steward (trevato): closing as superseded by #2182, the newer build of the same feature (from #2176). Work continues there.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs