fix(ec2): create /run/sshd before starting sshd (#1855)

Modern OpenSSH refuses to start without its privilege-separation
directory, and /run is a fresh tmpfs in most container images, so
/run/sshd genuinely is not there. sshd exited with "Missing privilege
separation directory: /run/sshd" and instances launched via
`aws ec2 run-instances` came up with no SSH, requiring the directory to
be created by hand inside the container.

Add a regression test that drives the launch path with an SSH public
key, records the container execs in order, and asserts /run/sshd is
created before /usr/sbin/sshd is invoked.

Signed-off-by: ProGamingDk <smashyalts@gmail.com>
Co-authored-by: Priamo <pgermosen@gmail.com>
This commit is contained in:
ProGamingDkandPriamo authored and GitHub committed 2026-08-19 23:51:10 -04:00
1 parent 7505110ed9
commit 3daab4a1ae
2 files changed
+52 -2

No files matched your search

@@ -512,6 +512,15 @@ public class Ec2ContainerManager {
instanceId, keygen.summary());
return;
}
// Modern OpenSSH refuses to start without its privilege-separation directory, and /run
// is a fresh tmpfs in most container images, so /run/sshd genuinely isn't there yet.
ContainerExecResult mkdir = execInContainerForResult(containerId,
new String[]{"mkdir", "-p", "/run/sshd"}, 5);
if (mkdir.exitCode() != 0) {
LOG.warnv("Could not create /run/sshd for EC2 instance {0}: {1}",
instanceId, mkdir.summary());
return;
}
// Start sshd without -D so it daemonizes itself and survives this exec session. Since sshd
// requires execution with an absolute path, several paths are tried until it starts
for (String sshdPath : ALLOWED_SSHD_PATHS) {