Skip to content

Commit f27cba6

Browse files
committed
fix(sandbox): strip supervisor-only credentials from entrypoint env
ProcessHandle::spawn_impl previously inherited the supervisor's full environment when starting the sandbox entrypoint, then drop_privileges() demoted the child to the sandbox user. The combination meant a later process running as the sandbox user (e.g. an SSH-spawned shell) could read /proc/<entrypoint_pid>/environ and recover the gateway-minted JWT. Explicitly env_remove the three sandbox-token env vars before exec so the entrypoint child carries none of the supervisor's identity material. SSH session shells already use env_clear() in apply_child_env, so this plugs the only remaining inheritance path. Related to #1354 (per-sandbox identity series, PR 3 follow-up). Signed-off-by: Taylor Mutch <[email protected]>
1 parent ea5eccb commit f27cba6

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ impl ProcessHandle {
155155
.kill_on_drop(true)
156156
.env(openshell_core::sandbox_env::SANDBOX, "1");
157157

158+
// Strip supervisor-only credentials from the entrypoint's inherited
159+
// environment. The entrypoint drops to the sandbox user before
160+
// `exec`; without this strip, anything running as the sandbox user
161+
// (e.g. an SSH-spawned shell) could read /proc/<entrypoint_pid>/environ
162+
// and recover the gateway-minted JWT. Issue #1354.
163+
cmd.env_remove(openshell_core::sandbox_env::SANDBOX_TOKEN)
164+
.env_remove(openshell_core::sandbox_env::SANDBOX_TOKEN_FILE)
165+
.env_remove(openshell_core::sandbox_env::K8S_SA_TOKEN_FILE);
166+
158167
inject_provider_env(&mut cmd, provider_env);
159168

160169
if let Some(dir) = workdir {
@@ -281,6 +290,15 @@ impl ProcessHandle {
281290
.kill_on_drop(true)
282291
.env(openshell_core::sandbox_env::SANDBOX, "1");
283292

293+
// Strip supervisor-only credentials from the entrypoint's inherited
294+
// environment. The entrypoint drops to the sandbox user before
295+
// `exec`; without this strip, anything running as the sandbox user
296+
// (e.g. an SSH-spawned shell) could read /proc/<entrypoint_pid>/environ
297+
// and recover the gateway-minted JWT. Issue #1354.
298+
cmd.env_remove(openshell_core::sandbox_env::SANDBOX_TOKEN)
299+
.env_remove(openshell_core::sandbox_env::SANDBOX_TOKEN_FILE)
300+
.env_remove(openshell_core::sandbox_env::K8S_SA_TOKEN_FILE);
301+
284302
inject_provider_env(&mut cmd, provider_env);
285303

286304
if let Some(dir) = workdir {

0 commit comments

Comments
 (0)