From c64b4b932b233d5ed6023f85065d5a14898014a6 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Sun, 29 Nov 2026 17:39:03 +0000 Subject: [PATCH] ci(images): stop baking ufw and fail2ban into the molecule images ADR 0002 keeps a package a role installs out of the molecule images, so its scenario exercises the install. The ufw and fail2ban roles install their packages, so both images drop them; iptables, openssh-server, python3-systemd and gnupg stay as fixtures. The labels, header comments, image docs and image-smoke package lists no longer claim the packages are baked or that a converge makes no network calls. Refs: #435 Assisted-by: Claude Code --- docs/images/molecule-ubuntu2404.md | 7 +++--- docs/images/molecule-ubuntu2604.md | 7 +++--- .../molecule/image-smoke-2604/verify.yml | 4 +--- extensions/molecule/image-smoke/verify.yml | 4 +--- images/molecule-ubuntu2404/Dockerfile | 22 +++++++++---------- images/molecule-ubuntu2604/Dockerfile | 22 +++++++++---------- roles/fail2ban/README.md | 2 +- .../molecule/check-absent/prepare.yml | 4 ++-- roles/ufw/molecule/check-absent/prepare.yml | 4 ++-- 9 files changed, 35 insertions(+), 41 deletions(-) diff --git a/docs/images/molecule-ubuntu2404.md b/docs/images/molecule-ubuntu2404.md index 98e8dec..8f0a78d 100644 --- a/docs/images/molecule-ubuntu2404.md +++ b/docs/images/molecule-ubuntu2404.md @@ -11,9 +11,10 @@ It is the release the hosts run today. - systemd as the init system (`systemd`, `systemd-sysv`), D-Bus, `sudo`, `iproute2`, `ca-certificates`. - Python for Ansible on the target: `python3`, `python3-apt`, `python3-systemd`. -- The packages the roles manage, preinstalled so a converge makes no network calls: - `iptables`, `ufw`, `fail2ban`, `openssh-server` (the `ssh` unit is enabled), and `gnupg` - (the docker scenario signs its stand-in APT repository with it). +- Test fixtures no role installs: `iptables`, `openssh-server` (the `ssh` unit is enabled), and + `gnupg` (the docker scenario signs its stand-in APT repository with it). +- No package a role installs, such as `ufw` or `fail2ban`: the role's scenario exercises that + install. The APT lists are removed, so such a scenario refreshes the APT cache in its prepare. - Throwaway SSH host keys and a machine-id generated at build time. They are not secrets and the image is a test target that must never be exposed to a network. diff --git a/docs/images/molecule-ubuntu2604.md b/docs/images/molecule-ubuntu2604.md index f53f2ff..c891f15 100644 --- a/docs/images/molecule-ubuntu2604.md +++ b/docs/images/molecule-ubuntu2604.md @@ -11,9 +11,10 @@ It is the release the hosts are moving to; every role scenario whose role declar - systemd as the init system (`systemd`, `systemd-sysv`), D-Bus, `sudo`, `iproute2`, `ca-certificates`. - Python for Ansible on the target: `python3`, `python3-apt`, `python3-systemd`. -- The packages the roles manage, preinstalled so a converge makes no network calls: - `iptables`, `ufw`, `fail2ban`, `openssh-server` (the `ssh` unit is enabled), and `gnupg` - (the docker scenario signs its stand-in APT repository with it). +- Test fixtures no role installs: `iptables`, `openssh-server` (the `ssh` unit is enabled), and + `gnupg` (the docker scenario signs its stand-in APT repository with it). +- No package a role installs, such as `ufw` or `fail2ban`: the role's scenario exercises that + install. The APT lists are removed, so such a scenario refreshes the APT cache in its prepare. - root's `sudo` skips the PAM account check (`pam_rootok`), so `become` works in the container. - Throwaway SSH host keys and a machine-id generated at build time. They are not secrets and the image is a test target that must never be exposed to a network. diff --git a/extensions/molecule/image-smoke-2604/verify.yml b/extensions/molecule/image-smoke-2604/verify.yml index a45cb09..710b69a 100644 --- a/extensions/molecule/image-smoke-2604/verify.yml +++ b/extensions/molecule/image-smoke-2604/verify.yml @@ -15,7 +15,7 @@ ansible.builtin.package_facts: manager: auto - - name: The packages the roles manage are preinstalled + - name: The fixtures the scenarios need are preinstalled ansible.builtin.assert: that: item in ansible_facts['packages'] quiet: true @@ -30,8 +30,6 @@ - python3-apt - python3-systemd - iptables - - ufw - - fail2ban - openssh-server - gnupg diff --git a/extensions/molecule/image-smoke/verify.yml b/extensions/molecule/image-smoke/verify.yml index 0d9e767..89d39e1 100644 --- a/extensions/molecule/image-smoke/verify.yml +++ b/extensions/molecule/image-smoke/verify.yml @@ -15,7 +15,7 @@ ansible.builtin.package_facts: manager: auto - - name: The packages the roles manage are preinstalled + - name: The fixtures the scenarios need are preinstalled ansible.builtin.assert: that: item in ansible_facts['packages'] quiet: true @@ -30,8 +30,6 @@ - python3-apt - python3-systemd - iptables - - ufw - - fail2ban - openssh-server - gnupg diff --git a/images/molecule-ubuntu2404/Dockerfile b/images/molecule-ubuntu2404/Dockerfile index 3946f10..a0f809e 100644 --- a/images/molecule-ubuntu2404/Dockerfile +++ b/images/molecule-ubuntu2404/Dockerfile @@ -1,7 +1,7 @@ # Molecule test target for the roles of this Collection: Ubuntu 24.04 with systemd -# as PID 1 and the packages the roles manage preinstalled, so a converge makes no -# network calls. It replaces the molecule test image that used to be built locally -# on the CI runner. +# as PID 1 and the fixtures the scenarios need preinstalled. A package a role installs +# is not baked in, so its scenario exercises the install (ADR 0002). It replaces the +# molecule test image that used to be built locally on the CI runner. # # Built by .gitea/workflows/image.yml with kaniko and pushed (never on pull # requests) to git.rkdr.net/mortis/molecule-ubuntu2404. Consumers reference it @@ -14,7 +14,7 @@ # scenario starts it with command /sbin/init, cgroupns_mode host, /sys/fs/cgroup # mounted rw, tmpfs on /run and /run/lock, capability NET_ADMIN. No privileged mode. # -# One RUN layer: about 30 MB compressed on top of the 29.8 MB base (estimated from +# One RUN layer: at most about 30 MB compressed on top of the 29.8 MB base (estimated from # the real .debs, with the .pyc files the postinst scripts compile), far below # Cloudflare's 100 MB request-body limit on git.rkdr.net (kaniko pushes a layer as # one request; gnupg adds a few MB, not measured). apt packages are not version-pinned, as in the original image; the @@ -28,7 +28,7 @@ FROM ubuntu:24.04@sha256:562111b88caa79c71391c0c4d3c2114a7d5c35915c20561fd893cb1e07929e6b LABEL org.opencontainers.image.title="molecule-ubuntu2404" \ - org.opencontainers.image.description="Disposable Ubuntu 24.04 test target for the molecule scenarios of the mortis.kamino Ansible Collection. systemd runs as PID 1 with D-Bus, sudo, python3 and the packages the roles manage (iptables, ufw, fail2ban, openssh-server) preinstalled, so a converge makes no network calls. Start it as a molecule platform (usage label); it carries throwaway SSH host keys and is a test target only, never to be exposed." \ + org.opencontainers.image.description="Disposable Ubuntu 24.04 test target for the molecule scenarios of the mortis.kamino Ansible Collection. systemd runs as PID 1 with D-Bus, sudo, python3 and the test fixtures (iptables, openssh-server, gnupg) preinstalled. A package a role installs is not baked in and no APT lists are kept, so a scenario refreshes the APT cache before a role installs one. Start it as a molecule platform (usage label); it carries throwaway SSH host keys and is a test target only, never to be exposed." \ org.opencontainers.image.source="https://git.rkdr.net/mortis/kamino" \ org.opencontainers.image.url="https://git.rkdr.net/mortis/kamino" \ org.opencontainers.image.documentation="https://git.rkdr.net/mortis/kamino/src/branch/main/docs/images/molecule-ubuntu2404.md" \ @@ -36,22 +36,20 @@ LABEL org.opencontainers.image.title="molecule-ubuntu2404" \ org.opencontainers.image.authors="Defame1297 and contributors" \ org.opencontainers.image.base.name="ubuntu:24.04" \ net.rkdr.mortis.purpose="Disposable Ubuntu 24.04 test target for the molecule scenarios of the mortis.kamino Ansible Collection." \ - net.rkdr.mortis.contents="Ubuntu 24.04, systemd, systemd-sysv, dbus, sudo, iproute2, ca-certificates, python3, python3-apt, python3-systemd, iptables, ufw, fail2ban, openssh-server (ssh enabled), gnupg" \ + net.rkdr.mortis.contents="Ubuntu 24.04, systemd, systemd-sysv, dbus, sudo, iproute2, ca-certificates, python3, python3-apt, python3-systemd, iptables, openssh-server (ssh enabled), gnupg" \ net.rkdr.mortis.usage="Molecule docker-driver platform with pre_build_image true, command /sbin/init, cgroupns_mode host, /sys/fs/cgroup mounted rw, tmpfs on /run and /run/lock, capability NET_ADMIN, security_opts apparmor=unconfined (not privileged). Pin git.rkdr.net/mortis/name:version@sha256:digest. See the documentation label." ENV DEBIAN_FRONTEND=noninteractive # systemd as PID 1 with D-Bus, sudo and networking tools; the Python Ansible needs on -# the target (python3-apt for the apt module); the firewall and intrusion-prevention -# packages the roles manage (python3-systemd is a dependency of fail2ban's systemd -# backend); sshd, enabled so a converge can test it under systemd; gnupg, which the docker -# scenario signs its stand-in APT repository with and which would otherwise cost it an -# apt update and install in every run. +# the target (python3-apt for the apt module, python3-systemd for the journal); iptables; +# sshd, enabled so a converge can test it under systemd; gnupg, which the docker scenario +# signs its stand-in APT repository with. ufw and fail2ban are left out: their roles install them. RUN apt-get update \ && apt-get install -y --no-install-recommends \ systemd systemd-sysv dbus sudo iproute2 ca-certificates \ python3 python3-apt python3-systemd \ - iptables ufw fail2ban \ + iptables \ openssh-server \ gnupg \ && rm -rf /var/lib/apt/lists/* \ diff --git a/images/molecule-ubuntu2604/Dockerfile b/images/molecule-ubuntu2604/Dockerfile index b495f2d..612c939 100644 --- a/images/molecule-ubuntu2604/Dockerfile +++ b/images/molecule-ubuntu2604/Dockerfile @@ -1,7 +1,7 @@ # Molecule test target for the roles of this Collection: Ubuntu 26.04 with systemd -# as PID 1 and the packages the roles manage preinstalled, so a converge makes no -# network calls. It replaces the molecule test image that used to be built locally -# on the CI runner. +# as PID 1 and the fixtures the scenarios need preinstalled. A package a role installs +# is not baked in, so its scenario exercises the install (ADR 0002). It replaces the +# molecule test image that used to be built locally on the CI runner. # # Built by .gitea/workflows/image.yml with kaniko and pushed (never on pull # requests) to git.rkdr.net/mortis/molecule-ubuntu2604. Consumers reference it @@ -14,7 +14,7 @@ # scenario starts it with command /sbin/init, cgroupns_mode host, /sys/fs/cgroup # mounted rw, tmpfs on /run and /run/lock, capability NET_ADMIN. No privileged mode. # -# One RUN layer: about 30 MB compressed on top of the 29.8 MB base (estimated from +# One RUN layer: at most about 30 MB compressed on top of the 29.8 MB base (estimated from # the real .debs, with the .pyc files the postinst scripts compile), far below # Cloudflare's 100 MB request-body limit on git.rkdr.net (kaniko pushes a layer as # one request; gnupg adds a few MB, not measured). apt packages are not version-pinned, as in the original image; the @@ -28,7 +28,7 @@ FROM ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db LABEL org.opencontainers.image.title="molecule-ubuntu2604" \ - org.opencontainers.image.description="Disposable Ubuntu 26.04 test target for the molecule scenarios of the mortis.kamino Ansible Collection. systemd runs as PID 1 with D-Bus, sudo, python3 and the packages the roles manage (iptables, ufw, fail2ban, openssh-server) preinstalled, so a converge makes no network calls. Start it as a molecule platform (usage label); it carries throwaway SSH host keys and is a test target only, never to be exposed." \ + org.opencontainers.image.description="Disposable Ubuntu 26.04 test target for the molecule scenarios of the mortis.kamino Ansible Collection. systemd runs as PID 1 with D-Bus, sudo, python3 and the test fixtures (iptables, openssh-server, gnupg) preinstalled. A package a role installs is not baked in and no APT lists are kept, so a scenario refreshes the APT cache before a role installs one. Start it as a molecule platform (usage label); it carries throwaway SSH host keys and is a test target only, never to be exposed." \ org.opencontainers.image.source="https://git.rkdr.net/mortis/kamino" \ org.opencontainers.image.url="https://git.rkdr.net/mortis/kamino" \ org.opencontainers.image.documentation="https://git.rkdr.net/mortis/kamino/src/branch/main/docs/images/molecule-ubuntu2604.md" \ @@ -36,24 +36,22 @@ LABEL org.opencontainers.image.title="molecule-ubuntu2604" \ org.opencontainers.image.authors="Defame1297 and contributors" \ org.opencontainers.image.base.name="ubuntu:26.04" \ net.rkdr.mortis.purpose="Disposable Ubuntu 26.04 test target for the molecule scenarios of the mortis.kamino Ansible Collection." \ - net.rkdr.mortis.contents="Ubuntu 26.04, systemd, systemd-sysv, dbus, sudo, iproute2, ca-certificates, python3, python3-apt, python3-systemd, iptables, ufw, fail2ban, openssh-server (ssh enabled), gnupg" \ + net.rkdr.mortis.contents="Ubuntu 26.04, systemd, systemd-sysv, dbus, sudo, iproute2, ca-certificates, python3, python3-apt, python3-systemd, iptables, openssh-server (ssh enabled), gnupg" \ net.rkdr.mortis.usage="Molecule docker-driver platform with pre_build_image true, command /sbin/init, cgroupns_mode host, /sys/fs/cgroup mounted rw, tmpfs on /run and /run/lock, capability NET_ADMIN, security_opts apparmor=unconfined (not privileged). Pin git.rkdr.net/mortis/name:version@sha256:digest. See the documentation label." ENV DEBIAN_FRONTEND=noninteractive # systemd as PID 1 with D-Bus, sudo and networking tools; the Python Ansible needs on -# the target (python3-apt for the apt module); the firewall and intrusion-prevention -# packages the roles manage (python3-systemd is a dependency of fail2ban's systemd -# backend); sshd, enabled so a converge can test it under systemd; gnupg, which the docker -# scenario signs its stand-in APT repository with and which would otherwise cost it an -# apt update and install in every run. +# the target (python3-apt for the apt module, python3-systemd for the journal); iptables; +# sshd, enabled so a converge can test it under systemd; gnupg, which the docker scenario +# signs its stand-in APT repository with. ufw and fail2ban are left out: their roles install them. # root's sudo (Ansible's become here) skips pam_unix's account check, whose unix_chkpwd # helper fails inside the container; non-root callers still go through pam_unix. RUN apt-get update \ && apt-get install -y --no-install-recommends \ systemd systemd-sysv dbus sudo iproute2 ca-certificates \ python3 python3-apt python3-systemd \ - iptables ufw fail2ban \ + iptables \ openssh-server \ gnupg \ && rm -rf /var/lib/apt/lists/* \ diff --git a/roles/fail2ban/README.md b/roles/fail2ban/README.md index 8ce1978..e1c6aff 100644 --- a/roles/fail2ban/README.md +++ b/roles/fail2ban/README.md @@ -82,7 +82,7 @@ Main entry point: `fail2ban` (everything), `fail2ban_install`, `fail2ban_validat ## Tests -The scenario `molecule/default/` runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It runs `check` before the converge (a fresh host, where the image already has fail2ban installed) and after it (a configured host). +The scenario `molecule/default/` runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It runs `check` before the converge (a fresh host, where the role installs fail2ban) and after it (a configured host). - Converge applies the main entry point with an extra `fail2ban_ignoreip` network and calls `service_jail` twice, one jail with a `logpath` and one with a `journalmatch`. - Converge also runs inputs that must be refused: a service filter without `failregex`, and a `fail2ban_ignoreip` entry with whitespace, a plain string instead of a list, and an entry starting with `;`. The `fail2ban_ignoreip` refusals are matched on their message. diff --git a/roles/fail2ban/molecule/check-absent/prepare.yml b/roles/fail2ban/molecule/check-absent/prepare.yml index 7e599de..ffd3d9f 100644 --- a/roles/fail2ban/molecule/check-absent/prepare.yml +++ b/roles/fail2ban/molecule/check-absent/prepare.yml @@ -1,6 +1,6 @@ --- -# The image ships fail2ban and no APT lists; the check step needs fail2ban gone and the lists back, -# or the install task cannot even preview the package. +# The purge keeps the scenario independent of what the image ships. The image keeps no APT lists, +# and the check step needs them, or the install task cannot even preview the package. - name: Prepare a host without fail2ban hosts: all gather_facts: false diff --git a/roles/ufw/molecule/check-absent/prepare.yml b/roles/ufw/molecule/check-absent/prepare.yml index 6c98ec3..bea1759 100644 --- a/roles/ufw/molecule/check-absent/prepare.yml +++ b/roles/ufw/molecule/check-absent/prepare.yml @@ -1,6 +1,6 @@ --- -# The image ships ufw and no APT lists; the check step needs ufw gone and the lists back, or the -# install task cannot even preview the package. +# The purge keeps the scenario independent of what the image ships. The image keeps no APT lists, +# and the check step needs them, or the install task cannot even preview the package. - name: Prepare a host without ufw hosts: all gather_facts: false