Repository navigation
fix(authz): align Runner, account, and MCP access checks - #1328
Conversation
crispinhu27
left a comment
There was a problem hiding this comment.
Reviewed 792bd12 (base main 848793b) and verified it in an isolated environment. I didn't find any blocking issues.
Scope: Runner register/renew owner scope (runners.go, RegisterRunner), first-run setup and self-registration policy (auth_register.go, LocalAccountCount), personal and project MCP writes and imports (mcp*.go, SaveMCPServers, the guard removed from project_write_access.go), role cloning and MCP dependencies (catalog.go), and the deployment docs.
Verification (Go 1.26.11 + MySQL 8.4.7, synthetic accounts and data only, each case run on both this head and the base):
- Built the head and base platforms and ran each against its own MySQL database, then drove the same HTTP scenarios through both:
- Runner: the bootstrap token presenting a user-bound runner ID now gets a new ID, and the original row keeps owner=bob. On base the machine was taken over with owner→0. Same-owner renewal (bind code) keeps the ID; base issued a new one. Platform runner renewal keeps its ID on both.
- Gateway mode (
AGENTFLOW_TRUST_IDENTITY_HEADERS=true) with no accounts:/api/auth/setupreturnsneedsSetup:false, and registering returns 403 with no user created. On base the first registrant became platform admin. Header sign-in returns 200 on both. Password-only installations still get first-run setup, and the first account becomes admin. - MCP: a personal PUT with a forged
ownerUserIdis bound to the signed-in user (base stored the forged owner). An import that overwrites another user's personal MCP returns 403 and leaves the stored URL and owner unchanged. A batch import with one invalid item writes nothing. A project-MCP PUT carrying masked headers keeps the stored secret. Non-members get 403 on PUT and DELETE of another project's MCP. - Clone: a non-member cloning an unshared role from someone else's project gets 403 (201 on base). Cloning a shared role no longer copies the source project's MCP or headers into the target project, and the other user's personal MCP is no longer copied into the cloner's personal scope. Base copied both.
go test ./internal/httpapi/... ./internal/repo/...(SQLite): the set of failing tests matches base. A focused run of the remaining 7 cases (assistant workspace checkpoint, browser, workspace lease) fails identically on head and base, so they are environment issues.TestChatClarificationEdgePathsfailed once in the parallel run and passed when rerun on its own.internal/repoon MySQL 8.4.7: onlyTestMySQLReadsObserveExternalChangesWithoutReloadandTestMySQLGitSSHCredentialLifecyclefail, the same as base. The newauthorization_writes_test.gopasses.go vetandgofmtare clean on the touched packages.- CI: 16/16 checks passed.
Not verified, and not counted against this review: I didn't run a real gateway or SSO identity provider or a real Runner daemon end to end. Those were covered at the HTTP layer with header sign-in and the register API.
Intentional behavior changes: non-blocking, but worth noting in the release notes.
- When a shared role is cloned by someone who can't write the source project, MCPs from the source project are dropped instead of copied.
- From reading the code (not run):
editableMCPnow callsallowMCPServerWrite, so MCP file downloads (GET /api/mcp-servers/:id/files/*) also require write access to the owning project. - On gateway or SSO deployments, and on installations with
AGENTFLOW_PLATFORM_ADMINSconfigured, the first administrator now has to be provisioned through configuration or the account command.
|
Review of How I tested
Results (main → this PR)
P2 – should fix
P3 – nits
Raw request/response results for both builds and the login-page screenshots are kept outside the repo. No screenshot branch was created. This token is the PR author's account, so this is a comment, not a formal review state. |
Cloning a shared role from a project the caller cannot write dropped its market MCPs. Market entries carry no project settings, so install them from the catalog in the target project instead. Install IDs for market, custom and cloned MCPs are predictable. Any signed-in user could create a personal MCP under such an ID and make every later install or clone into that project fail with 409. When the ID is held outside the destination, use an alternate ID keyed with the session secret, so retries still find the same row. Treat SSO as configured only when both the app token and login URL are set, the same condition the login page uses, so an install with only the app token keeps its browser setup step. Explain why a login listed in AGENTFLOW_PLATFORM_ADMINS cannot self-register, and document it. Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
crispinhu27
left a comment
There was a problem hiding this comment.
Re-review of 334fd8e8 (base main 848793b). My earlier APPROVE on 792bd120 was dismissed by the push. I found no blocking issues in the two new commits (0f1b081b, 334fd8e8), and the earlier verification still holds for the unchanged code.
Scope of this round: the incremental diff 792bd120..334fd8e8. That covers market-MCP install during role clone (cloneAgentMCPServers), destinationMCPInstallID (alternate IDs when an install ID is already held outside the destination), the SSO predicate in localSignupOptions, the dedicated 403 for allowlisted admin logins, the docs and CHANGELOG, and the new tests. I also re-ran the earlier security scenarios against this head.
Verification: Go 1.26.11 and MySQL 8.4.7, synthetic accounts and data only. I built three platforms, this head, 792bd120 and base 848793b3, and drove the same HTTP scenarios through each.
- Shared role cloned by a non-member of the source project, where the role depends on a project MCP, another user's personal MCP and the GitHub market MCP:
- This head returns 201 with
["mcp-github-project-qq"], installed from the catalog without the source project's headers. Repeating the clone reuses the same row. - On
792bd120the result was[], so the market dependency was dropped. - On base, the source project's MCP was copied.
- This head returns 201 with
- Predictable-ID squatting, where another user first creates a personal MCP under the install ID:
- On
792bd120, the market install returned 409 permanently, the clone returned 409, and custom installs (project and personal) returned 409. - On this head, all of them succeed and get an alternate ID such as
mcp-github-<hmac>-project-…ormcp-clone-pm1-<hmac>-project-…. - Repeating the market install returns 409 "already added". Repeating the clone reuses the same alternate ID.
- The squatter can't delete the alternate row (403).
- A project MCP from another project holding the ID is handled the same way. A 70-character custom ID stays bounded at 64 characters.
- On
- Signup under each auth mode, starting with no accounts:
- App token alone, or login URL alone: password setup stays available and the first account becomes admin. On
792bd120there was no browser path to an admin. - Both SSO settings, or gateway mode:
needsSetup:false, and register returns 403 with no user created. On base, the first registrant became admin. PLATFORM_ADMINS=Alice: registeringalicereturns 403 with the new "use the account command" message, whilebobregisters as a normal user.loopforge-account -user alice -admincreates alice, who then signs in withisPlatformAdmin:true.ALLOW_SIGNUP=false: the first account becomes admin and the second gets 403.
- App token alone, or login URL alone: password setup stays available and the first account becomes admin. On
- Regression checks on this head:
- A forged
ownerUserIdis bound to the signed-in user. - PUT on another user's personal MCP returns 403.
- A mixed import returns 403 with nothing written.
- Non-member PUT and DELETE return 403.
- Source-project secrets never appear in GET responses.
- A forged
go test ./internal/httpapi/... ./internal/repo/... ./internal/auth/...on head and base (SQLite): 25 identical failures on both, nearly all because the container has nobwrap. No head-only failures. All 13 new tests pass.go test ./internal/repo -run 'Authoriz|Runner|MCP|LocalAccount|Catalog|Import'against MySQL 8.4.7 passes.go vetandgofmtare clean on the touched packages. CI 16/16 passed.
Earlier items: the P2s and P3s in the author's comment on 792bd120 (market MCPs dropped on clone, install-ID squatting, the partial-SSO predicate, the misleading 409 for allowlisted logins, the docs/CHANGELOG notes and the PutRunner comment) were re-run above where they are behavioral, and the behavior now matches the expected outcome.
Not verified: a real SSO identity provider or authenticating gateway end to end (covered at the HTTP layer with environment configuration), and a real Runner daemon in this round. The Runner code did not change since 792bd120 apart from a comment.
|
Re-review of How I tested
P2-1: cloning a shared role keeps market MCPs ✅
P2-2: predictable install IDs can't be squatted ✅u4 first PUTs personal MCPs with the IDs
Earlier P3s
P3 – non-blockingOnce the keyed alternate ID is taken, repeated clones create duplicate copies. Reproduced: u1 deletes S's copy, u4 PUTs a personal MCP under that alternate ID, then u1 clones It no longer blocks anyone, so this is cosmetic. If you want to close it, the random branch can first look up an existing row in the destination with the same base (for clones: same Minor: Conclusion: no blocking issues, OK to merge. This token is the PR author's account, so this is a comment, not a formal approval. No screenshot branch was created; the login and register screenshots and the raw step results are kept outside the repo. |
When the predictable install ID and its keyed alternate were both held by another user, every clone or custom install fell back to a random ID. A project then got a new copy of the cloned MCP on each clone, and a repeated custom install created a row instead of returning 409. Try a fixed sequence of keyed alternates, and prefer a row the destination already holds under any candidate over a free one. Co-Authored-By: Claude Code <noreply@anthropic.com>
|
Re-review of Change
How I tested
No open issues from me. OK to merge. The token is the PR author's account, so this is a comment, not a formal approval. |
|
Follow-up fixes for the review of Changes
Verification
Result:
|
crispinhu27
left a comment
There was a problem hiding this comment.
Reviewed cd5fce1b (base main 848793b3) and verified it in an isolated environment. I found no blocking issues.
Scope of this round: the incremental 334fd8e8..cd5fce1b. My earlier review of 334fd8e8 was dismissed by the push. The change rewrites destinationMCPInstallID (internal/httpapi/mcp_market.go): the base ID is followed by a fixed, keyed sequence of 8 alternate digests, a row the destination already holds under any candidate wins over a free one, and a random ID is used only when every candidate is taken elsewhere. It also adds TestMCPInstallIDsStayStableWhenAlternatesAreSquatted.
Verification (Go 1.26.11, synthetic data only, head cd5fce1b, previous head 334fd8e8 and base 848793b3 each in their own worktree):
go build ./...,go vet ./internal/...: pass on head and base.go test ./internal/httpapi/ -run 'MCP|Runner|Auth|Register|Catalog' -count=1: pass.TestMCPInstallIDsStayStableWhenAlternatesAreSquatted -count=3: pass.- Full
go test ./internal/httpapi/ -count=1: head 15 fail / 1330 pass, base 15 fail / 1321 pass, and the two failure sets are identical. They come from environment-dependent cases (workspace checkpoints, browser stream, SSH checkout, run stream).TestChatClarificationEdgePathsis flaky on both sides (1 in 5 runs each) and is not caused by this change. - A throwaway test file (head worktree only, deleted afterwards) covered 9 candidates staying distinct and ≤64 chars, alternate #1 matching what
334fd8e8produced so existing rows are still found, the destination holding several candidates, bothniland empty keys, and cross-user listing.
Bug fixed by this commit, reproduced over HTTP: a squatter takes the base ID, the install goes to the alternate, the squatter deletes the base row, and the install runs again. On 334fd8e8 that second POST returned 201 and created a duplicate row, so repeated clones stopped finding their copy. On cd5fce1b it returns 409 with a single row, which is the intended behaviour.
Non-blocking notes (no action required for this PR):
- If every candidate is taken by other users, the function falls back to a random ID, so a row saved there is not found again. This needs the 8 keyed IDs, which depend on the session secret, and it is the same fallback
334fd8e8had. - Concurrent clones of the same role into the same project can now surface
MCP 已被创建或更改,请刷新后重试to the losing caller instead of quietly overwriting. Only one row is ever created; I saw it in 11 of 30 runs here and 14 of 30 on334fd8e8, so it predates this commit.
Not covered: no Docker here, and I did not repeat the MySQL-backed deployment scenarios from the earlier rounds beyond what CI covers; CI core and platform-required are green on this head. CI is 16/16 on cd5fce1b, and the PR has no conflict with current main (cb78a49). This approval is for cd5fce1b only.
What changed
Scope
Compatibility
The patch uses the existing database schema and Runner protocol. Password-only deployments retain first-run setup. Gateway and SSO deployments use their configured identity path for enrollment.
Validation
Safety