Skip to content

Commit a936c68

Browse files
committed
refactor(supervisor): use shared mode flags for the session host
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent 8b6b473 commit a936c68

6 files changed

Lines changed: 88 additions & 54 deletions

File tree

‎.agents/skills/helm-dev-environment/SKILL.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ Service, and NetworkPolicy in the release namespace, regardless of
7373
shared/managed/operator workspace mode, and the certgen hook issues its
7474
session-control Secrets. New sandbox generations run as sessions in that
7575
process. Its process-health `tcpSocket` probes connect to the mTLS
76-
session-control port (5501); there is no separate health port. Build the
76+
session-control port (5501); there is no separate health port. The chart starts
77+
`--mode=shared`, sets `--gateway-endpoint` to the gateway gRPC URL, and binds
78+
`--address` to this control/probe listener. Build the
7779
gateway, supervisor, and sandbox images from the same branch:
7880
all three must support the routed runtime connection. `workspace` is reserved
7981
and rejected. Omit the field to disable it. `mise run

‎crates/openshell-supervisor/README.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,15 @@ backend or enable a Windows workload runtime.
9999

100100
## Shared supervisor host (experimental)
101101

102-
`openshell-supervisor experimental-host` hosts the sessions of many sandboxes in
102+
`openshell-supervisor --mode=shared --gateway-endpoint <gateway-url> --address <ip:port>` hosts the sessions of many sandboxes in
103103
one process for the Kubernetes gateway topology experiment. It is Unix-only.
104104

105+
`--gateway-endpoint` selects the gateway each sandbox session dials. The current
106+
admission RPCs still arrive from the gateway at `--address`; moving admission
107+
onto a supervisor-initiated stream is a separate implementation step.
108+
105109
- **Admission.** A mutually authenticated TLS 1.3 listener
106-
(`--session-control-listen`, credentials in `--session-control-tls-dir`)
110+
(`--address`, credentials in `--session-control-tls-dir`)
107111
serves `PUT`, `GET`, and `DELETE /v1/sessions/{route}` and `GET /v1/sessions`
108112
as JSON. Only a client holding the admission certificate, which Helm gives
109113
only the gateway, can register sessions. A registration carries one

‎crates/openshell-supervisor/src/experimental.rs‎

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,34 @@
33

44
//! Supervisor shared by the sandboxes of one gateway (experimental).
55
6-
use clap::Parser;
76
use miette::Result;
8-
use std::net::SocketAddr;
9-
use std::path::PathBuf;
107

11-
#[derive(Debug, Parser)]
12-
#[command(name = "openshell-supervisor experimental-host")]
13-
#[command(about = "Supervise the sandboxes a gateway registers with this process")]
14-
struct Args {
15-
/// Gateway gRPC endpoint; each session authenticates with its own credentials.
16-
#[arg(long, env = openshell_core::sandbox_env::ENDPOINT)]
17-
openshell_endpoint: String,
18-
19-
/// Mutually authenticated session-control listener used by the gateway.
20-
/// Kubernetes TCP probes connect to it without completing TLS.
21-
#[arg(long)]
22-
session_control_listen: SocketAddr,
23-
24-
/// Directory with the session-control `tls.crt`, `tls.key`, and client `ca.crt`.
25-
#[arg(long)]
26-
session_control_tls_dir: PathBuf,
27-
28-
/// Listener for routed runtime-initiated Sandbox Protocol connections.
29-
#[arg(long)]
30-
runtime_listen: SocketAddr,
31-
32-
/// Private directory for per-session files.
33-
#[arg(long)]
34-
session_root: PathBuf,
35-
36-
#[arg(long, default_value = "warn", env = openshell_core::sandbox_env::LOG_LEVEL)]
37-
log_level: String,
38-
}
39-
40-
pub fn run(raw_args: &[String]) -> Result<()> {
41-
let args = Args::parse_from(raw_args);
8+
pub fn run(args: crate::Args) -> Result<()> {
429
run_platform(args)
4310
}
4411

4512
#[cfg(unix)]
46-
fn run_platform(args: Args) -> Result<()> {
13+
fn run_platform(args: crate::Args) -> Result<()> {
4714
use miette::{IntoDiagnostic as _, WrapErr as _};
4815
use std::sync::Arc;
4916
use std::sync::atomic::AtomicBool;
5017
use tracing_subscriber::{Layer as _, layer::SubscriberExt as _, util::SubscriberInitExt as _};
5118

19+
let address = args
20+
.address
21+
.ok_or_else(|| miette::miette!("--address is required for --mode=shared"))?;
22+
let gateway_endpoint = args
23+
.gateway_endpoint
24+
.ok_or_else(|| miette::miette!("--gateway-endpoint is required for --mode=shared"))?;
25+
let session_control_tls_dir = args.session_control_tls_dir.ok_or_else(|| {
26+
miette::miette!("--session-control-tls-dir is required for --mode=shared")
27+
})?;
28+
let runtime_listen = args
29+
.runtime_listen
30+
.ok_or_else(|| miette::miette!("--runtime-listen is required for --mode=shared"))?;
31+
let session_root = args
32+
.session_root
33+
.ok_or_else(|| miette::miette!("--session-root is required for --mode=shared"))?;
5234
let runtime = tokio::runtime::Builder::new_multi_thread()
5335
.enable_all()
5436
.build()
@@ -87,7 +69,7 @@ fn run_platform(args: Args) -> Result<()> {
8769
tokio::signal::unix::signal(tokio::signal::unix::SignalKind::interrupt())
8870
.into_diagnostic()?;
8971
let tls_file = |name: &str| {
90-
let path = args.session_control_tls_dir.join(name);
72+
let path = session_control_tls_dir.join(name);
9173
std::fs::read(&path)
9274
.into_diagnostic()
9375
.wrap_err_with(|| format!("read session-control TLS file {}", path.display()))
@@ -100,19 +82,19 @@ fn run_platform(args: Args) -> Result<()> {
10082
.map_err(|error| miette::miette!("{error}"))?;
10183
let host = openshell_supervisor::shared_host::SharedHost::start(
10284
openshell_supervisor::shared_host::SharedHostConfig {
103-
gateway_endpoint: args.openshell_endpoint.clone(),
104-
session_root: args.session_root.clone(),
105-
runtime_listen: args.runtime_listen,
85+
gateway_endpoint,
86+
session_root,
87+
runtime_listen,
10688
removal_grace: openshell_sandbox_backend::session_control::SESSION_REMOVAL_GRACE,
10789
},
10890
)?;
109-
let control = tokio::net::TcpListener::bind(args.session_control_listen)
91+
let control = tokio::net::TcpListener::bind(address)
11092
.await
11193
.into_diagnostic()
11294
.wrap_err("bind session-control listener")?;
11395
tracing::info!(
11496
runtime = %host.runtime_addr(),
115-
control = %args.session_control_listen,
97+
control = %address,
11698
"Shared supervisor ready for sessions"
11799
);
118100
let (stop, stopped) = tokio::sync::watch::channel(false);
@@ -138,6 +120,6 @@ fn run_platform(args: Args) -> Result<()> {
138120
}
139121

140122
#[cfg(not(unix))]
141-
fn run_platform(_args: Args) -> Result<()> {
142-
Err(miette::miette!("experimental-host requires Unix"))
123+
fn run_platform(_args: crate::Args) -> Result<()> {
124+
Err(miette::miette!("--mode=shared requires Unix"))
143125
}

‎crates/openshell-supervisor/src/main.rs‎

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ const DEBUG_RPC_SUBCOMMAND: &str = "debug-rpc";
2424
const HEALTH_SUBCOMMAND: &str = "health";
2525
const SERVICE_NAME: &str = "openshell-supervisor";
2626

27+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, ValueEnum)]
28+
enum SupervisorMode {
29+
/// Supervise a single sandbox generation.
30+
#[default]
31+
Dedicated,
32+
/// Host sandbox supervision sessions in a shared process.
33+
Shared,
34+
}
35+
2736
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, ValueEnum)]
2837
enum SupervisorRole {
2938
/// Attach an Isolation Backend and supervise one sandbox generation.
@@ -47,6 +56,30 @@ struct HealthArgs {
4756
#[command(about = "OpenShell policy and workload supervisor")]
4857
#[allow(clippy::struct_excessive_bools)]
4958
struct Args {
59+
/// Supervisor deployment mode.
60+
#[arg(long, value_enum, default_value_t)]
61+
mode: SupervisorMode,
62+
63+
/// Gateway endpoint for the shared supervisor's outbound connection.
64+
#[arg(long, required_if_eq("mode", "shared"))]
65+
gateway_endpoint: Option<String>,
66+
67+
/// Shared supervisor listen address, also used for TCP health probes.
68+
#[arg(long, required_if_eq("mode", "shared"))]
69+
address: Option<std::net::SocketAddr>,
70+
71+
/// Directory with shared-host session-control TLS credentials.
72+
#[arg(long, required_if_eq("mode", "shared"))]
73+
session_control_tls_dir: Option<PathBuf>,
74+
75+
/// Listener for routed runtime-initiated Sandbox Protocol connections.
76+
#[arg(long, required_if_eq("mode", "shared"))]
77+
runtime_listen: Option<std::net::SocketAddr>,
78+
79+
/// Private directory for shared-host session files.
80+
#[arg(long, required_if_eq("mode", "shared"))]
81+
session_root: Option<PathBuf>,
82+
5083
/// Supervisor responsibility to run.
5184
#[arg(long, value_enum, default_value_t)]
5285
role: SupervisorRole,
@@ -366,11 +399,20 @@ fn main() -> Result<()> {
366399
return openshell_supervisor::check_control_readiness(&args.socket);
367400
}
368401

369-
if raw_args.get(1).map(String::as_str) == Some("experimental-host") {
370-
return experimental::run(&raw_args[1..]);
371-
}
372-
373402
let args = Args::parse();
403+
if args.mode == SupervisorMode::Shared {
404+
return experimental::run(args);
405+
}
406+
if args.gateway_endpoint.is_some()
407+
|| args.address.is_some()
408+
|| args.session_control_tls_dir.is_some()
409+
|| args.runtime_listen.is_some()
410+
|| args.session_root.is_some()
411+
{
412+
return Err(miette::miette!(
413+
"shared supervisor options require --mode=shared"
414+
));
415+
}
374416
validate_role_arguments(&args)?;
375417
arm_parent_liveness(args.parent_liveness_stdin)?;
376418
validate_main_exit_marker(args.main_exit_marker.as_deref())?;

‎deploy/helm/openshell/templates/experimental-supervisor.yaml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ spec:
5959
image: {{ get $kubernetes "supervisor_image" | quote }}
6060
imagePullPolicy: {{ get (dict "always" "Always" "if_not_present" "IfNotPresent" "never" "Never") (get $kubernetes "supervisor_image_pull_policy" | default "if_not_present") | quote }}
6161
args:
62-
- experimental-host
63-
- --session-control-listen
62+
- --mode=shared
63+
- --gateway-endpoint
64+
- {{ $endpoint | quote }}
65+
- --address
6466
- 0.0.0.0:{{ get $shared "control_port" }}
6567
- --session-control-tls-dir
6668
- /etc/openshell/session-control

‎deploy/helm/openshell/tests/experimental_supervisor_test.yaml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ tests:
4646
- equal:
4747
path: spec.template.spec.containers[0].args
4848
value:
49-
- experimental-host
50-
- --session-control-listen
49+
- --mode=shared
50+
- --gateway-endpoint
51+
- https://openshell.gateway.svc.cluster.local:8080
52+
- --address
5153
- 0.0.0.0:5501
5254
- --session-control-tls-dir
5355
- /etc/openshell/session-control

0 commit comments

Comments
 (0)