Skip to content
Myr

Scrub a failed revoke's warning of the job's token, as every other sandbox failure line already is

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- Review of 314 found one gap in the "a token never appears in a log" promise: withRemote logged a failed revoke's Cause.pretty(cause) raw, so a store error that echoed the token would have logged it. The mint now builds the job's Remote once, and the release scrubs the warning's cause with it through the same scrub every error line uses. - Test: the recording RepoHost's failing revoke now dies, not fails, with the token's secret in its message: the worst a store can do, and the defect path catchCause must absorb. "fail no job when they cannot be revoked" now also asserts that each warning names method, repo and tokenId, inner token first, and that no minted secret is in any line. It went red by assertion (both secrets leaked) before the fix. - Module doc: the wire carries the token in plain text (the far side needs it) and decodes to a Redacted on either side; it said "the wire redacts it", which a sandbox author could misread. - Mutation spot-checks of the builder's tests (dropping the fork's token from merge's scrub list; a read token for land) each went red.

authored by oscabriel · committed by oscabriel · parent b761e6d · Browse files · 2 files+53 added−24 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+53 added−24 removed

  • tests:+35 added−13 removed
  • other:+18 added−11 removed

2 files+53 added−24 removed

modified:apps/platform/src/adapters/sandbox-credentials.ts+18 added-11 removed
2 unmodified lines
3 * the `SANDBOX` service binding (spec §4.3): the sandbox Worker has no4 * Artifacts binding, so each job takes a token the platform minted for it5 * alone, on one repo (tokens are per repo, S1 #10), with the narrowest scope6 * the job needs and a lifetime of minutes, revoked as soon as the job ends7 * (S1 change 2). A token never appears in a result, a refusal or a log: the8 * wire redacts it, refusals carry no free text (principle 3), and what a9 * failure log says is scrubbed of every token the job carried.7 * (S1 change 2). A token never appears in a result, a refusal or a log: it8 * crosses the binding in plain text, as the far side needs it, but decodes to9 * a `Redacted` on either side; refusals carry no free text (principle 3); and10 * what any failure log says, a failed revoke's included, is scrubbed of every11 * token the job carried.12 *13 * A job is encoded with the wire schemas both sides share, and its outcome14 * comes back as a JSON `Exit` decoded here (principle 2): a typed refusal15 * stays typed; anything else (a rejected call, an outcome that won't decode,
83 unmodified lines
99100/**101 * Mints a `need.scope` token on `need.repo` for one job, hands `use` its102 * remote, and revokes the token once `use` ends, however it ends. A revoke101 * that fails is logged, never raised: the token dies with its lifetime. A102 * repo the store does not know is `VerifierBlocked` for `method`.103 * that fails, or dies, is logged with the token scrubbed, never raised: the104 * token dies with its lifetime. A repo the store does not know is105 * `VerifierBlocked` for `method`.106 */107export const withRemote = <A, E, R>(108 method: SandboxMethod,109 need: RemoteNeed,
6 unmodified lines
116 .remote(need.repo)117 .pipe(Effect.catchTag("RepoNotFound", unknownRepo(method)));118119 return yield* Effect.acquireUseRelease(117 host118 .mintToken(need.repo, need.scope, jobTokenTtl)119 .pipe(Effect.catchTag("RepoNotFound", unknownRepo(method))),120 ({ secret }) => use({ token: secret, url }),121 ({ id }) =>120 host.mintToken(need.repo, need.scope, jobTokenTtl).pipe(121 Effect.map(({ id, secret }) => ({122 id,123 remote: { token: secret, url } satisfies Remote,124 })),125 Effect.catchTag("RepoNotFound", unknownRepo(method))126 ),127 ({ remote }) => use(remote),128 ({ id, remote }) =>129 host.revokeToken(need.repo, id).pipe(130 Effect.catchCause((cause) =>131 Effect.logWarning("sandbox job token not revoked").pipe(132 Effect.annotateLogs({126 cause: Cause.pretty(cause),133 cause: scrub(Cause.pretty(cause), [remote]),134 method,135 repo: need.repo,136 tokenId: id,137 })
78 unmodified lines
modified:apps/platform/test/sandbox-adapters.test.ts+35 added-13 removed
1import { describe, expect, expectTypeOf, it } from "@effect/vitest";2import { RepoHost, RepoNotFound } from "@repo/artifacts/repo-host";2import { RepoHost } from "@repo/artifacts/repo-host";3import type { TokenScope } from "@repo/artifacts/repo-host";4import { RepoHostMemory } from "@repo/artifacts/repo-host/memory";5import { Brand } from "@repo/brand";6import { CheckAt, CheckRunner } from "@repo/checks/check-runner";
136 unmodified lines
143144/**145 * The memory store with the canonical repo and a claim's fork, recording146 * every token it mints and every revoke it is asked for; with `failRevoke`,147 * every revoke fails after it is recorded.147 * every revoke dies after it is recorded, its error echoing the token's148 * secret.149 */150const recordingRepoHost = (failRevoke: boolean) =>151 Effect.gen(function* () {152 const store = yield* RepoHost;
22 unmodified lines
175 revokeToken: (repo, id) =>176 Effect.sync(() => revoked.push({ id, repo })).pipe(177 Effect.andThen(178 failRevoke178 ? Effect.fail(new RepoNotFound({ name: repo }))179 ? Effect.die(180 new Error(181 `cannot revoke ${minted.find((token) => token.id === id)?.secret}`182 )183 )184 : store.revokeToken(repo, id)185 )186 ),187 });
487 unmodified lines
675 );676 })677 );678679 it.effect(680 "fail no job when they cannot be revoked, and are warned of by repo and id alone",674 it.effect("fail no job when they cannot be revoked", () =>675 Effect.gen(function* () {676 const { lander, minted, revoked } = yield* world({ failRevoke: true });681 () =>682 Effect.gen(function* () {683 const { lander, minted, revoked } = yield* world({ failRevoke: true });684678 const { exit, lines } = yield* withLogs(lander.land(landMerge));685 const { exit, lines } = yield* withLogs(lander.land(landMerge));686680 expect(exit).toStrictEqual(Exit.succeed({ pending: [], sha: landed }));681 expect(revoked.map(({ id }) => id)).toStrictEqual(682 minted.map(({ id }) => id).toReversed()683 );684 expect(lines.map(({ level }) => level)).toStrictEqual(["WARN", "WARN"]);685 })687 expect(exit).toStrictEqual(Exit.succeed({ pending: [], sha: landed }));688 expect(revoked.map(({ id }) => id)).toStrictEqual(689 minted.map(({ id }) => id).toReversed()690 );691 expect(692 lines.map(({ annotations, level }) => ({693 level,694 method: annotations.method,695 repo: annotations.repo,696 tokenId: annotations.tokenId,697 }))698 ).toStrictEqual(699 minted.toReversed().map(({ id, repo }) => ({700 level: "WARN",701 method: "land",702 repo,703 tokenId: id,704 }))705 );706 expect(leaked(JSON.stringify(lines), minted)).toStrictEqual([]);707 })708 );709710 it.effect("appear in no result, refusal or log line", () =>711 Effect.gen(function* () {
33 unmodified lines