Repository navigation
feat(deploykit): deliver a use: secret: entry as a FILE step at realize - #551
Conversation
…lize
P07 unit 2b. DESIGN.md:2983 — "there is no `get`: a value reaches a consumer as a `secret:`
need, never as text" — and D-SEC-1, DESIGN.md:2511 — "Secrets come only from the configured
backend; they never enter the store, artifacts, labels, IR, state or output."
The authored shape (`#SecretUse`: `src` a host path, `dst` a venue path, `optional`) is a
FILE→FILE delivery, and the IR already has the step that performs one: `spec.FileStep{Source,
Dest, Mode}` is realized by `kit.walkFile`, which reads `Source` on the OPERATOR host at realize
and `DeployExecutor.PutFile`s the bytes into the venue. The step carries the two PATHS and a
mode; the value never enters the plan, the ledger, a log line or an artifact, so D-SEC-1 holds by
construction rather than by care. One emitter serves every substrate: `PutFile` is one method of
the substrate-neutral `DeployExecutor`, and every deploy target is out-of-process over that same
walk — no per-substrate code, no per-substrate shape.
THIS IS THE FIRST PRODUCER OF A FileStep IN THE TREE. Until now the only non-test construction
was the wire decoder (`spec/install_step_view.go:200`); `git -C sdk grep -c 'FileStep{'
origin/main -- '*.go'` is 0, charly's hits are all `*_test.go`, and no checked-out plugin emits
one. So `kit.walkFile` has had no compiled-plan caller before this change, which is why the
wiring is proved end-to-end below rather than only at the compiler.
## The four decisions, implemented
1. `optional` is decided at COMPILE time, on the operator host where the source actually lives:
an optional entry whose source is unreadable is skipped (DESIGN.md:735 — "the key is readable
when the host had one"); a REQUIRED entry whose source is unreadable is an error naming the
candy and the entry, so a typo cannot silently deliver nothing. THE RESIDUAL RACE IS NAMED IN
THE CODE: the source is stat'ed at compile and read at realize, so an optional entry whose
file disappears in between fails at realize instead of being skipped. Closing it needs an
`optional` field on the File step, which is a wire-shape change and a separate unit.
2. Sorted by entry NAME, so a plan is reproducible compile to compile.
3. Mode `0o600` — a secret delivered world-readable is not delivered.
4. Position: slot 2.8 in `BuildDeployPlan`, AFTER `extract` and BEFORE the candy's own op steps,
so a task that reads `dst` finds the file already in place.
## The accessor, and why it is not a reader-interface widening
`deploykit.specCandyAdapter` is the ONE production implementation of `spec.CandyReader`
(charly/layers.go wraps every candy through `deploykit.NewSpecCandyModel`), and it already holds
the raw `spec.CandyModel`. So the authored `use:` block is reached by one method on that one
type — `CandyUse()` — and a CandyModel that does not carry the authored model simply has no
`use:` entries to compile. `spec.CandyReader` is unchanged.
## Pin
`github.com/opencharly/spec` v0.2026320.2307 -> v0.2026321.1215 (the merge that made
`spec.CandyUse.Secret` a real map, opencharly/spec#360). Producer first, consumer second.
## R7, both halves, twice
PLANTED A (the CompileSecretSteps call removed from BuildDeployPlan):
--- FAIL: TestBuildDeployPlan_CarriesTheSecretDeliveryStep
the plan carries 0 file steps, want 1 — the secret delivery never reached the plan
PLANTED B (the name sort reversed):
--- FAIL: TestCompileSecretSteps_EmitsOneFileStepPerEntrySorted
steps are not in entry-NAME order: "/run/lab/zzz" then "/run/lab/aaa"
RESTORED:
--- PASS all five (per-entry sorted steps with mode 0600; optional-and-missing skips;
required-and-missing errors naming candy+entry; entry without `dst` errors;
and the plan-level wiring plus its before-the-op-steps position)
## Not in this change, deliberately
`deploykit.InjectSecretsIntoPlans` (the value-into-`OpStep.Op.Env` mechanism) is untouched: its
only caller is the out-of-tree `plugin-pod` overlay, which switches to the steps compiled here
in its own release. Deleting it in this diff would break that plugin at its next pin bump, and
the cutover is producer-first.
Gates on the final tree: go build ./... rc=0, go vet ./... rc=0, go test ./... rc=0 with 0
failures across 21 packages, the cross-compile matrix (linux/amd64, arm64, arm, 386) all rc=0,
golangci-lint 0 issues, gofmt -l empty.
Assisted-by: DeepSeek Harness ollama-cloud/deepseek-v4.1-flash (fully tested and validated)
Review — BLOCKHead SHA: Change class: code — a new Go compiler pass in Blocks
Non-blocking notes
Verdict: BLOCK ollama-cloud/deepseek-v4.1-flash — action-review. |
… only there Second review round on #551. The claim "one compiled step serves local, pod and vm" was written against a plan-level proof; this round makes it a realize proof, and closes the silent-skip hole in the accessor. ## The realize proof (the review's block 2) `walkFile` had never been driven by a compiled plan in this tree — this unit is the first producer of a `spec.FileStep`, and the only other construction anywhere is the wire decoder. So the claim was unproven at exactly the step that matters. `kit/secret_delivery_realize_test.go` (new, package kit_test) goes the whole way: a temp host file with known bytes, `deploykit.CompileSecretSteps`, `spec.StepsToView`, `kit.WalkPlans` against a recording `DeployExecutor`, and then TWO assertions: 1. the bytes arrive at `Dest` with mode `0600`, and nothing else was written; 2. **the bytes appear NOWHERE ELSE** — not in the plan, not in the serialized `InstallPlanView` that a ledger or a log would record. That is the D-SEC-1 assertion: the delivery is "a value reaches its consumer as a file, never as text", and (1) alone would pass on a plan that also carried the value in an env var. Both halves, planted and restored: PLANTED A (the step's Source corrupted — the walk cannot read it): --- FAIL: TestACompiledSecretStepLandsTheFileAndOnlyThere WalkPlans: walk step "File" (candy=lab-signing): read file source /nonexistent/planted: open /nonexistent/planted: no such file or directory PLANTED B (the value smuggled into an Op step's Env): --- FAIL: TestACompiledSecretStepLandsTheFileAndOnlyThere the secret VALUE is in the serialized plan — D-SEC-1: it never enters the IR, a label or a log RESTORED: --- PASS both `TestTheSecretStepRefusesAnUnreadableSource` pins the negative direction the race named in spec#363 creates: the source exists at compile (so the compile accepts a required entry) and is removed before the walk reads it — the walk must FAIL, not land nothing and report success. ## The accessor: a silent skip became a named error (the review's non-blocking note) `CompileSecretSteps` reached the authored `use:` block through a structural assertion on `secretUseCarrier`, and a CandyModel without it silently had no entries — the worst possible silent loss, because the deployment starts without the key it needs and reports success. Now: - `ErrUseBlockUnreachable` is returned, naming the offending Go type and pointing at `deploykit.NewSpecCandyModel`; the error wraps, so `errors.Is` classifies it. - `var _ secretUseCarrier = (*specCandyAdapter)(nil)` pins the one production implementation at compile time. - `TestCompileSecretSteps_UnreachableUseBlockIsAnError` pins the choice with a model that has every reader method and no accessor (`notACarrier{ Cmd CandyModel }` embeds the interface). - The doc records why a miss cannot happen on the production path (charly/layers.go is the scanner's only construction path, and the golden tool uses the same constructor) and what would break it (a caller that builds its own CandyModel). ## PR body corrections (for the next push) `## Filed issues` is `spec#363` (the `optional` gap THIS diff surfaced) and `sdk#552` (the `InjectSecretsIntoPlans` D-SEC-1 remainder, filed by the reviewer's finding). `spec#362` and `spec#348` are removed: both are real, but neither was surfaced by this diff, and listing them claims a provenance the section does not have. Gates on the final tree: go build ./... rc=0, go vet ./... rc=0, go test ./... -count=1 rc=0 with 0 failures across 21 packages, the cross-compile matrix (linux/amd64, arm64, arm, 386) all rc=0, golangci-lint 0 issues, gofmt -l empty. Assisted-by: DeepSeek Harness ollama-cloud/deepseek-v4.1-flash (fully tested and validated)
Review — PASSHead SHA: Security screen: PASS — no scope mismatch, no secrets/exfiltration, no guardrail weakening (the change moves values out of the IR, strengthening D-SEC-1), no supply-chain risk beyond the first-party Checklist: All applicable rules PASS or NA. Comment disposition: Prior bot BLOCK (head Core new behavior is load-bearing-tested (Planted A proves the step reaches the plan; the realize test fails if the read is broken or the value leaks into the IR); the delivery ordering is additionally guaranteed by the slot-2.8 placement in Verdict: PASS ollama-cloud/deepseek-v4.1-flash — action-review. |
Summary
The first producer of a
FileStep— and the mechanism was already there.DESIGN.md:2983 says "there is no
get: a value reaches a consumer as asecret:need, never as text", and D-SEC-1 (:2511) says a secret "never enters the store, artifacts, labels, IR, state or output". Today that is violated bydeploykit.InjectSecretsIntoPlans, which puts VALUES intoOpStep.Op.Envso the heredoc renderer emitsexport KEY=value.This compiles each
use: secret:entry into a file delivery instead:and
kit/walk.go'swalkFile— which already ships — does the rest:The IR carries only the two paths. The value never enters the plan, the ledger, a log or an artifact, so D-SEC-1 holds by construction rather than by care — and because
PutFileis one method of the substrate-neutralDeployExecutorwith every deploy target out-of-process on that same walk, one compiled step serves local, pod and vm.Nothing produced a
FileStepbefore this — measured, and it changed the proofSo
kit.walkFilehas never been driven by a compiled plan in this tree. That is why the R7 proof below is at PLAN level — "a compiled step actually lands in the plan, before the candy's own steps" — and not merely "the compiler returns the right struct." A struct assertion would have proved nothing about whether the step reaches the plan at all.The four decisions, and where each is visible
extract, before the candy's own op stepsinstall_build.go, so a task that readsdstfinds it in place0o600optionalsrc/dstis absentAnd an unreachable
use:block is an ERROR, not a silent skip.ErrUseBlockUnreachablewraps, soerrors.Isclassifies it; the message names the offending Go type and points atNewSpecCandyModel; andvar _ secretUseCarrier = (*specCandyAdapter)(nil)pins the one production implementation at compile time. A silent skip on a secret delivery is the worst possible failure — the deployment starts without the key it needs and reports success.TestCompileSecretSteps_UnreachableUseBlockIsAnErrorproves the miss with a struct that embeds the reader interface (every method, no accessor).The residual race is named in the code comment rather than hidden: the source is
stated at compile and read at realize, so an optional entry whose file vanishes in between fails at realize instead of being skipped. That isspec#363—FileStephas nooptional, so the tolerance is decided one step early. It does not block the delivery, and the issue asks for the shape that would remove the second authority.Producer-first, and the deletion that is NOT this module's
go.modbumpsgithub.com/opencharly/specv0.2026320.2307→v0.2026321.1215, the merge that madeCandyUse.Secreta real map. Producer first, consumer second.deploykit.InjectSecretsIntoPlansis untouched, deliberately. Its only caller is the out-of-treecandy/plugin-deploy-podoverlay (git -C sdk grep -rn 'InjectSecretsIntoPlans' origin/main→ one definition, zero in-module callers; the call site ischarly/.build/_candy/plugin-deploy-pod.v2026.274.2042/overlay.go:88). Deleting it here would break that plugin at its next pin bump. That deletion is the plugin's cutover leg, not this module's — producer-first, exactly as the rulebook orders it.How tested
The cross-compile matrix is there because this module is consumed by every substrate; a build that passes on amd64 alone has not been tested against the targets it ships to.
R7 — and the REALIZE path, which is the one that earns the sentence
Both plants are load-bearing: A proves the step reaches the plan, B proves the order is derived rather than incidental. A test that passes with the call removed would be testing the fixture, not the product.
But a plan-level proof is not a delivery proof, so
kit/secret_delivery_realize_test.gogoes the whole way —walkFilelives inpackage kit, so apackage kit_testfile can drivekit.WalkPlanswith a recordingDeployExecutor:CompileSecretStepson a candy whoseuse: secret:block came throughNewSpecCandyModel,spec.StepsToView→ the IR the deploy targets actually walk,kit.WalkPlans(ctx, recorder, …),Destwith mode0600and nothing else was written, and the bytes appear nowhere else — not in the plan, not in the serializedInstallPlanViewa ledger or a log would record.Plant B is the assertion that earns the Summary's sentence. It is not "the bytes moved" — it is "the bytes are nowhere except the destination", which is D-SEC-1 as a property rather than a hope.
And
TestTheSecretStepRefusesAnUnreadableSourcepins the racespec#363names: the source is present at compile (so a REQUIRED entry is accepted), then removed before the walk reads it — the walk FAILS rather than landing nothing and reporting success.R10 honesty, premise and exit status pasted
opencharly/sdkis the mechanism-kit module: nodisposable:target, no service, no binary. Its gate is the module suite, the cross-compile matrix and lint, all pasted. Thegrepexits 1 — no match is not a success.Rulebook compliance
/charly-internals:go(the module's Go conventions),/charly-internals:install-plan(the InstallPlan/step IR this extends),/charly-internals:plugin(the provider/need model theuse: secret:entry belongs to).FileStephas nooptional) is filed asspec#363, with the residual race named in the code rather than smoothed over.spec#363exists precisely becauseoptionalis currently decided at compile time and belongs on the step. The adapter gains ONE accessor rather than wideningspec.CandyReader, so there is still exactly one production implementation.origin/main78cf7c8; no other session's worktree touched.FileStephad ever existed.disposable:target; premise and exit status pasted.Change classification
Kind: a new compiler pass in
sdk/deploykitplus aspecpin bump.Breaking change + rollback: none.
BuildDeployPlangains a step at slot 2.8 for a candy that declaresuse: secret:; a candy that declares none compiles byte-identically (CompileSecretStepsreturns nil for an absentCandyUse).spec.CandyReaderis not widened — the accessor lives ondeploykit's adapter. The pin bump moves to a mergedspectag. Rollback reverts the pin and removes the pass; nothing downstream reads the new steps yet, so the rollback is invisible to every current consumer.Filed issues
optional, so a secret delivery decides #SecretUse.optional at compile time (residual race) spec#363 —FileStephas nooptional, so this module decides#SecretUse.optionalat compile time with a named residual race. Asks foroptional?: boolon the File shape sowalkFilecan skip an unreadable source — one authority for the tolerance instead of two.InjectSecretsIntoPlansputs secret VALUES into the IR, which D-SEC-1 forbids; delete it onceplugin-deploy-podcompilesFileSteps. Filed from this PR's own finding, with the producer-first order and the out-of-tree call site named.Files changed
deploykit/compile_secret_steps.goCompileSecretStepslowersuse: secret:entries to sorted, mode-0o600FileSteps; compile-timeoptionalwith the residual race namedkit/secret_delivery_realize_test.gokit.WalkPlanswith a recording executor, asserting the bytes land atDestat mode0600and appear NOWHERE else, not even in the serialized plandeploykit/compile_secret_steps_test.gooptional+missing skips, required+missing errors naming candy and entry, entry withoutdsterrors, and the plan-level wiring that the step precedes the first Op stepdeploykit/install_build.goextractand before the candy's own op stepsdeploykit/spec_candy_adapter.goCandyUse()accessor, sospec.CandyReaderis not widenedgo.modspecpinv0.2026320.2307→v0.2026321.1215(producer first)go.sumAgent: lead
Assisted-by: DeepSeek Harness ollama-cloud/deepseek-v4.1-flash (fully tested and validated)