diff options
| -rw-r--r-- | README.md | 33 | ||||
| -rw-r--r-- | docs/DECISIONS.md | 59 | ||||
| -rw-r--r-- | tests/kata.rs | 52 | ||||
| -rw-r--r-- | tests/remote_agent.rs | 4 |
4 files changed, 147 insertions, 1 deletions
@@ -41,6 +41,39 @@ aur-build packages # what the index is serving process. The CLI and the UI drive the same code paths, so anything the web interface can do, an operator can do from a shell at 3am. +## Where builds run + +One `sandbox` object in `config.json` says where untrusted recipe code executes. +It names exactly one kind, and a kind that is missing a field it needs — or a +kind that does not exist — is a startup error, not a fallback: + +```jsonc +{ "sandbox": { "kind": "loopback" } } // the default: subprocesses of this process + +{ "sandbox": { "kind": "remote", // sandboxes dial in; you boot them + "listen": "0.0.0.0:8787", "token": "…", + "shared_workspace": true } } + +{ "sandbox": { "kind": "agent-sandbox", // Kata VMs, provisioned per lease by the cluster + "api": "https://k8s:6443", "namespace": "builds", "bearer": "…", + "image": "aur-build-sandbox:latest", + "listen": "0.0.0.0:8787", "token": "…", + "shared_workspace": true } } +``` + +`loopback` is the default and needs nothing, which is what keeps a fresh +`init` working with no configuration at all — and it is honest about what it is: +the sandbox is the hub's own user, with no isolation. `remote` and +`agent-sandbox` differ only in who boots the sandbox: an operator, or the +cluster from an agent-sandbox CR whose `activeDeadlineSeconds` is the lease TTL, +so the orchestrator enforces the deadline even if the hub dies. + +`shared_workspace` is required (explicitly, `true`) by both remote kinds. The +build workspace is not shipped to the sandbox yet — `Run` frames carry a +hub-side working directory — so a remote build only works where the staging +directory is visible at the same path on both sides. Asserting it is what stops +`"remote"` from silently meaning "on the hub". + ## Layout ``` diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md index 58d694a..32daa8c 100644 --- a/docs/DECISIONS.md +++ b/docs/DECISIONS.md @@ -450,3 +450,62 @@ tree — you move the directory and point `--root` at it, which is how the CLI already worked. And an existing tree that was already split by the doubling keeps its two databases until someone notices and moves the rows; the fix stops the bleeding rather than reconstructing what went into the wrong tree. + +## The sandbox backend is a tagged enum, and an unwired kind is an error + +`sandbox_backend` was a string, and `backend_for` matched it with `_ => loopback`. +The design documents a Kata backend, so `sandbox_backend = "kata"` was a +configuration an operator could write in good faith — and it meant "run the +untrusted PKGBUILD as the hub's own user", silently. There was no validation of +any kind in the crate: an empty `agent_token`, a missing listen address, a +half-filled cluster coordinate set, all parsed and failed later as something +else. + +**Choice.** One `sandbox` object, three kinds — `loopback`, `remote`, +`agent-sandbox` — internally tagged, `deny_unknown_fields`, required fields +required by the type rather than by a validation pass someone must remember. +An unknown kind is a parse error naming the value and the valid set; a misspelled +field is named rather than read as absent. `Config::validate` catches what a type +cannot see (a field present but empty) and runs both at startup and wherever a +backend is constructed, so nothing that builds one can skip it. Retired flat keys +are refused when they carry intent — a config saying `"remote"` errors and names +the replacement — while the `"loopback"` plus empty strings that `init` used to +write is noise, not intent, and keeps loading. `agent-sandbox` parses, validates, +and builds a real `KataBackend` over `K8sSandboxProvisioner`; the +containerd/`nerdctl` payload builder is deleted rather than left as a route the +configuration refuses. + +Two consequences of "actually reachable from config" needed fixing on the way. +The agent listener was bound per build, because `Ctx::new` constructed a backend +per build, so a second concurrent build on a fixed `listen` died of `EADDRINUSE` +— the listener is now shared per `(address, token)` for the life of the process, +with the token in the key so two tokens cannot quietly share one. And a Kata +backend cannot share only a listener: it routes dial-ins by nonce into a map of +its own, so two on one address would each see half of them; the whole backend is +shared per configuration instead, keyed by a digest so the token and bearer are +not copied into a second place. + +**Cost.** Existing configs that named a non-loopback backend must be rewritten — +deliberately, because silently reinterpreting them is the bug. And a kind that is +valid but not yet implemented is now a hard error at the first build instead of a +silent downgrade, which is correct but will bite someone mid-rollout. + +## A remote sandbox must be told the workspace is shared + +The workspace is not shipped to a remote sandbox: `Run` frames carry a hub-side +cwd and `build` runs `makepkg` in `ctx.srcdir`. On a hub that shares that path +with the sandbox — the test tier, and any same-host deployment — this works. On +one that does not, it fails obscurely inside `makepkg`. Worse, a misconfiguration +could make a "remote" build succeed on the hub, which is the exact substitution +the whole enum exists to prevent, one layer down. + +**Choice.** Both remote kinds require `"shared_workspace": true`, and the refusal +explains the gap rather than just naming the field. The field defaults to false +rather than being required by the type precisely so the error can say why. +`loopback` needs no assertion because it shares the filesystem by construction. + +**Cost.** This is a guard, not a fix. The real fix is the workspace manifest and +tar sync the design sketches, which touches the wire protocol, `collect`, and the +I9 containment checks; until then a genuinely networked remote deployment is not +possible, and the config now says so at startup instead of letting `makepkg` +discover it. diff --git a/tests/kata.rs b/tests/kata.rs index 12aa607..29a6f29 100644 --- a/tests/kata.rs +++ b/tests/kata.rs @@ -14,7 +14,7 @@ use aur_build::config::Config; use aur_build::error::Result; use aur_build::sandbox::kata::{KataBackend, LocalAgentProvisioner, ProvisionRequest, Provisioner}; use aur_build::sandbox::{Cmd, SandboxBackend, SandboxSpec}; -use common::shim_dir; +use common::{env_with_fixture, shim_dir}; #[test] fn a_provisioned_sandbox_rendezvous_and_runs_a_command() { @@ -175,3 +175,53 @@ fn a_loopback_config_never_becomes_agent_sandbox_or_vice_versa() { assert!(!id.contains("kata@"), "loopback must not report kata: {id}"); assert!(!id.contains("remote@"), "loopback must not report remote: {id}"); } + +/// The seam's whole claim, tested as one thing: a real package built and +/// published through the kata lease path — a real `sandbox-agent` process, a +/// real nonce-matched rendezvous, real frames — with a VM being the only thing +/// this host cannot provide. If the lease path and the loopback path disagree +/// about anything, this is where it shows. +#[test] +fn a_fixture_builds_and_publishes_through_the_kata_lease_path() { + let (env, _fx) = env_with_fixture("plain-make"); + aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, "plain-make").unwrap(); + let c = aur_build::review::candidates::pending_candidates(&env.db).unwrap().remove(0); + let dd = aur_build::review::diff::render_and_store(&env.db, &env.cfg, &c).unwrap(); + aur_build::review::approve::approve(&env.db, "tester", c.id, &c.identity_hash, &dd, None).unwrap(); + let c = aur_build::review::candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap(); + let id = aur_build::pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap(); + + let mut ctx = aur_build::pipeline::Ctx::new(&env.cfg, &env.db, &id).unwrap(); + let prov = Arc::new(LocalAgentProvisioner::new(shim_dir().join("sandbox-agent"))); + let backend = KataBackend::bind(&env.cfg, "127.0.0.1:0", "kata-e2e", prov).unwrap(); + ctx.backend = Arc::new(backend); + + let out = aur_build::pipeline::run_with(&ctx).unwrap(); + let release = match out { + aur_build::pipeline::Outcome::Succeeded { release_id } => release_id, + other => panic!("the kata path must publish, got {other:?}"), + }; + assert!(release > 0); + + // Published, not merely built: the served index now names the package. + let world = aur_build::pipeline::publish::index_world(&env.db).unwrap(); + assert!( + world.iter().any(|w| w.pkgbase == "plain-make" && w.version == "1.0-1"), + "the index must serve what the kata build produced: {world:?}" + ); + + // And it ran inside the leased sandbox: the agent streamed the build output + // over the wire into the same log file the SSE tail reads, and the shim saw + // exactly one makepkg. + let log = std::fs::read_to_string(env.cfg.build_log_path(&id)).unwrap(); + assert!(log.contains("Making package"), "agent output must reach the log:\n{log}"); + let shimlog = env.cfg.hooks.shim_dir.clone().unwrap(); + assert_eq!(aur_build::shims::called_with(&shimlog, "makepkg", ""), 1); + + // Deliberately no assertion that the sandbox is gone: the pipeline never + // calls `destroy`, and the design says the TTL is the guarantee and destroy + // is courtesy (wire.rs). The lease window bounds how long a box lives, not + // a teardown call — which is worth knowing, because it means a busy hub + // holds up to `steps x builds` sandboxes until their TTL bites. +} + diff --git a/tests/remote_agent.rs b/tests/remote_agent.rs index 22e803a..24e259e 100644 --- a/tests/remote_agent.rs +++ b/tests/remote_agent.rs @@ -44,7 +44,10 @@ fn a_full_build_runs_over_the_agent_protocol() { .expect("spawn sandbox-agent"); let out = pipeline::run_with(&ctx).unwrap(); + // Kill *and* reap: an unreaped child is a zombie the next test inherits, and + // clippy is right that a spawn nobody waits on is unfinished business. let _ = agent.kill(); + let _ = agent.wait(); assert!(matches!(out, pipeline::Outcome::Succeeded { .. }), "{out:?}"); // The agent-streamed output landed in the same file the SSE tail reads. @@ -161,6 +164,7 @@ fn a_dial_in_goes_to_whichever_backend_is_waiting() { let spec = SandboxSpec::new("extra-x86_64", "task", Duration::from_secs(10)); let sbx = second.acquire(&spec); let _ = agent.kill(); + let _ = agent.wait(); assert!(sbx.is_ok(), "the second backend must be able to take the dial-in: {:?}", sbx.err()); } |
