Give checks the env as 611's job carries it, open values for landed runs, and parse env schemas in the Worker
Before adoption: this commit came in with the history the project adopted, so no landing records it.
W6 group 2 integration: 606, 611, 612, 613 and 614 merged with --no-ff from 0ede7b2 in that order, without a textual conflict (disjoint territories). bun install and fix left no change; there is no gen script since 598. - 611 x 614 (typecheck): 611 reshaped CheckJob's placeholders and proxies to {key, placeholder} and the EnvProxy wire rule, and env-port's RunEnv picks them from the job, so 614's runEnv (EnvKey[] and EnvItem[]) no longer typed. runEnv now gives each sensitive item's placeholderFor and proxyMap's rules on the wire, an absent or empty method or path left off (the wire is NonEmptyString, and the parser reads path="" as ""). For landed: true it also sets landed and the values of the shape's sensitive items, opened through the vault (614 #5, 611's note for 614). - RunEnv now picks landed and values too; the envs that are stored or cross a Workflow step (AnswerRun.env, Checked.env, the decider kernel's runEnv and carry) take the new UnlandedRunEnv (placeholders and proxies alone), so no value is representable there, and Schema encoding strips any extra key (611's note for 613/614/699). - bytes:check: the five branches together put the platform entry at 1,682,896 of 1,665,000, each under it alone. apps/platform/wrangler.jsonc sets "keep_names": false (614 #1 option a): esbuild's name-keeping wrapped every function in a helper call, about 130 KB. Nothing in the Worker reads a minified name at run time: Effect's tagged errors take name from their tag, services are keyed by strings, and the runtime finds DO, Workflow and entrypoint classes by export name, which minifying keeps. ASSUMPTION: no dependency reads a class's own name for behavior; 699's live smoke confirms. bindings.test.ts lists keep_names among the keys that declare no binding. - With the room, envLive composes 603's EnvSchemaParserEnvSpec (614 #1: "one line"), and EnvSchemaParserOffEntry is gone, so a stage reads each project's .env.schema and setEnv can store values (616, 699). env-values.test.ts now composes envLive itself, so a Worker that stops parsing fails it. - Tests: the unlanded run's case expects 611's wire shape; new cases: a landed run carries the stored value opened beside the same placeholders and proxies, a landed run with no value set carries none, and an empty @proxy path is left off the rule (real parser). The first two and the reshaped unlanded case were red by assertion first; the empty-path case was written after the fix and fails under a planted fault (empty path kept). - verify green (project 439, platform 415, sandbox 75, checks 313; platform entry 1,597,754 of 1,665,000 with the parser, sandbox 569,083, web JavaScript 2,364,070 of 2,500,000).
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
10 files+209 added−91 removed
- tests:+107 added−23 removed
- other:+102 added−68 removed
Provenance
- Commit
234865c- Tree
8b2022d- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent
678c8b8
10 files changed+209 added−91 removed
modified:apps/platform/src/visibility/env.ts+12 added-41 removed
1234567891011121314678910111819202112132314151617272829303132333435363738394041424344451819204621222350242526272829535455565758/** * The visibility cartridge's env, as the platform provides it (W6 614): * the project service's `ProjectEnv` over an `.env.schema` parser and the * vault that seals write-only values under the stage's `MASTER_KEY` (610's * WebCrypto envelope). It reads each project's schemas at the landed SHA * through the platform's `RepoHost`, the public namespace's. * * The parser is the one part the Worker does not carry yet: 603's adapter * over `@env-spec/parser` adds 44,410 bytes to the platform's entry, which * then measures 1,696,434 of `bytes:check`'s 1,665,000. Until it runs off * the entry (614's Comments), the Worker's parser reads no schema, so a * project's env shape is empty there, as without the cartridge; `envOn` * takes the real adapter wherever a host can carry it (the platform's * Node tests do). * through the platform's `RepoHost`, the public namespace's. The parser is * 603's adapter over `@env-spec/parser`, which reads a schema into plain * data and runs nothing in it. */import type { RepoHost } from "@repo/artifacts/repo-host";import { ProjectEnvLive } from "@repo/project/visibility/env";import { EnvSchemaParser, EnvSchemaUnreadable,} from "@repo/visibility/env-schema";import { EnvSchemaParserEnvSpec } from "@repo/visibility/env-schema/env-spec";import { WriteOnlyValuesWebCrypto } from "@repo/visibility/vault/webcrypto";import { Effect, Layer } from "effect";import { Layer } from "effect";
import type { PlatformConfig } from "../platform.ts";
/** * A parser that reads no schema: each is unreadable, so the env shape has * no items, no value can be set, and every check runs with the env it * would have without the cartridge. Nothing is guessed from the text. */export const EnvSchemaParserOffEntry: Layer.Layer<EnvSchemaParser> = Layer.succeed(EnvSchemaParser, { parse: (file) => Effect.fail( new EnvSchemaUnreadable({ file, reason: "the platform does not carry the env-schema parser yet", }) ), });
/** The project service's env for one stage's config, with `parser` reading the schemas. */export const envOn = ( config: PlatformConfig,/** The project service's env for one stage's config, as the Worker composes it. */export const envLive = ( config: PlatformConfig parser: Layer.Layer<EnvSchemaParser>): Layer.Layer<never, never, RepoHost> => ProjectEnvLive.pipe( Layer.provide( Layer.merge(parser, WriteOnlyValuesWebCrypto(config.MASTER_KEY)) Layer.merge( EnvSchemaParserEnvSpec, WriteOnlyValuesWebCrypto(config.MASTER_KEY) ) ) );
/** The project service's env as the Worker composes it. */export const envLive = ( config: PlatformConfig): Layer.Layer<never, never, RepoHost> => envOn(config, EnvSchemaParserOffEntry);modified:apps/platform/src/workflows/answer/lanes.ts+2 added-2 removed
29 unmodified lines30 import { countLanes, measure } from "@repo/checks/kinds/ratchet";31 import { classifyFailure } from "@repo/gate/classify";32 import { MeasuredCount, runBlockOf } from "@repo/project/answer-runs";33 import type { AnswerRun } from "@repo/project/answer-runs";34-import { noRunEnv, RunEnv } from "@repo/project/env-port";34+import { noRunEnv, UnlandedRunEnv } from "@repo/project/env-port";35 import { LandingState } from "@repo/project/landing";36 import { Projects } from "@repo/project/projects";37 import { LaneOutcome, LaneResult } from "@repo/protocol/domain/answer";38 import { CheckSpec } from "@repo/protocol/domain/check";46 unmodified lines85 base: CommitSha,86 /** Every path the answer changed against its base. */87 changed: Schema.Array(RepoPath),88 /** The env every check job of the answer carries (W6 609): placeholders, never a value. */89- env: Schema.optionalKey(RunEnv),89+ env: Schema.optionalKey(UnlandedRunEnv),90 finish: AskKind.fields.finish,91 /**92 * The answer's fork, which holds the merged tree: the Lander keeps it there93 * under `${Brand.refsPrefix}merge/<tree>` for the Checker to fetch.563 unmodified linesmodified:apps/platform/test/visibility/env-values.test.ts+4 added-5 removed
1 /**2 * Write-only values over the platform's surfaces (W6 614): the handler the3 * Worker serves, its Project DOs in process on SQLite, the platform's ports4- * in memory, and the visibility cartridge's env composed over them with5- * 603's real parser and 610's WebCrypto vault under the fake env's test4+ * in memory, and the visibility cartridge's env as the Worker composes it5+ * (603's real parser and 610's WebCrypto vault) under the fake env's test6 * `MASTER_KEY`. A decider sets datekit's token over `/rpc` with their7 * token; anyone reads the env shape over `/rpc` and sees who set it and8 * when. The value is in no response body, no log line and no event, and9 * the row the DO keeps is sealed. These tests live in the cartridge and go28 unmodified lines38 import { RulesEvaluator } from "@repo/rules/rules-evaluator";39 import { gitClient } from "@repo/testkit/git-client";40 import { aProject } from "@repo/testkit/scenarios";41 import { untouchable } from "@repo/testkit/untouchable";42-import { EnvSchemaParserEnvSpec } from "@repo/visibility/env-schema/env-spec";42 import { SealedValue } from "@repo/visibility/vault";43 import {44 Cause,45 Context,16 unmodified lines62 } from "../../src/adapters/rate-limits.ts";63 import { decodeEnv, platformOn } from "../../src/platform.ts";64 import { projectShell } from "../../src/project-shell.ts";65 import { serve } from "../../src/surfaces.ts";67-import { envOn } from "../../src/visibility/env.ts";66+import { envLive } from "../../src/visibility/env.ts";67 import { fakeEnv } from "../fake-env.ts";68 import { origin } from "../harness.ts";69 import { inProcessNamespace } from "../project-namespace.ts";70 97 unmodified lines168 ProjectionMemory,169 MemoryRateLimits(WorkerCaps),170 Layer.succeed(Fetch, untouchable<Fetch["Service"]>("Fetch")),171 Layer.succeed(Upstream, untouchable<Upstream["Service"]>("Upstream")),173- envOn(config, EnvSchemaParserEnvSpec)172+ envLive(config)173 ).pipe(Layer.provideMerge(RepoHostMemory))174 );175 176 const noRuns = Layer.succeed(231 unmodified linesmodified:apps/platform/test/bindings.test.ts+1 added
134 unmodified lines135 "compatibility_date",136 "compatibility_flags",137 "containers",138 "env",139+ "keep_names",140 "main",141 "migrations",142 "minify",143 "name",246 unmodified linesmodified:apps/platform/wrangler.jsonc+7 added
19 unmodified lines20 // sends the fetch through the public internet (SSRF protection).21 "compatibility_flags": ["nodejs_compat", "global_fetch_strictly_public"],22 // Rat Stack's byte limits are for a minified bundle (scripts/startup-budget.ts).23 "minify": true,24+ // esbuild's name-keeping wraps every function and class in a helper call25+ // that restores its name after minifying: about 130 KB of the entry (W626+ // 614 #1). Nothing here reads a name at run time: Effect's tagged errors27+ // set `name` from their tag, services are keyed by strings, and the28+ // runtime finds Durable Objects, Workflows and entrypoints by export name,29+ // which minifying keeps. A stack trace shows minified function names.30+ "keep_names": false,31 "workers_dev": true,32 "preview_urls": false,33 "observability": { "enabled": true },34 "migrations": [{ "tag": "v1", "new_sqlite_classes": ["Project"] }],243 unmodified linesmodified:packages/project/src/visibility/env.ts+57 added-14 removed
10 unmodified lines11 * for a `@sensitive` item of the shape, sealed by the vault under the12 * platform's master key; the row and a public `ValueSet` ledger entry are13 * the call's writes, and nothing returns the value.14 * - The env a check runs with: a placeholder for every sensitive item and15- * the `@proxy` items, so unlanded code never sees a value.16- * - The scan: the one place a stored value is opened, to find it in a text17- * or a blob, and it answers with the item's key alone.15+ * the `@proxy` rules, so unlanded code never sees a value; a run of16+ * landed code alone also carries the values, opened for that run.17+ * - The scan: the other place a stored value is opened, to find it in a18+ * text or a blob, and it answers with the item's key alone.19 * - After a landing: a `ProxyWidened` decision for each item whose value20 * may now reach a host it could not before (Q20; VL §8.7 #4).21 */22 import { RepoHost, Revision } from "@repo/artifacts/repo-host";23+import type { EnvProxy } from "@repo/checks/check-runner";24 import { Hostname } from "@repo/protocol/domain/common";25 import type { Evidence } from "@repo/protocol/domain/common";26 import { DecisionSubject } from "@repo/protocol/domain/decision";27 import type { Decision } from "@repo/protocol/domain/decision";17 unmodified lines45 import { EnvSchemaParser } from "@repo/visibility/env-schema";46 import { envSchemaViewOf } from "@repo/visibility/env-shape";47 import { scanBytes, scanText } from "@repo/visibility/leak-scan";48 import type { Watched } from "@repo/visibility/leak-scan";49+import { placeholderFor, proxyMap } from "@repo/visibility/proxy";50+import type { ProxyRule } from "@repo/visibility/proxy";51 import { SealedValue, WriteOnlyValues } from "@repo/visibility/vault";52 import {53 Array,54 Cache,210 unmodified lines265 const decodeSealed = Schema.decodeUnknownEffect(266 Schema.toCodecJson(SealedValue)267 );268 269+/** `text`, unless it is absent or empty: the check job's wire takes no empty method or path. */270+const nonEmpty = (text: Option.Option<string>) =>271+ Option.getOrUndefined(Option.filter(text, (each) => each !== ""));272+273+/** A proxy rule as the check job carries it (611's `EnvProxy`): no key for a method or path the rule leaves open. */274+const onTheWire = (rule: ProxyRule): EnvProxy => {275+ const method = nonEmpty(rule.method);276+ const path = nonEmpty(rule.path);277+278+ return {279+ block: rule.block,280+ host: rule.host,281+ key: rule.key,282+ placeholder: rule.placeholder,283+ ...(method !== undefined && { method }),284+ ...(path !== undefined && { path }),285+ };286+};287+288 /** A host list as evidence shows it: `none` before an item had any. */289 const hostsText = (hosts: readonly string[]) =>290 hosts.length === 0 ? "none" : hosts.join(", ");291 154 unmodified lines446 effects: [],447 writes: { decisions: [...decisions.values()] },448 };449 }),427- // A landed run would get the values opened; until the check job has428- // a field for them (611 adds it), a landed run sees the placeholders429- // too, and nothing here opens a value for any run.430- runEnv: (_landed, snapshot) =>431- Effect.map(landedRead(snapshot), ({ schema }) => {450+ // Every run sees placeholders and goes out through the proxy rules; a451+ // run of landed code alone also carries the values, opened here for452+ // the call that runs it (611's gateway swaps them in on the way out).453+ runEnv: ({ landed }, snapshot) =>454+ Effect.gen(function* () {455+ const { schema } = yield* landedRead(snapshot);456 const sensitive = schema.items.filter((item) => item.sensitive);457 434- return sensitive.length === 0435- ? noRunEnv436- : {437- placeholders: sensitive.map(({ key }) => key),438- proxies: sensitive.filter((item) => item.proxy !== undefined),439- };458+ if (sensitive.length === 0) {459+ return noRunEnv;460+ }461+462+ const unlanded = {463+ placeholders: sensitive.map((item) => ({464+ key: item.key,465+ placeholder: placeholderFor(item),466+ })),467+ proxies: proxyMap(schema).map(onTheWire),468+ };469+470+ if (!landed) {471+ return unlanded;472+ }473+474+ const keys = new Set(sensitive.map(({ key }) => key));475+476+ return {477+ ...unlanded,478+ landed,479+ values: yield* watched(480+ snapshot.envValues.filter((row) => keys.has(row.key))481+ ),482+ };483 }),484 scan: (scanned, snapshot) =>485 Array.isReadonlyArrayEmpty(snapshot.envValues)486 ? Effect.succeedNone69 unmodified linesmodified:packages/project/src/answer-runs.ts+2 added-2 removed
37 unmodified lines38 import type { RequestId } from "@repo/protocol/ids";39 import { Refusal, VerifierBlocked } from "@repo/protocol/refusal";40 import { Context, Effect, Option, Schema } from "effect";41 42-import { RunEnv } from "./env-port.ts";42+import { UnlandedRunEnv } from "./env-port.ts";43 import { Change, LandingState, PendingDecision } from "./landing.ts";44 import type { LandingCommand, LandingEffect } from "./landing.ts";45 46 const Attempt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));74 unmodified lines121 /**122 * The env every check job of the answer carries (`ProjectEnv.runEnv` for123 * unlanded code): placeholders and proxies, never a value. Absent, none.124 */125- env: Schema.optionalKey(RunEnv),125+ env: Schema.optionalKey(UnlandedRunEnv),126 /** Whether a decider must finish it before it lands: the ask kind's `finish`. */127 finish: AskKind.fields.finish,128 /** What the checks run on the merged tree: the ask's check first, then every project lane. */129 lanes: Schema.Array(CheckLane),104 unmodified linesmodified:packages/project/src/deciders.ts+3 added-3 removed
111 unmodified lines112 import { recordOf } from "./attention/record.ts";113 import { today } from "./attention/today.ts";114 import { standing } from "./attention/vouch.ts";115 import { ClaimState } from "./claim.ts";116-import type { RunEnv } from "./env-port.ts";116+import type { UnlandedRunEnv } from "./env-port.ts";117 import { ProjectEventInput } from "./events.ts";118 import { pushFacts } from "./facts.ts";119 import { Lander, Rebuild } from "./lander.ts";120 import type { ComposedFile } from "./lander.ts";262 unmodified lines383 now: DateTime.Utc384 ) => Effect.Effect<ProjectRow>;385 readonly read: Effect.Effect<H>;386 /** The env a check of unlanded code carries (`ProjectEnv.runEnv`). */387- readonly runEnv: Effect.Effect<RunEnv>;387+ readonly runEnv: Effect.Effect<UnlandedRunEnv>;388 /** A push's stage 0–1 facts with the layer paths and whether the pusher reads a layer (`ProjectVisibility`). */389 readonly withLayers: (facts: PushFacts) => Effect.Effect<PushFacts>;390 /** A repo's URL at the gateway. */391 readonly remote: (fork: RepoName) => Effect.Effect<string>;1345 unmodified lines1737 */1738 const carry = (1739 input: {1740 /** The env every check job carries: the decider's change is unlanded code. */1741- readonly env: RunEnv;1741+ readonly env: UnlandedRunEnv;1742 readonly lanes: readonly CheckLane[];1743 readonly message: string;1744 readonly now: DateTime.Utc;1745 /** The project's run block, which every check job carries. */340 unmodified linesmodified:packages/project/src/env-port.ts+19 added-6 removed
23 unmodified lines24 import { noPlan, policyIn } from "./visibility-port.ts";25 import type { VisibilityPlan } from "./visibility-port.ts";26 27 /**28- * The env a check job carries: what unlanded code sees in place of each29- * write-only value, and the outbound hosts whose requests the platform30- * rewrites. The `CheckJob`'s own fields, so the job's schema decides their31- * form (611 reshapes them) and this follows.28+ * The env a check job of unlanded code carries: what the code sees in place29+ * of each write-only value, and the outbound hosts whose requests the30+ * platform's env gateway rewrites. Never a value, so it is what an answer's31+ * run keeps (`AnswerRun.env`) and what crosses a Workflow step. The32+ * `CheckJob`'s own fields, so the job's schema decides their form (611).33 */33-export const RunEnv = Schema.Struct(34+export const UnlandedRunEnv = Schema.Struct(35 Struct.pick(CheckJob.fields, ["placeholders", "proxies"])36 );37 38+export type UnlandedRunEnv = typeof UnlandedRunEnv.Type;39+40+/**41+ * The env a check job carries: as for unlanded code, and for a job of42+ * landed code alone, `landed` and the values opened for it (611). Built in43+ * the call that runs the job and dropped after: never stored, never in a44+ * Workflow step's output.45+ */46+export const RunEnv = Schema.Struct(47+ Struct.pick(CheckJob.fields, ["landed", "placeholders", "proxies", "values"])48+);49+50 export type RunEnv = typeof RunEnv.Type;51 52 /** The env a job carries when the project has no write-only values: none. */40-export const noRunEnv: RunEnv = { placeholders: [], proxies: [] };53+export const noRunEnv: UnlandedRunEnv = { placeholders: [], proxies: [] };54 55 /** A project's env schema at one commit, as `envShape` shows it but for where and whose. */56 export type EnvSchemaFile = Omit<EnvSchemaView, "at" | "project">;57 95 unmodified linesmodified:packages/project/test/visibility/env.test.ts+102 added-18 removed
205 unmodified lines206 sensitive: true,207 tags: ["release"],208 });209 210+/** What a check sees in place of the token's value. */211+const tokenPlaceholder = "__SENTRY_AUTH_TOKEN_PLACEHOLDER__";212+213+/**214+ * The env a check of datekit's code runs with, as the check job carries it215+ * (611's wire): the token's placeholder, and its one `@proxy` host with216+ * the path it allows and no method named.217+ */218+const tokenRunEnv = {219+ placeholders: [{ key: token, placeholder: tokenPlaceholder }],220+ proxies: [221+ {222+ block: false,223+ host: "sentry.io",224+ key: token,225+ path: "/api/**",226+ placeholder: tokenPlaceholder,227+ },228+ ],229+};230+231 /** The project as ines-v first pushes it: a package and its env schema. */232 const start = (schema: string): Files => [233 ["package.json", '{ "name": "datekit" }\n'],234 ["src/index.ts", "export const now = () => 0;\n"],358 unmodified lines593 }).pipe(Effect.provide(world))594 );595 });596 597+/** datekit's schema with the token behind `proxy`'s argument list. */598+const proxied = (proxy: string) =>599+ [600+ "# @defaultSensitive=false",601+ "# ---",602+ "# @type=enum(development, test, production)",603+ "APP_ENV=development",604+ "",605+ "# @sensitive",606+ `# @proxy(${proxy})`,607+ "SENTRY_AUTH_TOKEN=",608+ "",609+ ].join("\n");610+611 describe("the env a check of unlanded code runs with", () => {612 it.effect(613 "names a placeholder for every sensitive item and the @proxy items, and holds no value",614 () =>4 unmodified lines619 620 const env = yield* ProjectEnv;621 const run = yield* env.runEnv({ landed: false }, yield* stored);622 588- expect(run).toStrictEqual({589- placeholders: [token],590- proxies: [sentryAuthToken],591- });623+ expect(run).toStrictEqual(tokenRunEnv);624 expect(JSON.stringify(run)).not.toContain(value);625 }).pipe(Effect.provide(world))626 );627+628+ it.effect(629+ "leaves an empty @proxy path or method off the rule, as the check job's wire takes none",630+ () =>631+ Effect.gen(function* () {632+ yield* begun(proxied('domain="sentry.io", path="", method="POST"'));633+634+ const env = yield* ProjectEnv;635+636+ expect(637+ (yield* env.runEnv({ landed: false }, yield* stored)).proxies638+ ).toStrictEqual([639+ {640+ block: false,641+ host: "sentry.io",642+ key: token,643+ method: "POST",644+ placeholder: tokenPlaceholder,645+ },646+ ]);647+ }).pipe(Effect.provide(worldWith(EnvSchemaParserEnvSpec)))648+ );649 });650 651+describe("the env a check of landed code runs with", () => {652+ it.effect(653+ "carries the stored value, opened, beside the same placeholders and proxies",654+ () =>655+ Effect.gen(function* () {656+ const api = yield* begun();657+658+ yield* api.setEnv(ines, { key: token, value: Redacted.make(value) });659+660+ const env = yield* ProjectEnv;661+662+ const { values, ...run } = yield* env.runEnv(663+ { landed: true },664+ yield* stored665+ );666+667+ expect({668+ run,669+ values: values?.map((each) => ({670+ key: each.key,671+ value: Redacted.value(each.value),672+ })),673+ }).toStrictEqual({674+ run: { ...tokenRunEnv, landed: true },675+ values: [{ key: token, value }],676+ });677+ }).pipe(Effect.provide(world))678+ );679+680+ it.effect("carries no value for an item whose value nobody set", () =>681+ Effect.gen(function* () {682+ yield* begun();683+684+ const env = yield* ProjectEnv;685+686+ expect(yield* env.runEnv({ landed: true }, yield* stored)).toStrictEqual({687+ ...tokenRunEnv,688+ landed: true,689+ values: [],690+ });691+ }).pipe(Effect.provide(world))692+ );693+});694+695 describe("the scan for stored values", () => {696 it.effect(697 "finds a stored value in a text or a blob by its item, and never the placeholder",698 () =>20 unmodified lines719 }).pipe(Effect.provide(world))720 );721 });722 625-/** datekit's schema with the token behind `proxy`'s argument list. */626-const proxied = (proxy: string) =>627- [628- "# @defaultSensitive=false",629- "# ---",630- "# @type=enum(development, test, production)",631- "APP_ENV=development",632- "",633- "# @sensitive",634- `# @proxy(${proxy})`,635- "SENTRY_AUTH_TOKEN=",636- "",637- ].join("\n");638-723 const narrow = proxied('domain="sentry.io"');724 725 const wide = proxied('domain=["sentry.io", "upload.example.invalid"]');726 193 unmodified lines