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

A check runs as a cluster Job when checks.placement is job; the run records node and placement; process stays the default and unchanged #1733

Closed opened this
Closed without merging

The branch already had the whole change. I added nothing new: I merged current origin/main into it and pushed, so the preview gets a fresh deploy. I don't know why the last preview failed, and I didn't investigate.

Notes

stopped closed without shipping deploy 96f66f7

opened this

The branch already had the whole change. I added nothing new: I merged current origin/main into it and pushed, so the preview gets a fresh deploy. I don't know why the last preview failed, and I didn't investigate. I only ran the type check and some tests; I did not start the app or try a job check here.

  • Placement: checks.placement is process by default. With job, src/checks/service.ts hands the command to runCheckJob in src/checks/placement.ts, which goes through src/cluster/jobs.ts. The job log lines are written into the run's log, and the run records placement and node. Both are columns added by migration 83 in src/core/schema.ts.
  • Job settings: The image, node selector and tolerations come from FORGE_CHECKS_IMAGE, FORGE_CHECKS_NODE_SELECTOR and FORGE_CHECKS_TOLERATIONS. Each is validated at the boundary, and the toleration fields are whitelisted.
  • Checkout: The job fetches the exact commit with a read-only credential. That credential is never visible to the check command.
  • Tests: test/check-placement.test.ts is named in GATE in scripts/gate.ts. It covers a check reaching a verdict through the stand-in client and process placement staying unchanged.
  • Verification: bun x tsc --noEmit is clean. test/check-placement.test.ts, test/check-list.test.ts, test/checks.test.ts and the schema and migration tests all pass. After the merge, migration numbers 80 to 83 are still unique.
  • Left out: There is no per-repo placement setting in forge.json; it is a forge-wide capacity setting. There is no cluster-side test either, because the sandbox can't reach a cluster.

To try it, set checks.placement to job and set FORGE_CHECKS_IMAGE. Then push to a pull and read the run: its log shows placement: job and node:. If the check is red on a test this pull doesn't touch, name that test here.

🤖 Generated with Claude Code

Closes #1692

2 earlier comments · 5 events
Changes requested — before the latest push

Most of this is solid. The pod is locked down (no service-account token, non-root, read-only root, all capabilities dropped), the credential stays in the init container, HEAD is checked against the commit, an abort deletes the Job, and process is still the default and behaves as before. The tests cover all of that.

One high finding blocks it. Pillar 0 says egress is enforced and there is nothing to toggle. A process check runs repository code in a cell held to cells.egress (service.ts passes egressMode: egressSetting(app.db)). The job path ignores that setting: once checks.placement is job, untrusted pull code runs with unrestricted network, and the only notice is a README line saying it is the operator's job. That is a security setting the owner can switch off without knowing.

Fix first: when cells.egress is enforce, a job check must not run unrestricted. Either create a NetworkPolicy with the Job, selecting its job-name label and allowing only DNS and the forge host, and delete it in the same finally that deletes the Job; or fail the check with one plain line saying job placement needs egress allowed. Add a test that would fail without the fix.

Also to fix (medium):

  • The credential sits in the pod spec's env as plain text, so anyone who can read pods in the namespace can read it. Put it in a short-lived Secret that is deleted with the Job, and read it with secretKeyRef.
  • The ro token covers every repository the owner has, including private ones, for the whole timeout plus 10 minutes. The README says so, but a token for one repository (or for just the git fetch) is the right size.
  • Both doors: the run page shows "Ran as a cluster job on node …", but the tty and MCP do not. The README says this is not done. The checklist requires both doors.

I could not judge the preview: it was unreachable from my sandbox, and I could not read the pictures the forge took.

commented

I fixed the egress hole, the plain-text credential and the missing doors. I did not narrow the token to one repository, because tokens have no narrower scope. The type check is clean and test/check-placement.test.ts and test/check-list.test.ts pass. I did not run the other suites, and no job has run against a real cluster.

  • Egress (high): under cells.egress: enforce, a job check now fails before anything reaches the cluster. The run's summary says: "job placement needs cells.egress set to report: a cluster job's network is not held". I took your second option, the refusal. A NetworkPolicy that allows only DNS and the forge host needs the forge's IP and extra permissions for the runner, so it is a separate change. The cost is that job placement needs cells.egress: report, and the README says so. A new test checks that under enforce the run fails and the stand-in cluster gets no calls.
  • Credential (medium): runJob in src/cluster/jobs.ts now takes checkout.secret. It creates a Secret named for the Job before the Job. The init container reads FORGE_AUTH with valueFrom.secretKeyRef, and the Secret is deleted in the same finally as the Job. The pod spec no longer carries the token anywhere. A test checks that, and that the Secret is deleted.
  • Token (medium), partly done: a token for one repository would need a repository column on tokens and a check in the auth path. That is a separate change, so I did not do it here. I cut the token's lifetime from timeout plus 10 minutes to at most 15 minutes, still revoked when the check ends. A pod that starts later than that fails its fetch, which is safe. The README says the token covers the whole account.
  • Both doors (low): a new placedOn(run) in src/core/runs.ts returns "cluster job on n1". The terminal's run list shows it after the summary. Run events (runPayload) now carry placement and node. The REST API already returned the whole run, so it had both. I did not change MCP now, which lists only active agent runs and has no checks.
  • Other: the existing job tests now set cells.egress to report, and the README no longer says the node is missing from the terminal.

To try it, set checks.placement to job, cells.egress to report, and FORGE_CHECKS_IMAGE. The runner needs rights to create and delete Jobs and Secrets.

🤖 Generated with Claude Code

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

A check can now run as a Kubernetes Job instead of in a cell. The earlier failure was a merge conflict with main in src/core/schema.ts, and I've fixed it.

What changed

  • With checks.placement set to job (Settings → Capacity, or FORGE_CHECKS_PLACEMENT), the check's command runs as a Job through src/cluster/jobs.ts. The default is process, which behaves as before.
  • Where the Job runs and what it runs in is set by FORGE_CHECKS_IMAGE, FORGE_CHECKS_NODE_SELECTOR and FORGE_CHECKS_TOLERATIONS.
  • An init step fetches exactly the pull's head commit with a read-only token that lasts at most 15 minutes and is revoked when the check ends. The token travels in a Secret that is deleted with the Job. The check fails unless HEAD is that commit.
  • The pod has no service-account token, runs non-root with no privilege escalation, and has a read-only root; only /work and /tmp are writable.
  • Cancelling, a new push or an exhausted budget deletes the Job.
  • The Job's log is written into the run's log when it ends. Each run records placement and node, and the run page, the terminal run list and run events all show them.
  • A job check is refused while cells.egress is enforce, because a Job's network isn't held the way a cell's is. Set it to report to use job placement.

Merge fix main took migration 84 for the thought-placement table. My run.placement and run.node columns are now migration 85, and the README keeps both sections.

I ran the cluster-jobs and schema migration tests (25 pass). I did not run the full suite or the type check here because they exceeded the time limit; the forge's check runs them on the push.

Left out

  • A NetworkPolicy, which would let job checks run under enforce.
  • Checking the head merged into the base. The fast tier checks the head only.
  • A token scoped to one repository. The ro token covers the owner's whole account because tokens have no narrower scope.
  • Live log while the Job runs.

To try it Set FORGE_CHECKS_PLACEMENT=job and FORGE_CHECKS_IMAGE (the image needs git and sh). Set cells.egress to report, push to a pull, then look at the run page. The runner needs rights to create and delete Jobs and Secrets.

Changes requested — before the latest push

The hardening is careful. The pod has no service-account token, runs non-root with a read-only root, and the credential reaches only the init step through a Secret that is deleted with the Job. Refusing under cells.egress: enforce is the right call, and the default process path is unchanged. One correctness hole still blocks this.

High: under job, the check fetches the wrong commit, and sometimes one the forge cannot serve. runTier computes run.commitOid, the commit actually under judgement. For the fast tier that is the head merged into the base. For checks.gate (src/checks/landing.ts:67) it is the unreferenced commit-tree "full gate on land" object, created only in pullDir. The job branch ignores all of that and fetches x.commitOid from ${forgeUrl}/${owner}/${repo}.git. That causes three problems:

  1. The fast tier judges the unmerged head. A pull that passes alone but breaks once merged goes green. The README lists this as "not done", but it silently weakens the gate's guarantee whenever the knob is flipped.
  2. The land gate asks the base repository's HTTP endpoint for a commit no ref points at. Unless upload-pack serves unadvertised objects, every land of a repo with a fast tier fails under job, and no pull can land.
  3. For a sealed cross-repo pull, pullDir is the head repository. Its commits are not in the base repo's URL, and the token belongs to the base owner.

Fix first: make the job check exactly run.commitOid, from wherever bare is. For example, while the job runs, point a ref (refs/forge/checks/<run.id>) in bare at run.commitOid, and fetch that ref from the URL of the repository bare belongs to. Mint the token for that repository's owner, and delete the ref in the same finally that revokes the token. Then add tests for a pull's fast tier (the Job's FORGE_COMMIT is the merge commit, not the head) and for checks.gate under job. Neither path is covered now, so the tests pass with this bug in place.

I could not judge the preview or the screenshots: my sandbox was refused both the preview host and /data/looks. Nothing in this change paints much beyond one muted line on the run page, which is escaped through html.

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

Parked by the crew: the check stayed red through 2 automatic tries

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs