mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 15:49:33 -05:00
feat(ec2): bind the host's /lib/modules read-only into systemd guests (#7354)
A systemd guest shares the Docker host's kernel but ships none of its modules, so `modprobe br_netfilter` (Kubernetes node setup, e.g. Kubernetes The Hard Way lab 9) fails with "Module not found in directory /lib/modules/<kver>" even when the module is built in. kind binds the host's tree the same way. Docker creates a missing bind source as an empty directory, so hosts without /lib/modules still launch. Privileged systemd guests can now load any module in that tree into the shared host (or Docker Desktop / OrbStack VM) kernel, so docs/services/ec2.md carries a warning saying so. test(ec2): prove a systemd guest gets /lib/modules read-only on a real daemon Ec2SystemdGuestDockerIntegrationTest launches through the real Ec2ContainerManager container spec against Docker, with an Alpine image standing in for a systemd cloud image (its busybox /sbin/init stays up as PID 1), and checks the mount both from the daemon's inspect and from the guest's /proc/mounts. It is skipped when Docker is unavailable. docs/services/ec2.md now says that on Docker Desktop or OrbStack the tree is the VM's and may not match its running kernel, and states exactly when an instance runs privileged: only with security-group enforcement off. With enforcement on, the guest joins the protected namespace unprivileged, and a namespace that cannot be created fails the launch. docs(ec2): say the read-only modules mount does not bind a privileged guest; keep test cleanup from masking failures The read-only bind keeps an unprivileged guest from changing the tree, but a privileged guest can remount it read-write, so the first paragraph no longer claims the guest cannot load a module the host kernel lacks. The systemd guest test now logs a failed container removal instead of throwing it over the assertion error it is reporting. fix(ec2): bind only the running kernel's /lib/modules dir into systemd guests; tear down the integration test via terminate() test(ec2): pin that the guest's /lib/modules outside the bound kernel dir stays writable; document missing-dir and linux-modules caveats
This commit is contained in:
1 parent
42b28be218
commit
0de5566d22
4 files changed
+166
-1
No files matched your search
@@ -761,10 +761,34 @@ public class Ec2ContainerManager {
|
||||
.withMount(new Mount().withType(MountType.TMPFS).withTarget("/run"))
|
||||
.withMount(new Mount().withType(MountType.TMPFS).withTarget("/run/lock"))
|
||||
.withBind("/sys/fs/cgroup", "/sys/fs/cgroup");
|
||||
// The guest shares the Docker host's kernel but ships none of its modules, so
|
||||
// `modprobe br_netfilter` (Kubernetes node setup) fails with "not found" even
|
||||
// when the module is built in. Only the running kernel's directory is bound: the
|
||||
// guest's dpkg owns the rest of /lib/modules, and a read-only bind of the whole
|
||||
// tree breaks apt-get upgrade, DKMS and linux-modules-extra.
|
||||
String kernelVersion = hostKernelVersion();
|
||||
if (kernelVersion != null) {
|
||||
String modules = "/lib/modules/" + kernelVersion;
|
||||
specBuilder.withReadOnlyBind(modules, modules);
|
||||
}
|
||||
}
|
||||
return specBuilder.build();
|
||||
}
|
||||
|
||||
/** The Docker daemon's kernel version, or null when it cannot be read (the modules bind is then skipped). */
|
||||
private String hostKernelVersion() {
|
||||
try {
|
||||
String version = dockerClient.infoCmd().exec().getKernelVersion();
|
||||
if (version != null && !version.isBlank()) {
|
||||
return version;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.debugv("Could not read the Docker host's kernel version: {0}", e.getMessage());
|
||||
}
|
||||
LOG.warn("Docker host kernel version unknown; systemd guest launches without /lib/modules");
|
||||
return null;
|
||||
}
|
||||
|
||||
private void failLaunch(Instance instance) {
|
||||
failLaunch(instance, instance.getPrivateIpAddress());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user