Skip to content
Myr

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).

authored by oscabriel · committed by oscabriel · parent 678c8b8 · Browse files · 10 files+209 added−91 removed
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

10 files+209 added−91 removed

modified:apps/platform/src/visibility/env.ts+12 added-41 removed
modified:apps/platform/src/workflows/answer/lanes.ts+2 added-2 removed
29 unmodified lines
30import { countLanes, measure } from "@repo/checks/kinds/ratchet";31import { classifyFailure } from "@repo/gate/classify";32import { MeasuredCount, runBlockOf } from "@repo/project/answer-runs";33import type { AnswerRun } from "@repo/project/answer-runs";34import { noRunEnv, RunEnv } from "@repo/project/env-port";34import { noRunEnv, UnlandedRunEnv } from "@repo/project/env-port";35import { LandingState } from "@repo/project/landing";36import { Projects } from "@repo/project/projects";37import { LaneOutcome, LaneResult } from "@repo/protocol/domain/answer";38import { CheckSpec } from "@repo/protocol/domain/check";
46 unmodified lines
85 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 lines
modified: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 go
28 unmodified lines
38import { RulesEvaluator } from "@repo/rules/rules-evaluator";39import { gitClient } from "@repo/testkit/git-client";40import { aProject } from "@repo/testkit/scenarios";41import { untouchable } from "@repo/testkit/untouchable";42import { EnvSchemaParserEnvSpec } from "@repo/visibility/env-schema/env-spec";42import { SealedValue } from "@repo/visibility/vault";43import {44 Cause,45 Context,
16 unmodified lines
62} from "../../src/adapters/rate-limits.ts";63import { decodeEnv, platformOn } from "../../src/platform.ts";64import { projectShell } from "../../src/project-shell.ts";65import { serve } from "../../src/surfaces.ts";67import { envOn } from "../../src/visibility/env.ts";66import { envLive } from "../../src/visibility/env.ts";67import { fakeEnv } from "../fake-env.ts";68import { origin } from "../harness.ts";69import { inProcessNamespace } from "../project-namespace.ts";70
97 unmodified lines
168 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 );175176 const noRuns = Layer.succeed(
231 unmodified lines
modified:apps/platform/test/bindings.test.ts+1 added
134 unmodified lines
135 "compatibility_date",136 "compatibility_flags",137 "containers",138 "env",139 "keep_names",140 "main",141 "migrations",142 "minify",143 "name",
246 unmodified lines
modified:apps/platform/wrangler.jsonc+7 added
19 unmodified lines
20 // 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 lines
modified:packages/project/src/visibility/env.ts+57 added-14 removed
10 unmodified lines
11 * 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 */22import { RepoHost, Revision } from "@repo/artifacts/repo-host";23import type { EnvProxy } from "@repo/checks/check-runner";24import { Hostname } from "@repo/protocol/domain/common";25import type { Evidence } from "@repo/protocol/domain/common";26import { DecisionSubject } from "@repo/protocol/domain/decision";27import type { Decision } from "@repo/protocol/domain/decision";
17 unmodified lines
45import { EnvSchemaParser } from "@repo/visibility/env-schema";46import { envSchemaViewOf } from "@repo/visibility/env-shape";47import { scanBytes, scanText } from "@repo/visibility/leak-scan";48import type { Watched } from "@repo/visibility/leak-scan";49import { placeholderFor, proxyMap } from "@repo/visibility/proxy";50import type { ProxyRule } from "@repo/visibility/proxy";51import { SealedValue, WriteOnlyValues } from "@repo/visibility/vault";52import {53 Array,54 Cache,
210 unmodified lines
265const decodeSealed = Schema.decodeUnknownEffect(266 Schema.toCodecJson(SealedValue)267);268269/** `text`, unless it is absent or empty: the check job's wire takes no empty method or path. */270const nonEmpty = (text: Option.Option<string>) =>271 Option.getOrUndefined(Option.filter(text, (each) => each !== ""));272273/** A proxy rule as the check job carries it (611's `EnvProxy`): no key for a method or path the rule leaves open. */274const onTheWire = (rule: ProxyRule): EnvProxy => {275 const method = nonEmpty(rule.method);276 const path = nonEmpty(rule.path);277278 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};287288/** A host list as evidence shows it: `none` before an item had any. */289const hostsText = (hosts: readonly string[]) =>290 hosts.length === 0 ? "none" : hosts.join(", ");291
154 unmodified lines
446 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);457434 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 }461462 const unlanded = {463 placeholders: sensitive.map((item) => ({464 key: item.key,465 placeholder: placeholderFor(item),466 })),467 proxies: proxyMap(schema).map(onTheWire),468 };469470 if (!landed) {471 return unlanded;472 }473474 const keys = new Set(sensitive.map(({ key }) => key));475476 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.succeedNone
69 unmodified lines
modified:packages/project/src/answer-runs.ts+2 added-2 removed
37 unmodified lines
38import type { RequestId } from "@repo/protocol/ids";39import { Refusal, VerifierBlocked } from "@repo/protocol/refusal";40import { Context, Effect, Option, Schema } from "effect";4142import { RunEnv } from "./env-port.ts";42import { UnlandedRunEnv } from "./env-port.ts";43import { Change, LandingState, PendingDecision } from "./landing.ts";44import type { LandingCommand, LandingEffect } from "./landing.ts";4546const Attempt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
74 unmodified lines
121 /**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 lines
modified:packages/project/src/deciders.ts+3 added-3 removed
111 unmodified lines
112import { recordOf } from "./attention/record.ts";113import { today } from "./attention/today.ts";114import { standing } from "./attention/vouch.ts";115import { ClaimState } from "./claim.ts";116import type { RunEnv } from "./env-port.ts";116import type { UnlandedRunEnv } from "./env-port.ts";117import { ProjectEventInput } from "./events.ts";118import { pushFacts } from "./facts.ts";119import { Lander, Rebuild } from "./lander.ts";120import type { ComposedFile } from "./lander.ts";
262 unmodified lines
383 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 lines
1737 */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 lines
modified:packages/project/src/env-port.ts+19 added-6 removed
23 unmodified lines
24import { noPlan, policyIn } from "./visibility-port.ts";25import type { VisibilityPlan } from "./visibility-port.ts";2627/**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 */33export const RunEnv = Schema.Struct(34export const UnlandedRunEnv = Schema.Struct(35 Struct.pick(CheckJob.fields, ["placeholders", "proxies"])36);3738export type UnlandedRunEnv = typeof UnlandedRunEnv.Type;3940/**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 */46export const RunEnv = Schema.Struct(47 Struct.pick(CheckJob.fields, ["landed", "placeholders", "proxies", "values"])48);4950export type RunEnv = typeof RunEnv.Type;5152/** The env a job carries when the project has no write-only values: none. */40export const noRunEnv: RunEnv = { placeholders: [], proxies: [] };53export const noRunEnv: UnlandedRunEnv = { placeholders: [], proxies: [] };5455/** A project's env schema at one commit, as `envShape` shows it but for where and whose. */56export type EnvSchemaFile = Omit<EnvSchemaView, "at" | "project">;57
95 unmodified lines
modified:packages/project/test/visibility/env.test.ts+102 added-18 removed
205 unmodified lines
206 sensitive: true,207 tags: ["release"],208});209210/** What a check sees in place of the token's value. */211const tokenPlaceholder = "__SENTRY_AUTH_TOKEN_PLACEHOLDER__";212213/**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 */218const 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};230231/** The project as ines-v first pushes it: a package and its env schema. */232const start = (schema: string): Files => [233 ["package.json", '{ "name": "datekit" }\n'],234 ["src/index.ts", "export const now = () => 0;\n"],
358 unmodified lines
593 }).pipe(Effect.provide(world))594 );595});596597/** datekit's schema with the token behind `proxy`'s argument list. */598const 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");610611describe("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 lines
619620 const env = yield* ProjectEnv;621 const run = yield* env.runEnv({ landed: false }, yield* stored);622588 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 );627628 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"'));633634 const env = yield* ProjectEnv;635636 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});650651describe("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();657658 yield* api.setEnv(ines, { key: token, value: Redacted.make(value) });659660 const env = yield* ProjectEnv;661662 const { values, ...run } = yield* env.runEnv(663 { landed: true },664 yield* stored665 );666667 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 );679680 it.effect("carries no value for an item whose value nobody set", () =>681 Effect.gen(function* () {682 yield* begun();683684 const env = yield* ProjectEnv;685686 expect(yield* env.runEnv({ landed: true }, yield* stored)).toStrictEqual({687 ...tokenRunEnv,688 landed: true,689 values: [],690 });691 }).pipe(Effect.provide(world))692 );693});694695describe("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 lines
719 }).pipe(Effect.provide(world))720 );721});722625/** datekit's schema with the token behind `proxy`'s argument list. */626const 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");638723const narrow = proxied('domain="sentry.io"');724725const wide = proxied('domain=["sentry.io", "upload.example.invalid"]');726
193 unmodified lines