Skip to content

Commit dd368eb

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 d250f7a commit dd368eb

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
@@ -146,6 +146,15 @@ impl ProcessHandle {
146146
.kill_on_drop(true)
147147
.env(openshell_core::sandbox_env::SANDBOX, "1");
148148

149+
// Strip supervisor-only credentials from the entrypoint's inherited
150+
// environment. The entrypoint drops to the sandbox user before
151+
// `exec`; without this strip, anything running as the sandbox user
152+
// (e.g. an SSH-spawned shell) could read /proc/<entrypoint_pid>/environ
153+
// and recover the gateway-minted JWT. Issue #1354.
154+
cmd.env_remove(openshell_core::sandbox_env::SANDBOX_TOKEN)
155+
.env_remove(openshell_core::sandbox_env::SANDBOX_TOKEN_FILE)
156+
.env_remove(openshell_core::sandbox_env::K8S_SA_TOKEN_FILE);
157+
149158
inject_provider_env(&mut cmd, provider_env);
150159

151160
if let Some(dir) = workdir {
@@ -272,6 +281,15 @@ impl ProcessHandle {
272281
.kill_on_drop(true)
273282
.env(openshell_core::sandbox_env::SANDBOX, "1");
274283

284+
// Strip supervisor-only credentials from the entrypoint's inherited
285+
// environment. The entrypoint drops to the sandbox user before
286+
// `exec`; without this strip, anything running as the sandbox user
287+
// (e.g. an SSH-spawned shell) could read /proc/<entrypoint_pid>/environ
288+
// and recover the gateway-minted JWT. Issue #1354.
289+
cmd.env_remove(openshell_core::sandbox_env::SANDBOX_TOKEN)
290+
.env_remove(openshell_core::sandbox_env::SANDBOX_TOKEN_FILE)
291+
.env_remove(openshell_core::sandbox_env::K8S_SA_TOKEN_FILE);
292+
275293
inject_provider_env(&mut cmd, provider_env);
276294

277295
if let Some(dir) = workdir {

0 commit comments

Comments
 (0)