mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ec2): install packages with yum on Amazon Linux 2 guests (#2448)
Two package-manager probes in Ec2ContainerManager try dnf, apt-get and apk.
public.ecr.aws/amazonlinux/amazonlinux:2 ships **yum** and none of those
three, so both chains fall through on an Amazon Linux 2 guest:
- startSshd(): the trailing "command -v sshd" then fails, the method returns
early, and the instance is never reachable over SSH -- despite Floci
allocating a host port for it and injecting authorized_keys.
- metadataProxyInstallCommand(): reaches its else branch and exits 1 with
"No supported package manager found for IMDS proxy dependencies", leaving
the instance without a link-local IMDS endpoint.
This affects instances launched explicitly from ami-amazonlinux2 (or its ID
ami-0abcdef1234567890), not every instance: image-catalog.yaml pins
defaultDockerImage to amazonlinux:2023, which has dnf and already works. A
missing ImageId and unrecognised IDs both fall back to that default.
Verified against the image itself:
$ docker run --rm public.ecr.aws/amazonlinux/amazonlinux:2 sh -c '
command -v yum; for m in apt-get dnf apk; do command -v $m; done'
/usr/bin/yum # and nothing else
$ yum install -y openssh-server openssh-clients -> sshd, scp
$ yum install -y iproute socat curl ca-certificates -> ip, socat, curl
yum is probed after dnf so that dnf still wins on Amazon Linux 2023 and
modern Fedora/RHEL, where both exist and yum is only a compatibility shim.
The yum branch installs openssh-clients alongside the server, matching what
the dnf and apt-get branches do since #2449 -- an AL2 guest needs scp for
the same reason every other guest does.
Also extracts the probe into sshdInstallProbeCommand() so the tests can
assert against the string production actually issues rather than against a
copy of it declared in the test file.
This commit is contained in:
1 parent
b27b32f044
commit
c9f456ea7a
2 files changed
+91
-31
No files matched your search
@@ -270,6 +270,40 @@ class Ec2ContainerManagerTest {
|
||||
+ Ec2ContainerManager.SSH_CLIENT_MISSING_EXIT_CODE), script);
|
||||
}
|
||||
|
||||
@Test
|
||||
void sshdInstallProbeHandlesYumForAmazonLinux2() {
|
||||
// public.ecr.aws/amazonlinux/amazonlinux:2 ships only yum -- no dnf, no apt-get, no
|
||||
// apk. It is NOT the default image (image-catalog.yaml pins that to amazonlinux:2023,
|
||||
// which has dnf); it is reached by explicitly requesting ami-amazonlinux2. Without a
|
||||
// yum branch the if/elif chain falls through, the trailing "command -v sshd" fails,
|
||||
// and startSshd() returns early, so such an instance is never reachable over SSH.
|
||||
//
|
||||
// Asserted against the production accessor, not the SSHD_INSTALL_PROBE_CMD copy below,
|
||||
// so removing the yum branch fails THIS test rather than only the withCmd verify.
|
||||
String script = Ec2ContainerManager.sshdInstallProbeCommand()[2];
|
||||
|
||||
assertTrue(script.contains("command -v yum"), script);
|
||||
// The yum branch installs the client package alongside the server, exactly as the dnf
|
||||
// branch does -- an AL2 guest needs scp for the same reason every other guest does.
|
||||
assertTrue(script.contains("yum install -y openssh-server openssh-clients"), script);
|
||||
// dnf must still win where both exist (Amazon Linux 2023, modern Fedora/RHEL), where
|
||||
// yum is only a compatibility shim over dnf.
|
||||
assertTrue(script.indexOf("command -v dnf") < script.indexOf("command -v yum"),
|
||||
"dnf must be probed before yum");
|
||||
}
|
||||
|
||||
@Test
|
||||
void metadataProxyInstallCommandHandlesYumForAmazonLinux2() {
|
||||
// The IMDS proxy dependency install had the same gap, and unlike the sshd probe it
|
||||
// ends in an explicit failure: on an ami-amazonlinux2 instance it reached the else
|
||||
// branch and exited 1 with "No supported package manager found for IMDS proxy
|
||||
// dependencies", leaving the instance without a link-local metadata endpoint.
|
||||
String script = Ec2ContainerManager.metadataProxyInstallCommand()[2];
|
||||
|
||||
assertTrue(script.contains("command -v yum"), script);
|
||||
assertTrue(script.contains("yum install -y iproute socat curl ca-certificates"), script);
|
||||
}
|
||||
|
||||
@Test
|
||||
void metadataProxyStartCommandBindsAwsLinkLocalMetadataAddress() {
|
||||
String[] command = Ec2ContainerManager.metadataProxyStartCommand("floci", 9169);
|
||||
@@ -577,6 +611,7 @@ class Ec2ContainerManagerTest {
|
||||
private static final String[] SSHD_INSTALL_PROBE_CMD = {"sh", "-c",
|
||||
"if ! command -v sshd >/dev/null 2>&1 || ! command -v scp >/dev/null 2>&1; then"
|
||||
+ " if command -v dnf >/dev/null 2>&1; then dnf install -y openssh-server openssh-clients >/dev/null 2>&1;"
|
||||
+ " elif command -v yum >/dev/null 2>&1; then yum install -y openssh-server openssh-clients >/dev/null 2>&1;"
|
||||
+ " elif command -v apt-get >/dev/null 2>&1; then DEBIAN_FRONTEND=noninteractive apt-get install -y openssh-server openssh-client >/dev/null 2>&1;"
|
||||
+ " elif command -v apk >/dev/null 2>&1; then apk add --no-cache openssh >/dev/null 2>&1;"
|
||||
+ " fi;"
|
||||
|
||||
Reference in new issue
Block a user