fix(ec2): let a systemd guest's init start sshd (#6882)

Floci started /usr/sbin/sshd itself in every guest, including systemd ones
whose image starts sshd from its own unit at boot. The two raced for port
22: if Floci's won, ssh.service failed, and the stray daemon outside systemd
kept the port, so a later `systemctl restart ssh` (to apply an
sshd_config change, as user data commonly does) failed too. On EC2 the AMI's
init alone starts sshd; systemd guests now work the same way.
This commit is contained in:
Allen Sanborn authored and GitHub committed 2026-10-28 21:11:09 -04:00
1 parent 177f8e9360
commit 0e87e6f1de
3 files changed
+13 -2

No files matched your search

@@ -1185,6 +1185,7 @@ class Ec2ContainerManagerTest {
when(inspect.exec()).thenReturn(withIp);
harness.stubSuccessfulExecs(new CountDownLatch(0), new CountDownLatch(0));
Instance instance = instance("i-systemd");
instance.setUserData("#!/bin/sh\necho ready\n");
harness.manager.launch(instance,
new ResolvedAmiImage("floci/ami-ubuntu:24.04-arm64", ResolvedAmiImage.SYSTEMD_RUNTIME, true,
@@ -1196,6 +1197,10 @@ class Ec2ContainerManagerTest {
verify(harness.builder).withCmd(List.of("/sbin/init"));
verify(harness.builder).withCgroupnsMode("host");
verify(harness.builder).withBind("/sys/fs/cgroup", "/sys/fs/cgroup");
// User data runs after the sshd step, so once it has started that step is settled.
awaitUntil(() -> commandIndex(harness.executedCommands, "/var/lib/user-data.sh") >= 0, Duration.ofSeconds(2));
assertEquals(-1, commandIndex(harness.executedCommands, "/usr/sbin/sshd"),
"a systemd guest's init starts sshd; Floci must not start a second one");
verify(harness.lifecycleManager).create(any(ContainerSpec.class), eq("linux/arm64"));
}