Skip to content

Commit 1fe79f5

Browse files
authored
fix(sandbox): harden isolated supervisor startup (#3426)
As part of the RFC-0012 changes, the Podman runtime moved trusted networking into a paired supervisor running as the resolved non-root identity, while the capability-free sandbox retained ownership of seccomp-mediated I/O. The supervisor still generated interception TLS material under the root-owned /etc/openshell-tls directory, and the sandbox treated the documented ENOENT notification race as a fatal listener failure. This meant TLS interception could fail with a permission error, and an exiting target process could stop the network broker while the kernel was preparing its notification. Now, we store generated supervisor TLS material in its writable /run tmpfs and retry ENOENT notification races while preserving fatal handling for other listener errors. Signed-off-by: Kris Hicks <khicks@nvidia.com>
1 parent fc07165 commit 1fe79f5

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

‎crates/openshell-driver-podman/src/container.rs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,13 @@ pub fn build_isolation_specs(
14941494
openshell_core::sandbox_env::ADMITTED_ISOLATION_BACKEND.into(),
14951495
openshell_sandbox_backend::BACKEND_NAME.into(),
14961496
);
1497+
// The supervisor runs as the resolved non-root workload identity. Keep
1498+
// generated interception CA material under its writable /run tmpfs rather
1499+
// than the root-owned default at /etc/openshell-tls.
1500+
supervisor.env.insert(
1501+
openshell_core::sandbox_env::PROXY_TLS_DIR.into(),
1502+
"/run/openshell/proxy-tls".into(),
1503+
);
14971504
supervisor.user = user;
14981505
supervisor.groups = input
14991506
.identity
@@ -1801,6 +1808,14 @@ mod tests {
18011808
.contains(&"nocopy".into())
18021809
);
18031810
assert_eq!(specs.supervisor.entrypoint, vec!["/openshell-supervisor"]);
1811+
assert_eq!(
1812+
specs
1813+
.supervisor
1814+
.env
1815+
.get(openshell_core::sandbox_env::PROXY_TLS_DIR)
1816+
.map(String::as_str),
1817+
Some("/run/openshell/proxy-tls")
1818+
);
18041819
}
18051820

18061821
fn json_struct(value: Value) -> prost_types::Struct {

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ const DNS_RELAY_ADDRESS: SocketAddr = SocketAddr::V4(std::net::SocketAddrV4::new
4141
const RELAY_CONNECT_TIMEOUT: Duration = Duration::from_secs(5);
4242
const NETWORK_DECISION_TIMEOUT: Duration = Duration::from_secs(30);
4343

44+
fn retry_notification_receive(error: &io::Error) -> bool {
45+
error.kind() == io::ErrorKind::Interrupted || error.raw_os_error() == Some(libc::ENOENT)
46+
}
47+
4448
#[derive(Debug)]
4549
struct PendingOpenSlot(Arc<AtomicUsize>);
4650

@@ -271,7 +275,12 @@ impl NetworkBroker {
271275
while broker_healthy.load(Ordering::Acquire) {
272276
let notification = match listener.receive() {
273277
Ok(notification) => notification,
274-
Err(error) if error.kind() == io::ErrorKind::Interrupted => continue,
278+
// ENOENT is a documented seccomp user-notification
279+
// race: the target thread exited or its blocked
280+
// syscall was interrupted while the kernel was
281+
// preparing the notification. It does not mean the
282+
// listener itself is unhealthy.
283+
Err(error) if retry_notification_receive(&error) => continue,
275284
Err(error) => {
276285
tracing::error!(%error, "sandbox network broker listener failed");
277286
broker_healthy.store(false, Ordering::Release);
@@ -1754,6 +1763,19 @@ mod tests {
17541763
use std::io::{Read as _, Write as _};
17551764
use std::os::unix::net::{UnixListener, UnixStream};
17561765

1766+
#[test]
1767+
fn notification_receive_retries_interrupted_and_disappeared_targets() {
1768+
assert!(retry_notification_receive(&io::Error::from(
1769+
io::ErrorKind::Interrupted
1770+
)));
1771+
assert!(retry_notification_receive(&io::Error::from_raw_os_error(
1772+
libc::ENOENT
1773+
)));
1774+
assert!(!retry_notification_receive(&io::Error::from_raw_os_error(
1775+
libc::EBADF
1776+
)));
1777+
}
1778+
17571779
#[test]
17581780
fn relay_rejects_descriptor_replaced_after_policy_decision() {
17591781
let metadata = SocketMetadata {

0 commit comments

Comments
 (0)