Repository navigation
Runner registry, credentials, switch and revocation cascade (DM-05) - #2149
Merged
neuromechanist merged 9 commits intoNov 13, 2026
Merged
neuromechanist merged 9 commits into
neuromechanist merged 9 commits into
Conversation
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR2149Version: 🤖 Updated on each push. |
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Card DM-05 of the portable compute plan: runner registry, credentials, the dark switch and the revocation cascade.
An owner registers, lists and revokes a runner from the CLI; a registration secret (
nmr_) buys a 15-minute access token (nmra_) and nothing else; both prefixes are refused by every other path before any lookup; revoking a runner, or ending its registering owner, ends its tokens and its work in one batch.Migration 0140 adds
compute_runners,compute_runner_tokensand twelvecompute_jobscolumns (executor, accounting, claim and lease, runner usage), with the partial index of waiting runner jobs; no foreign key, noadmitted_at.computeRunnersEnabledneeds compute on andCOMPUTE_RUNNERS_ENABLEDexactly "1"; it is absent fromwrangler-sccn.tomland pinned by the flag test, and named in AGENTS.md.Routes:
POST /compute/runners/tokenandGET /compute/runners/me(runnerAccess), and the owner'sPOST|GET /admin/compute/runnersandPOST /admin/compute/runners/:id/revoke; refusals use the protocol's words.authMiddleware(throughresolveBearerUser) andresolveApiKeyUseranswer 401runner_credential_not_acceptedfor either prefix; the principal RPC refuses them as an invalid credential.Cascade statements that
runnerRevokeStatements(runnerId, reason)andrunnerEndStatements(userId, reason)add, in this order, each ending in a WHERE clause with plain placeholders: (1) DELETE the runner's access tokens, (2) UPDATE its unstarted claimedcreatedjobs to clear runner, claim and lease, (3) UPDATE its started or past-createdlive jobs tounreportedwith the lease cleared, keepingrunner_id, (4) UPDATE the registration to revoked with a reason, last.Callers of
runnerEndStatements: three (finalizeRevocation,tombstoneUserCascade, the role demotion handler), listed inRUNNER_END_CALLERSand held by a source-scan test that reuses the compute scan; before this PR there were none. The compute set stays at two callers and the OpenID Connect set at six, both unchanged. A key revocation and a sign-out are deliberately not callers; the emailed key regeneration is a named exception.CLI:
nemar admin compute runners register|list|revoke; the secret is printed once with a mode-0600 warning, help has an Exit codes block.Gates run:
bun run typecheckandbun run lintpass;bunx biome checkon every touched TypeScript file passes;bun run migrations:d1-checkpasses (128 migrations on real D1, catalog matches bun:sqlite); the eight Acceptance test files pass (171 tests).Also run and passing: the credential and compute cascade suites (admin-credential-cascade, admin-revoke-route, mail-ticket-cascades, private-site-cascade, test-account-sweep, compute-end-callers, compute-release-cascade, oidc-cascade and its callers and D1 variants, optional-auth-api-key, the two compute migration suites, contract and state suites, private-site RPC).
Each new test was proven by mutating the line it guards (about 75 mutations, listed in the card report); two guards are redundant by design (a revoked secret is refused by the lookup and again by the token INSERT), so only both mutated together are caught.
Not run, would check: the full
bun test(the epic gate) because it takes about 80 minutes.Deviations: the listing and revoke answers have no shape in the runner contract, so open schemas are declared in
src/lib/api/compute-runners.ts; two registry-only words (runner_not_found,runner_name_taken) are declared in the admin route file;compute-end-scan.tstakes a target so one scan holds both statement sets.Card: DM-05.
Review round 1 fixes (head 640540a):
A registration is now written
FROM usersof an approved, undeleted owner (0 changes isowner_only, and no audit row), and the secret lookup, the token INSERT andresolveRunnerAccessall joinusersfor the same standing; route-level tests cover a late registration after each of the three callers, and a pre-guard row is shown dead.A claimed job with a cancel recorded is no longer released: it goes to
unreportedkeepingrunner_idandrunner_claimed_at, lease cleared. For DM-07: after a revoke anunreportedjob keepsrunner_idandrunner_claimed_atwith a NULLlease_expires_at, so the sweep keys on stateunreportedplus the runner's revoked flag, never lease expiry.Deviation recorded: a claimed
queued(slurm, nostarted_at) job goes tounreportedtoo, because releasing it would need the forbidden backward edgequeued -> created.The
compute.runner.registeredaudit row recordskey_id; the docblock and.rules/revocation.mdcarry the stolen-key incident step (list runners after revoking a leaked owner key, revoke any you do not recognize). ADR 0121's key-revocation exception is unchanged.Migration 0140 also adds
CHECK (executor = 'tapis' OR source = 'pipeline')(carried on the added column, no rebuild; real D1 accepts it) and thecompute_jobs_runnerindex onrunner_id(EXPLAIN QUERY PLAN pinned for all four job statements).The demotion failure comment and warning now name runner registrations; the exchange is in the strict IP rate bucket (
rateLimit.tsAUTH_PATHS, a minimal edit outside the card's file list);RunnerPrincipalandRunnerRowuse the shared unions.New tests: a route-table-wide refusal test (both prefixes against every route, compared with an unknown key),
resolvePrincipalwithtokensholding the hash, direct service tests (exchange on a revoked id, owner standing at each use), and the bucket pin.Not done on purpose: release does not clear
webhook_nonce(nothing in this card mints one at claim; patch note for DM-06 and DM-07: clear it on release and mint a fresh one at claim so a released claim's job token dies). A concurrent double revoke can write twocompute.runner.revokedaudit rows; cosmetic, left.Review round 2 fixes (head 6fd59ad):
finalizeRevocationnow writes the revoked status (and the service-access stamps) as the LAST statement of the same atomic batch as the cascade, instead of a separate statement after it; a late registration is either before the batch (ended by it) or after it (refused by the standing guard), so a re-approval brings nothing back, and the retry property of the batch is unchanged. The other two callers have no such gap:tombstoneUserCascadeis one guarded batch whose first statement setsdeleted_at, and the role demotion writes the role before its batch, so a registration after the role write is already refused.Test: for each of the three callers the real route runs over a database that injects
registerRunnerright after the first batch commits, then re-approves the owner; the registration must be refused and nothing resolves. Reverting the status write to a separate statement after the batch fails only the finalizeRevocation case, as expected.The
resolvePrincipaltest comment no longer claims to guard the behaviour-neutralcase; the migration EXPLAIN pin is nowUSING INDEX compute_jobs_runner\b; a lowercasebearerscheme is refused by authentication (resolveBearerUseris case-sensitive), sokeyIdOfcannot see one, and a test pins that.Known and left: if the demotion's credential batch fails, the runners are not ended, but the owner no longer stands (role written first), so the join refuses them until a re-promotion; the failure is logged with the manual step, as for tokens.