mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
## Why Host root-owned SSH config drop-ins can appear to belong to `nobody` inside the user namespace, causing OpenSSH to reject them and preventing SSH connections. ## What changed Mask `/etc/ssh/ssh_config.d` with an empty, read-only directory by default for filesystem-restricted commands. Preserve explicit read grants to drop-ins and overlapping write grants, and avoid masking through symlinks or unsafe ancestor directories. The main `/etc/ssh/ssh_config` and user configuration still apply. Settings in masked drop-ins, including `KnownHostsCommand`, are skipped. ## Testing Add an isolated SSH handshake regression test that verifies a connection succeeds with system drop-ins masked and that a changed host key is still rejected. GitOrigin-RevId: e8d9cd7a4bd29480d1b930efc96510362a88d3fc
47 lines
1.8 KiB
Rust
47 lines
1.8 KiB
Rust
//! Masking system drop-ins must preserve host-key checks in the main SSH configuration.
|
|
|
|
use super::codex_linux_sandbox_exe;
|
|
use codex_protocol::models::PermissionProfile;
|
|
use codex_protocol::permissions::FileSystemSandboxPolicy;
|
|
use codex_protocol::permissions::NetworkSandboxPolicy;
|
|
use std::process::Command;
|
|
|
|
#[test]
|
|
fn ssh_masks_system_dropins_and_rejects_a_changed_host_key() {
|
|
// The fixture stages root-owned files, then runs the client as UID 1000.
|
|
if unsafe { libc::geteuid() } != 0 {
|
|
eprintln!("skipping SSH handshake: root is required to create the two-owner fixture");
|
|
return;
|
|
}
|
|
let profile = PermissionProfile::from_runtime_permissions(
|
|
&FileSystemSandboxPolicy::read_only(),
|
|
NetworkSandboxPolicy::Enabled,
|
|
);
|
|
let fixture = codex_utils_cargo_bin::find_resource!("tests/fixtures/ssh_handshake.sh").unwrap();
|
|
let output = Command::new("unshare")
|
|
.args(["--mount-proc", "--net", "--pid", "--fork"])
|
|
.args(["--propagation", "private", "--", "/bin/sh"])
|
|
.arg(fixture)
|
|
.arg(codex_linux_sandbox_exe())
|
|
.arg(serde_json::to_string(&profile).unwrap())
|
|
.output();
|
|
let output = match output {
|
|
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
|
|
eprintln!("skipping SSH handshake: unshare is unavailable");
|
|
return;
|
|
}
|
|
result => result.unwrap(),
|
|
};
|
|
if output.status.code() == Some(77)
|
|
|| (output.stderr.starts_with(b"unshare:")
|
|
&& String::from_utf8_lossy(&output.stderr).contains("Operation not permitted"))
|
|
{
|
|
eprintln!(
|
|
"skipping SSH handshake: {}",
|
|
String::from_utf8_lossy(&output.stderr)
|
|
);
|
|
return;
|
|
}
|
|
assert!(output.status.success(), "{output:?}");
|
|
}
|