summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-19 15:23:23 +0000
committeraur-build <aur-build@localhost>2026-11-19 15:23:23 +0000
commit32eaaeae9e0fe2c2285fb79efa0e579150d8bd83 (patch)
treef363a135cf4a5cf48d5a5ab57f8a127e617feab2 /src
parent8912f71afb9697c8645209ec0e67f67098bb16a1 (diff)
downloadaur-build-32eaaeae9e0fe2c2285fb79efa0e579150d8bd83.tar.gz
aur-build-32eaaeae9e0fe2c2285fb79efa0e579150d8bd83.zip
config: refuse a sandbox configuration that cannot work, at startup
The enum makes the impossible unrepresentable, but two things survive any type: a field that is present and empty, and an assertion the type leaves defaulted on purpose. `Config::validate` catches both, and it runs at startup — before the watcher, the dispatcher or the UI are up and looking healthy — and again where a backend is constructed, so nothing that builds one can skip it. The one that matters is the workspace. `Run` frames carry a hub-side working directory and the srcdir is never shipped to the sandbox, so a `remote` backend on a machine that does not share the hub's filesystem would fail in `makepkg` with a missing directory — and, worse, would *succeed* in the case nobody wants: quietly building untrusted code on the hub. So a remote or agent-sandbox config must say `"shared_workspace": true`, and the refusal says why rather than just naming the field. Loopback needs no assertion because it shares the filesystem by construction, which is also why it stays the zero-config default. Empty `listen`, `token`, `api`, `namespace`, `bearer` and `image` are each refused by name. Two tests drive the compiled binary rather than the library, because a guard that only exists as a callable function is a guard the CLI can walk past.
Diffstat (limited to 'src')
-rw-r--r--src/config.rs57
-rw-r--r--src/main.rs3
-rw-r--r--src/pipeline/mod.rs4
3 files changed, 64 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs
index b86aada..d583b05 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -311,6 +311,63 @@ impl Config {
.to_string()
}
+ /// Refuse a configuration that cannot work, before anything builds with it.
+ ///
+ /// The enum already makes the impossible unrepresentable; this catches what
+ /// a type cannot see — a field that is present but empty, and the one
+ /// assertion the type deliberately leaves defaulted so the refusal can
+ /// explain itself instead of arriving as a parse error. Called at startup
+ /// (so the operator hears about it now, not at the first build) and again
+ /// where a backend is constructed (so a hand-built `Config` cannot skip it).
+ pub fn validate(&self) -> crate::error::Result<()> {
+ let require = |field: &str, value: &str| -> crate::error::Result<()> {
+ if value.trim().is_empty() {
+ return Err(crate::error::Error::invalid(format!(
+ "sandbox kind \"{}\" needs a non-empty \"{field}\"",
+ self.sandbox.kind()
+ )));
+ }
+ Ok(())
+ };
+ match &self.sandbox {
+ Sandbox::Loopback => {}
+ Sandbox::Remote { listen, token, .. } => {
+ require("listen", listen)?;
+ require("token", token)?;
+ }
+ Sandbox::AgentSandbox { api, namespace, bearer, image, listen, token, .. } => {
+ for (field, value) in [
+ ("api", api),
+ ("namespace", namespace),
+ ("bearer", bearer),
+ ("image", image),
+ ("listen", listen),
+ ("token", token),
+ ] {
+ require(field, value)?;
+ }
+ }
+ }
+ if self.sandbox.shared_workspace() {
+ return Ok(());
+ }
+ // The one gap a remote configuration cannot be trusted to notice by
+ // itself: the workspace is not shipped to the sandbox, so a remote
+ // build only works where hub and sandbox see the same path. Refusing
+ // here is what stops "remote" from silently meaning "on the hub".
+ Err(crate::error::Error::invalid(format!(
+ concat!(
+ "sandbox kind \"{}\" was not told that hub and sandbox share a filesystem: ",
+ "set \"shared_workspace\": true in the sandbox object. The build workspace is ",
+ "not shipped to a remote sandbox — `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 here is what keeps a ",
+ "remote configuration from silently building on the hub it was meant to leave."
+ ),
+ self.sandbox.kind()
+ )))
+ }
+
/// Read `<root>/config.json`.
///
/// The crate's own error type, like everything else that can fail (m-15):
diff --git a/src/main.rs b/src/main.rs
index 9e3b1e0..ccd20a2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -132,6 +132,9 @@ fn main() -> anyhow::Result<()> {
} else {
Config::load(&root)?
};
+ // Startup, not first-build: a configuration that cannot work is refused
+ // before the watcher, the dispatcher or the UI are up and looking healthy.
+ cfg.validate()?;
if let Cmd::Serve { bind } = &cli.cmd {
let mut cfg = cfg;
if let Some(b) = bind {
diff --git a/src/pipeline/mod.rs b/src/pipeline/mod.rs
index 9a53d80..350df0c 100644
--- a/src/pipeline/mod.rs
+++ b/src/pipeline/mod.rs
@@ -180,6 +180,10 @@ impl Ctx {
/// point. `remote` binds the agent listener for the lifetime of this
/// run's context.
fn backend_for(cfg: &Config) -> Result<Arc<dyn SandboxBackend>> {
+ // The startup guard in the CLI catches this first; repeating it here is
+ // what makes "the config was never validated" impossible for anything
+ // that constructs a backend — a test, a future daemon, a tool.
+ cfg.validate()?;
match &cfg.sandbox {
crate::config::Sandbox::Loopback => {
Ok(Arc::new(crate::sandbox::loopback::LoopbackBackend::new(cfg)))