Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 11 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
5 changes: 3 additions & 2 deletions crates/openshell-driver-docker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
5 changes: 3 additions & 2 deletions crates/openshell-driver-docker/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
4 changes: 2 additions & 2 deletions crates/openshell-driver-docker/tests/serve_configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
&[
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions crates/openshell-driver-podman/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 30 additions & 34 deletions crates/openshell-driver-podman/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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<PathBuf>,

#[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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions crates/openshell-driver-podman/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
4 changes: 3 additions & 1 deletion crates/openshell-driver-podman/tests/podman_preflight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions crates/openshell-driver-podman/tests/serve_configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
&[
Expand Down Expand Up @@ -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",
Expand Down
Loading