Skip to content

Commit e8ec295

Browse files
committed
feat(sandbox): operator-declared skippable bootstrap subsystems
The supervisor performs three privileged startup steps an outer sandbox (gVisor, Firecracker, Kata) may own instead: network-namespace creation, the supervisor seccomp prelude, and the workload seccomp filter. On bare metal all three are attempted and a host refusal is fatal. Add --skip-bootstrap (env OPENSHELL_SKIP_BOOTSTRAP): a comma-separated list of subsystems (netns, supervisor-seccomp, workload-seccomp, or all) the operator declares the environment owns. A skipped subsystem is not attempted; a subsystem that is NOT skipped and fails stays fatal. Empty (the default) attempts all three and aborts on any failure -- byte-identical to upstream. This configures the supervisor from the deployment environment instead of catching refusals at runtime: under an outer sandbox the operator declares 'the runtime owns netns/seccomp', so those steps are skipped and every other failure remains a genuine error. Per ai-openshell#1650 the config + the three call sites (run.rs, netns/mod.rs, sandbox/linux/mod.rs) live in openshell-supervisor-process, re-exported from openshell-sandbox. Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>
1 parent 7a152fa commit e8ec295

6 files changed

Lines changed: 198 additions & 2 deletions

File tree

‎crates/openshell-sandbox/src/lib.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ use openshell_core::policy::{NetworkMode, NetworkPolicy, ProxyPolicy, SandboxPol
6161
use openshell_core::provider_credentials::ProviderCredentialState;
6262
use openshell_supervisor_network::opa::OpaEngine;
6363
pub use openshell_supervisor_process::process::{ProcessHandle, ProcessStatus};
64+
pub use openshell_supervisor_process::{
65+
BootstrapSubsystem, parse_skip_bootstrap, set_skipped_bootstrap,
66+
};
6467
use openshell_supervisor_process::skills;
6568
use tokio::sync::mpsc::UnboundedSender;
6669

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ struct Args {
152152
/// enforcement runs in another pod.
153153
#[arg(long, default_value = DEFAULT_MODE)]
154154
mode: Mode,
155+
156+
/// Bootstrap subsystems the environment (e.g. an outer sandbox like gVisor)
157+
/// owns, so the supervisor SKIPS attempting them instead of failing on the
158+
/// host's refusal. Comma-separated: `netns`, `supervisor-seccomp`,
159+
/// `workload-seccomp`, or `all`. Empty (the default) attempts all three and
160+
/// treats any failure as fatal — byte-identical to upstream. A subsystem
161+
/// that is NOT skipped and fails is still fatal.
162+
#[arg(long, value_delimiter = ',', env = "OPENSHELL_SKIP_BOOTSTRAP")]
163+
skip_bootstrap: Vec<String>,
155164
}
156165

157166
/// Copy the running executable to `dest`, creating parent directories as
@@ -222,6 +231,15 @@ fn main() -> Result<()> {
222231

223232
let args = Args::parse();
224233

234+
// Operator-declared skips: bootstrap subsystems the environment owns are
235+
// not attempted; everything else stays fatal-on-failure (the upstream
236+
// default). Done before run_sandbox so the declaration is in place before
237+
// any bootstrap step runs. Empty (default) skips nothing.
238+
if !args.skip_bootstrap.is_empty() {
239+
let skipped = openshell_sandbox::parse_skip_bootstrap(&args.skip_bootstrap)?;
240+
openshell_sandbox::set_skipped_bootstrap(skipped);
241+
}
242+
225243
// Try to open a rolling log file; fall back to stderr-only logging if it fails
226244
// (e.g., /var/log is not writable in custom workload images).
227245
// Rotates daily, keeps the 3 most recent files to bound disk usage.

‎crates/openshell-supervisor-process/src/lib.rs‎

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,156 @@ pub mod supervisor_session;
2323
pub mod bypass_monitor;
2424
#[cfg(target_os = "linux")]
2525
pub mod netns;
26+
27+
use miette::Result;
28+
use std::sync::OnceLock;
29+
30+
// Operator-declared bootstrap policy.
31+
//
32+
// The supervisor performs three privileged startup steps that an outer sandbox
33+
// (gVisor, Firecracker, Kata) may own instead of the supervisor: network
34+
// namespace creation, the supervisor seccomp prelude, and the workload seccomp
35+
// filter. On bare-metal Linux all three are attempted and a host refusal is
36+
// fatal. When the operator declares — via `--skip-bootstrap` /
37+
// `OPENSHELL_SKIP_BOOTSTRAP` — that the environment owns one of them, the
38+
// supervisor SKIPS it (never attempts it). Any subsystem that is NOT skipped
39+
// and fails is still fatal. The default (skip nothing) is byte-identical to
40+
// upstream: attempt everything, abort on any failure.
41+
42+
/// A privileged bootstrap step the supervisor performs at startup.
43+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
44+
pub enum BootstrapSubsystem {
45+
/// `unshare(CLONE_NEWNET)` + the veth/nftables setup behind the proxy.
46+
NetworkNamespace,
47+
/// The supervisor seccomp prelude (`apply_supervisor_startup_hardening`).
48+
SupervisorSeccomp,
49+
/// The workload per-policy seccomp filter in `sandbox::linux::enforce`.
50+
WorkloadSeccomp,
51+
}
52+
53+
impl BootstrapSubsystem {
54+
/// Stable short name, used in `--skip-bootstrap` tokens and logs.
55+
#[must_use]
56+
pub fn as_str(self) -> &'static str {
57+
match self {
58+
Self::NetworkNamespace => "netns",
59+
Self::SupervisorSeccomp => "supervisor-seccomp",
60+
Self::WorkloadSeccomp => "workload-seccomp",
61+
}
62+
}
63+
64+
/// Parse an operator-facing token. Case-insensitive; accepts the short and
65+
/// long spellings. Returns `None` for an unknown token.
66+
#[must_use]
67+
pub fn parse_token(token: &str) -> Option<Self> {
68+
match token.trim().to_ascii_lowercase().as_str() {
69+
"netns" | "network-namespace" => Some(Self::NetworkNamespace),
70+
"supervisor-seccomp" | "supervisor_seccomp" => Some(Self::SupervisorSeccomp),
71+
"workload-seccomp" | "workload_seccomp" => Some(Self::WorkloadSeccomp),
72+
_ => None,
73+
}
74+
}
75+
}
76+
77+
/// Set-once skip declaration. Unset (the default) skips nothing.
78+
static SKIPPED_BOOTSTRAP: OnceLock<[bool; 3]> = OnceLock::new();
79+
80+
/// Declare which bootstrap subsystems the environment owns, so the supervisor
81+
/// skips attempting them. Call once at process start, before the supervisor
82+
/// boots; a second call is ignored.
83+
pub fn set_skipped_bootstrap(subsystems: impl IntoIterator<Item = BootstrapSubsystem>) {
84+
let mut skip = [false; 3];
85+
for subsystem in subsystems {
86+
skip[subsystem as usize] = true;
87+
}
88+
let _ = SKIPPED_BOOTSTRAP.set(skip);
89+
}
90+
91+
/// Parse operator tokens (`--skip-bootstrap` values / `OPENSHELL_SKIP_BOOTSTRAP`).
92+
///
93+
/// `all` skips every subsystem; otherwise each token must name one (see
94+
/// [`BootstrapSubsystem::parse_token`]). Empty/blank tokens are ignored;
95+
/// empty input skips nothing.
96+
///
97+
/// # Errors
98+
/// Returns an error naming the offending token if it is not `all` or a known
99+
/// subsystem.
100+
pub fn parse_skip_bootstrap<I, S>(tokens: I) -> Result<Vec<BootstrapSubsystem>>
101+
where
102+
I: IntoIterator<Item = S>,
103+
S: AsRef<str>,
104+
{
105+
let mut skip = Vec::new();
106+
for token in tokens {
107+
let token = token.as_ref().trim();
108+
if token.is_empty() {
109+
continue;
110+
}
111+
if token.eq_ignore_ascii_case("all") {
112+
return Ok(vec![
113+
BootstrapSubsystem::NetworkNamespace,
114+
BootstrapSubsystem::SupervisorSeccomp,
115+
BootstrapSubsystem::WorkloadSeccomp,
116+
]);
117+
}
118+
match BootstrapSubsystem::parse_token(token) {
119+
Some(subsystem) => skip.push(subsystem),
120+
None => {
121+
return Err(miette::miette!(
122+
"unknown --skip-bootstrap subsystem '{token}' \
123+
(expected: netns, supervisor-seccomp, workload-seccomp, or all)"
124+
));
125+
}
126+
}
127+
}
128+
Ok(skip)
129+
}
130+
131+
/// Whether the operator declared `subsystem` as environment-owned. A skipped
132+
/// subsystem is not attempted; a non-skipped subsystem's failure stays fatal.
133+
pub(crate) fn bootstrap_skipped(subsystem: BootstrapSubsystem) -> bool {
134+
SKIPPED_BOOTSTRAP
135+
.get()
136+
.is_some_and(|skip| skip[subsystem as usize])
137+
}
138+
139+
#[cfg(test)]
140+
mod bootstrap_tests {
141+
use super::{BootstrapSubsystem, parse_skip_bootstrap};
142+
143+
const ALL: [BootstrapSubsystem; 3] = [
144+
BootstrapSubsystem::NetworkNamespace,
145+
BootstrapSubsystem::SupervisorSeccomp,
146+
BootstrapSubsystem::WorkloadSeccomp,
147+
];
148+
149+
#[test]
150+
fn parse_all_expands_to_every_subsystem() {
151+
assert_eq!(parse_skip_bootstrap(["all"]).unwrap().len(), 3);
152+
}
153+
154+
#[test]
155+
fn parse_named_subset_preserves_order() {
156+
let got = parse_skip_bootstrap(["netns", "workload-seccomp"]).unwrap();
157+
assert_eq!(
158+
got,
159+
vec![
160+
BootstrapSubsystem::NetworkNamespace,
161+
BootstrapSubsystem::WorkloadSeccomp
162+
]
163+
);
164+
}
165+
166+
#[test]
167+
fn parse_skips_blanks_and_rejects_unknown() {
168+
assert!(parse_skip_bootstrap(["", " "]).unwrap().is_empty());
169+
assert!(parse_skip_bootstrap(["bogus"]).is_err());
170+
}
171+
172+
#[test]
173+
fn token_roundtrips_via_as_str() {
174+
for subsystem in ALL {
175+
assert_eq!(BootstrapSubsystem::parse_token(subsystem.as_str()), Some(subsystem));
176+
}
177+
}
178+
}

‎crates/openshell-supervisor-process/src/netns/mod.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,14 @@ pub fn create_netns_for_proxy(
400400
if !matches!(policy.network.mode, NetworkMode::Proxy) {
401401
return Ok(None);
402402
}
403+
if crate::bootstrap_skipped(crate::BootstrapSubsystem::NetworkNamespace) {
404+
tracing::warn!(
405+
subsystem = "netns",
406+
"Skipping network namespace creation (--skip-bootstrap: outer sandbox owns it); \
407+
proxy egress is cooperating-client only, not bypass-proof, in this mode"
408+
);
409+
return Ok(None);
410+
}
403411
match NetworkNamespace::create() {
404412
Ok(ns) => {
405413
let proxy_port = policy

‎crates/openshell-supervisor-process/src/run.rs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,14 @@ pub async fn run_process(
8989
// tasks. By this point the orchestrator has finished privileged startup
9090
// helpers (network namespace setup, nftables probes via run_networking),
9191
// and the SSH listener and entrypoint child have not been exposed yet.
92-
crate::sandbox::apply_supervisor_startup_hardening()?;
92+
if crate::bootstrap_skipped(crate::BootstrapSubsystem::SupervisorSeccomp) {
93+
tracing::warn!(
94+
subsystem = "supervisor-seccomp",
95+
"Skipping supervisor seccomp prelude (--skip-bootstrap: outer sandbox owns it)"
96+
);
97+
} else {
98+
crate::sandbox::apply_supervisor_startup_hardening()?;
99+
}
93100

94101
// Spawn the bypass detection monitor. It tails dmesg for nftables LOG
95102
// entries fired by rules installed on the workload's network namespace

‎crates/openshell-supervisor-process/src/sandbox/linux/mod.rs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ pub fn enforce(prepared: PreparedSandbox) -> Result<()> {
3838
if let Some(ruleset) = prepared.landlock {
3939
landlock::enforce(ruleset)?;
4040
}
41-
seccomp::apply(&prepared.policy)?;
41+
if crate::bootstrap_skipped(crate::BootstrapSubsystem::WorkloadSeccomp) {
42+
tracing::warn!(
43+
subsystem = "workload-seccomp",
44+
"Skipping workload seccomp filter (--skip-bootstrap: outer sandbox owns it)"
45+
);
46+
} else {
47+
seccomp::apply(&prepared.policy)?;
48+
}
4249
Ok(())
4350
}
4451

0 commit comments

Comments
 (0)