Skip to content

Commit f452e9f

Browse files
committed
fix(sandbox): preserve standard sbin paths for CDI workloads
Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent 5e6241d commit f452e9f

5 files changed

Lines changed: 626 additions & 18 deletions

File tree

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

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub struct LocalBoundaryExec {
2929
ca_file_paths: Option<Arc<(std::path::PathBuf, std::path::PathBuf)>>,
3030
provider_credentials: ProviderCredentialState,
3131
user_environment: HashMap<String, String>,
32+
repair_standard_sbin: bool,
3233
runtime: Arc<crate::boundary_io::BoundaryRuntimeState>,
3334
#[cfg(target_os = "linux")]
3435
launcher: openshell_isolation_interface::linux::workload_launcher::WorkloadLauncher,
@@ -53,22 +54,36 @@ impl LocalBoundaryExec {
5354
ca_file_paths,
5455
provider_credentials,
5556
user_environment,
57+
repair_standard_sbin: false,
5658
runtime,
5759
#[cfg(target_os = "linux")]
5860
launcher,
5961
}
6062
}
6163

64+
/// Configure whether workload paths should include the standard sbin directories.
65+
#[must_use]
66+
pub fn with_standard_sbin_path_repair(mut self, enabled: bool) -> Self {
67+
self.repair_standard_sbin = enabled;
68+
self
69+
}
70+
6271
fn command(&self, spec: &ExecSpec) -> Result<Command, BackendError> {
6372
if spec.program.is_empty() {
6473
return Err(BackendError::Process("exec program is empty".to_string()));
6574
}
75+
let repair_standard_sbin = self.repair_standard_sbin;
76+
let args = crate::process::process_args_with_standard_sbin_paths(
77+
&spec.program,
78+
&spec.args,
79+
repair_standard_sbin,
80+
);
6681
let mut command = Command::new(&spec.program);
67-
command.args(&spec.args);
82+
command.args(args);
6883
let effective_workdir = spec.workdir.as_deref().or(self.base_workdir.as_deref());
6984
let (session_user, session_home) =
7085
crate::process::session_user_and_home(&self.policy, effective_workdir);
71-
let path = std::env::var("PATH").unwrap_or_else(|_| "/usr/local/bin:/usr/bin:/bin".into());
86+
let path = crate::child_env::child_path_from_env(repair_standard_sbin);
7287
command
7388
.env_clear()
7489
.env(openshell_core::sandbox_env::SANDBOX, "1")
@@ -79,7 +94,17 @@ impl LocalBoundaryExec {
7994
.env("TERM", if spec.pty { "xterm-256color" } else { "dumb" });
8095
for (key, value) in &self.user_environment {
8196
if !key.starts_with("OPENSHELL_") {
82-
command.env(key, value);
97+
if key == "PATH" {
98+
command.env(
99+
key,
100+
crate::child_env::maybe_path_with_standard_sbin_paths(
101+
value,
102+
repair_standard_sbin,
103+
),
104+
);
105+
} else {
106+
command.env(key, value);
107+
}
83108
}
84109
}
85110
if let Some((ca_cert_path, combined_bundle_path)) = self.ca_file_paths.as_deref() {
@@ -89,13 +114,33 @@ impl LocalBoundaryExec {
89114
}
90115
for (key, value) in self.provider_credentials.child_env_with_gcp_resolved() {
91116
if !crate::process::is_supervisor_only_env_var(&key) {
92-
command.env(key, value);
117+
if key == "PATH" {
118+
command.env(
119+
key,
120+
crate::child_env::maybe_path_with_standard_sbin_paths(
121+
&value,
122+
repair_standard_sbin,
123+
),
124+
);
125+
} else {
126+
command.env(key, value);
127+
}
93128
}
94129
}
95130
crate::process::strip_proxy_env_std(&mut command);
96131
for (key, value) in &spec.env {
97132
if !key.starts_with("OPENSHELL_") {
98-
command.env(key, value);
133+
if key == "PATH" {
134+
command.env(
135+
key,
136+
crate::child_env::maybe_path_with_standard_sbin_paths(
137+
value,
138+
repair_standard_sbin,
139+
),
140+
);
141+
} else {
142+
command.env(key, value);
143+
}
99144
}
100145
}
101146
if let Some(workdir) = spec.workdir.as_deref().or(self.base_workdir.as_deref()) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,6 +2545,7 @@ mod linux {
25452545
process_id: format!("{}:main:0", self.config.generation),
25462546
spec,
25472547
policy,
2548+
cdi_active: self.config.cdi_context.is_some(),
25482549
provider_env_revision,
25492550
provider_env,
25502551
ca_file_paths,
@@ -2891,6 +2892,7 @@ mod linux {
28912892
process_id: String,
28922893
spec: AgentSpecWire,
28932894
policy: openshell_core::policy::SandboxPolicy,
2895+
cdi_active: bool,
28942896
provider_env_revision: u64,
28952897
provider_env: std::collections::HashMap<String, String>,
28962898
ca_file_paths: Option<(std::path::PathBuf, std::path::PathBuf)>,
@@ -2925,6 +2927,7 @@ mod linux {
29252927
process_id,
29262928
spec,
29272929
policy,
2930+
cdi_active,
29282931
provider_env_revision,
29292932
provider_env,
29302933
ca_file_paths,
@@ -2945,6 +2948,7 @@ mod linux {
29452948
spec.timeout_secs,
29462949
spec.interactive,
29472950
&policy,
2951+
cdi_active,
29482952
entrypoint_pid,
29492953
provider_credentials.clone(),
29502954
provider_env,
@@ -5152,6 +5156,7 @@ containerEdits:
51525156
process_id: "generation-retained:main:0".to_string(),
51535157
spec: agent_spec.clone(),
51545158
policy,
5159+
cdi_active: false,
51555160
provider_env_revision: 0,
51565161
provider_env: std::collections::HashMap::new(),
51575162
ca_file_paths: None,

0 commit comments

Comments
 (0)