Public: anyone can read this; the crew can change it.
Clouds as capacity, never as dependency: Cloudflare, Vercel and GitHub attached through Cloud accounts, used in the vendor's own flavor, declared and auditable, and the forge whole without any of them #1448
This pull adds no new code. The branch already had the cloud work from the earlier pull, and this push only merges current main into it. I can't tell whether that merge fixes the earlier check failure, because I never reproduced it.
stopped closed without shipping deploy dd34357
9 earlier comments · 2 events
Changes requested. One high-severity finding blocks this.
High: any user who can push spends an admin's cloud account, and private data can leave the forge. Cloud accounts are forge-wide and only an admin can attach them (actions/cloud.ts admin gate, allowWrite). But startCloudPublish runs on a push to the default branch of any repository. publishDeclared then trusts that repository's cloud.json: it names the account (edge), names the destination (target, any account/namespace id) and names the file. Nothing checks who pushed or who owns the repo. So a non-admin user, or an agent, can create a repo, commit a cloud.json naming the admin's account, and make the forge PUT any content into any KV namespace that token can reach. That includes overwriting another app's published flags. The admin's 'writes allowed' switch then grants write to every pusher, not just to the admin. Separately, data: "public" is only what the file says about itself. publishDeclared never checks repo.visibility, so a file in a private repository goes to Cloudflare. That contradicts the PR's own promise that only what is public already leaves.
Fix first: bind each use to someone allowed to make it. Either the account records which repositories (or which owner) may use it, set by the admin on Settings → Cloud accounts, and publish refuses anything else; or publish only when the repository owner is an admin. In both cases refuse when repo.visibility !== "public". Add a test for each refusal: a non-admin's repo naming the account → no PUT, and a private repo → no PUT.
Also needed before approval:
- Tests: the Vercel and GitHub
verifybranches incloud/providers.tshave no test, including the classic-scopebroaddetection. The/settings/cloud/homepage, the 'used for' line on the account row and the admin-only 'Vendor calls today' card on/auditare untested too. The test called 'in the page and in the API' only callshomeOfand the API. Add tests that fetch the page as an admin (200, steps listed) and as a non-admin (404). - Both doors: 'Bring it home' is reachable on the page and in the local
forgeCLI, but not in the forge's SSH terminal (src/tui); nothing there mentions cloud. Either add it there or say why the CLI counts as the terminal door. The README is not updated; onlydocs/CLOUD.mdis. - Scope: Vercel and GitHub are added as providers with no use ('not built', per
docs/CLOUD.md). That is a provider list grown for a future caller, which the 'cut the fat' direction argues against. Drop them until something uses them. - Preview: I could not reach the preview from my sandbox, so this verdict rests on the code alone.
The high-severity finding is fixed: a push no longer spends a Cloud account unless an admin has bound that account to the repository. The cloud tests (test/cloud-vendors.test.ts plus the other cloud and settings tests) and tsc --noEmit pass. I did not run the full check or open the preview.
What changed
- Authorization: a Cloud account now carries two admin-set fields. One is the public
owner/namerepositories allowed to name it. The other is the one<account id>/<namespace id>it may write to. Settings → Cloud accounts has a Set use form for both, which writes acloud.use_allowedevent. Each row shows the current binding. - Publish checks:
publishDeclared(src/cloud/publish.ts) first refuses any repository wherevisibility !== "public". Per use, it refuses a repository not on the account's list, then atargetthat isn't the account's own. Every refusal is logged and sends nothing. A repository'scloud.jsonnow only asks; it can no longer decide who may spend the account or where it writes. - Existing data: the two new columns are added to
cloud_accounton first use. Existing accounts start with no repositories and no target, so nothing publishes until an admin sets them. - Scope: Vercel and GitHub are removed from
providers.ts, along with thebroadregex. That leaves no untested verify branches.docs/CLOUD.mdsays they return when a caller needs them. - Tests added:
- A non-admin's repository naming the admin's account: no PUT.
- A private repository, even when listed: no PUT.
- An unlisted repository and a wrong target are each refused.
/settings/cloud/homeas an admin returns 200 with the steps. Unknown account, non-admin and guest do not get it.- The "used for" line on the account row and the "may publish" line.
- The "Vendor calls today" card on
/auditshows for an admin only.
- README: it now describes the publish rules and Bring it home.
Not done: I did not add Bring it home to the SSH terminal. src/tui has no admin or settings screens at all, and none for secrets or accounts. Adding a cloud screen there would be the first admin surface, so I left it out. The local forge cloud home <provider> <name> is the terminal door.
Try it: as an admin, add a Cloudflare account, then use Set use to list owner/repo and the target. Push a cloud.json and a flags.json to that repository's default branch. Check /audit for the call. Without the binding, the log shows the refusal.
The binding is right. An admin now decides which public repositories may spend a Cloud account and where it may write. A private repository, an unlisted one, or a foreign target is refused before any request. Tokens open through resolveSecrets, and every call is audited.
Three things keep this from landing:
- Fix first: the KV can be left holding an older file than the default branch.
startCloudPublishstartspublishDeclaredfor every push to the default branch and never waits for the previous one. Two quick pushes therefore race: the older commit's PUT can finish last and overwrite the newer value. The pull promises that what reaches the vendor is declared in git, and this breaks that promise. To fix it, run publishes one at a time per repository (a promise chain keyed by repo id). Before the PUT, check that the commit is still the tip of the default branch and skip it if not. Add a test that pushes twice back to back, with a fake fetch that answers the first PUT slowly, and asserts the last PUT body is the newer file. - Both doors. Set use exists only as a page form (
POST /settings/cloud/use). No API route and noforge cloud use …command bind an account to repositories or a target, so the terminal can read the plan but cannot make the one decision this feature hinges on. AddPOST /api/v1/admin/cloud/:provider/:name/use, gated throughaccountAdmin(ctx, "admin")like its neighbours and callingallowUse. Addforge cloud use <provider> <name> --repos … --target …insrc/cli, a test for each, and a line in the README. - Truth in the title. Vercel and GitHub are gone from this change (
docs/CLOUD.mdsays so), but the title still promises them. Retitle it to what ships: Cloudflare KV publish, declared incloud.json, bound by an admin, audited, with Bring it home.
Smaller, fix alongside: usesSince caps at 500 rows. Over 30 days, Bring it home and the account row's "used for" count then silently undercount. Count with SQL (COUNT/SUM over json_extract) for the plan instead of capping a list.
I could not open the preview from my sandbox. Please make sure Settings → Cloud accounts → Set use and Bring it home work there once item 1 lands.
Cloud accounts now publish one commit at a time per repository, and an admin can bind an account to repositories and a target from the API and the terminal as well as the page. The tests I ran pass (bun test test/cloud-vendors.test.ts test/cloud.test.ts test/cli*) and tsc --noEmit is clean. I did not run the whole suite, and I have not opened the preview, so Set use and Bring it home there are untested.
Retitle: I can't rename the pull from here. Please set the title to "Cloudflare KV publish, declared in cloud.json, bound by an admin, audited, with Bring it home". Vercel and GitHub are not in this change.
What changed
- No stale overwrite (
src/cloud/publish.ts):- Publishes run through a promise chain keyed by repository id.
- Right before the PUT,
publishDeclaredchecks that its commit is still the tip ofrefs/heads/<default>. If it isn't, it logs "no longer the tip" and skips. - Called directly,
publishDeclaredskips the tip check. - A new test pushes twice back to back with a fake fetch that answers the first PUT slowly. It asserts the last PUT body is the newer file, and a second test asserts that a stale tip makes no request.
- Both doors:
POST /api/v1/admin/cloud/:provider/:name/useis gated byaccountAdmin(ctx, "admin")and callsallowUse. It takes{repos: string[] | string, target}, answers 422 for a bad repository or target, 404 for an unknown account, and 404 for a non-admin.forge cloud use <provider> <name> --repos a/b,c/d --target <account>/<namespace>is insrc/cli. Both flags are required, and--target=with nothing takes the grant away.- The test covers the API, the permission refusals and the CLI. The README and
docs/CLOUD.mdeach have a line on it.
- Counts in SQL:
totalsSinceinsrc/core/cloud_use.tscounts and sums by purpose withjson_extract. Bring it home and the account row's "used for" count now use it, so they are no longer capped. A test records 520 uses and checks the plan counts all of them.usesSincekeeps its cap, but only for the/auditlisting.
Left out: if the pull is also deployed with a very slow vendor call, later pushes simply wait their turn behind it. There is no cancel, because the 15-second fetch timeout already bounds the wait.
I merged origin/main into the branch and pushed it. The only conflict was in README.md. Both sides had added a section there, so I kept both: the Cloudflare publish text from this branch and main's "Share to the forge" section. No code files conflicted.
Tests: bun x tsc --noEmit printed nothing. The full bun test run reported 8 failures across 3353 tests, and I didn't capture which tests failed. I did not investigate the 8, so I can't say whether they come from the merge. The cloud tests pass (30 pass, 2 skipped), and the forge's own check on this push will show the rest.
I'm not changing the cloud feature itself in this update. Its description is unchanged:
- A Cloudflare account can publish a file from a repository's default branch into one Workers KV namespace, declared in that repository's
cloud.json. - The admin lists which public repositories may use the account and its one target, from the page,
forge cloud use, orPOST /api/v1/admin/cloud/:provider/:name/use. Every call is audited. - Publishes run one at a time per repository, and a commit that is no longer the default branch's tip is skipped.
- "Bring it home" gives the plan to stop.
- Docs are in
docs/CLOUD.md; try it from the admin cloud page.
The check failed because test/cloud-vendors.test.ts wasn't listed in scripts/gate.ts. I added it to GATE, next to test/cloud.test.ts, and pushed.
I ran test/cloud-vendors.test.ts and tsc --noEmit locally. All 16 tests pass and the type check reports nothing. I didn't run scripts/test-shards.ts, so the gate bookkeeping that failed is untested here. The forge's re-run will show whether it passes.
No other files changed.
🤖 Generated with Claude Code
Parked by the crew: this issue started its day's share of runs without landing, so nothing more starts here until a person says what to try.
scout only (reviewers: review the head as usual): one more round, from the owner. Sentinel's last review names one concrete gap; fix exactly that on this branch and push, and say in one line what you changed. If you think the review is wrong, say why in one line instead.
Sentinel's last review said the limit = 500 cap made the Bring it home numbers stop growing at 500 uses. That was already fixed on this branch in 25506a81. The plan now counts in SQL with totalsSince, so there is no row cap.
What was missing was a test that would catch the cap coming back. I added one that records 600 uses and checks the plan counts all of them (test/cloud-vendors.test.ts). bun test test/cloud passes (28 tests), and I did not run the type check or the full gate.
I changed no source code, and the other review comments were already handled in earlier commits.
Try it with FORGE_TEST_SOCKET=port bun test test/cloud.
🤖 Generated with Claude Code
I fixed the failing check by merging origin/main into the branch and pushing; the new check run hasn't reported yet. The check failed because test/crew-sandbox-real.test.ts was in neither GATE nor EXCLUDED in scripts/gate.ts. Main had already fixed that in commit 08f24838 (released as 0.7.104), which lists it in EXCLUDED. I made no code changes of my own.
Locally, after the merge, tsc --noEmit is clean and test/cloud-vendors.test.ts passes (17 tests). I did not run the whole suite.
This pull is still the clouds-as-capacity change from issue 1146. It also includes the cloud-vendors test now listed in the gate and the test that the "Bring it home" plan counts past 500 uses.
I fixed the two asks-bulk test failures and pushed; the forge's check on that push hasn't reported yet. test/asks-bulk.test.ts now passes (21 tests) and tsc --noEmit is clean.
Both tests were stale. They failed the same way on origin/main, so my changes didn't cause them. I changed the tests, not the code:
- Card request test: it asserted
id="asks-link", the Asks button that main removed in 0.7.104. I deleted that assertion. - Muted repository test: it asserted the card does not contain "muted". The undo bar carries a
muted smallCSS class, so that check broke once an earlier test had closed some asks. It now asserts that "repository muted" is absent, which is what the test means.
The forge's check log also showed shards 2 and 4 exiting 143 without naming a test. I didn't investigate those and don't know if they will recur.
Parked by the crew: the check stayed red through 2 automatic tries
This pull adds no new code. The branch already had the cloud work from the earlier pull, and this push only merges current
maininto it. I can't tell whether that merge fixes the earlier check failure, because I never reproduced it.test/following.test.ts. I ran that file after mergingmain(60 commits ahead) and all 20 tests pass. The cloud code doesn't touch the following code, so my guess ismainhas moved on since then.bunx tscerrors with "Cannot find type definition file for 'bun'", which looks like a sandbox problem rather than a code one. The forge's check will run both on this push.What the branch delivers (from the earlier commits, for review):
cloud.jsondeclares which of Cloudflare, Vercel and GitHub a repository or app may use. Nothing is allowed by default, and an undeclared use is refused. Every vendor call is audited.docs/CLOUD.md.What the branch leaves out:
.forgejo/workflows.The issue lists all three, so the issue is only partly done. They are good candidates for separate smaller issues.
To try it: run
FORGE_TEST_SOCKET=port bun test test/cloud*(20 tests pass).🤖 Generated with Claude Code
Closes #1146