Author SHA1 Message Date
Defame1297 d88e5d237a fix(system_baseline): persist sysctls in an own sysctl.d drop-in
Build / build (pull_request) Successful in 1m5s
Lint / lint (pull_request) Successful in 4m54s
Molecule / select (pull_request) Successful in 3s
Molecule / scenarios (pull_request) Successful in 18m54s
Molecule / Result (pull_request) Successful in 0s
systemd-sysctl on Debian 13 does not read /etc/sysctl.conf, so the
hardened values were lost on reboot. The role now applies the live values
on their own, writes them to a drop-in under /etc/sysctl.d and removes its
keys from /etc/sysctl.conf.

Refs #510

Assisted-by: Claude Code:claude-opus-5-5
2026-12-03 17:23:51 +00:00
Defame1297 cf99893855 Merge pull request 'fix(images): build when Ubuntu has upgraded a base package' (#509) from fix/images-base-upgrade into main
Images / image (0.1, Dockerfile, ubuntu:24.04@sha256:168a88cc61bdd95c8f871e3903d4e0a525e340c2b28a70dadd6d1503ecc7c391, molecule-ubuntu2404, images/molecule-ubuntu2404) (push) Successful in 2m55s
Images / image (0.1, Dockerfile, ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd, molecule-ubuntu2604, images/molecule-ubuntu2604) (push) Successful in 3m19s
Images / image (0.1, images/molecule-controller/Dockerfile, ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd, molecule-controller, ) (push) Successful in 3m54s
Images / image (0.2, images/ci/Dockerfile, ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd, ci, ) (push) Successful in 6m12s
Reviewed-on: #509
Reviewed-by: Defame1297 <[email protected]>
2026-12-03 16:44:00 +00:00
Defame1297 508ed5ce12 docs(images): name the leftover check in the setup step comment
Build / build (pull_request) Successful in 22s
Molecule / select (pull_request) Successful in 2s
Molecule / scenarios (pull_request) Skipped
Molecule / Result (pull_request) Successful in 0s
Lint / lint (pull_request) Successful in 2m14s
The check compares package names and unowned files now, not a pristine
filesystem.

Assisted-by: Claude Code
2026-12-03 08:38:26 +00:00
Defame1297 9127ac565a fix(images): build when Ubuntu upgrades a base package
Installing the job container's tools upgrades base packages once Ubuntu
has newer ones, and the purge does not downgrade them, so the version
check failed every image. Kaniko now empties the root filesystem and
unpacks the base image before its first snapshot (--pre-cleanup), so the
versions no longer matter. Extra packages and files no package owns
still fail the job.

With the filesystem emptied, a failed build can leave no rm for the last
step, so the build step empties the credential file itself.

The images also kept the base image's package versions. Each Dockerfile
now upgrades them, and the base digests move to the newest published.

Refs #508

Assisted-by: Claude Code
2026-12-03 08:30:16 +00:00
Defame1297 e446e1e09a Merge pull request 'ci: follow-ups after moving Molecule to the molecule-controller image' (#506) from ci/505-controller-followups into main
Images / image (0.1, Dockerfile, ubuntu:24.04@sha256:562111b88caa79c71391c0c4d3c2114a7d5c35915c20561fd893cb1e07929e6b, molecule-ubuntu2404, images/molecule-ubuntu2404) (push) Failing after 13s
Images / image (0.1, Dockerfile, ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db, molecule-ubuntu2604, images/molecule-ubuntu2604) (push) Failing after 16s
Images / image (0.1, images/molecule-controller/Dockerfile, ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db, molecule-controller, ) (push) Failing after 14s
Images / image (0.2, images/ci/Dockerfile, ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db, ci, ) (push) Failing after 13s
Reviewed-on: #506
2026-12-03 08:11:51 +00:00
Defame1297 2f5a997dd7 Merge remote-tracking branch 'origin/main' into ci/505-controller-followups
Build / build (pull_request) Successful in 24s
Molecule / select (pull_request) Successful in 5s
Lint / lint (pull_request) Successful in 2m57s
Molecule / scenarios (pull_request) Successful in 35m31s
Molecule / Result (pull_request) Successful in 1s
# Conflicts:
#	requirements-dev.lock
2026-12-02 09:47:21 +00:00
Defame1297 8497af3407 Merge pull request 'chore(deps): update own ci images' (#504) from renovate/own-ci-images into main
Reviewed-on: #504
2026-12-02 09:29:37 +00:00
Defame1297 22f5bc33e9 chore: correct comments the ci image change left stale
Build / build (pull_request) Successful in 28s
Molecule / select (pull_request) Successful in 12s
Lint / lint (pull_request) Successful in 3m0s
Molecule / Result (pull_request) Canceled after 0s
Molecule / scenarios (pull_request) Canceled after 18m22s
image.yml's push paths listed extensions/molecule/requirements.yml under
the ci image, which no longer bakes it; it now sits with the
molecule-controller files. The list only triggers the build, so the paths
are unchanged. requirements-dev.txt no longer feeds Molecule, so the
proxmoxer comment names lint only. The ufw probe comments now say the
probe's stdout is empty in check mode, in two lines each, and two lines
in lint.yml and the workflow rules are re-wrapped.

Assisted-by: Claude Code
2026-12-02 09:26:03 +00:00
Defame1297 a48cd063ea fix(ci): treat only a NAME_UNKNOWN 404 as an image with no tags
next_image_version.py read any 404 on the first tags/list page as a
repository not pushed yet, so a wrong registry path or a proxy's 404 page
would restart the image at <base>.0 instead of failing. The OCI
distribution spec answers a missing repository with 404 and the error
code NAME_UNKNOWN, so only that answer now means no tags.

RegistryError carried only the readable text of the body, so it now also
carries the body's OCI error codes. The tests cover a plain 404 page and a
404 with another code, both of which now raise.

Assisted-by: Claude Code
2026-12-02 08:51:21 +00:00
Defame1297 6fee0ea8b2 fix(ufw): detect check mode without a command's skipped result
The probes in install.yml, orphan_rules.yml, service_rules.yml and
sysctl.yml took a skipped `command` task as the sign of check mode.
ansible-core 2.22 deprecates that: command.py marks its check-mode
`r['skipped'] = True` for removal in 2.25, and the 2.22 changelog says
"Returning skipped from a module or action plugin is deprecated and will be
removed in ansible-core 2.25". The probe would then report ok, and the role
would delete rules and edit sysctl.conf under --check.

The probe now runs `echo ran` and reads its output: a command does not run
in check mode, under --check or the check_mode keyword, so the output is
empty there. Checked against ansible-core 2.22 and a copy with the skipped
return removed, in a normal play, a check_mode play and --check.
service_rules.yml had the same probe and is changed with the others.

Assisted-by: Claude Code
2026-12-02 08:44:38 +00:00
Defame1297 39ec8e5b3c build(ci): drop molecule's Docker driver and community.docker from the ci image
Molecule runs in the molecule-controller image. In the ci image, only
Lint's "Test the repository scripts" step uses molecule:
test_check_scenarios_load_checkout.py runs check_scenarios_load_checkout.py,
which imports molecule's config lookup, and test_run_molecule_scenarios.py
expands platform names with molecule's interpolator. Both skip silently
without molecule, so molecule stays, with a comment naming the step.

Nothing in Lint or Build uses the Docker driver (molecule-plugins[docker])
or the docker SDK it pulls in: those tests use molecule's default driver
and a stub docker module. No linted file calls a community.docker module,
and a local clone, which never installs extensions/molecule/requirements.yml,
passes ansible-lint. So the driver, docker, selinux and community.docker
leave the ci image, and extensions/molecule/requirements.yml leaves its
pin record: a community.docker bump no longer publishes a ci version.

The lock is regenerated with scripts/lock-requirements.sh. Every script
test passes, none skipped, in a venv installed from the new lock.

Assisted-by: Claude Code
2026-12-02 08:43:39 +00:00
Defame1297 3414880d05 ci(molecule): rename the run script after the molecule-controller image
scripts/run_molecule_in_ci_image.sh runs inside the molecule-controller
image, not the ci image, so its name pointed readers at the wrong image.
Its test file and class follow, and every reference is updated. ADR 0003
keeps the old name: it records what that change touched.

main's selector sees the old and the new path (it diffs with
--no-renames) and neither is on IGNORED, so this pull request runs every
scenario through the renamed script of its own checkout.

Assisted-by: Claude Code
2026-12-02 08:27:57 +00:00
Defame1297 08c589e910 docs(requirements): name the molecule-controller image as Molecule's consumer
Molecule runs in the molecule-controller image, which bakes these
collections, and the run script installs them when a pull request changes
them. The header still said the ci image served Molecule and that the
workflow installed them itself.

Assisted-by: Claude Code
2026-12-02 08:21:41 +00:00
46 changed files with 441 additions and 159 deletions

No files matched your search

+4 -4
View File
@@ -53,8 +53,8 @@ issue.
- **Lint and Build run in the pinned `ci` image and compare the pin files with the checksums
baked into it (`/opt/ci-pins.sha256`).** A pull request that changes `requirements-dev.txt`,
`requirements-dev.lock`, `requirements.yml`, `extensions/molecule/requirements.yml` or
`.pre-commit-config.yaml` takes the slow path, which installs the pinned tools and collections.
`requirements-dev.lock`, `requirements.yml` or `.pre-commit-config.yaml` takes the slow path,
which installs the pinned tools and collections.
*Why:* a pull request is tested on its own pins, and an unchanged one starts in seconds.
*Held:* control: the "Check the baked tooling against the pins" step.
- **On the fast path the network is cut by environment**: `PIP_NO_INDEX=1`, the proxy variables
@@ -109,7 +109,7 @@ issue.
(release versions, `build_ignore`) do not change what a scenario runs, and the Build check
proves the collection builds; they had caused about a third of full pull request runs and their
minutes (#338). *Held:* control: `scripts/check_scenarios_load_checkout.py`, which
`run_molecule_in_ci_image.sh` runs on the selected scenarios before they start, fails the run
`run_molecule_in_controller.sh` runs on the selected scenarios before they start, fails the run
when the environment molecule gives `ansible-playbook` resolves `mortis.kamino` anywhere else,
or when `prerun` is not off once the base config is merged as molecule's CLI merges it (a
scenario turns it on, or the base config is moved or turns it on).
@@ -148,7 +148,7 @@ issue.
`requirements-molecule.lock` selects every scenario; `requirements-dev.*` pins only Lint's tools
and selects none. *Why:* a pull request that bumps ansible-core or molecule must run its
scenarios on them before it automerges. *Held:* control: the pin comparison in
`run_molecule_in_ci_image.sh`, and the selector's tests for which pin files select what.
`run_molecule_in_controller.sh`, and the selector's tests for which pin files select what.
- **Every scenario sets `scenario.test_sequence` to molecule's default minus both `destroy`
steps, with a role scenario's `check` right before and right after `converge`, names each
platform `${KAMINO_RUN_ID:-local}-<name>` and labels it
+2 -2
View File
@@ -66,8 +66,8 @@ jobs:
HTTP_PROXY=http://127.0.0.1:9 HTTPS_PROXY=http://127.0.0.1:9 no_proxy= NO_PROXY= >> "$GITHUB_ENV"
echo "::notice::Later steps run with a dead proxy; a download fails the job (bake it into images/ci)."
else
echo "::warning::requirements-dev.txt, requirements-dev.lock, requirements.yml," \
"extensions/molecule/requirements.yml or .pre-commit-config.yaml differ from the ci image;" \
echo "::warning::requirements-dev.txt, requirements-dev.lock, requirements.yml" \
"or .pre-commit-config.yaml differ from the ci image;" \
"installing the pinned tools for this run."
/opt/venv/bin/pip install --quiet --require-hashes -r requirements-dev.lock -r requirements-dev.txt
fi
+30 -32
View File
@@ -39,15 +39,15 @@ on: # yamllint disable-line rule:truthy
- main
paths:
- 'images/**'
# The ci image bakes these files' contents in (images/ci/Dockerfile).
# The ci image bakes these files' contents in (images/ci/Dockerfile); requirements.yml too.
- 'requirements-dev.txt'
- 'requirements-dev.lock'
- 'requirements.yml'
- 'extensions/molecule/requirements.yml'
- '.pre-commit-config.yaml'
# The molecule-controller image bakes these (images/molecule-controller/Dockerfile).
# The molecule-controller image bakes these, and requirements.yml (its Dockerfile).
- 'requirements-molecule.txt'
- 'requirements-molecule.lock'
- 'extensions/molecule/requirements.yml'
- '.gitea/workflows/image.yml'
workflow_dispatch: {}
@@ -83,22 +83,22 @@ jobs:
base: "0.1"
subpath: images/molecule-ubuntu2404
dockerfile: Dockerfile
job_image: ubuntu:24.04@sha256:562111b88caa79c71391c0c4d3c2114a7d5c35915c20561fd893cb1e07929e6b
job_image: ubuntu:24.04@sha256:168a88cc61bdd95c8f871e3903d4e0a525e340c2b28a70dadd6d1503ecc7c391
- name: molecule-ubuntu2604
base: "0.1"
subpath: images/molecule-ubuntu2604
dockerfile: Dockerfile
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
job_image: ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd
- name: ci
base: "0.2"
subpath: ""
dockerfile: images/ci/Dockerfile
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
job_image: ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd
- name: molecule-controller
base: "0.1"
subpath: ""
dockerfile: images/molecule-controller/Dockerfile
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
job_image: ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd
container:
image: ${{ matrix.job_image }}
# Keeps a runaway build from taking the whole runner down with it.
@@ -107,21 +107,17 @@ jobs:
DEBIAN_FRONTEND: noninteractive
IMAGE_PATH: mortis/${{ matrix.name }}
steps:
# One step, in this order, so the filesystem the build starts from is the pristine
# base image. Kaniko unpacks the base image into the job container's own root
# filesystem and snapshots from there, so anything installed in the job container
# first (curl and its libraries) would count as "already present" and be missing
# from the layers that install the same packages (ca-certificates, libkrb5 ...).
# Kaniko unpacks the base image into the job container's own root filesystem and
# snapshots from there, so anything left in it (curl and its libraries) would count
# as "already present" and be missing from the layers that install the same packages.
# The build's --pre-cleanup empties that filesystem first; this step also cleans up
# after itself, so a leftover fails the job instead of relying on that flag alone.
# The tools are therefore installed, used, and exactly the packages the install
# added are purged (not `autoremove`, which would also drop base packages that
# are marked auto-installed). The result is compared with what was recorded
# before the install: the package names and versions must be identical, and any
# file difference under /usr, /lib, /bin, /sbin, /opt or /etc fails the job.
# Names only, no sizes or modes, and /var/log, /run and dpkg's *-old files are
# not compared: logs and dpkg state the install touched may end up in the first
# layer as modified files. That is cosmetic. Not yet checked: listing the layers
# (crane export | tar t, looking for run/act, root/ and var/log/apt) needs a
# read:package token, which the Claude token lacks.
# are marked auto-installed). The package names must then equal those recorded before
# the install, and a new file under /usr, /lib, /bin, /sbin, /opt or /etc that no
# package owns fails the job. Versions may differ: the install upgrades a base package
# when Ubuntu has a newer one, and the build starts from the base image's copy again.
#
# The pinned kaniko v1.28.6 image has index digest
# sha256:2fa20b0a4b40c7db72b479d57e55c2cf79f2178533b2d3bcbd129d6bd3c087ed and
@@ -163,7 +159,6 @@ jobs:
snapshot > /kaniko/fs.before
pkgs() { dpkg-query -W -f='${Package}:${Architecture}\n' | LC_ALL=C sort; }
pkgs > /kaniko/pkgs.before
dpkg-query -W -f='${Package}:${Architecture} ${Version}\n' | LC_ALL=C sort > /kaniko/pkgv.before
apt-get update
apt-get install -y --no-install-recommends ca-certificates curl python3
@@ -173,7 +168,7 @@ jobs:
printf 'header = "Authorization: token %s"\n' "$JOB_TOKEN" \
| curl -fsSL -K - "${SERVER_URL}/api/v1/repos/${REPO}/archive/${SHA}.tar.gz" \
| tar -xz -C /tmp/src --strip-components=1
# -B: no bytecode left behind to break the pristine-filesystem check below.
# -B: no bytecode left behind to break the leftover check below.
env -u PAT_USER -u PAT_TOKEN -u JOB_TOKEN python3 -B -E -s \
/tmp/src/scripts/next_image_version.py /tmp/src "$IMAGE_NAME" "$SERVER_URL" > /kaniko/image-version
if [ -s /kaniko/image-version ]; then
@@ -243,25 +238,24 @@ jobs:
fi
fi
# Back to the pristine base image (see above): purge exactly what the install
# added, then compare packages (names and versions) and files with the record.
# Purge exactly what the install added, then compare packages and files with the record (see above).
pkgs > /kaniko/pkgs.installed
comm -13 /kaniko/pkgs.before /kaniko/pkgs.installed | xargs apt-get purge -y
apt-get clean
rm -rf /var/lib/apt/lists/* /tmp/*
dpkg-query -W -f='${Package}:${Architecture} ${Version}\n' | LC_ALL=C sort > /kaniko/pkgv.after
if ! diff /kaniko/pkgv.before /kaniko/pkgv.after; then
echo "::error::The installed packages differ from the pristine base image (listed above): the install" \
"upgraded or left packages behind, so the build would start from a modified filesystem."
pkgs > /kaniko/pkgs.after
if ! diff /kaniko/pkgs.before /kaniko/pkgs.after; then
echo "::error::The installed packages are not those of the base image (differences above)."
exit 1
fi
snapshot > /kaniko/fs.after
diff /kaniko/fs.before /kaniko/fs.after > /kaniko/fs.diff || true
if grep -E '^[<>] /(usr|lib|bin|sbin|opt|etc)/' /kaniko/fs.diff; then
echo "::error::The job container differs from the pristine base image (listed above); the build would produce wrong layers."
comm -13 /kaniko/fs.before /kaniko/fs.after > /kaniko/fs.new
# dpkg -S fails on a path no package owns; an upgraded base package may bring new files of its own.
if ! sed -nE '\#^/(usr|lib|bin|sbin|opt|etc)/#p' /kaniko/fs.new | xargs -r -d '\n' dpkg -S > /dev/null; then
echo "::error::The install left files behind that no package owns (listed above)."
exit 1
fi
echo "Package and filesystem check passed ($(grep -c '^[<>]' /kaniko/fs.diff || true) unrelated file differences outside the checked directories)"
echo "Package and filesystem check passed"
- name: Build and push with kaniko
env:
@@ -279,6 +273,9 @@ jobs:
set +x
set -eu
export DOCKER_CONFIG=/kaniko/.docker
# A build that fails right after --pre-cleanup leaves no rm for the last step, so empty the
# credential file with a shell builtin.
trap '{ : > "$DOCKER_CONFIG/config.json"; } 2> /dev/null || true' EXIT
# The CA bundle from the kaniko image: the base image has none.
export SSL_CERT_DIR=/kaniko/ssl/certs
registry="${SERVER_URL#https://}"
@@ -331,6 +328,7 @@ jobs:
"${ctx[@]}" \
"${dests[@]}" \
"${labels[@]}" \
--pre-cleanup \
--snapshot-mode=redo \
--cache=false \
--push-retry 3 \
+4 -4
View File
@@ -6,8 +6,8 @@ name: Lint
# The tools come from the ci image (images/ci, built by image.yml): the pinned Python
# tools of requirements-dev.txt, the collections of requirements.yml and the hook
# environments of .pre-commit-config.yaml are baked in. When a PR changes one of those
# files or extensions/molecule/requirements.yml the checksum check below fails and the
# job installs the pinned tools and collections itself for this run (slower, same result).
# files the checksum check below fails and the job installs the pinned tools and
# collections itself for this run (slower, same result).
on: # yamllint disable-line rule:truthy
pull_request:
branches:
@@ -65,8 +65,8 @@ jobs:
HTTP_PROXY=http://127.0.0.1:9 HTTPS_PROXY=http://127.0.0.1:9 no_proxy= NO_PROXY= >> "$GITHUB_ENV"
echo "::notice::Later steps run with a dead proxy; a download fails the job (bake it into images/ci)."
else
echo "::warning::requirements-dev.txt, requirements-dev.lock, requirements.yml," \
"extensions/molecule/requirements.yml or .pre-commit-config.yaml differ from the ci image;" \
echo "::warning::requirements-dev.txt, requirements-dev.lock, requirements.yml" \
"or .pre-commit-config.yaml differ from the ci image;" \
"installing the pinned tools and collections for this run."
/opt/venv/bin/pip install --quiet --require-hashes -r requirements-dev.lock -r requirements-dev.txt
# --force: the baked copy of a changed pin is replaced, not kept as "already installed".
+1 -1
View File
@@ -220,7 +220,7 @@ jobs:
-v "$ac_root:$ac_root" -v "$ac_root/passwd:/etc/passwd:ro" -w "$PWD" \
-e "AC_ROOT=$ac_root" -e "HOME=$ac_root/home" -e "USER=$(id -un)" \
-e MOLECULE_IMAGE -e MOLECULE_IMAGE_2604 -e KAMINO_RUN_ID -e MOLECULE_LANES \
"$CONTROLLER_IMAGE" scripts/run_molecule_in_ci_image.sh <<< "$SELECTED"
"$CONTROLLER_IMAGE" scripts/run_molecule_in_controller.sh <<< "$SELECTED"
# A cancelled run can leave its containers running when the docker client is killed.
- name: Remove this run's containers
@@ -0,0 +1,5 @@
---
trivial:
- >-
ufw - The check-mode probes read whether a command ran instead of whether it was skipped, which
ansible-core 2.25 stops reporting for a command in check mode.
@@ -0,0 +1,6 @@
---
bugfixes:
- >-
system_baseline - The sysctl hardening survives a reboot on Debian 13, where ``systemd-sysctl`` no longer reads
``/etc/sysctl.conf``. The role now writes its values to ``/etc/sysctl.d/99-zz-system-baseline.conf`` and removes its
keys from ``/etc/sysctl.conf``, so the first run reports ``changed`` once.
@@ -0,0 +1,4 @@
---
minor_changes:
- >-
system_baseline - New input ``system_baseline_sysctl_file``, the path of the drop-in that persists the sysctl hardening.
+7 -8
View File
@@ -10,13 +10,12 @@ runs in the [`molecule-controller`](molecule-controller.md) image instead
Ubuntu 26.04 with:
- **Python tools** in `/opt/venv` (on `PATH`; it runs on Python 3.14, the version of `.python-version`, from the baked copy and not from the distribution's `python3`), from `requirements-dev.lock` (the hashed lock of `requirements-dev.txt`, installed with `pip install --require-hashes`): `ansible-core`,
`ansible-lint`, `pre-commit`, `antsibull-changelog`, `galaxy-importer`, `reuse`, `molecule` and
`molecule-plugins[docker]` (the Docker driver, with the `docker` Python SDK), and `proxmoxer`, the controller-side
library the modules of `community.proxmox` import.
`ansible-lint`, `pre-commit`, `antsibull-changelog`, `galaxy-importer`, `reuse`, `molecule`
(without its Docker driver: Lint's "Test the repository scripts" step runs the tests that import it), and
`proxmoxer`, the controller-side library the modules of `community.proxmox` import.
- **The collections the roles call** in `/opt/collections` (`ANSIBLE_COLLECTIONS_PATH` is set to it), from
`requirements.yml`: `community.general`, `ansible.posix` and `community.proxmox` at the exact versions CI tests against, so
`ansible-lint --offline` resolves their modules instead of mocking them; and from
`extensions/molecule/requirements.yml`, `community.docker`, which the Molecule Docker driver's own playbooks call.
`ansible-lint --offline` resolves their modules instead of mocking them.
- **Every pre-commit hook environment** of `.pre-commit-config.yaml` in `/opt/pre-commit`
(`PRE_COMMIT_HOME`): conventional-pre-commit, gitleaks, yamllint, ruff, shellcheck-py, pre-commit-hooks, actionlint and zizmor. The Go
hooks are prebuilt; their toolchains, and the binaries of those repositories that no hook runs, are removed to
@@ -28,7 +27,7 @@ Ubuntu 26.04 with:
`python3`, so sanity runs its compile test for those interpreters instead of skipping it.
- `git`, `shellcheck` (actionlint runs it over `run:` blocks), `python3`, `python3-venv` and `ca-certificates`.
The image runs as root and sets no working directory.
- `/opt/ci-pins.sha256`: the checksums of the five pin files this image was built from.
- `/opt/ci-pins.sha256`: the checksums of the four pin files this image was built from.
It has no Node, so JavaScript actions (`actions/checkout`) cannot run in it: clone with `git`.
@@ -61,8 +60,8 @@ jobs:
pre-commit run --all-files --show-diff-on-failure
```
`/opt/ci-pins.sha256` lists the five pin files by their checkout-relative path, so `sha256sum -c` runs in the checkout root. When
the checkout's `requirements-dev.txt`, `requirements-dev.lock`, `requirements.yml`, `extensions/molecule/requirements.yml` and `.pre-commit-config.yaml` match, the baked tools and
`/opt/ci-pins.sha256` lists the four pin files by their checkout-relative path, so `sha256sum -c` runs in the checkout root. When
the checkout's `requirements-dev.txt`, `requirements-dev.lock`, `requirements.yml` and `.pre-commit-config.yaml` match, the baked tools and
collections are used as they are, and Lint and Build cut the network by environment (proxy variables and
`PIP_NO_INDEX`) for all but the script tests, so a tool that downloads at run time fails the job. When a pull request changes a pin the check fails and the job installs the pinned
tools and collections itself for that run
+1 -1
View File
@@ -33,7 +33,7 @@ checkout). In the checkout root, run `sha256sum --quiet -c /opt/molecule-pins.sh
and collections for that run first (slower, same result), until the image is rebuilt from `main`.
`.gitea/workflows/molecule.yml` is its consumer: it pins the image as `CONTROLLER_IMAGE`, and
`scripts/run_molecule_in_ci_image.sh` runs the pin check inside it. Read the workflow for the full command.
`scripts/run_molecule_in_controller.sh` runs the pin check inside it. Read the workflow for the full command.
## Tags and pinning
+2 -1
View File
@@ -7,7 +7,8 @@ It is the release the hosts run today.
## What is in it
- Ubuntu 24.04 (the official `ubuntu:24.04` image, pinned by digest in the Dockerfile).
- Ubuntu 24.04 (the official `ubuntu:24.04` image, pinned by digest in the Dockerfile, with its packages
upgraded when the image is built).
- 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`.
+2 -1
View File
@@ -7,7 +7,8 @@ It is the release the hosts are moving to; every role scenario whose role declar
## What is in it
- Ubuntu 26.04 (the official `ubuntu:26.04` image, pinned by digest in the Dockerfile).
- Ubuntu 26.04 (the official `ubuntu:26.04` image, pinned by digest in the Dockerfile, with its packages
upgraded when the image is built).
- 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`.
+2 -2
View File
@@ -2,8 +2,8 @@
# Collections the Molecule test harness itself calls, as opposed to the roles under test (those are
# in the requirements.yml at the repository root). The Docker driver of molecule-plugins runs
# community.docker modules in its own create and destroy playbooks, so every scenario needs it.
# The ci image (images/ci) bakes it into /opt/collections next to the root one; a pull request that
# changes it fails the image's pin check, so the Molecule job installs it itself.
# The molecule-controller image (images/molecule-controller) bakes it into /opt/collections next to the
# root one; a pull request that changes it fails the image's pin check, so the Molecule job installs it itself.
# Renovate (renovate.json, ansible-galaxy manager) bumps this pin.
collections:
- name: community.docker
+2
View File
@@ -65,6 +65,8 @@ it to this repository's organisation in the Gitea registry as `<version>` and `l
the fast path Lint and Build cut the network by environment, so a download through pip or a
proxy-honouring client fails the job; review for a raw socket, for the script tests, which keep
network, and for Molecule.
- **Each Dockerfile upgrades the base image's packages in its first apt layer.** *Why:* Ubuntu
publishes package updates before it refreshes the base image. *Held:* review.
- **Recorded speed:** a speed optimisation that adds machinery states its measured saving where
it lives (a comment next to it). *Why:* machinery is kept only for a saving someone can check.
*Held:* review.
+15 -19
View File
@@ -13,12 +13,13 @@
# - OS packages: git, shellcheck (actionlint runs it over run: blocks), the
# distribution's python3 and ca-certificates.
# - /opt/venv: requirements-dev.lock, the hashed lock of requirements-dev.txt (ansible-core, ansible-lint, pre-commit,
# antsibull-changelog, galaxy-importer, reuse, molecule and its Docker driver, proxmoxer), on the Python of
# antsibull-changelog, galaxy-importer, reuse, molecule, proxmoxer), on the Python of
# .python-version (PYTHON_VERSION below), the one the lock was resolved on and a clone's .venv uses.
# molecule is there for Lint's "Test the repository scripts" step, whose molecule tests import it; its
# Docker driver and community.docker are not: Molecule runs in the molecule-controller image.
# - /opt/collections: the collections of requirements.yml (the versions the roles are
# tested against), found through ANSIBLE_COLLECTIONS_PATH, so `ansible-lint --offline`
# resolves their modules without a mock list; and those of extensions/molecule/requirements.yml
# (community.docker), which the Molecule Docker driver's own playbooks call.
# resolves their modules without a mock list.
# - /opt/pre-commit: every hook environment of .pre-commit-config.yaml, installed by
# `pre-commit install-hooks` (gitleaks and actionlint are built from source by
# pre-commit, which downloads a Go toolchain: that is most of the time saved).
@@ -27,8 +28,8 @@
# - Python 3.11, 3.13 and PYTHON_VERSION as python<MINOR> on PATH, so that
# `ansible-test sanity` runs its compile test for them instead of skipping it.
# They come from python-build-standalone through uv, pinned by the uv version.
# - /opt/ci-pins.sha256: the checksums of requirements-dev.txt, requirements-dev.lock, requirements.yml,
# extensions/molecule/requirements.yml and .pre-commit-config.yaml this image was built from. A job runs
# - /opt/ci-pins.sha256: the checksums of requirements-dev.txt, requirements-dev.lock, requirements.yml
# and .pre-commit-config.yaml this image was built from. A job runs
# `sha256sum -c /opt/ci-pins.sha256` in its checkout; when a pull request changes a
# pin the check fails and the job installs the tools as before, until the image
# is rebuilt from main.
@@ -36,15 +37,16 @@
# Layers: each COPY / RUN below is one layer, and a layer is pushed as one request,
# so it must stay below Cloudflare's 100 MB request-body limit on git.rkdr.net. The
# build stage prints the sizes it will copy; the first push is the real test.
# Base image: ubuntu:26.04 index digest as of 2026-10-26, same as molecule-ubuntu2604.
# Base image: ubuntu:26.04 index digest as of 2026-12-03, same as molecule-ubuntu2604.
FROM ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db AS os
FROM ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd AS os
ENV DEBIAN_FRONTEND=noninteractive
# No python3-pip: tools are installed with the venv's own pip. python3-venv brings
# ensurepip. apt lists are removed in the same layer.
# ensurepip. The upgrade brings in updates newer than the base image. apt lists are removed in the same layer.
RUN apt-get update \
&& apt-get upgrade -y --with-new-pkgs --no-install-recommends \
&& apt-get install -y --no-install-recommends \
ca-certificates git python3 python3-venv shellcheck \
&& rm -rf /var/lib/apt/lists/*
@@ -66,8 +68,6 @@ ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \
WORKDIR /src
COPY requirements-dev.txt requirements-dev.lock requirements.yml .pre-commit-config.yaml ./
# Kept at its checkout path: its name matches the root requirements.yml.
COPY extensions/molecule/requirements.yml extensions/molecule/
# The interpreters come first: /opt/venv is built from the pinned one (PYTHON_VERSION, kept equal to
# .python-version and to the lock header by `check_image_versions.py pins`), not from the distribution's
@@ -99,13 +99,11 @@ RUN "$(echo /opt/python/cpython-${PYTHON_VERSION}.*/bin/python${PYTHON_VERSION})
&& /opt/venv/bin/python --version \
&& /opt/venv/bin/pip install --require-hashes -r requirements-dev.lock -r requirements-dev.txt
# The collections of requirements.yml and extensions/molecule/requirements.yml. ANSIBLE_COLLECTIONS_PATH is set to the target for the
# The collections of requirements.yml. ANSIBLE_COLLECTIONS_PATH is set to the target for the
# install only: a collection found anywhere else on the path would be skipped as "already
# installed" and not copied here.
RUN ANSIBLE_COLLECTIONS_PATH=/opt/collections \
/opt/venv/bin/ansible-galaxy collection install -r requirements.yml -p /opt/collections \
&& ANSIBLE_COLLECTIONS_PATH=/opt/collections \
/opt/venv/bin/ansible-galaxy collection install -r extensions/molecule/requirements.yml -p /opt/collections \
&& du -sh /opt/collections
# pre-commit needs a git repository to resolve a config. The hook repositories are
@@ -178,7 +176,7 @@ FROM os AS final
ARG PYTHON_VERSION=3.14
LABEL org.opencontainers.image.title="ci" \
org.opencontainers.image.description="CI tooling image for the mortis.kamino Ansible Collection: the Lint and Build workflows run in it, so a job only checks out the code and runs; Molecule runs in the molecule-controller image. It bakes in ansible-core, ansible-lint, pre-commit with every hook environment of the repository, antsibull-changelog, galaxy-importer, reuse, molecule with its Docker driver, proxmoxer, the collections of requirements.yml and extensions/molecule/requirements.yml, git, shellcheck, Python 3.11, 3.13 and the version of .python-version (the tools in /opt/venv run on it) next to the distribution python3 and primed ansible-test sanity virtualenvs. Pin it by tag and digest, as a job container or with docker run; it has no Node, so clone with git." \
org.opencontainers.image.description="CI tooling image for the mortis.kamino Ansible Collection: the Lint and Build workflows run in it, so a job only checks out the code and runs; Molecule runs in the molecule-controller image. It bakes in ansible-core, ansible-lint, pre-commit with every hook environment of the repository, antsibull-changelog, galaxy-importer, reuse, molecule (for the script tests), proxmoxer, the collections of requirements.yml, git, shellcheck, Python 3.11, 3.13 and the version of .python-version (the tools in /opt/venv run on it) next to the distribution python3 and primed ansible-test sanity virtualenvs. Pin it by tag and digest, as a job container or with docker run; it has no Node, so clone with git." \
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/ci.md" \
@@ -186,7 +184,7 @@ LABEL org.opencontainers.image.title="ci" \
org.opencontainers.image.authors="Defame1297 and contributors" \
org.opencontainers.image.base.name="ubuntu:26.04" \
net.rkdr.mortis.purpose="CI tooling image for the mortis.kamino Ansible Collection: the Lint and Build workflows run in it, so a job only checks out the code and runs." \
net.rkdr.mortis.contents="Ubuntu 26.04, /opt/venv (ansible-core, ansible-lint, pre-commit, antsibull-changelog, galaxy-importer, reuse, molecule, molecule-plugins[docker], proxmoxer), /opt/collections (community.general, ansible.posix, community.proxmox, community.docker), /opt/pre-commit hook environments, ansible-test sanity venvs, python3 (distribution), python3.11, python3.13, python<PYTHON_VERSION> (the one of /opt/venv), git, shellcheck, /opt/ci-pins.sha256" \
net.rkdr.mortis.contents="Ubuntu 26.04, /opt/venv (ansible-core, ansible-lint, pre-commit, antsibull-changelog, galaxy-importer, reuse, molecule, proxmoxer), /opt/collections (community.general, ansible.posix, community.proxmox), /opt/pre-commit hook environments, ansible-test sanity venvs, python3 (distribution), python3.11, python3.13, python<PYTHON_VERSION> (the one of /opt/venv), git, shellcheck, /opt/ci-pins.sha256" \
net.rkdr.mortis.usage="Lint and Build: job container on the kamino-docker runner, git.rkdr.net/mortis/ci:version@sha256:digest with PRE_COMMIT_HOME set to /opt/pre-commit. Run sha256sum -c /opt/ci-pins.sha256 in the checkout root and install the pinned tools and collections when a pull request changed them, else use /opt/venv/bin and ANSIBLE_COLLECTIONS_PATH=/opt/collections. See the documentation label."
ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \
@@ -203,16 +201,14 @@ COPY --from=build /root/.ansible/test /root/.ansible/test
# The target interpreters ansible-test looks for on PATH, and the pin record.
COPY --from=build /src/requirements-dev.txt /src/requirements-dev.lock /src/requirements.yml /src/.pre-commit-config.yaml /opt/ci-pins/
# Under its checkout path, so `sha256sum -c` in a checkout root finds it.
COPY --from=build /src/extensions/molecule/requirements.yml /opt/ci-pins/extensions/molecule/
RUN set -eu; \
for v in $(printf '%s\n' 3.11 3.13 "${PYTHON_VERSION}" | sort -u); do \
ln -sf "$(echo /opt/python/cpython-${v}.*/bin/python${v})" "/usr/local/bin/python${v}"; \
"python${v}" --version; \
done; \
cd /opt/ci-pins; \
sha256sum requirements-dev.txt requirements-dev.lock requirements.yml extensions/molecule/requirements.yml \
.pre-commit-config.yaml > /opt/ci-pins.sha256; \
sha256sum requirements-dev.txt requirements-dev.lock requirements.yml .pre-commit-config.yaml \
> /opt/ci-pins.sha256; \
ansible --version | head -n1; \
ansible-galaxy collection list; \
pre-commit --version; \
+3 -2
View File
@@ -24,14 +24,15 @@
# stay below Cloudflare's 100 MB request-body limit on git.rkdr.net. The build stage prints the
# compressed size of each directory it copies.
FROM ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db AS os
FROM ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd AS os
ENV DEBIAN_FRONTEND=noninteractive
# python3 and python3-venv only bootstrap uv in the build stage; ca-certificates serve the
# install a job runs when a pull request changes a pin; git lets the selector diff the checkout.
# apt lists are removed in the same layer.
# The upgrade brings in updates newer than the base image. apt lists are removed in the same layer.
RUN apt-get update \
&& apt-get upgrade -y --with-new-pkgs --no-install-recommends \
&& apt-get install -y --no-install-recommends ca-certificates git python3 python3-venv \
&& rm -rf /var/lib/apt/lists/*
+6 -3
View File
@@ -17,15 +17,16 @@
# 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
# one request; gnupg adds a few MB, not measured, and the upgraded base packages about 4 MB).
# 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
# openssh-server and systemd postinst scripts). ssh.service runs `sshd -t` and
# fails without host keys, so they cannot be removed; image scanners will flag them.
# They are throwaway keys of a test target that is never exposed.
# ubuntu:24.04 index digest as of 2026-10-24 (24.04.5).
FROM ubuntu:24.04@sha256:562111b88caa79c71391c0c4d3c2114a7d5c35915c20561fd893cb1e07929e6b
# ubuntu:24.04 index digest as of 2026-12-03.
FROM ubuntu:24.04@sha256:168a88cc61bdd95c8f871e3903d4e0a525e340c2b28a70dadd6d1503ecc7c391
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 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." \
@@ -41,11 +42,13 @@ LABEL org.opencontainers.image.title="molecule-ubuntu2404" \
ENV DEBIAN_FRONTEND=noninteractive
# The upgrade brings in updates newer than the base image.
# systemd as PID 1 with D-Bus, sudo and networking tools; the Python Ansible needs on
# 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 upgrade -y --with-new-pkgs --no-install-recommends \
&& apt-get install -y --no-install-recommends \
systemd systemd-sysv dbus sudo iproute2 ca-certificates \
python3 python3-apt python3-systemd \
+6 -3
View File
@@ -17,15 +17,16 @@
# 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
# one request; gnupg adds a few MB, not measured, and the upgraded base packages about 4 MB).
# 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
# openssh-server and systemd postinst scripts). ssh.service runs `sshd -t` and
# fails without host keys, so they cannot be removed; image scanners will flag them.
# They are throwaway keys of a test target that is never exposed.
# ubuntu:26.04 index digest as of 2026-10-26.
FROM ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
# ubuntu:26.04 index digest as of 2026-12-03.
FROM ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd
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 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." \
@@ -41,6 +42,7 @@ LABEL org.opencontainers.image.title="molecule-ubuntu2604" \
ENV DEBIAN_FRONTEND=noninteractive
# The upgrade brings in updates newer than the base image.
# systemd as PID 1 with D-Bus, sudo and networking tools; the Python Ansible needs on
# 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
@@ -48,6 +50,7 @@ ENV DEBIAN_FRONTEND=noninteractive
# 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 upgrade -y --with-new-pkgs --no-install-recommends \
&& apt-get install -y --no-install-recommends \
systemd systemd-sysv dbus sudo iproute2 ca-certificates \
python3 python3-apt python3-systemd \
+1 -20
View File
@@ -687,11 +687,6 @@ distro==1.9.0 \
# via
# ansible-lint
# bindep
# selinux
docker==7.2.0 \
--hash=sha256:a3f45fdeb9165e2d25d9a1d02ddf3bc70fb572cf5ebbf9b58558c22caf29b71f \
--hash=sha256:cebb93773d334f778e023a7ee352a8d6e13ab1bd3b863a4d4a59dec897df43ac
# via molecule-plugins
docutils==0.23 \
--hash=sha256:25d013af9bf23bc1c7b2b093dff4208166c53a94786c9e447808335ef1185fea \
--hash=sha256:746f5060322511280a1e50eb76846ed6bf2342984b2ac04dc42caa1a8d78799e
@@ -1207,12 +1202,6 @@ mdurl==0.1.2 \
molecule==26.11.1 \
--hash=sha256:34035f2852f1c0461539051ec1dd2398492c1e4f370ba507b81a781f322e4147 \
--hash=sha256:dcd147fb60bb66c060e0bf6a3eaa18f34433a18254a6f56f25ac254fb7980f64
# via
# -r requirements-dev.txt
# molecule-plugins
molecule-plugins==26.11.0 \
--hash=sha256:194be2c43d950545cc699ab19f1a55b26853809e6e8c855ea1a42edacf5c7ee7 \
--hash=sha256:513808288b7027c465b124e66a2a31002c7c907b2fea9002f63ee90bb2d0ef84
# via -r requirements-dev.txt
multidict==7.2.1 \
--hash=sha256:02009b402129a73e1f3da68f48eb999afbacd29f25aef0d5052b84ff5c2786a2 \
@@ -1969,9 +1958,7 @@ requests==2.34.2 \
# via
# apm-cli
# azure-core
# docker
# galaxy-importer
# molecule-plugins
resolvelib==1.2.1 \
--hash=sha256:7d08a2022f6e16ce405d60b68c390f054efcfd0477d4b9bd019cc941c28fad1c \
--hash=sha256:fb06b66c8da04172d9e72a21d7d06186d8919e32ae5ab5cdf5b9d920be805ac2
@@ -2139,10 +2126,6 @@ ruamel-yaml==0.19.1 \
# via
# ansible-lint
# apm-cli
selinux==0.3.0 \
--hash=sha256:2a88b337ac46ad0f06f557b2806c3df62421972f766673dd8bf26732fb75a9ea \
--hash=sha256:ecf7add45c939e9dda682c390a2cd0a845c94a4793a2cce9e8870d4ee9501f99
# via molecule-plugins
semantic-version==2.10.0 \
--hash=sha256:bdabb6d336998cbb378d4b9db3a4b56a1e3235701dc05ea2690d9a997ed5041c \
--hash=sha256:de78a3b8e0feda74cabc54aab2da702113e33ac9d9eb9d2389bcf1f58b7d9177
@@ -2223,9 +2206,7 @@ tzdata==2026.6 \
urllib3==2.8.0 \
--hash=sha256:0cf3cae568d36aa9576b28dfb35f11328f1cb974ca7647d9475ebb86c75ac6e3 \
--hash=sha256:63bf2ead4c879426ebf22ef2a781eeb4aa3b4ae798a0435506f8687fd5bb9b63
# via
# docker
# requests
# via requests
virtualenv==21.15.14 \
--hash=sha256:6c6e7aaf88064767c75c32a9df92eaa425cee5db4cc21caf031a78d89375d57f \
--hash=sha256:816503d7826a2269abc03f7f0dd48ffd3b63db1958a7a3cbeea5a70dd7fe0ff1
+4 -3
View File
@@ -1,4 +1,4 @@
# Pinned tooling for lint, build and Molecule, used by CI (.gitea/workflows) and locally:
# Pinned tooling for Lint and Build, used by CI (.gitea/workflows) and locally:
# python3 -m venv .venv && . .venv/bin/activate && pip install --require-hashes -r requirements-dev.lock -r requirements-dev.txt
# This file holds the direct pins; requirements-dev.lock is their hashed lock (every transitive
# package too, with the sha256 of each release file) and is what gets installed; pip refuses an
@@ -12,10 +12,11 @@ pre-commit==4.7.0
antsibull-changelog==0.38.0
galaxy-importer==0.4.45
reuse==6.3.0
# molecule without its Docker driver: Lint's "Test the repository scripts" step imports it in
# test_check_scenarios_load_checkout.py and test_run_molecule_scenarios.py, which skip without it.
molecule==26.11.1
molecule-plugins[docker]==26.11.0
# proxmoxer: the controller-side library community.proxmox's modules import (they refuse anything below 2.3),
# so lint and Molecule run where a consumer's controller would.
# so lint runs where a consumer's controller would.
proxmoxer==2.3.0
# apm-cli: for changing apm.yml (run apm install, commit the lock). Keep it at 0.36.1 or later (#252):
# before 0.29.0, `apm audit --ci` compares the whole .claude/settings.json and fails on any hand-written key.
+3 -2
View File
@@ -2,8 +2,9 @@
# Collections the roles of this Collection call (the dependencies of galaxy.yml, pinned exactly).
# galaxy.yml holds the lower bounds a consumer needs; this file holds the versions CI tests
# against. One file feeds every consumer, so they cannot drift apart:
# - the ci image (images/ci/Dockerfile) bakes it into /opt/collections for Lint and Molecule;
# - the Molecule job (.gitea/workflows/molecule.yml) installs it itself when a pull request changes it;
# - the ci image (images/ci/Dockerfile) bakes it into /opt/collections for Lint;
# - the molecule-controller image (images/molecule-controller/Dockerfile) bakes it for Molecule,
# and scripts/run_molecule_in_controller.sh installs it itself when a pull request changes it;
# - scripts/dev-setup.sh installs it into .ansible/collections for local lint.
# Renovate (renovate.json, ansible-galaxy manager) bumps these pins.
collections:
+16 -3
View File
@@ -15,7 +15,7 @@ The role targets Ubuntu guests (the `ubuntu_lxc` and `ubuntu_vm` profiles) and P
- Facts must be gathered (`gather_facts: true`); `reboot.yml` reads `ansible_facts['os_family']`.
- `system_baseline_system_type` is required and has no default (the role does not read a global such as `system_type`; map it in the inventory). Valid values: `ubuntu_lxc`, `ubuntu_vm` or `pve`.
- Use it by its fully qualified name, `mortis.kamino.system_baseline`.
- Collections: `community.general` (locale, timezone) and `ansible.posix` (sysctl, mount).
- Collections: `community.general` (locale, timezone) and `ansible.posix` (mount).
- Run it after the roles that manage users and SSH, and before the roles that harden services and manage firewalls and jails. A firewall role that rewrites sysctl values (ufw re-applies its stock `/etc/ufw/sysctl.conf` when it is enabled) must run after this role and needs the same values as this role's `sysctl_hardening` to keep them.
- Role dependencies: none.
@@ -44,6 +44,7 @@ templating error instead of the role's own message.
| `system_baseline_unattended_upgrade_origins` | from profile | no | Pinned `Origins-Pattern` entries; `[]` keeps the distribution default (see below) |
| `system_baseline_unattended_upgrade_package_blacklist` | `[]` | no | Packages unattended-upgrades must not touch, as regular expressions (see below) |
| `system_baseline_sysctl_hardening` | from profile | no | List of `name` and `value` sysctl pairs |
| `system_baseline_sysctl_file` | `/etc/sysctl.d/99-zz-system-baseline.conf` | no | Drop-in that persists the sysctl pairs: a `.conf` file directly under `/etc/sysctl.d` (see "Sysctl hardening") |
| `system_baseline_secure_tmp_mounts` | from profile | no | Paths remounted as tmpfs with `noexec,nosuid,nodev` |
| `system_baseline_journal_max_use` | `200M` | no | Upper bound of the persistent journal (journald `SystemMaxUse`): a number with an optional upper-case `B`, `K`, `M`, `G`, `T`, `P` or `E`, such as `1.5G`; a bare number is bytes. journald does not take `infinity`. Empty leaves the host alone and removes nothing a former run wrote (see "Leaving journald alone") |
| `system_baseline_tmux_autostart` | `false` | no | Attach interactive SSH logins to a tmux session (`ubuntu_lxc` and `ubuntu_vm` only) |
@@ -129,18 +130,19 @@ The two task files besides `main` are a supported interface, for a caller that d
The scenario `molecule/default/` runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It installs packages from the Ubuntu mirrors, so the runner needs outbound network. It runs `check` before the converge (a fresh host) and after it (a configured host).
- Verify first checks, on the controller, that the role refuses a bad input with its own message before any change: an unknown `system_baseline_system_type`, an unknown `system_baseline_apt_upgrade` (main flow and `update` entry point), a negative reboot throttle or a negative or boolean post-reboot delay (main flow and `reboot` entry point), a line break in `system_baseline_apt_daily_timeout`, a bad `system_baseline_journal_max_use` (`infinity`, a lower-case unit, a unit with a trailing `B`, a line break, a number), and a bad package blacklist (a quote, a null item, a bare string).
- Verify first checks, on the controller, that the role refuses a bad input with its own message before any change: an unknown `system_baseline_system_type`, an unknown `system_baseline_apt_upgrade` (main flow and `update` entry point), a negative reboot throttle or a negative or boolean post-reboot delay (main flow and `reboot` entry point), a line break in `system_baseline_apt_daily_timeout`, a bad `system_baseline_journal_max_use` (`infinity`, a lower-case unit, a unit with a trailing `B`, a line break, a number), a bad `system_baseline_sysctl_file` (`/etc/sysctl.conf`, `99-sysctl.conf`, a path with `..`, a name without `.conf`, empty), and a bad package blacklist (a quote, a null item, a bare string).
- Converge applies the `ubuntu_lxc` profile, with tmux autostart and `system_baseline_apt_daily_timeout: 1h`. Verify only resolves the `pve` and `ubuntu_vm` profiles and a consumer override, on the controller, asserting the resolved inputs.
- Verify checks the installed and removed packages, the journal size cap, the apt settings in `20auto-upgrades` and `50unattended-upgrades`, the locale, and that systemd loaded the `apt-daily.service` timeout.
- Verify checks the tmux snippet: root-owned, valid shell, the session and quoted window command, no effect without a terminal, a session name or window command ending in a newline refused, and the file removed when autostart is off.
- Verify refuses bad items in `system_baseline_extra_packages` and `system_baseline_extra_remove_packages` (whitespace, a null, an empty string, a trailing minus, upper case, a bare string) and a package that one input installs and another purges; converge applies the `ubuntu_lxc` profile with `jq` as an extra package and `ed` as an extra removal; verify checks that `jq` is installed, `ed` is gone and the profile's packages are still there, and that an extra `tmux` installs the snippet where a flat list without it installs none.
- Verify also checks that a bad `system_baseline_apt_tmpdir` (under `/tmp` or `/var/tmp`, relative, with `..`, empty) is refused in the main flow and in the `update` entry point. It reads `tasks/update.yml` and checks that the scratch directory is created with mode `0700`, that both apt tasks set `TMPDIR` to it, that the connection is reset afterwards, and that the vzdump guard is imported before the upgrade, whose `when` reads the guard's fact: the scenario skips the `update` tag, so the upgrade itself never runs there.
- Verify runs the vzdump guard in check mode on the Ubuntu container with `system_baseline_system_type: pve` and a `pvesh` stub, in seven cases (a running, a finished or no vzdump task, the input off, `ubuntu_lxc`); six run the guard's task file alone and the `ubuntu_lxc` case runs the whole `update` entry point. Each case asserts the fact that decides the upgrade and that `pvesh` was run, with `--source active`, only when it should be. It does not assert that the apt task itself was skipped. The stub stands for the real answer, which no CI image has.
- Prepare seeds `/etc/sysctl.conf` with keys of the role and other lines. Verify checks that the drop-in holds exactly the profile's keys, that only the role's keys left `/etc/sysctl.conf`, that a key removed from the list leaves the drop-in and that a missing `/etc/sysctl.conf` is not created. It runs the runtime apply on the container's read-only `/proc/sys`: no change for the live value, a reported change in check mode and a failure for a value that cannot be set.
- Verify ends by running the role once with `system_baseline_journal_max_use: ""` after removing the drop-in, and asserts that no drop-in is written and that `systemd-journald` was not restarted.
- Verify runs the `reboot` entry point with `system_baseline_reboot_if_required: false`, without and with `/var/run/reboot-required`, and checks the fact and that the host did not reboot.
- The `pve` origins pin is applied to the Ubuntu container and read back with `apt-config dump`, then removed again. The package blacklist is written, read back as a list, left alone by a second run and removed by an empty list.
Not covered: Molecule skips `sysctl`, `secure_tmp`, `update` and `timezone` (no privileged container); see `molecule/default/molecule.yml`. So `system_baseline_update` is checked only for its default; the skip itself is not exercised by a test. No host reboots, and the `pve` profile is not converged: Debian 13 is not verified by a test.
Not covered: Molecule skips the sysctl runtime apply in the role run, `secure_tmp`, `update` and `timezone` (no privileged container); see `molecule/default/molecule.yml`. So `system_baseline_update` is checked only for its default; the skip itself is not exercised by a test. No test writes a live sysctl value or reboots to see `systemd-sysctl` load the drop-in. No host reboots, and the `pve` profile is not converged: Debian 13 is not verified by a test.
## Notes
@@ -228,6 +230,17 @@ An upgrade of a Proxmox node can restart Proxmox services while a backup holds a
`system_baseline_journal_max_use: ""` skips the journald task: no drop-in directory, no `50-system-baseline.conf` and no restart of `systemd-journald`. Use it where another drop-in, role or policy owns the journal size. A file an earlier run wrote stays, as for an empty `system_baseline_apt_daily_timeout`; remove it by hand if the cap should go. A value that is not empty and not a size journald reads (`infinity`, `10m`, one with a line break) stops the run before any change, in the same way as the apt-daily value.
### Sysctl hardening
The role sets each pair of `system_baseline_sysctl_hardening` on the running kernel when the live value differs, then writes the list to `system_baseline_sysctl_file`, which `systemd-sysctl` loads at boot. A value that cannot be set stops the run before the file is written. `--tags sysctl` does both.
- The role owns the whole drop-in: a key removed from the list leaves the file, and its live value stays until the next reboot. When the list repeats a key, the last entry wins.
- At boot the last file that sets a key wins, in the order of the file names. The default sorts after `99-sysctl.conf`, but a name that starts with a letter loads later: for example Proxmox VE's `/usr/lib/sysctl.d/pve-firewall.conf`, which sets `net.ipv4.conf.all.rp_filter`. To override such a file, choose a name that sorts after it.
- Changing `system_baseline_sysctl_file` does not remove the old file, which is still loaded at boot; remove it by hand.
- The keys of the list are removed from `/etc/sysctl.conf`, where earlier releases of the role wrote them. Other lines stay, including a key that had already been dropped from the list.
- ufw applies its own `/etc/ufw/sysctl.conf` when it starts and can override values such as `net.ipv4.conf.all.log_martians`. Set the same values there (`ufw_sysctl_overrides` of the `ufw` role).
- A container may not run `systemd-sysctl` at boot (the unit is skipped when `/proc/sys` is read-only). The values then apply only when the role runs.
### Apt scratch directory
The upgrade runs over the SSH connection Ansible uses. An `openssh-server` upgrade restarts `ssh.service`, and a unit with `PrivateTmp=yes` (the `systemd_hardening` role sets it) has its own `/tmp` and `/var/tmp`, which systemd deletes when the unit stops. The files apt staged there for the running upgrade then disappear and dpkg fails, leaving packages unpacked but not configured. So the `update` flow creates `system_baseline_apt_tmpdir` (root, mode `0700`), runs the upgrade and the autoremove with `TMPDIR` set to it, and opens a new connection afterwards, so that later tasks get a fresh private `/tmp`.
+7
View File
@@ -24,6 +24,9 @@ system_baseline_skip_upgrade_during_vzdump: false
# Upper bound of the persistent journal (journald SystemMaxUse); older archived files are removed above it. Empty leaves the host alone
# (tasks/journald.yml is not run; a drop-in an earlier run wrote stays).
system_baseline_journal_max_use: 200M
# Drop-in that persists the sysctl hardening (tasks/sysctl.yml). The last file that sets a key wins at boot, so the name sorts after
# 99-sysctl.conf. A file whose name starts with a letter still loads later.
system_baseline_sysctl_file: /etc/sysctl.d/99-zz-system-baseline.conf
# Attach an interactive SSH login to a tmux session (see tasks/tmux.yml). Off by default: it changes what every login does.
# Installed only when tmux is among the packages to install: the ubuntu_lxc and ubuntu_vm profiles have it, the pve profile has none unless
# system_baseline_extra_packages adds it.
@@ -276,4 +279,8 @@ system_baseline_unattended_upgrade_origins: "{{ system_baseline_profile.unattend
# package blacklist"). Entries are regular expressions matched against the package name.
system_baseline_unattended_upgrade_package_blacklist: []
system_baseline_sysctl_hardening: "{{ system_baseline_profile.sysctl_hardening }}"
# What the role acts on, as {name: value}. Internal. The last entry of a repeated key wins, and a boolean word becomes the number sysctl takes.
__system_baseline_sysctl: >-
{{ dict(system_baseline_sysctl_hardening | map(attribute='name') | zip(system_baseline_sysctl_hardening | map(attribute='value') | map('string')
| map('regex_replace', '(?i)^(y|yes|on|t|true)$', '1') | map('regex_replace', '(?i)^(n|no|off|f|false)$', '0'))) }}
system_baseline_secure_tmp_mounts: "{{ system_baseline_profile.secure_tmp_mounts }}"
@@ -60,6 +60,15 @@ argument_specs:
is bytes); anything else (C(infinity), a lower-case unit, a line break) is refused before any change. Empty leaves the host
alone: no drop-in is written and journald is not restarted.
Clearing the value later does not remove a file already written.
system_baseline_sysctl_file:
type: str
default: /etc/sysctl.d/99-zz-system-baseline.conf
description:
- >-
Drop-in that persists C(system_baseline_sysctl_hardening) across reboots. The role owns the whole file. It must be a C(.conf)
file directly under C(/etc/sysctl.d), other than C(99-sysctl.conf); anything else is refused before any change.
- The last file that sets a key wins at boot, in the order of the file names; a name that starts with a letter sorts after the default.
- Changing the value later does not remove the old file.
system_baseline_tmux_autostart:
type: bool
default: false
@@ -45,9 +45,9 @@ platforms:
provisioner:
name: ansible
options:
# sysctl and tmpfs mounts need a privileged container; a full upgrade adds only
# time; the timezone needs timedatectl. The rest of the role runs for real.
skip-tags: molecule-notest,notest,sysctl,secure_tmp,update,timezone
# Applying sysctls (molecule-notest) and tmpfs mounts need a privileged container; a full upgrade
# adds only time; the timezone needs timedatectl. The rest of the role runs for real.
skip-tags: molecule-notest,notest,secure_tmp,update,timezone
verifier:
name: ansible
scenario:
@@ -1,14 +1,15 @@
---
# A package the role must remove, and the locales tool the role assumes exists
# (it does on a stock Ubuntu host). jq (system_baseline_extra_packages) must be absent, so that the role is what installs it, and ed
# (system_baseline_extra_remove_packages, on no profile list) must be present, so that the role is what purges it.
# (system_baseline_extra_remove_packages, on no profile list) must be present, so that the role is what purges it. procps has the sysctl
# command verify needs.
- name: Prepare
hosts: all
gather_facts: false
tasks:
- name: Install a package on the role's remove list and locale-gen
- name: Install packages the role removes and tools it assumes
ansible.builtin.apt:
name: [telnet, locales, ed]
name: [telnet, locales, ed, procps]
state: present
update_cache: true
@@ -16,3 +17,13 @@
ansible.builtin.apt:
name: jq
state: absent
- name: Seed /etc/sysctl.conf with keys of the role and lines it must leave alone
ansible.builtin.copy:
dest: /etc/sysctl.conf
mode: "0644"
content: |
# net.ipv4.tcp_syncookies=1
net.ipv4.tcp_syncookies=1
vm.max_map_count = 262144
net.ipv4.conf.all.accept_redirects = 0
@@ -0,0 +1,18 @@
---
# One refusal: the role must stop on validation, before it changes anything, with a message that names the variable.
- name: Run the role with a bad system_baseline_sysctl_file
block:
- name: Include system_baseline
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
vars:
system_baseline_system_type: ubuntu_lxc
system_baseline_sysctl_file: "{{ system_baseline_refused_sysctl_file }}"
- name: Unreachable when validation works
ansible.builtin.fail:
msg: system_baseline ran with an invalid system_baseline_sysctl_file
rescue:
- name: The validation stopped the play
ansible.builtin.assert:
that: "'system_baseline_sysctl_file must be' in ansible_failed_result.msg | default('')"
quiet: true
@@ -151,6 +151,25 @@
- "200M\nStorage=none"
- 300
# The role overwrites the whole drop-in: /etc/sysctl.conf, the link to it, another directory and a name systemd-sysctl does not read
# each stop the run before any change.
- name: A bad sysctl drop-in path is refused
hosts: localhost
connection: local
check_mode: true
gather_facts: false
tasks:
- name: Refuse each bad value
ansible.builtin.include_tasks: tasks/refuse_sysctl_file.yml
vars:
system_baseline_refused_sysctl_file: "{{ item }}"
loop:
- /etc/sysctl.conf
- /etc/sysctl.d/99-sysctl.conf
- /etc/sysctl.d/../sysctl.conf
- /etc/sysctl.d/baseline
- ""
# A quote, a null item and a bare string (not a list) each stop the run: the bare string would otherwise be split into one-character
# patterns, and the null item would become an empty pattern that matches every package.
- name: A bad package blacklist is refused
@@ -818,6 +837,123 @@
- {type: pve, input: false, running: false, asked: false, answer: [{type: vzdump, upid: a, starttime: 1}]}
- {type: ubuntu_lxc, input: true, running: false, asked: false, answer: [{type: vzdump, upid: a, starttime: 1}], tasks_from: update}
# The converge persisted the ubuntu_lxc list and cleaned /etc/sysctl.conf. The rest runs the task files directly: persisting a shorter list
# without /etc/sysctl.conf, then the runtime apply against the container's read-only /proc/sys.
- name: The sysctl hardening is persisted in its own drop-in
hosts: all
gather_facts: false
vars:
system_baseline_system_type: ubuntu_lxc
tasks:
- name: Read the drop-in and /etc/sysctl.conf
ansible.builtin.command:
argv: [cat, "{{ item }}"]
loop:
- /etc/sysctl.d/99-zz-system-baseline.conf
- /etc/sysctl.conf
register: system_baseline_verify_sysctl
changed_when: false
- name: The drop-in holds the profile's keys and only they left /etc/sysctl.conf
ansible.builtin.assert:
that:
- system_baseline_verify_sysctl.results[0].stdout_lines | reject('match', '#') | list == system_baseline_verify_sysctl_expected
- system_baseline_verify_sysctl.results[1].stdout_lines == ['# net.ipv4.tcp_syncookies=1', 'vm.max_map_count = 262144']
quiet: true
vars:
system_baseline_verify_sysctl_expected:
- net.ipv4.tcp_syncookies=1
- net.ipv4.conf.all.accept_source_route=0
- net.ipv4.conf.all.accept_redirects=0
- net.ipv4.conf.all.secure_redirects=0
- net.ipv4.icmp_echo_ignore_broadcasts=1
- net.ipv4.icmp_ignore_bogus_error_responses=1
- name: Remove /etc/sysctl.conf
ansible.builtin.file:
path: /etc/sysctl.conf
state: absent
- name: Persist a list that repeats one key
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
tasks_from: sysctl
vars:
system_baseline_sysctl_hardening:
- { name: net.ipv4.tcp_syncookies, value: 0 }
- { name: net.ipv4.tcp_syncookies, value: "yes" }
- name: Read the drop-in again
ansible.builtin.command:
argv: [cat, /etc/sysctl.d/99-zz-system-baseline.conf]
register: system_baseline_verify_sysctl_short
changed_when: false
- name: Stat /etc/sysctl.conf
ansible.builtin.stat:
path: /etc/sysctl.conf
register: system_baseline_verify_sysctl_conf
- name: Only the last entry is left and /etc/sysctl.conf was not created
ansible.builtin.assert:
that:
- system_baseline_verify_sysctl_short.stdout_lines | reject('match', '#') | list == ['net.ipv4.tcp_syncookies=1']
- not system_baseline_verify_sysctl_conf.stat.exists
quiet: true
- name: Read a live value
ansible.builtin.command:
argv: [cat, /proc/sys/net/ipv4/tcp_syncookies]
register: system_baseline_verify_sysctl_live
changed_when: false
- name: Apply the value the kernel already has
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
tasks_from: sysctl_apply
vars:
system_baseline_sysctl_hardening:
- { name: net.ipv4.tcp_syncookies, value: "{{ system_baseline_verify_sysctl_live.stdout }}" }
- name: Nothing was applied
ansible.builtin.assert:
that: __system_baseline_sysctl_apply is not changed
quiet: true
- name: Preview a different value in check mode
check_mode: true
block:
- name: Include system_baseline, tasks_from sysctl_apply
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
tasks_from: sysctl_apply
vars:
system_baseline_sysctl_hardening:
- { name: net.ipv4.tcp_syncookies, value: "{{ 1 - system_baseline_verify_sysctl_live.stdout | int }}" }
- name: The pending change is reported
ansible.builtin.assert:
that: __system_baseline_sysctl_apply is changed
quiet: true
- name: Apply a value that cannot be set
block:
- name: Include system_baseline, tasks_from sysctl_apply
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
tasks_from: sysctl_apply
vars:
system_baseline_sysctl_hardening:
- { name: net.ipv4.tcp_syncookies, value: "{{ 1 - system_baseline_verify_sysctl_live.stdout | int }}" }
- name: Unreachable when a refused value fails
ansible.builtin.fail:
msg: system_baseline ignored a sysctl that could not be set
rescue:
- name: The refused write stopped the play
ansible.builtin.assert:
that: ansible_failed_task.name is search('Apply the sysctl hardening settings')
quiet: true
# An empty system_baseline_journal_max_use leaves journald alone: with the drop-in gone, the role neither writes it again nor restarts
# systemd-journald. It runs last, because it applies the role with its defaults (the converge's tmux autostart and apt-daily timeout are
# not set here) and the checks above read what the converge wrote.
+6 -1
View File
@@ -38,7 +38,12 @@
when: system_baseline_apt_daily_timeout | length > 0
tags: apt-daily-timeout
- name: Harden sysctl
# Applied first, so a value the kernel refuses stops the run before it is persisted. molecule's containers have a read-only /proc/sys.
- name: Apply the sysctl hardening
ansible.builtin.import_tasks: sysctl_apply.yml
tags: [sysctl, molecule-notest]
- name: Persist the sysctl hardening
ansible.builtin.import_tasks: sysctl.yml
tags: sysctl
+17 -7
View File
@@ -1,9 +1,19 @@
---
- name: Apply sysctl hardening settings
ansible.posix.sysctl:
name: "{{ item.name }}"
value: "{{ item.value }}"
sysctl_set: true
reload: true
loop: "{{ system_baseline_sysctl_hardening }}"
# Values persist in the role's own drop-in: systemd-sysctl does not read /etc/sysctl.conf on every supported release.
- name: Persist the sysctl hardening settings
ansible.builtin.template:
src: sysctl.conf.j2
dest: "{{ system_baseline_sysctl_file }}"
owner: root
group: root
mode: "0644"
become: true
# Not ansible.posix.sysctl, which rewrites every other line of the file. A missing file is left missing.
- name: Remove the role's keys from /etc/sysctl.conf
ansible.builtin.lineinfile:
path: /etc/sysctl.conf
regexp: '^\s*{{ item | regex_escape }}\s*='
state: absent
loop: "{{ __system_baseline_sysctl.keys() | list }}"
become: true
@@ -0,0 +1,30 @@
---
# Not ansible.posix.sysctl, which always manages a file too. The absolute path is for a PATH without the sbin directories.
# A key that cannot be read (unknown or write-only) counts as different, so the write below decides.
- name: Read the live sysctl values
ansible.builtin.command:
argv: [/usr/sbin/sysctl, -e, -n, "{{ item.key }}"]
loop: "{{ __system_baseline_sysctl | dict2items }}"
register: __system_baseline_sysctl_live
changed_when: false
failed_when: false
check_mode: false
become: true
# `removes` names a path that always exists: with it, check mode reports the pending write as changed instead of skipping the command.
# sysctl exits 0 for a read-only key and only warns (`setting key ...`), so stderr counts too.
- name: Apply the sysctl hardening settings
ansible.builtin.command:
argv: [/usr/sbin/sysctl, -w, "{{ item.item.key }}={{ item.item.value }}"]
removes: /proc/sys
environment:
LC_ALL: C
loop: "{{ __system_baseline_sysctl_live.results }}"
loop_control:
label: "{{ item.item.key }}={{ item.item.value }}"
when: item.stdout | default('') | split != item.item.value | split
register: __system_baseline_sysctl_apply
failed_when: >-
__system_baseline_sysctl_apply.rc | default(0) != 0
or __system_baseline_sysctl_apply.stderr | default('') is search('setting key')
become: true
+12
View File
@@ -62,6 +62,18 @@
quiet: true
tags: always
# The role owns the whole file, and systemd-sysctl reads only *.conf. 99-sysctl.conf can be the distribution's link to /etc/sysctl.conf.
- name: Validate the sysctl drop-in path
ansible.builtin.assert:
that:
- system_baseline_sysctl_file is match('^/etc/sysctl\.d/[A-Za-z0-9_][A-Za-z0-9._-]*\.conf\Z')
- system_baseline_sysctl_file != '/etc/sysctl.d/99-sysctl.conf'
fail_msg: >-
system_baseline_sysctl_file must be a .conf file directly under /etc/sysctl.d (letters, digits, . _ and - in the name), other than
99-sysctl.conf.
quiet: true
tags: always
# The value is written into a unit file: one line, starting with a digit, so no line break can add a second directive. systemd itself
# refuses a value it cannot parse (it ignores the setting and logs it).
- name: Validate the apt-daily start timeout
@@ -0,0 +1,4 @@
# Managed by Ansible (mortis.kamino.system_baseline, tasks/sysctl.yml). Do not edit: the next run overwrites it.
{% for name, value in __system_baseline_sysctl.items() %}
{{ name }}={{ value }}
{% endfor %}
+1 -1
View File
@@ -45,7 +45,7 @@ There is no discovery by variable name, and a variable that looks like one fails
### `service_rules`
A service role that owns firewall rules calls the role with `include_role` and `tasks_from: service_rules` after the main entry has run, with `apply: {tags: [...]}` so `--tags <role>` reaches these tasks. The entry point installs nothing and touches no default policy, no `before.rules` and no base rule. Outside check mode (`--check` or the `check_mode` keyword; the role detects it with a skipped probe task, not `ansible_check_mode`) it fails when ufw is not installed and active. In check mode it skips the reconcile only when `ufw status` fails (ufw not installed yet, the main entry may not have reached the host); a host with ufw installed but inactive is reconciled as usual.
A service role that owns firewall rules calls the role with `include_role` and `tasks_from: service_rules` after the main entry has run, with `apply: {tags: [...]}` so `--tags <role>` reaches these tasks. The entry point installs nothing and touches no default policy, no `before.rules` and no base rule. Outside check mode (`--check` or the `check_mode` keyword; the role detects it with a probe command that does not run there, not `ansible_check_mode`) it fails when ufw is not installed and active. In check mode it skips the reconcile only when `ufw status` fails (ufw not installed yet, the main entry may not have reached the host); a host with ufw installed but inactive is reconciled as usual.
| Variable | Default | Required | Description |
|---|---|---|---|
+1 -1
View File
@@ -68,7 +68,7 @@
# svc_o2 that looks like the SSH rule, and a rule of svc_m. The managed owners below are
# the ones used above plus svc_m (listed but never called), so svc_o1 and svc_o2 are
# orphans. The cases that must change nothing run first and the purge last, so the
# idempotence run finds nothing left to delete. Under --check the role's own skipped probe
# idempotence run finds nothing left to delete. Under --check the role's own check-mode probe
# keeps the purge from deleting, and orphan_check.yml skips its counts.
- name: Report and purge the rules of unmanaged owners
hosts: all
+2 -2
View File
@@ -474,8 +474,8 @@
# apply of community.general.ufw reports changed for the would-be rule, so molecule's
# idempotence run (a second converge) would fail on it. Verify runs once, outside that count.
# The play runs under the check_mode keyword, which does not set ansible_check_mode in the
# included role; the role detects check mode with a probe task instead (a command task is
# skipped under the keyword). A present call that would add a rule and an absent call for an
# included role; the role detects check mode with a probe task instead (a command does
# not run under the keyword). A present call that would add a rule and an absent call for an
# owner that holds rules must change nothing. The two reads of the rule list are forced to
# run (check_mode: false) and compared as a whole.
- name: Check mode of service_rules changes nothing
+4 -4
View File
@@ -6,10 +6,10 @@
state: present
register: __ufw_install
# ansible_check_mode is not used: the play-level `check_mode: true` keyword does not set it inside
# include_role tasks. A command task is skipped in both forms, the same probe as tasks/sysctl.yml.
# Not ansible_check_mode, which the play-level `check_mode: true` keyword does not set in include_role
# tasks, nor `is skipped`, which ansible-core 2.25 drops: the probe's stdout is empty in check mode.
- name: Probe whether the run is in check mode
ansible.builtin.command: "true"
ansible.builtin.command: echo ran
register: __ufw_install_probe
changed_when: false
@@ -17,4 +17,4 @@
# Undefined when this file's tags are skipped; the guards then default it to true.
- name: Remember whether ufw can be configured
ansible.builtin.set_fact:
__ufw_can_configure: "{{ __ufw_install is not changed or __ufw_install_probe is not skipped }}"
__ufw_can_configure: "{{ __ufw_install is not changed or __ufw_install_probe.stdout == 'ran' }}"
+4 -5
View File
@@ -63,17 +63,16 @@
the rule tags): {{ ufw_managed_owners }}
quiet: true
# ansible_check_mode is not used: the play-level `check_mode: true` keyword does not set
# that magic variable inside include_role tasks (only --check does). A command task is
# skipped in both forms and its result says so, which is the one signal that holds for both.
# Not ansible_check_mode, which the play-level `check_mode: true` keyword does not set in include_role
# tasks, nor `is skipped`, which ansible-core 2.25 drops: the probe's stdout is empty in check mode.
- name: Probe whether the run is in check mode
ansible.builtin.command: "true"
ansible.builtin.command: echo ran
register: ufw_oa_probe
changed_when: false
- name: Remember whether the run is in check mode
ansible.builtin.set_fact:
ufw_oa_check: "{{ ufw_oa_probe is skipped }}"
ufw_oa_check: "{{ ufw_oa_probe.stdout != 'ran' }}"
- name: Read the firewall status
become: true
+4 -5
View File
@@ -121,17 +121,16 @@
- ufw_manage_rules
tags: [ufw, ufw_service_rules]
block:
# ansible_check_mode is not used: the play-level `check_mode: true` keyword does not set
# that magic variable inside include_role tasks (only --check does). A command task is
# skipped in both forms and its result says so, which is the one signal that holds for both.
# Not ansible_check_mode, which the play-level `check_mode: true` keyword does not set in include_role
# tasks, nor `is skipped`, which ansible-core 2.25 drops: the probe's stdout is empty in check mode.
- name: Probe whether the run is in check mode
ansible.builtin.command: "true"
ansible.builtin.command: echo ran
register: ufw_sr_probe
changed_when: false
- name: Remember whether the run is in check mode
ansible.builtin.set_fact:
ufw_sr_check: "{{ ufw_sr_probe is skipped }}"
ufw_sr_check: "{{ ufw_sr_probe.stdout != 'ran' }}"
- name: Read the firewall status
become: true
+4 -5
View File
@@ -7,18 +7,17 @@
check_mode: false
when: ufw_enabled and ufw_sysctl_overrides | length > 0
# ansible_check_mode is not used: the play-level `check_mode: true` keyword does not set that
# magic variable inside include_role tasks (only --check does). A command task
# is skipped in both forms and its result says so, the same probe as tasks/service_rules.yml.
# Not ansible_check_mode, which the play-level `check_mode: true` keyword does not set in include_role
# tasks, nor `is skipped`, which ansible-core 2.25 drops: the probe's stdout is empty in check mode.
- name: Probe whether the run is in check mode
ansible.builtin.command: "true"
ansible.builtin.command: echo ran
register: ufw_sysctl_probe
changed_when: false
when: ufw_enabled and ufw_sysctl_overrides | length > 0
- name: Remember whether the run is in check mode
ansible.builtin.set_fact:
ufw_sysctl_check: "{{ ufw_sysctl_probe is skipped }}"
ufw_sysctl_check: "{{ ufw_sysctl_probe.stdout != 'ran' }}"
when: ufw_enabled and ufw_sysctl_overrides | length > 0
# In check mode on a fresh host ufw is not installed yet, so the file is absent.
+16 -4
View File
@@ -70,9 +70,18 @@ USER_AGENT = "kamino-next-image-version"
class RegistryError(Exception):
def __init__(self, url, status, text, challenge=""):
def __init__(self, url, status, text, challenge="", codes=()):
super().__init__(f"GET {url}: HTTP {status}: {text}")
self.status, self.challenge = status, challenge
self.status, self.challenge, self.codes = status, challenge, codes
def _error_codes(raw):
"""The OCI error codes of an error body (`{"errors": [{"code": ...}]}`), or () for any other body."""
try:
errors = json.loads(raw).get("errors") or []
return tuple(e.get("code") for e in errors if isinstance(e, dict))
except (ValueError, AttributeError, TypeError):
return ()
def _readable(raw):
@@ -92,7 +101,9 @@ def _fetch(url, headers):
except urllib.error.HTTPError as exc:
raw = exc.read(20000).decode("utf-8", errors="replace")
challenge = exc.headers.get("WWW-Authenticate", "")
raise RegistryError(url, exc.code, _readable(raw), challenge) from exc
raise RegistryError(
url, exc.code, _readable(raw), challenge, _error_codes(raw)
) from exc
class Registry:
@@ -139,7 +150,8 @@ class Registry:
body, headers = self._get(path)
except RegistryError as exc:
# A repository not pushed yet is 404 NAME_UNKNOWN (OCI distribution spec): no tags.
if exc.status == 404 and not tags:
# Any other 404, such as a wrong registry path, must fail rather than restart at .0.
if exc.status == 404 and "NAME_UNKNOWN" in exc.codes and not tags:
return []
raise
tags += body.get("tags") or []
@@ -7,7 +7,7 @@
# writable for the runner user) and put them first, then check that the scenarios on stdin load this
# checkout and run them. CI_BASE_PYTHON is a test seam.
#
# AC_ROOT=<dir holding ansible_collections> scripts/run_molecule_in_ci_image.sh < scenario-dirs
# AC_ROOT=<dir holding ansible_collections> scripts/run_molecule_in_controller.sh < scenario-dirs
set -euo pipefail
selected="$(cat)"
+3 -2
View File
@@ -511,11 +511,12 @@ class PureTest(unittest.TestCase):
)
self.assertEqual(civ.dockerfile_labels('FROM c\nLABEL a="unbalanced\n'), {})
def test_the_molecule_collections_are_an_input_of_the_ci_image(self):
def test_the_molecule_collections_are_not_an_input_of_the_ci_image(self):
# Lint uses no collection of them, so their bump must not publish a ci version.
root = pathlib.Path(__file__).resolve().parents[2]
entry = civ.matrix_of((root / civ.MATRIX_FILE).read_text())["ci"]
files = civ.inputs_of(entry, (root / entry["dockerfile"]).read_text())[1]
self.assertIn("extensions/molecule/requirements.yml", files)
self.assertNotIn("extensions/molecule/requirements.yml", files)
def test_the_controller_pins_are_inputs_of_the_controller_image(self):
root = pathlib.Path(__file__).resolve().parents[2]
+15
View File
@@ -105,6 +105,7 @@ class FakeRegistry(http.server.BaseHTTPRequestHandler):
no_realm = False
empty_token = False
unknown = False # the repository does not exist yet
not_found = None # a 404 body without NAME_UNKNOWN
agents = None # a fresh list per test, set in setUp
def do_GET(self):
@@ -128,6 +129,8 @@ class FakeRegistry(http.server.BaseHTTPRequestHandler):
b"{}",
extra={"WWW-Authenticate": f'Bearer realm="{realm}",service="reg"'},
)
elif self.not_found is not None:
self.reply(404, self.not_found, "text/plain")
elif self.unknown:
body = {"errors": [{"code": "NAME_UNKNOWN", "message": "unknown"}]}
self.reply(404, json.dumps(body).encode())
@@ -155,6 +158,7 @@ class RegistryClient(unittest.TestCase):
def setUp(self):
FakeRegistry.refuse = FakeRegistry.refuse_token = FakeRegistry.no_realm = False
FakeRegistry.empty_token = FakeRegistry.unknown = False
FakeRegistry.not_found = None
FakeRegistry.agents = []
server = QuietServer(("127.0.0.1", 0), FakeRegistry)
threading.Thread(target=server.serve_forever, daemon=True).start()
@@ -176,6 +180,17 @@ class RegistryClient(unittest.TestCase):
niv.next_version("0.1", self.registry.tags(), "c", no_label), "0.1.0"
)
def test_a_404_without_name_unknown_is_a_registry_error(self):
for body in (
b"404 page not found",
b'{"errors":[{"code":"NOT_FOUND","message":"no such route"}]}',
):
with self.subTest(body=body):
FakeRegistry.not_found = body
with self.assertRaises(niv.RegistryError) as caught:
self.registry.tags()
self.assertEqual(caught.exception.status, 404)
def test_a_missing_manifest_is_still_a_registry_error(self):
FakeRegistry.unknown = True
with self.assertRaises(niv.RegistryError) as caught:
@@ -1,6 +1,6 @@
# SPDX-FileCopyrightText: Defame1297 and contributors
# SPDX-License-Identifier: GPL-3.0-or-later
"""Tests for scripts/run_molecule_in_ci_image.sh with stub tools in place of the molecule-controller
"""Tests for scripts/run_molecule_in_controller.sh with stub tools in place of the molecule-controller
image's.
Run with: python3 -m unittest discover -s tests/scripts
@@ -14,7 +14,7 @@ import tempfile
import unittest
REPO = pathlib.Path(__file__).resolve().parents[2]
SCRIPT = REPO / "scripts" / "run_molecule_in_ci_image.sh"
SCRIPT = REPO / "scripts" / "run_molecule_in_controller.sh"
# Each stub appends its name, arguments and the paths it saw to STUB_LOG; STUB_FAIL_<name> fails it.
STUB = """#!/usr/bin/env bash
@@ -50,7 +50,7 @@ echo "runner args=$* path=$PATH acp=$ANSIBLE_COLLECTIONS_PATH" \\
@unittest.skipUnless(shutil.which("bash"), "bash is required")
class RunMoleculeInCiImageTest(unittest.TestCase):
class RunMoleculeInControllerTest(unittest.TestCase):
def setUp(self):
self.tmp = pathlib.Path(tempfile.mkdtemp(prefix="kamino-runci-")).resolve()
self.addCleanup(shutil.rmtree, self.tmp, True)
+1 -1
View File
@@ -616,7 +616,7 @@ class WorkflowJobsTest(unittest.TestCase):
self.assertEqual(
step["env"]["SELECTED"], "${{ needs.select.outputs.scenarios }}"
)
self.assertIn('run_molecule_in_ci_image.sh <<< "$SELECTED"', step["run"])
self.assertIn('run_molecule_in_controller.sh <<< "$SELECTED"', step["run"])
def test_the_result_runs_whatever_the_others_ended_as(self):
job = self.JOBS["result"]