Skip to content
Open
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
9 changes: 9 additions & 0 deletions crates/openshell-core/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ pub struct SandboxPolicy {
pub network: NetworkPolicy,
pub landlock: LandlockPolicy,
pub process: ProcessPolicy,

/// Opt-in "nested container runtime" sandbox class.
///
/// When true, the seccomp filter permits the user-namespace and mount
/// syscalls an unprivileged in-userns container runtime needs to start
/// (see [`crate::proto`] `SandboxPolicy.allow_nested_container_runtime`).
/// Defaults to false so every default sandbox keeps the full filter.
pub allow_nested_container_runtime: bool,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -116,6 +124,7 @@ impl TryFrom<ProtoSandboxPolicy> for SandboxPolicy {
network,
landlock: proto.landlock.map(LandlockPolicy::from).unwrap_or_default(),
process: proto.process.map(ProcessPolicy::from).unwrap_or_default(),
allow_nested_container_runtime: proto.allow_nested_container_runtime,
})
}
}
Expand Down
9 changes: 9 additions & 0 deletions crates/openshell-policy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,9 @@ fn to_proto(raw: PolicyFile) -> Result<SandboxPolicy> {
}),
network_policies,
network_middlewares,
// Nested container-runtime class is derived from policy YAML defaults;
// not surfaced through this raw-file path, so it stays off here.
allow_nested_container_runtime: false,
})
}

Expand Down Expand Up @@ -1081,6 +1084,8 @@ pub fn restrictive_default_policy() -> SandboxPolicy {
}),
network_policies: HashMap::new(),
network_middlewares: HashMap::default(),
// The restrictive default keeps every sandbox-escape protection.
allow_nested_container_runtime: false,
}
}

Expand Down Expand Up @@ -2358,6 +2363,7 @@ network_policies:
landlock: None,
network_policies: HashMap::new(),
network_middlewares: HashMap::default(),
allow_nested_container_runtime: false,
};
assert!(validate_sandbox_policy(&policy).is_ok());
}
Expand Down Expand Up @@ -2808,6 +2814,7 @@ network_policies:
landlock: None,
network_policies: HashMap::new(),
network_middlewares: HashMap::default(),
allow_nested_container_runtime: false,
};
assert!(validate_sandbox_policy(&policy).is_ok());
}
Expand All @@ -2824,6 +2831,7 @@ network_policies:
landlock: None,
network_policies: HashMap::new(),
network_middlewares: HashMap::default(),
allow_nested_container_runtime: false,
};
assert!(validate_sandbox_policy(&policy).is_ok());
}
Expand Down Expand Up @@ -2903,6 +2911,7 @@ network_policies:
landlock: None,
network_policies: HashMap::new(),
network_middlewares: HashMap::default(),
allow_nested_container_runtime: false,
};
assert!(validate_sandbox_policy(&policy).is_ok());
}
Expand Down
3 changes: 3 additions & 0 deletions crates/openshell-sandbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,7 @@ mod baseline_tests {
},
landlock: LandlockPolicy::default(),
process: ProcessPolicy::default(),
allow_nested_container_runtime: false,
};

enrich_sandbox_baseline_paths(&mut policy);
Expand Down Expand Up @@ -1893,6 +1894,7 @@ async fn load_policy(
},
landlock: config.landlock,
process: config.process,
allow_nested_container_runtime: false,
};
enrich_sandbox_baseline_paths(&mut policy);
// File mode has no operator-registered middleware to connect.
Expand Down Expand Up @@ -3142,6 +3144,7 @@ mod tests {
},
landlock: LandlockPolicy::default(),
process: ProcessPolicy::default(),
allow_nested_container_runtime: false,
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/openshell-supervisor-process/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,7 @@ mod tests {
network: NetworkPolicy::default(),
landlock: LandlockPolicy::default(),
process,
allow_nested_container_runtime: false,
}
}

Expand Down Expand Up @@ -1991,6 +1992,7 @@ mod tests {
run_as_user,
run_as_group,
},
allow_nested_container_runtime: false,
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/openshell-supervisor-process/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub async fn run_process(
// tasks. By this point the orchestrator has finished privileged startup
// helpers (network namespace setup, nftables probes via run_networking),
// and the SSH listener and entrypoint child have not been exposed yet.
crate::sandbox::apply_supervisor_startup_hardening()?;
crate::sandbox::apply_supervisor_startup_hardening(policy.allow_nested_container_runtime)?;

// Spawn the bypass detection monitor. It tails dmesg for nftables LOG
// entries fired by rules installed on the workload's network namespace
Expand Down Expand Up @@ -600,6 +600,7 @@ mod tests {
},
landlock: LandlockPolicy::default(),
process: ProcessPolicy::default(),
allow_nested_container_runtime: false,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ mod tests {
compatibility: LandlockCompatibility::HardRequirement,
},
process: ProcessPolicy::default(),
allow_nested_container_runtime: false,
}
}

Expand Down
8 changes: 6 additions & 2 deletions crates/openshell-supervisor-process/src/sandbox/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ pub fn enforce(prepared: PreparedSandbox) -> Result<()> {
}

/// Apply the supervisor seccomp prelude after privileged bootstrap completes.
pub fn apply_supervisor_prelude() -> Result<()> {
seccomp::apply_supervisor_prelude()
///
/// `allow_nested` opts this supervisor into the nested container-runtime class,
/// which omits the mount-family block from the prelude so the workload children
/// forked from this supervisor can mount (they inherit the prelude filter).
pub fn apply_supervisor_prelude(allow_nested: bool) -> Result<()> {
seccomp::apply_supervisor_prelude(allow_nested)
}

/// Legacy single-phase apply. Kept for backward compatibility.
Expand Down
Loading