diff --git a/Cargo.lock b/Cargo.lock index 64ef3a740..1b48062ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -756,6 +756,7 @@ dependencies = [ "objc2-web-kit", "rcgen", "regex-lite", + "ring", "rustls", "ruzstd", "serde", diff --git a/crates/kiri/Cargo.toml b/crates/kiri/Cargo.toml index d61921852..18b58970b 100644 --- a/crates/kiri/Cargo.toml +++ b/crates/kiri/Cargo.toml @@ -20,6 +20,8 @@ ruzstd = "0.9" ureq = { version = "3", default-features = false, features = ["rustls-no-provider"] } # HTTPS for container names: the same rustls and ring ureq already brings in. rustls = { version = "0.23", default-features = false, features = ["ring", "std", "tls12"] } +# Secrets at rest: ChaCha20-Poly1305, from the ring rustls already brings in. +ring = { version = "0.17", default-features = false, features = ["std", "alloc"] } rcgen = { version = "0.14", default-features = false, features = ["ring", "pem", "crypto"] } # The `name` filter is a regular expression in Docker (k3d sends `^[/]?name$`). # regex-lite: RE2 syntax like Go's regexp, without the Unicode tables' size. diff --git a/crates/kiri/src/daemon/api.rs b/crates/kiri/src/daemon/api.rs index 1f8c6e180..ce0f02a07 100644 --- a/crates/kiri/src/daemon/api.rs +++ b/crates/kiri/src/daemon/api.rs @@ -88,6 +88,8 @@ pub fn serve(stream: UnixStream, engine: Arc, caller: Caller) -> io::Res fn streams_body(method: &str, path: &str) -> bool { matches!((method, path), ("PUT", p) if p.starts_with("/containers/") && p.ends_with("/archive")) || matches!((method, path), ("POST", p) if p.starts_with("/kiri/containers/") && p.ends_with("/upper")) + // A secret's value can be a cert or a key. + || (method == "POST" && path == "/kiri/secrets") || (method == "POST" && matches!(path, "/images/load" | "/images/create" | "/build")) } @@ -176,6 +178,12 @@ fn route(req: &Request, engine: &Arc, caller: &Caller, w: &mut UnixStrea http::respond_with(w, 200, "text/plain; charset=utf-8", "Builder-Version: 1\r\n", if m == "HEAD" { b"" } else { b"OK" })?; return Ok(Next::KeepAlive); } + // Prometheus-style metrics for a scraper: counts read from the state + // the daemon already holds, never a round-trip to the guest. + ("GET", "/metrics") => { + http::respond_with(w, 200, "text/plain; version=0.0.4; charset=utf-8", "", &metrics(engine).into_bytes())?; + return Ok(Next::KeepAlive); + } ("GET", "/version") => return reply(w, Ok(version()), 200), ("POST", "/auth") => return reply(w, auth(req), 200), // Kiri's own: the window's Start and Stop. @@ -188,6 +196,18 @@ fn route(req: &Request, engine: &Arc, caller: &Caller, w: &mut UnixStrea ("POST", "/kiri/stop") => return reply(w, engine.stop_all().map(|()| Value::Null), 204), ("POST", "/kiri/sleep") => return reply(w, engine.sleep_now().map(|()| Value::Null), 204), ("GET", "/kiri/proxy") => return reply(w, Ok(super::proxy::report()), 200), + // Kiri's own secrets: values sealed at rest under the engine's own + // key (`secrets.key`), listed and read by name, never with a value + // back. A container start names one in its env with + // `secret:`; that is the only place a value goes. + ("GET", "/kiri/secrets") => return reply(w, secrets_list(engine), 200), + ("POST", "/kiri/secrets") => return reply(w, secrets_set(req, engine), 201), + ("GET", p) if p.strip_prefix("/kiri/secrets/").is_some_and(|n| !n.is_empty() && !n.contains('/')) => { + return reply(w, secret_info(engine, p.strip_prefix("/kiri/secrets/").unwrap_or_default()), 200); + } + ("DELETE", p) if p.strip_prefix("/kiri/secrets/").is_some_and(|n| !n.is_empty() && !n.contains('/')) => { + return reply(w, secret_remove(engine, p.strip_prefix("/kiri/secrets/").unwrap_or_default()), 204); + } ("POST", "/kiri/proxy") => return reply(w, set_proxy(req), 200), ("PUT", "/kiri/proxy/system") => return reply(w, set_host_proxy(req), 200), // kiri-win's Windows roots, for the engine in WSL (#303). @@ -246,6 +266,15 @@ fn route(req: &Request, engine: &Arc, caller: &Caller, w: &mut UnixStrea let id = p.strip_prefix("/kiri/containers/").and_then(|r| r.strip_suffix("/upper")).unwrap_or_default(); return upper_put(req, engine, id, w, r); } + // Kiri's own: a checkpoint of a container's writable files as an + // image (its `upper` layer plus the image under it), named by the + // body's `image` or by a default `checkpoint:-