From 27ce5e21b661537d1989b996ec36435f4ddc6486 Mon Sep 17 00:00:00 2001 From: tlongwell-block <109685178+tlongwell-block@users.noreply.github.com> Date: Sun, 2 Aug 2026 01:30:52 -0400 Subject: [PATCH 1/2] feat(k8s): refuse respond-to modes the harness cannot parse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The merged guard validated the allowlist but projected the mode string straight through. `respond_to` is an opaque `Option` on the wire and a `clap::ValueEnum` at the harness (`config.rs:448-454`), so an unrecognized mode dies at rc=2 — before config parsing runs, earlier than the allowlist errors the guard already covers. Same ending as before: exit 1 under `restartPolicy: Never` is Terminated -> Delete -> recreate, one Secret leaked per attempt. Found by Sami's acceptance audit, which measured the harness's real surface instead of reading it. Re-running his matrix against the shipped predicate: 8 of 10 rows already agreed, and the 2 that disagreed were both this — `respond_to: "npub1abc"` and a padded `" allowlist "`. Matched exactly and untrimmed, because clap does not trim: `" allowlist "` is rc=2 at the harness even though the trimmed string is valid, so trimming here would accept a deploy the harness refuses. Validated against the harness's four modes, not the desktop's three. `parse_wire` rejects `nobody` deliberately (`managed_agents/types.rs:871-880`) but the harness starts fine with it; this guard exists to cover non-desktop callers, so inheriting that narrowing would refuse a working launch. `every_mode_the_harness_accepts_is_deployable` pins all four. The matrix also runs through the built binary in `wire_fixtures.rs`. `build_env` precedes `client::connect` (`main.rs:124` before `:132`), so under an impossible KUBECONFIG the error string is the ordering assertion: "kubeconfig" means the gate passed and we reached the cluster, "deploy refused" means we stopped before writing a Secret. Asserting only `ok:false` would pass on the connection error and prove nothing. Mutation-tested. Dropping the mode check fails both negatives; trimming before the match fails the padded case only; dropping `nobody` to mirror the desktop fails the positive control only — each test failing for the reason it names, control 148+4 green. Co-authored-by: Dawn (sprout agent) Signed-off-by: tlongwell-block <109685178+tlongwell-block@users.noreply.github.com> --- crates/buzz-backend-kubernetes/src/env.rs | 77 +++++++++++++++++- .../tests/wire_fixtures.rs | 79 +++++++++++++++++++ 2 files changed, 155 insertions(+), 1 deletion(-) diff --git a/crates/buzz-backend-kubernetes/src/env.rs b/crates/buzz-backend-kubernetes/src/env.rs index 58e6c3c133..badff621e8 100644 --- a/crates/buzz-backend-kubernetes/src/env.rs +++ b/crates/buzz-backend-kubernetes/src/env.rs @@ -86,6 +86,15 @@ fn identity_component(value: &str) -> Option<&str> { /// `RespondTo` (kebab-case) and as `buzz-acp`'s CLI parses it. const RESPOND_TO_ALLOWLIST: &str = "allowlist"; +/// Every gate mode `buzz-acp` accepts, spelled as its `clap::ValueEnum` parses +/// them (`config.rs:95-101`, kebab-case via `RespondTo`'s `Display`). +/// +/// Deliberately the **harness's** four and not the desktop's three: the desktop +/// rejects `nobody` on purpose (`managed_agents/types.rs:871-880`), but the +/// harness starts fine with it. This guard exists to cover non-desktop callers, +/// so inheriting a desktop-only narrowing would refuse a launch that works. +const RESPOND_TO_MODES: [&str; 4] = ["owner-only", RESPOND_TO_ALLOWLIST, "anyone", "nobody"]; + /// Refuse a respond-to gate the harness will reject at config parse. /// /// The local spawn path re-validates this before spawning — "doing it here @@ -97,13 +106,24 @@ const RESPOND_TO_ALLOWLIST: &str = "allowlist"; /// sweep does, at `ORPHAN_SECRET_MIN_AGE_SECS`). The user-visible ending is /// "startup not confirmed", indistinguishable from a slow cluster. /// -/// Mirrors `buzz-acp`'s own rules exactly (`config.rs:996-1004,629-641`), +/// Mirrors `buzz-acp`'s own rules exactly (`config.rs:95-101,996-1004,629-641`), /// deliberately including their asymmetry: the allowlist is validated **only** /// in allowlist mode, and merely warned about otherwise. Validating it in /// every mode would refuse a deploy whose identical local spawn succeeds — /// and a stale list is already harmless here, since /// `BUZZ_ACP_RESPOND_TO_ALLOWLIST` is an authoritative key that tier 3 clears. fn validate_respond_to_gate(respond_to: &str, allowlist: Option<&[String]>) -> Result<(), String> { + // Exact, untrimmed: `clap` does not trim, so `" allowlist "` is `rc=2` at + // the harness — a parse failure even earlier than the config errors below. + if !RESPOND_TO_MODES.contains(&respond_to) { + return Err(format!( + "deploy refused: respond_to {respond_to:?} is not a mode the \ + harness accepts (expected one of {}) — the pod would fail to \ + parse its arguments, be replaced, and leave a Secret behind on \ + every attempt", + RESPOND_TO_MODES.join(", ") + )); + } if respond_to != RESPOND_TO_ALLOWLIST { return Ok(()); } @@ -654,4 +674,59 @@ mod tests { assert_eq!(env["BUZZ_ACP_RESPOND_TO"], mode); } } + + /// `respond_to` is an opaque `String` on the wire but a `clap::ValueEnum` + /// at the harness, so an unrecognized mode dies at `rc=2` — before config + /// parsing runs at all, earlier than either refusal above. Measured + /// against the built binary: `invalid value 'npub1abc' for '--respond-to'`. + /// This is the shape our own fixture carried until it was corrected. + #[test] + fn a_mode_the_harness_cannot_parse_is_refused() { + for bad in ["npub1abc", "OWNER-ONLY", "owner_only", "allowlistt", "x"] { + let agent = payload_json(serde_json::json!({ "respond_to": bad })); + let err = build(&agent).unwrap_err(); + assert!( + err.contains("is not a mode the harness accepts"), + "{bad:?} was accepted; error was: {err}" + ); + } + } + + /// `clap` does not trim its value-enum input, so a padded mode is `rc=2` + /// even though the same string trimmed is valid. Measured: `invalid value + /// ' allowlist ' for '--respond-to'`. Trimming here would accept a deploy + /// the harness refuses — the exact direction this guard exists to prevent. + #[test] + fn a_padded_mode_is_refused_because_clap_does_not_trim() { + for padded in [" allowlist ", "allowlist ", " owner-only", "\tnobody"] { + let agent = payload_json(serde_json::json!({ + "respond_to": padded, + "respond_to_allowlist": [pubkey('a')], + })); + let err = build(&agent).unwrap_err(); + assert!( + err.contains("is not a mode the harness accepts"), + "{padded:?} was accepted; error was: {err}" + ); + } + } + + /// Positive control for the mode check, and the reason it validates the + /// harness's four rather than the desktop's three: `nobody` is rejected by + /// `parse_wire` on purpose (`managed_agents/types.rs:871-880`) but starts + /// fine at the harness. A guard mirroring the desktop enum would refuse a + /// working launch from a non-desktop caller — the callers this guard is + /// for. Without this test, refusing `nobody` would pass everything above. + #[test] + fn every_mode_the_harness_accepts_is_deployable() { + for mode in ["owner-only", "allowlist", "anyone", "nobody"] { + let agent = payload_json(serde_json::json!({ + "respond_to": mode, + "respond_to_allowlist": [pubkey('a')], + })); + let env = build(&agent) + .unwrap_or_else(|e| panic!("{mode} is valid at the harness but was refused: {e}")); + assert_eq!(env["BUZZ_ACP_RESPOND_TO"], mode); + } + } } diff --git a/crates/buzz-backend-kubernetes/tests/wire_fixtures.rs b/crates/buzz-backend-kubernetes/tests/wire_fixtures.rs index 0bca51a04b..2c3af82b1f 100644 --- a/crates/buzz-backend-kubernetes/tests/wire_fixtures.rs +++ b/crates/buzz-backend-kubernetes/tests/wire_fixtures.rs @@ -133,3 +133,82 @@ fn the_full_desktop_payload_is_accepted() { "the full payload was rejected before reaching the cluster: {error}" ); } + +/// Sami's pre-registered respond-to matrix, driven through the built binary. +/// +/// `build_env` runs at `main.rs:124`, `client::connect` at `:132`, so under a +/// kubeconfig that cannot exist the error string *is* the ordering assertion: +/// "kubeconfig" means the gate passed and we reached the cluster, anything +/// else means we refused before writing a Secret. A test asserting only +/// `ok: false` would pass on the connection error and prove nothing. +/// +/// The cases are applied to the real full-launch request so each one differs +/// from a known-good deploy in exactly the field under test. +#[test] +fn the_respond_to_gate_matches_the_harness_acceptance_surface() { + let key_a = "a".repeat(64); + let padded_upper = format!(" {} ", "A".repeat(64)); + // (name, respond_to, allowlist, must reach the cluster) + let cases: Vec<(&str, &str, Option>, bool)> = vec![ + ("allowlist + []", "allowlist", Some(vec![]), false), + ("allowlist + absent", "allowlist", None, false), + ( + "allowlist + junk", + "allowlist", + Some(vec!["beefcafe".into()]), + false, + ), + ("unparseable mode", "npub1abc", None, false), + ("padded mode", " allowlist ", None, false), + ( + "allowlist + two valid", + "allowlist", + Some(vec![key_a.clone(), "b".repeat(64)]), + true, + ), + ( + "owner-only + junk list", + "owner-only", + Some(vec!["beefcafe".into()]), + true, + ), + ( + "allowlist + padded upper", + "allowlist", + Some(vec![padded_upper]), + true, + ), + ("nobody", "nobody", None, true), + ("anyone", "anyone", None, true), + ]; + + let base: serde_json::Value = + serde_json::from_str(&read("deploy-full-launch.request.json")).unwrap(); + + for (name, mode, allowlist, reaches_cluster) in cases { + let mut request = base.clone(); + let agent = &mut request["agent"]; + agent["respond_to"] = serde_json::json!(mode); + agent["respond_to_allowlist"] = match &allowlist { + Some(list) => serde_json::json!(list), + None => serde_json::Value::Null, + }; + + let (stdout, code) = run(&request.to_string()); + assert_eq!(code, 0, "{name}: provider did not exit cleanly"); + let response: serde_json::Value = serde_json::from_str(&stdout).unwrap(); + let error = response["error"].as_str().unwrap_or_default(); + let reached = error.contains("kubeconfig"); + + assert_eq!( + reached, reaches_cluster, + "{name}: expected reaches_cluster={reaches_cluster}, got error: {error}" + ); + if !reaches_cluster { + assert!( + error.contains("deploy refused"), + "{name}: refused, but not by the gate: {error}" + ); + } + } +} From f2e1f379dcfdb707e945d4d625109813a59066d3 Mon Sep 17 00:00:00 2001 From: tlongwell-block <109685178+tlongwell-block@users.noreply.github.com> Date: Sun, 2 Aug 2026 01:34:39 -0400 Subject: [PATCH 2/2] test(k8s): transcribe launch.args from the resolver, not a test literal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Quinn found that the fixture's `agent` half was executed but its `launch` half was not: `agents_tests.rs:447-455` built an `EffectiveHarnessDescriptor` as a struct literal and asserted the fixture against it, so `command`, `args` and `env` were pinned to values the test itself wrote down. The same literal sat on both sides of the `assert_eq!` — consistency, not correctness, and the fourth instance this arc of a value that agrees with itself. Mari then executed `resolve_effective_harness_descriptor` against a coherent source record (`runtime: "goose"` plus model/provider/env_vars, so the resolver sees what the payload serializer sees). Everything matched the committed fixture except one field: launch.args: ["run", "--session"] -> ["acp"] Transcribed from her executed result, not derived — the README's own rule is that "recorded" means executed and transcribed, and `launch` was the one field group still exempt from it. Co-authored-by: Dawn (sprout agent) Signed-off-by: tlongwell-block <109685178+tlongwell-block@users.noreply.github.com> --- .../fixtures/provider-wire/deploy-full-launch.request.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/buzz-backend-kubernetes/tests/fixtures/provider-wire/deploy-full-launch.request.json b/crates/buzz-backend-kubernetes/tests/fixtures/provider-wire/deploy-full-launch.request.json index 39de2c5c6f..28fe6ce90e 100644 --- a/crates/buzz-backend-kubernetes/tests/fixtures/provider-wire/deploy-full-launch.request.json +++ b/crates/buzz-backend-kubernetes/tests/fixtures/provider-wire/deploy-full-launch.request.json @@ -11,8 +11,7 @@ "idle_timeout_seconds": null, "launch": { "args": [ - "run", - "--session" + "acp" ], "command": "goose", "env": {