FLT-394 parser redesign plan, v3.1 (author: Clahadore)¶
- Review history:
- v1: standard council.
- v2: goldfish. Red team VETO; design critic NOT READY.
- v3: the same two stages re-checked it. Still VETO and NOT READY, on narrower points.
- v3.1 takes those findings and the Master Orchestrator's guidance (Andrew is AFK) and goes to a council-proxy decision.
- Base:
aed4b75. - Code:
tools/LocalStackDrift, C#, net10.0. - Where it runs: all work runs on the streaming PC (Docker 29.6.1, SDK 10.0.301) over
ssh streaming→pwsh -File. - Scope: local dev tooling, so proportionate; this is not a sandbox product.
Structure¶
- Phase A is capture only. It writes no production code. Its output is a receipt plus plan v4.
- Phase B is the build. It starts only when the SecurityThreatVeto and DesignCriticAndReadiness stages pass v4.
- Open decisions. Every item marked [R] is a question for the receipt and has a named fallback, so it can't stall the plan. v4 replaces each [R] with the captured answer or applies its fallback. Any decision NOT marked [R] is fixed by this plan.
Security model¶
- Socket holders. Anyone with access to the Docker socket is root-equivalent. Compose labels are an attribution hint, not an integrity boundary. This tool catches accidental and unreviewed drift; it does not stop a hostile socket holder who relabels containers (an accepted residual risk, documented in the README).
- Secret leaves: env values, healthcheck argv, env_file/secret/config bodies, and command args.
- They never reach a log at any level, an exception, a finding, a receipt, a ticket, git, or a hash committed to git.
- Inspect stdout and compose stdout may hold them in memory only, and may never be written out.
- Daemon pin. Every Docker call:
- runs with
DOCKER_HOST,DOCKER_CONTEXTandDOCKER_TLS_VERIFYcleared; - aborts with exit 2 unless the context is the local npipe engine;
- uses argv arrays (no shell strings) with
--before every id or name.
Phase A: capture¶
A0. Fixture project flt394-fixture on streaming.
- Inputs. Everything is authored by us:
- one pinned image, by digest, running sleep, with no credentials in the reference;
- no env_file, extends or include;
- the Docker socket is never mounted.
- Safety:
- Before starting, abort with nonzero and WITHOUT running cleanup if any container, volume or network already carries com.docker.compose.project=flt394-fixture, or if any fixture volume or network name already exists.
- Every created object also gets flt394.run-id=<random>, set only by this process, and its id is recorded.
- Cleanup in finally deletes ONLY the recorded ids, with -f and --project-directory pinned to the script's temp dir.
- The run then exits nonzero if any cleanup command fails, or if any object with that run-id or project label remains: one-offs and docker create volumes included.
- Host exposure:
- Bind sources are subdirectories of an empty temp dir created by the script.
- privileged, cap_add and devices sit on one container with no publish and no host mount.
- network_mode is none.
- The 0.0.0.0 publish goes on a docker create container that is never started.
- The healthcheck argv is a sentinel echo with no network call.
- Coverage:
- two services, one with 2 replicas;
- named, external and anonymous volumes;
- a bind mount;
- long and service tmpfs with options;
- an image mount, with a subpath if supported;
- fixed 127.0.0.1 and fixed 0.0.0.0 ports;
- ports: ["8080"], a UDP port, a published range, an expose-only port, and a port both exposed and published;
- two bindings for one target;
- a :ro volume, plus service read_only: true (the rootfs);
- unsorted cap_add, cap_drop, security_opt, one device, user, pid, ipc;
- healthchecks with $$, $$$, $$$$, a lone $, and a ${...}, plus a service with no healthcheck;
- depends_on with each condition;
- restart omitted, no, and on-failure:3;
- env values containing = and containing sentinel-secret-value;
- a container created but not started, a stopped container, and a compose run one-off.
Try an explicit null binding via docker create. If it can't be produced, record the exact commands tried.
A1. Receipt (Fixtures/RECEIPT.md).
- How it's produced. An in-process reducer reads the Docker output in memory and emits ONLY versions, booleans, field presence and JSON types. Its stdout is matched against an allowlist pattern: no JSON literals, no KEY=value. No raw dump of anything is ever written. The agent reads the receipt file, not command output.
- Real stacks. For the three real greatroom manifests, hardcoded relative paths taken from local-stacks/greatroom/manifest.json (absolute paths, .. and symlinks that leave the repo are rejected), the reducer records only type vectors and booleans.
- Env_file. Materialization is answered with a fixture sentinel file, never with real env files.
- The questions:
1. Versions: Docker, the Engine API, Compose, dotnet.
2. The JSON type set of every field we read.
3. Whether the real manifests render object ports under --no-interpolate.
4. Inspect behavior:
- .Id vs .ID and the raw-map fallback;
- whether split works when run on a constant only;
- HostConfig.PortBindings (configured) and NetworkSettings.Ports (runtime) per port case, including created and stopped containers;
- ExposedPorts;
- RestartPolicy;
- the Mounts fields per type, including the image reference field and subpath;
- whether service tmpfs appears in Mounts;
- the Desktop bind Source spelling;
- the security fields, including ReadonlyRootfs;
- the healthcheck Test, both sides, for every $ case;
- timing units;
- the trailing bytes after --format output.
5. Labels: service, container-number, the oneoff value, config-hash, the depends_on grammar and its condition set, and the volume-inspect labels per volume kind. Also whether N comes from deploy.replicas and/or scale, and whether docker compose config --hash=* reproduces the live config-hash.
6. docker ps format: one JSON object per row of the selected fields, for a compose container, a one-off and a non-compose container (missing labels must come out as JSON null).
7. A scratch STJ app on SDK 10.0.301 checks:
- which [JsonSourceGenerationOptions] settings the generator honors;
- whether JsonException names the unknown member and omits the token;
- trailing whitespace vs a second value.
8. Stryker.NET: the pinned version's net10.0 support, the thresholds.break exit code, the zero-mutant behavior, and its config schema. Plus a live advisory/CVE check on the pinned versions.
A2. Fixtures.
- Deserializer inputs are synthetic flt394-fixture captures only, production-shaped and committed raw. The only secret-shaped values are sentinels.
- Real stacks produce no committed document and no committed hash of a secret leaf. Only their type vectors go into RECEIPT.
- Gitleaks gate:
- It runs as a nonzero-exit step BEFORE git add, with a pinned config that allowlists only the synthetic capture paths.
- A positive control fails the scan: a planted fake AWS key in a temporary copy.
- A test asserts the allowlist doesn't cover any other path.
- Pinned field allowlist: the set of JSON keys that may appear in committed fixtures. A test fails on any other key.
- Integrity: each fixture's sha256 is checked against its sidecar by a test.
- npipe and cluster: hand-written and labeled schema-derived, used only for the mount-unsupported path.
A3. Plan v4. Every [R] is resolved and drift codes are frozen. The two stages re-run on v4.
Phase B decisions¶
D1. Compose input.
- Declared state: docker compose config --format json --no-interpolate, plus --hash=* [R].
- A test pins --no-interpolate in the argv.
- The project id is compose name and must match ^[a-z0-9][a-z0-9_-]*$, or the run exits 2.
- No YAML library.
D2. Projections, each a template we own.
- Every template is byte-equal to a frozen constant, checked by a test.
- projectionVersion is required. A mismatch against the build constant exits 2.
- The three projections:
- ps: one row per container with the ID, Names, project, service, container-number, oneoff and config-hash labels. A missing label is null. A failed ps exits 2.
- Container inspect: one process per full id. Stdout is one JSON value followed by optional whitespace; any further token throws.
- Volume inspect: run with -- <name>. The name must first match ^[a-zA-Z0-9][a-zA-Z0-9_.-]*$ [R]. The output is the name plus the project and volume label facts only.
- Env names come from the template if it can emit names without values [R]. Fallback: a names-only C# converter over Config.Env that never keeps a value or logs the buffer. The sentinel tests stay either way.
- Healthcheck Test may enter stdout, but only the hashing converter reads it.
- A rendering test: run the real template on a container whose env and healthcheck contain the sentinel, and assert stdout has the env name and lacks the sentinel in the env section.
- Intentional deviations from the Engine API are listed in Fixtures/README.md.
D3. Deserialization.
- Contexts and options:
- Three source-generated contexts, with options on [JsonSourceGenerationOptions].
- JsonSerializer.Deserialize is banned in tools/LocalStackDrift/ (generated files excluded), except inside ONE named helper that takes a JsonTypeInfo. That helper has its own test.
- Also banned: new JsonSerializerOptions, JsonExtensionData, PropertyNameCaseInsensitive, JsonNode, JsonDocument, JsonElement, TryGetProperty, GetProperty, EnumerateArray, EnumerateObject.
- Field rules:
- Every property has an explicit [JsonPropertyName]. Optional fields are T? = null.
- [JsonRequired] goes only on fields the receipt shows are always emitted.
- Fields with more than one observed JSON type get a converter that accepts exactly those types.
- No CLR type is chosen before the receipt exists.
- Inspect projection: Disallow on unmapped members.
- Compose:
- Disallow on the compared subtrees.
- Other root and service keys must be on an allowlist of the keys observed in the receipt, cross-checked against a pinned compose-go revision. Their values are Skip()ped unread. Any key outside the allowlist exits 2 with "compose field X is not known to check".
- [R] Fallback if the generator can't do this, or its message doesn't name the key: ONE Utf8JsonReader key-walker for the compose root and service objects, still skipping values unread. It is the single named exception to the grep ban.
- Compose environment: names only; values are Skip()ped, null included.
- Healthcheck digest:
- Kind = element 0, not hashed.
- The other elements are each UTF-8 with a 4-byte little-endian length prefix, then SHA-256, as hex.
- The compose side applies left-to-right $$→$; the live side is not unescaped. The algorithm is frozen only once it matches every $ case in the capture.
- The property type is HealthcheckTestDigest(Kind, Argc, Sha256).
- Errors:
- The projection boundary catches Exception, not just JsonException, and throws ProjectionException(sourceId, jsonPath, line) with no inner exception.
- A test feeds the sentinel in an env value and a healthcheck token, through both a JsonException path and a non-JsonException converter failure, and asserts the sentinel is absent from the message, ToString, stdout, stderr, every log level, every finding, and every string reachable in the deserialized object graph (a reflection walk).
- Healthcheck findings print only Kind, Argc and the digest.
- Restart: live "", "no" and an omitted compose value all mean no.
- Non-object compose ports: exit 2 with "ports not normalized: an uninterpolated ${...} keeps the whole list as strings".
- Port ranges: exit 2 until a range rule exists.
- Required tests: an optional field omitted must deserialize; a second JSON value must throw; an unknown field, an unknown enum, an explicit null, a missing required field and the old flat shape must each throw.
D4. Scope and join.
- Scope: the in-scope set is the containers whose project label equals compose name.
- Join key: (service label, container-number). Each container must also have a config-hash label equal to that service's --hash value [R]; otherwise config-hash-mismatch.
- Count: each service expects N non-oneoff containers, N = replicas/scale [R], default 1.
- Zero → missing-container.
- More than N, or a duplicate key → extra-container, keeping both containers in the result.
- An undeclared service label → undeclared-service.
- A one-off for a declared service → extra-container. This is deliberate: after a compose run, the check stays red until the one-off is removed.
- Disappearing objects: "No such object" between ps and inspect → missing-container. A volume-inspect error → volume-unverified. Neither is ever a match.
- Consistency model: one ps snapshot plus per-id inspect; a replacement id is seen on the next run.
- Out-of-scope containers are listed by name and id and never inspected.
D5. Comparison.
- Exact multisets, compared both ways.
- Ports, compared on the CONFIGURED HostConfig.PortBindings, not runtime state, so a stopped container is judged on its configuration.
- Identity: {target, protocol, mode, exposure}. Exposure is fixed {hostPort, hostIpClass} or random {hostIpClass}. An unknown mode exits 2.
- hostIpClass: "" = 0.0.0.0 = v4-any. A 0.0.0.0 + :: pair with the same hostPort is one dual-any. A lone :: equals neither. 127.0.0.1 is its own class.
- Codes: a null binding → port-unverified. Unmatched declared → port-missing. Unmatched live → undeclared-publish.
- Expose: declared expose must be a subset of Config.ExposedPorts (image EXPOSE entries land there too and expose nothing to the host) → expose-missing. An expose-only port must have no binding.
- Mounts, as a multiset:
- Named and external volumes: resolved name + target + RW + subpath.
- Anonymous volumes: Type=volume, the same target, a name that is not any declared resolved name, and a successful volume projection with project = name and no volume label; otherwise volume-unverified.
- Bind mounts: target + RW + propagation + source.
- Source rule: if a side has a receipt VM prefix (streaming engine table), map it; then fold slashes and the drive letter, and compare.
- Mismatch if the folded strings differ, or if only one side had a prefix.
- Image mounts: the reference field [R] + target + RW + subpath.
- Tmpfs: target + the options the receipt shows. Two declarations of the same target exit 2.
- Mount RW: volume read_only ⇔ RW: false; omitted ⇔ RW: true.
- npipe and cluster: mount-unsupported for that mount; the rest of the container is still compared.
- Codes: mount-missing, undeclared-mount, mount-mismatch.
- Security fields → security-field-mismatch:
- Compared: service read_only (the ReadonlyRootfs), privileged, network_mode, pid, ipc, user, userns_mode, runtime, cgroupns, group_add, sysctls, cap_add, cap_drop, security_opt, devices.
- Caps, security_opt and group_add are sets. A device is a tuple (canonical host path, container path, permissions).
- device_cgroup_rules, secrets and configs exit 2 if declared.
- No security field is accepted unseen.
- Existing comparisons gain codes:
- image-mismatch, image-unpinned, image-missing;
- healthcheck-mismatch, healthcheck-unverifiable;
- depends-on-mismatch, with conditions limited to service_started, service_healthy, service_completed_successfully [R] and a strict svc:condition:required grammar;
- restart-mismatch, status-mismatch.
- Output: drift[<code>]: <where>: <text>. Text never includes a secret leaf.
- Exit lattice: 0 means no findings; 1 means any drift code; 2 means any structural error. When both occur, 2 wins.
D6. Tests.
- Codes: each code has a clean and a drift case. Unit-fixture JSON is labeled "unit"; the live set comes from re-capturing mutated fixture projects.
- Also tested:
- TOCTOU;
- an in-scope malformed inspect exits 2;
- out-of-scope containers are never inspected (the stub asserts it, and a variant without the filter exits 2);
- a duplicate key;
- the one-off case;
- an exit-code assertion for every code.
- Restart: EmptyRestartEqualsNo covers omitted vs "no" and "" vs "no".
- Lint oracle: two manifests, one empty and one drifted, asserting both outcomes.
- ${...} detectors: they treat $$ as a literal, with a case for each.
D7. Mutation gate.
- Config: a committed stryker-config.json with the pinned version [R] and thresholds.break: 80.
- What is mutated: converters, deserializers, comparers, the hashing converter, the finding formatter, and stdout handling.
- Floors: per-file integer mutant floors are committed from a committed dry-run report.
- Enforcement: the script fails when the score is below break, or when any file is below its floor (zero included).
- Can-fail proof: a probe branch that drops the score below break must fail, and is never landed.
- Excluded tests: exactly these five, pinned by a test that fails if the list changes:
- LocalStackDrift.Tests.ProcessRunnerTests.LargeInputToChildThatNeverReadsReturnsWithinDeadline
- DrainsBothPipesBeforeWritingLargeInputAndUsesBomlessUtf8
- ChildExitingWithoutReadingInputDoesNotThrow
- TimeoutCapturesStdoutAndStderrBeforeReturning
- TimeoutObservesQueuedInputBeforeDisposingProcess
- CI wiring is required to land. The merge waits on Andrew's runner-label decision.
D8. WT-7917 invariants: - Kept: invariants 1 to 4, with invariant 3 stricter. - Invariant 5 is replaced by exit 2. - Invariant 6 now applies to the compose side only.
Out of scope, as follow-ups: ProcessRunner E/F/G and the proof-command oracles.
Phase B steps¶
Each step is automated, and Clahadore runs every check himself:
1. contexts and converters, with the D3 tests;
2. templates and runners, with the byte-equality, argv, scope and TOCTOU tests;
3. D5 compare, with the frozen codes and exits;
4. lint and the D6 oracles;
5. Stryker, with its script, the probe branch and the floors.
6. Streaming verification:
- the failing set equals exactly the five tests;
- lint on the real manifests is clean;
- a live probe project with anonymous and image mounts exits 0;
- mutations exit 1 with these codes: port-missing+undeclared-publish, undeclared-mount, extra-container, mount-mismatch, volume-unverified, security-field-mismatch, healthcheck-mismatch.
Receipts contain commands and exit codes only. 7. Council code review, then land as one fast-forward chain once CI is wired.
Builder: Susie (muse-spark-1.3, max) on streaming. Jenny is the fallback.