fix(images): let become work on molecule-ubuntu2604 and add gnupg
Build / build (pull_request) Successful in 30s
Molecule / molecule (pull_request) Failing after 1m4s
Lint / lint (pull_request) Successful in 1m56s

In the booted 26.04 container, pam_unix's account check for sudo runs
the unix_chkpwd helper, which fails there, so become from root fails
with "account validation failure". /etc/pam.d/sudo now lets root
through with pam_rootok before common-account; a non-root caller still
goes through pam_unix. The build fails if the line does not apply.

gnupg joins the image, as in the 24.04 image: the docker and gitea
scenarios need it on the target. The temporary diagnostics are removed.

Closes #376

Assisted-by: Claude Code
This commit is contained in:
Defame1297 committed 2026-11-25 21:42:58 +00:00
1 parent 5364f18728
commit efd3a550c5
3 files changed
+15 -26

No files matched your search

+3 -1
View File
@@ -12,7 +12,9 @@ It is the release the hosts are moving to; the roles are tested on it next to 24
`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).
`iptables`, `ufw`, `fail2ban`, `openssh-server` (the `ssh` unit is enabled), and `gnupg`
(the docker scenario signs its stand-in APT repository with it).
- 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.
@@ -33,6 +33,7 @@
- ufw
- fail2ban
- openssh-server
- gnupg
- name: Query the units a role scenario relies on
ansible.builtin.systemd:
@@ -57,27 +58,6 @@
ansible.builtin.command: iptables -S
changed_when: false
# TEMPORARY diagnostics for #376; removed before review.
- name: "DIAG #376: test the cause and the candidate fix without become"
ansible.builtin.shell: |
set -o pipefail
echo "== status: $(grep -E '^(Seccomp|Seccomp_filters|NoNewPrivs|CapEff)' /proc/self/status | tr '\t\n' ' ')"
echo "== unix_chkpwd root chkexpiry:"; /usr/sbin/unix_chkpwd root chkexpiry </dev/null; echo "rc=$?"
echo "== sudo before:"; sudo -n -u root true; echo "rc=$?"
sed -i '0,/^@include common-account/s//account sufficient pam_rootok.so\n@include common-account/' /etc/pam.d/sudo
echo "== pam.d/sudo account lines:"; grep -E '^(account|@include common-account)' /etc/pam.d/sudo
echo "== sudo after pam_rootok:"; sudo -H -S -n -u root /bin/sh -c 'echo BECOME-SUCCESS' </dev/null; echo "rc=$?"
echo "== journal:"; journalctl --no-pager -o short-iso -n 20 SYSLOG_FACILITY=10 | tail -20
args:
executable: /bin/bash
changed_when: false
failed_when: false
register: kamino_diag_376
- name: "DIAG #376: show the result"
ansible.builtin.debug:
var: kamino_diag_376.stdout_lines
- name: Run a task with become, as the role scenarios do
ansible.builtin.command: id -u
become: true
+11 -4
View File
@@ -17,7 +17,7 @@
# One RUN layer: 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). apt packages are not version-pinned, as in the original image; the
# one request; gnupg adds a few MB, not measured). apt packages are not version-pinned, as in the original image; the
# base image is pinned by digest and a rebuild is a reviewed digest bump downstream.
#
# The image carries SSH host keys and a machine-id generated at build time (the
@@ -36,7 +36,7 @@ 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)" \
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.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
@@ -44,15 +44,22 @@ 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.
# 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.
# 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 \
openssh-server \
gnupg \
&& rm -rf /var/lib/apt/lists/* \
&& systemctl enable ssh
&& systemctl enable ssh \
&& sed -i '0,/^@include common-account/s//account sufficient pam_rootok.so\n@include common-account/' /etc/pam.d/sudo \
&& grep -qx 'account sufficient pam_rootok.so' /etc/pam.d/sudo
STOPSIGNAL SIGRTMIN+3
CMD ["/sbin/init"]