From 78c41e303ff98918f8143ad26a03be384cc28492 Mon Sep 17 00:00:00 2001 From: Adrien Langou Date: Fri, 4 Dec 2026 12:55:26 +0100 Subject: [PATCH] fix(podman)!: require explicit TCP for standalone drivers Port the desktop changes from ai-openshell/openshell#6079. Select the standalone listener before opening the backend and preserve existing socket directory permissions on the Docker and Podman driver paths. BREAKING CHANGE: standalone Podman invocations relying on implicit TCP must select a Unix socket or explicitly opt in and specify a bind address. Signed-off-by: Adrien Langou --- Cargo.lock | 28 ++++---- Cargo.toml | 24 ++++--- crates/openshell-driver-docker/src/main.rs | 5 +- crates/openshell-driver-docker/src/serve.rs | 5 +- .../tests/serve_configure.rs | 4 +- crates/openshell-driver-podman/README.md | 10 +++ crates/openshell-driver-podman/src/main.rs | 64 +++++++++---------- crates/openshell-driver-podman/src/serve.rs | 5 +- .../tests/podman_preflight.rs | 4 +- .../tests/serve_configure.rs | 4 +- 10 files changed, 81 insertions(+), 72 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e9288fe..36af0c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2562,7 +2562,7 @@ dependencies = [ [[package]] name = "openshell-core" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" +source = "git+https://github.com/ai-openshell/openshell?rev=39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34#39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" dependencies = [ "async-trait", "base64 0.22.1", @@ -2608,7 +2608,7 @@ dependencies = [ [[package]] name = "openshell-crypto" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" +source = "git+https://github.com/ai-openshell/openshell?rev=39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34#39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" dependencies = [ "aws-lc-rs", "jsonwebtoken", @@ -2667,7 +2667,7 @@ dependencies = [ [[package]] name = "openshell-driver-launch" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" +source = "git+https://github.com/ai-openshell/openshell?rev=39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34#39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" dependencies = [ "http", "prost", @@ -2727,7 +2727,7 @@ dependencies = [ [[package]] name = "openshell-driver-sdk" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" +source = "git+https://github.com/ai-openshell/openshell?rev=39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34#39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" dependencies = [ "http", "libc", @@ -2799,7 +2799,7 @@ dependencies = [ [[package]] name = "openshell-extension-core" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" +source = "git+https://github.com/ai-openshell/openshell?rev=39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34#39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" dependencies = [ "h2", "hyper", @@ -2814,7 +2814,7 @@ dependencies = [ [[package]] name = "openshell-isolation-interface" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" +source = "git+https://github.com/ai-openshell/openshell?rev=39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34#39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" dependencies = [ "openshell-core", "serde", @@ -2826,7 +2826,7 @@ dependencies = [ [[package]] name = "openshell-ocsf" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" +source = "git+https://github.com/ai-openshell/openshell?rev=39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34#39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" dependencies = [ "jiff 1.0.3", "serde", @@ -2840,7 +2840,7 @@ dependencies = [ [[package]] name = "openshell-otel" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" +source = "git+https://github.com/ai-openshell/openshell?rev=39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34#39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" dependencies = [ "async-trait", "bytes", @@ -2872,7 +2872,7 @@ dependencies = [ [[package]] name = "openshell-otel-test-support" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" +source = "git+https://github.com/ai-openshell/openshell?rev=39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34#39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" dependencies = [ "bytes", "http", @@ -2896,7 +2896,7 @@ dependencies = [ [[package]] name = "openshell-policy" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" +source = "git+https://github.com/ai-openshell/openshell?rev=39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34#39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" dependencies = [ "hickory-proto", "miette", @@ -2911,7 +2911,7 @@ dependencies = [ [[package]] name = "openshell-policy-schema" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" +source = "git+https://github.com/ai-openshell/openshell?rev=39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34#39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" dependencies = [ "miette", "noyalib", @@ -2924,7 +2924,7 @@ dependencies = [ [[package]] name = "openshell-sandbox-backend" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" +source = "git+https://github.com/ai-openshell/openshell?rev=39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34#39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" dependencies = [ "async-trait", "bytes", @@ -2956,7 +2956,7 @@ dependencies = [ [[package]] name = "openshell-spiffe" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" +source = "git+https://github.com/ai-openshell/openshell?rev=39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34#39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" dependencies = [ "async-trait", "base64 0.22.1", @@ -2968,7 +2968,7 @@ dependencies = [ [[package]] name = "openshell-vfio" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" +source = "git+https://github.com/ai-openshell/openshell?rev=39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34#39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" dependencies = [ "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index 057ab6a..9a0120f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,19 +13,17 @@ license = "Apache-2.0" repository = "https://github.com/NVIDIA/OpenShell" [workspace.dependencies] -# OpenShell platform crates, pinned to one commit of ai-openshell/openshell: a main commit (v0.1.11 plus later changes). -# It has the driver launch protocol and SDK (PR 5914), which the drivers here build on, and the -# openshell-container-runtime crate (PR 6023). -openshell-core = { git = "https://github.com/ai-openshell/openshell", rev = "9972314fa89320860e734f533e08d6994407d5fe", default-features = false } -openshell-isolation-interface = { git = "https://github.com/ai-openshell/openshell", rev = "9972314fa89320860e734f533e08d6994407d5fe" } -openshell-sandbox-backend = { git = "https://github.com/ai-openshell/openshell", rev = "9972314fa89320860e734f533e08d6994407d5fe" } -openshell-otel = { git = "https://github.com/ai-openshell/openshell", rev = "9972314fa89320860e734f533e08d6994407d5fe" } -openshell-driver-sdk = { git = "https://github.com/ai-openshell/openshell", rev = "9972314fa89320860e734f533e08d6994407d5fe" } -openshell-driver-launch = { git = "https://github.com/ai-openshell/openshell", rev = "9972314fa89320860e734f533e08d6994407d5fe" } -openshell-otel-test-support = { git = "https://github.com/ai-openshell/openshell", rev = "9972314fa89320860e734f533e08d6994407d5fe" } -openshell-policy = { git = "https://github.com/ai-openshell/openshell", rev = "9972314fa89320860e734f533e08d6994407d5fe" } -openshell-vfio = { git = "https://github.com/ai-openshell/openshell", rev = "9972314fa89320860e734f533e08d6994407d5fe" } -openshell-crypto = { git = "https://github.com/ai-openshell/openshell", rev = "9972314fa89320860e734f533e08d6994407d5fe", default-features = false, features = ["aws-lc"] } +# Keep the OpenShell platform crates on the same ai-openshell/openshell revision. +openshell-core = { git = "https://github.com/ai-openshell/openshell", rev = "39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34", default-features = false } +openshell-isolation-interface = { git = "https://github.com/ai-openshell/openshell", rev = "39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" } +openshell-sandbox-backend = { git = "https://github.com/ai-openshell/openshell", rev = "39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" } +openshell-otel = { git = "https://github.com/ai-openshell/openshell", rev = "39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" } +openshell-driver-sdk = { git = "https://github.com/ai-openshell/openshell", rev = "39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" } +openshell-driver-launch = { git = "https://github.com/ai-openshell/openshell", rev = "39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" } +openshell-otel-test-support = { git = "https://github.com/ai-openshell/openshell", rev = "39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" } +openshell-policy = { git = "https://github.com/ai-openshell/openshell", rev = "39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" } +openshell-vfio = { git = "https://github.com/ai-openshell/openshell", rev = "39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34" } +openshell-crypto = { git = "https://github.com/ai-openshell/openshell", rev = "39f8f1f8cdfb1e81d7a868bc5d26a00e09855e34", default-features = false, features = ["aws-lc"] } openshell-container-runtime = { path = "crates/openshell-container-runtime" } tokio = { version = "1.53.3", features = ["full"] } diff --git a/crates/openshell-driver-docker/src/main.rs b/crates/openshell-driver-docker/src/main.rs index 3f94fd0..c821ee4 100644 --- a/crates/openshell-driver-docker/src/main.rs +++ b/crates/openshell-driver-docker/src/main.rs @@ -97,8 +97,9 @@ async fn main() -> Result<()> { .await .into_diagnostic()?; - let listener = openshell_core::external_driver_socket::bind_private(&args.bind_socket) - .map_err(|err| miette::miette!("{err}"))?; + let listener = + openshell_core::external_driver_socket::bind_in_owned_directory(&args.bind_socket) + .map_err(|err| miette::miette!("{err}"))?; let _cleanup = openshell_core::external_driver_socket::SocketCleanup::new(args.bind_socket.clone()); info!(socket = %args.bind_socket.display(), "Starting Docker compute driver"); diff --git a/crates/openshell-driver-docker/src/serve.rs b/crates/openshell-driver-docker/src/serve.rs index b2901a0..501a6e2 100644 --- a/crates/openshell-driver-docker/src/serve.rs +++ b/crates/openshell-driver-docker/src/serve.rs @@ -87,8 +87,9 @@ async fn run( let settings = read_settings()?; openshell_driver_sdk::check_backend_within("Docker", check_backend(&settings)).await?; - let listener = openshell_core::external_driver_socket::bind_private(&args.bind_socket) - .map_err(StartResult::error)?; + let listener = + openshell_core::external_driver_socket::bind_in_owned_directory(&args.bind_socket) + .map_err(StartResult::error)?; let _cleanup = openshell_core::external_driver_socket::SocketCleanup::new(args.bind_socket.clone()); diff --git a/crates/openshell-driver-docker/tests/serve_configure.rs b/crates/openshell-driver-docker/tests/serve_configure.rs index 28ca4b1..05252b8 100644 --- a/crates/openshell-driver-docker/tests/serve_configure.rs +++ b/crates/openshell-driver-docker/tests/serve_configure.rs @@ -90,7 +90,7 @@ async fn serve() -> Serving { let dir = tempfile::tempdir().unwrap(); let docker = dir.path().join("docker.sock"); fake_docker(&docker); - let socket = dir.path().join("driver.sock"); + let socket = dir.path().join("private/driver.sock"); let table = format!("socket_path = \"{}\"\n", docker.display()); let mut child = command( &[ @@ -250,7 +250,7 @@ fn docker_host_finds_the_socket_when_the_table_sets_none() { let dir = tempfile::tempdir().unwrap(); let docker = dir.path().join("docker.sock"); fake_docker(&docker); - let socket = dir.path().join("driver.sock"); + let socket = dir.path().join("private/driver.sock"); let mut child = command( &[ "serve", diff --git a/crates/openshell-driver-podman/README.md b/crates/openshell-driver-podman/README.md index b60b472..4a294c6 100644 --- a/crates/openshell-driver-podman/README.md +++ b/crates/openshell-driver-podman/README.md @@ -165,6 +165,16 @@ When `[openshell.gateway.otlp.agent]` is enabled, the driver sets agent trace relay. On Podman Machine it rewrites a loopback agent endpoint to the desktop host, as it does for the supervisor's trace endpoint. +## Standalone mode + +When you start `openshell-driver-podman` directly, use a directory dedicated to the driver, +for example `--bind-socket "$XDG_RUNTIME_DIR/openshell-podman/driver.sock"`. +The socket uses mode `0600`. The driver creates missing directories with mode `0700`, +subject to the process umask. +An existing parent directory must be owned by the driver user and must not allow group or other writes. +If you used the default TCP listener for +local development, pass `--allow-unauthenticated-tcp --bind-address 127.0.0.1:50061`. + ## Launched mode ```text diff --git a/crates/openshell-driver-podman/src/main.rs b/crates/openshell-driver-podman/src/main.rs index 84079c8..2cc5387 100644 --- a/crates/openshell-driver-podman/src/main.rs +++ b/crates/openshell-driver-podman/src/main.rs @@ -4,13 +4,13 @@ use clap::Parser; use miette::{IntoDiagnostic, Result}; use std::future::Future; -use std::net::SocketAddr; use std::num::{NonZeroI64, NonZeroU64}; use std::path::PathBuf; use tracing::info; mod serve; +use openshell_core::external_driver_socket::standalone::{ListenMode, TransportArgs}; use openshell_core::proto::compute::v1::compute_driver_server::ComputeDriverServer; use openshell_core::sandbox_env::SupervisorOtlpArgs; use openshell_core::{AppArmorProfile, ImagePullPolicy, VERSION}; @@ -28,16 +28,8 @@ struct Args { default_value = "{}" )] admission_config_json: openshell_core::resource_admission::DriverAdmissionConfig, - /// Public compute-driver Unix socket used by an external gateway. - #[arg(long, env = "OPENSHELL_COMPUTE_DRIVER_SOCKET")] - bind_socket: Option, - - #[arg( - long, - env = "OPENSHELL_COMPUTE_DRIVER_BIND", - default_value = "127.0.0.1:50061" - )] - bind_address: SocketAddr, + #[command(flatten)] + transport: TransportArgs, #[arg(long, env = "OPENSHELL_LOG_LEVEL", default_value = "info")] log_level: String, @@ -219,6 +211,7 @@ async fn main() -> Result<()> { std::process::exit(code); } let args = Args::parse(); + let transport = args.transport.listen_mode()?; let _tracing = openshell_otel::install_driver_tracing( openshell_driver_podman::otel_tracing::TRACING, openshell_otel::DriverTracingConfig { @@ -288,29 +281,32 @@ async fn main() -> Result<()> { .into_diagnostic()?; let service = ComputeDriverServer::new(ComputeDriverService::new(driver)); - if let Some(socket_path) = args.bind_socket { - let listener = openshell_core::external_driver_socket::bind_private(&socket_path) - .map_err(|err| miette::miette!("{err}"))?; - let _cleanup = - openshell_core::external_driver_socket::SocketCleanup::new(socket_path.clone()); - info!(socket = %socket_path.display(), "Starting Podman compute driver"); - tonic::transport::Server::builder() - .layer(openshell_otel::compute_driver_rpc_layer()) - .add_service(service) - .serve_with_incoming_shutdown( - openshell_core::external_driver_socket::SameUidUnixIncoming::new(listener), - shutdown_signal(), - ) - .await - .into_diagnostic() - } else { - info!(address = %args.bind_address, "Starting Podman compute driver"); - tonic::transport::Server::builder() - .layer(openshell_otel::compute_driver_rpc_layer()) - .add_service(service) - .serve_with_shutdown(args.bind_address, shutdown_signal()) - .await - .into_diagnostic() + let server = tonic::transport::Server::builder() + .layer(openshell_otel::compute_driver_rpc_layer()) + .add_service(service); + match transport { + ListenMode::Unix(socket_path) => { + let listener = + openshell_core::external_driver_socket::bind_in_owned_directory(&socket_path) + .map_err(|err| miette::miette!("{err}"))?; + let _cleanup = + openshell_core::external_driver_socket::SocketCleanup::new(socket_path.clone()); + info!(socket = %socket_path.display(), "Starting Podman compute driver"); + server + .serve_with_incoming_shutdown( + openshell_core::external_driver_socket::SameUidUnixIncoming::new(listener), + shutdown_signal(), + ) + .await + .into_diagnostic() + } + ListenMode::Tcp(address) => { + tracing::warn!(%address, "Starting Podman compute driver with unauthenticated TCP"); + server + .serve_with_shutdown(address, shutdown_signal()) + .await + .into_diagnostic() + } } } diff --git a/crates/openshell-driver-podman/src/serve.rs b/crates/openshell-driver-podman/src/serve.rs index 4350bad..9c63a4a 100644 --- a/crates/openshell-driver-podman/src/serve.rs +++ b/crates/openshell-driver-podman/src/serve.rs @@ -91,8 +91,9 @@ async fn run( let settings = read_settings()?; openshell_driver_sdk::check_backend_within("Podman", check_backend(&settings)).await?; - let listener = openshell_core::external_driver_socket::bind_private(&args.bind_socket) - .map_err(StartResult::error)?; + let listener = + openshell_core::external_driver_socket::bind_in_owned_directory(&args.bind_socket) + .map_err(StartResult::error)?; let _cleanup = openshell_core::external_driver_socket::SocketCleanup::new(args.bind_socket.clone()); diff --git a/crates/openshell-driver-podman/tests/podman_preflight.rs b/crates/openshell-driver-podman/tests/podman_preflight.rs index 439cb95..887a42f 100644 --- a/crates/openshell-driver-podman/tests/podman_preflight.rs +++ b/crates/openshell-driver-podman/tests/podman_preflight.rs @@ -30,7 +30,9 @@ async fn run_with_unreachable_podman_socket() -> (String, i32, Duration, PathBuf let start = Instant::now(); let mut cmd = tokio::process::Command::new(env!("CARGO_BIN_EXE_openshell-driver-podman")); - cmd.arg("--podman-socket") + cmd.arg("--bind-socket") + .arg(tmpdir.path().join("compute-driver.sock")) + .arg("--podman-socket") .arg(&missing_socket) .current_dir(tmpdir.path()) .kill_on_drop(true) diff --git a/crates/openshell-driver-podman/tests/serve_configure.rs b/crates/openshell-driver-podman/tests/serve_configure.rs index 896f790..7c24082 100644 --- a/crates/openshell-driver-podman/tests/serve_configure.rs +++ b/crates/openshell-driver-podman/tests/serve_configure.rs @@ -88,7 +88,7 @@ async fn serve() -> Serving { let dir = tempfile::tempdir().unwrap(); let podman = dir.path().join("podman.sock"); fake_podman(&podman); - let socket = dir.path().join("driver.sock"); + let socket = dir.path().join("private/driver.sock"); let table = format!("socket_path = \"{}\"\n", podman.display()); let mut child = command( &[ @@ -236,7 +236,7 @@ fn the_podman_socket_variable_is_honoured_before_the_table() { let dir = tempfile::tempdir().unwrap(); let podman = dir.path().join("podman.sock"); fake_podman(&podman); - let socket = dir.path().join("driver.sock"); + let socket = dir.path().join("private/driver.sock"); let mut child = command( &[ "serve",