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
1 change: 1 addition & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ CDI. Branch and release feature-test matrices run this suite on Docker.
| `omitted-access-file` | Bind without `ro` or `rw` | Launch rejects the effectively writable mount. |
| `mps-pipe-directory` | Directory at `/tmp/nvidia-mps` mounted `nosuid`, `nodev`, `noexec` | Read and write succeed on its contents. |
| `mps-pipe-directory-without-noexec` | The same directory without `noexec` | Launch rejects the mount. |
| `sbin-path` | Spec environment edit narrowing `PATH` to `/usr/local/bin:/usr/bin:/bin` | The standard sbin directories are appended to the workload's `PATH`. |
| `device-node` | Null character device at `/dev/tmachine-cdi-null` | Non-root; write succeeds. |
| `device-node-with-gid` | Group-restricted null device at `/dev/tmachine-cdi-group-null` | Non-root with the device's group; write succeeds. |
| `unix-socket` | Echo socket at `/tmachine-cdi/socket/echo.sock` | Sibling file in the host directory is not visible. |
Expand Down
55 changes: 50 additions & 5 deletions crates/openshell-sandbox/src/boundary_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct LocalBoundaryExec {
ca_file_paths: Option<Arc<(std::path::PathBuf, std::path::PathBuf)>>,
provider_credentials: ProviderCredentialState,
user_environment: HashMap<String, String>,
repair_standard_sbin: bool,
runtime: Arc<crate::boundary_io::BoundaryRuntimeState>,
#[cfg(target_os = "linux")]
launcher: crate::linux::workload_launcher::WorkloadLauncher,
Expand Down Expand Up @@ -64,6 +65,7 @@ impl LocalBoundaryExec {
ca_file_paths,
provider_credentials,
user_environment,
repair_standard_sbin: false,
runtime,
#[cfg(target_os = "linux")]
launcher,
Expand Down Expand Up @@ -126,6 +128,13 @@ impl LocalBoundaryExec {
})
}

/// Configure whether workload paths should include the standard sbin directories.
#[must_use]
pub fn with_standard_sbin_path_repair(mut self, enabled: bool) -> Self {
self.repair_standard_sbin = enabled;
self
}

fn command(&self, spec: &ExecSpec) -> Result<Command, BackendError> {
let (program, args) = if let Some(shell_spec) = &spec.shell {
let shell = openshell_core::shell::find_login_shell().ok_or_else(|| {
Expand Down Expand Up @@ -156,12 +165,18 @@ impl LocalBoundaryExec {
if program.is_empty() {
return Err(BackendError::Process("exec program is empty".to_string()));
}
let repair_standard_sbin = self.repair_standard_sbin;
let args = crate::process::process_args_with_standard_sbin_paths(
&program,
&args,
repair_standard_sbin,
);
let mut command = Command::new(&program);
command.args(&args);
command.args(args);
let effective_workdir = spec.workdir.as_deref().or(self.base_workdir.as_deref());
let (session_user, session_home) =
crate::process::session_user_and_home(&self.policy, effective_workdir);
let path = std::env::var("PATH").unwrap_or_else(|_| "/usr/local/bin:/usr/bin:/bin".into());
let path = crate::child_env::child_path_from_env(repair_standard_sbin);
command
.env_clear()
.env(openshell_core::sandbox_env::SANDBOX, "1")
Expand All @@ -174,7 +189,17 @@ impl LocalBoundaryExec {
}
for (key, value) in &self.user_environment {
if !key.starts_with(crate::process::RESERVED_ENV_PREFIX) {
command.env(key, value);
if key == "PATH" {
command.env(
key,
crate::child_env::maybe_path_with_standard_sbin_paths(
value,
repair_standard_sbin,
),
);
} else {
command.env(key, value);
}
}
}
if let Some((ca_cert_path, combined_bundle_path)) = self.ca_file_paths.as_deref() {
Expand All @@ -184,13 +209,33 @@ impl LocalBoundaryExec {
}
for (key, value) in self.provider_credentials.child_env_with_gcp_resolved() {
if !crate::process::is_supervisor_only_env_var(&key) {
command.env(key, value);
if key == "PATH" {
command.env(
key,
crate::child_env::maybe_path_with_standard_sbin_paths(
&value,
repair_standard_sbin,
),
);
} else {
command.env(key, value);
}
}
}
crate::process::strip_proxy_env_std(&mut command);
for (key, value) in &spec.env {
if !key.starts_with(crate::process::RESERVED_ENV_PREFIX) {
command.env(key, value);
if key == "PATH" {
command.env(
key,
crate::child_env::maybe_path_with_standard_sbin_paths(
value,
repair_standard_sbin,
),
);
} else {
command.env(key, value);
}
}
}
if let Some(workdir) = spec.workdir.as_deref().or(self.base_workdir.as_deref()) {
Expand Down
5 changes: 5 additions & 0 deletions crates/openshell-sandbox/src/boundary_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2717,6 +2717,7 @@ mod linux {
spec,
policy,
launch_context,
cdi_active: self.config.cdi_context.is_some(),
provider_env_revision,
provider_env,
ca_file_paths,
Expand Down Expand Up @@ -3093,6 +3094,7 @@ mod linux {
spec: AgentSpecWire,
policy: openshell_core::policy::SandboxPolicy,
launch_context: WorkloadLaunchContext,
cdi_active: bool,
provider_env_revision: u64,
provider_env: std::collections::HashMap<String, String>,
ca_file_paths: Option<(std::path::PathBuf, std::path::PathBuf)>,
Expand Down Expand Up @@ -3128,6 +3130,7 @@ mod linux {
spec,
policy,
launch_context,
cdi_active,
provider_env_revision,
provider_env,
ca_file_paths,
Expand All @@ -3149,6 +3152,7 @@ mod linux {
spec.interactive,
&policy,
&launch_context,
cdi_active,
entrypoint_pid,
provider_credentials.clone(),
provider_env,
Expand Down Expand Up @@ -6019,6 +6023,7 @@ mod linux {
spec: agent_spec.clone(),
policy,
launch_context: WorkloadLaunchContext::default(),
cdi_active: false,
provider_env_revision: 0,
provider_env: std::collections::HashMap::new(),
ca_file_paths: None,
Expand Down
Loading
Loading