From a659e83e6b6ee5ea059fe590f3892678765b8917 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Thu, 26 Nov 2026 21:56:10 +0000 Subject: [PATCH 01/11] chore(release): 3.1.0 Minor release: adds the tailscale role, and fixes six roles that failed under --check on a host where they were not installed yet. Assisted-by: Claude Code:claude-opus-5-5 --- CHANGELOG.rst | 18 ++++++++++++++++ README.md | 4 ++-- changelogs/.plugin-cache.yaml | 6 +++++- changelogs/changelog.yaml | 28 +++++++++++++++++++++++++ changelogs/fragments/134-check-mode.yml | 17 --------------- changelogs/fragments/tailscale-role.yml | 9 -------- galaxy.yml | 2 +- 7 files changed, 54 insertions(+), 30 deletions(-) delete mode 100644 changelogs/fragments/134-check-mode.yml delete mode 100644 changelogs/fragments/tailscale-role.yml diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5e714a7..c20337f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,24 @@ mortis.kamino Release Notes .. contents:: Topics +v3.1.0 +====== + +Minor Changes +------------- + +- tailscale - New role. Installs Tailscale from the upstream APT repository with the keyring pinned by sha256, sets ``--tun=userspace-networking`` in the ``tailscaled`` flags when ``tailscale_userspace_networking`` is true, enables ``tailscaled`` and, with ``tailscale_up`` (default ``true``), runs ``tailscale up`` with ``tailscale_auth_key`` while the node is not Running; it can also update to the APT candidate version and remove or purge. Declares Ubuntu noble and resolute; the molecule scenario installs the real package but does not join a tailnet. + +Bugfixes +-------- + +- cloudflared - Do not fail under ``--check`` on a host where the cloudflared account or systemd unit does not exist yet. +- docker - Do not fail under ``--check`` on a host where the Docker repository and packages are not installed yet. +- gitea - Do not fail under ``--check`` on a host where Gitea is not installed yet. +- gitea_runner - Do not fail under ``--check`` on a host where the runner account, Docker or the systemd unit does not exist yet. +- traefik - Do not fail under ``--check`` on a host where Traefik is not installed yet. +- user_management - Do not fail under ``--check`` when a managed user does not exist yet. + v3.0.0 ====== diff --git a/README.md b/README.md index ee00e4d..b2f970d 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ An Ansible Collection of reusable, hardened roles for a self-hosted home lab: `pihole`, `pve_lxc`, `sshd`, `system_baseline`, `systemd_hardening`, `tailscale`, `traefik`, `ufw` and `user_management`, plus the internal `_binary_update`. Roles still to come are listed under [Roadmap](#roadmap). -Status: roles arrive in waves. Release 3.0.0 holds the `cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, `pihole`, `pve_lxc`, `sshd`, `system_baseline`, `systemd_hardening`, `traefik`, `ufw` and `user_management` roles (and the internal `_binary_update`, which `cloudflared`, `gitea`, `gitea_runner` and `traefik` call). +Status: roles arrive in waves. Release 3.1.0 holds the `cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, `pihole`, `pve_lxc`, `sshd`, `system_baseline`, `systemd_hardening`, `tailscale`, `traefik`, `ufw` and `user_management` roles (and the internal `_binary_update`, which `cloudflared`, `gitea`, `gitea_runner` and `traefik` call). ## Consuming @@ -17,7 +17,7 @@ name (FQCN) only, `mortis.kamino.`: collections: - name: https://git.rkdr.net/mortis/kamino.git type: git - version: v3.0.0 + version: v3.1.0 ``` Its dependencies (`community.general`, `ansible.posix`, `community.proxmox`) are declared in `galaxy.yml`, so diff --git a/changelogs/.plugin-cache.yaml b/changelogs/.plugin-cache.yaml index 8b38374..8d3c40a 100644 --- a/changelogs/.plugin-cache.yaml +++ b/changelogs/.plugin-cache.yaml @@ -51,6 +51,10 @@ objects: description: Harden systemd for a system type name: systemd_hardening version_added: null + tailscale: + description: Install Tailscale and bring the node up + name: tailscale + version_added: null traefik: description: Install, configure, update or remove Traefik as a systemd binary name: traefik @@ -81,4 +85,4 @@ plugins: strategy: {} test: {} vars: {} -version: 3.0.0 +version: 3.1.0 diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index 0b22a3c..8e11d64 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -446,3 +446,31 @@ releases: - 133-drop-jammy-and-ubuntu-all.yml - 133-ubuntu-2604.yml release_date: '2026-11-26' + 3.1.0: + changes: + bugfixes: + - cloudflared - Do not fail under ``--check`` on a host where the cloudflared + account or systemd unit does not exist yet. + - docker - Do not fail under ``--check`` on a host where the Docker repository + and packages are not installed yet. + - gitea - Do not fail under ``--check`` on a host where Gitea is not installed + yet. + - gitea_runner - Do not fail under ``--check`` on a host where the runner account, + Docker or the systemd unit does not exist yet. + - traefik - Do not fail under ``--check`` on a host where Traefik is not installed + yet. + - user_management - Do not fail under ``--check`` when a managed user does not + exist yet. + minor_changes: + - tailscale - New role. Installs Tailscale from the upstream APT repository + with the keyring pinned by sha256, sets ``--tun=userspace-networking`` in + the ``tailscaled`` flags when ``tailscale_userspace_networking`` is true, + enables ``tailscaled`` and, with ``tailscale_up`` (default ``true``), runs + ``tailscale up`` with ``tailscale_auth_key`` while the node is not Running; + it can also update to the APT candidate version and remove or purge. Declares + Ubuntu noble and resolute; the molecule scenario installs the real package + but does not join a tailnet. + fragments: + - 134-check-mode.yml + - tailscale-role.yml + release_date: '2026-11-26' diff --git a/changelogs/fragments/134-check-mode.yml b/changelogs/fragments/134-check-mode.yml deleted file mode 100644 index b10398a..0000000 --- a/changelogs/fragments/134-check-mode.yml +++ /dev/null @@ -1,17 +0,0 @@ ---- -bugfixes: - - >- - cloudflared - Do not fail under ``--check`` on a host where the cloudflared account or systemd - unit does not exist yet. - - >- - docker - Do not fail under ``--check`` on a host where the Docker repository and packages are - not installed yet. - - >- - gitea - Do not fail under ``--check`` on a host where Gitea is not installed yet. - - >- - gitea_runner - Do not fail under ``--check`` on a host where the runner account, Docker or the - systemd unit does not exist yet. - - >- - traefik - Do not fail under ``--check`` on a host where Traefik is not installed yet. - - >- - user_management - Do not fail under ``--check`` when a managed user does not exist yet. diff --git a/changelogs/fragments/tailscale-role.yml b/changelogs/fragments/tailscale-role.yml deleted file mode 100644 index 64f1bed..0000000 --- a/changelogs/fragments/tailscale-role.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- -minor_changes: - - >- - tailscale - New role. Installs Tailscale from the upstream APT repository with the keyring pinned by sha256, - sets ``--tun=userspace-networking`` in the ``tailscaled`` flags when ``tailscale_userspace_networking`` is true, - enables ``tailscaled`` and, with ``tailscale_up`` (default ``true``), runs ``tailscale up`` with - ``tailscale_auth_key`` while the node is not Running; it can also update to the APT candidate version and remove - or purge. Declares Ubuntu noble and resolute; the molecule scenario installs the real package but does not join a - tailnet. diff --git a/galaxy.yml b/galaxy.yml index fd5c00c..f930b4d 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,7 +1,7 @@ --- namespace: mortis name: kamino -version: 3.0.0 +version: 3.1.0 readme: README.md authors: - Defame1297 From f7fde63f7d59233a0f0818ef54a03655100db62b Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Thu, 26 Nov 2026 22:17:42 +0000 Subject: [PATCH 02/11] ci: run the Lint and Build fast path without network When the pins match the ci image every tool is baked in, so a runtime download is a bake-in defect; failing the job makes it visible. Assisted-by: Claude Code --- .gitea/workflows/AGENTS.md | 5 +++++ .gitea/workflows/build.yml | 13 ++++++++----- .gitea/workflows/lint.yml | 14 +++++++++----- docs/images/ci.md | 3 ++- images/AGENTS.md | 5 +++-- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/.gitea/workflows/AGENTS.md b/.gitea/workflows/AGENTS.md index f5afa9c..cc34b0b 100644 --- a/.gitea/workflows/AGENTS.md +++ b/.gitea/workflows/AGENTS.md @@ -57,6 +57,11 @@ issue. `.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 tool steps run in a network namespace without network** (`unshare -rn` + through `$OFFLINE`), except "Test the repository scripts", whose fake registry needs loopback; + the slow path keeps network. *Why:* a runtime download is a bake-in defect and must fail the + job, not silently slow it. *Held:* control: the `$OFFLINE` prefix set by the "Check the baked + tooling against the pins" step. - **Triggers:** both run on pull requests to `main` and on manual dispatch; Build also runs on `v*` tags, where it checks the tag against `galaxy.yml`. *Why:* the tag is what consumers install. *Held:* review. diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 16216f4..a71904c 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -60,6 +60,9 @@ jobs: run: | if sha256sum --quiet -c /opt/ci-pins.sha256; then echo "The pin files match the ci image; using the baked tools." + # -r adds a user namespace: a job container lacks CAP_SYS_ADMIN for a plain unshare -n. + echo "OFFLINE=unshare -rn --" >> "$GITHUB_ENV" + echo "::notice::The tool steps run without network; 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;" \ @@ -79,7 +82,7 @@ jobs: echo "::error::$TAG is a lightweight tag; releases must be annotated (git tag -a)" exit 1 fi - version="$(python3 -c 'import sys, yaml; print(yaml.safe_load(open("galaxy.yml"))["version"])')" + version="$($OFFLINE python3 -c 'import sys, yaml; print(yaml.safe_load(open("galaxy.yml"))["version"])')" if [ "$TAG" != "v$version" ]; then echo "::error::tag $TAG does not match galaxy.yml version $version (expected v$version)" exit 1 @@ -106,7 +109,7 @@ jobs: run: | export PATH="/opt/venv/bin:$PATH" mkdir -p /tmp/dist - ansible-galaxy collection build --force --output-path /tmp/dist . + $OFFLINE ansible-galaxy collection build --force --output-path /tmp/dist . ls -l /tmp/dist sha256sum /tmp/dist/*.tar.gz @@ -119,7 +122,7 @@ jobs: echo "::error::expected exactly one tarball in /tmp/dist, found $# match(es): $*" exit 1 fi - python3 scripts/check_tarball.py "$1" + $OFFLINE python3 scripts/check_tarball.py "$1" # galaxy-importer without ansible-test and without Docker. The importer reads its # configuration from this file. @@ -138,7 +141,7 @@ jobs: exit 1 fi GALAXY_IMPORTER_CONFIG=/tmp/galaxy-importer.cfg \ - python3 -m galaxy_importer.main "$1" + $OFFLINE python3 -m galaxy_importer.main "$1" # Sanity tests need the collection at ansible_collections//. - name: Run ansible-test sanity @@ -159,4 +162,4 @@ jobs: { cat tests/sanity/ignore-common.txt; if [ -f "$ignore" ]; then cat "$ignore"; fi; } > /tmp/ignore.new mv /tmp/ignore.new "$ignore" echo "Sanity ignore list for ansible-core ${core}: $(wc -l < "$ignore") lines" - ansible-test sanity --requirements --color no + $OFFLINE ansible-test sanity --requirements --color no diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml index 2a8515e..a6f65a2 100644 --- a/.gitea/workflows/lint.yml +++ b/.gitea/workflows/lint.yml @@ -59,6 +59,9 @@ jobs: run: | if sha256sum --quiet -c /opt/ci-pins.sha256; then echo "The pin files match the ci image; using the baked tools." + # -r adds a user namespace: a job container lacks CAP_SYS_ADMIN for a plain unshare -n. + echo "OFFLINE=unshare -rn --" >> "$GITHUB_ENV" + echo "::notice::The tool steps run without network; 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;" \ @@ -71,7 +74,7 @@ jobs: - name: Run pre-commit on all files run: | export PATH="/opt/venv/bin:$PATH" - pre-commit run --all-files --show-diff-on-failure + $OFFLINE pre-commit run --all-files --show-diff-on-failure # Image pins (scripts/check_image_versions.py): a pin in a workflow must name an # image of the matrix. Not a pre-commit hook: a change to .pre-commit-config.yaml @@ -79,7 +82,7 @@ jobs: - name: Check image pins run: | export PATH="/opt/venv/bin:$PATH" - python3 scripts/check_image_versions.py pins + $OFFLINE python3 scripts/check_image_versions.py pins # A pull request from a renovate/ branch may only move version, tag, digest and pin # lines (scripts/check_bot_pr_diff.py), so the bot's automerge cannot change workflow @@ -106,8 +109,9 @@ jobs: else echo "::notice::$BASE_REF has no scripts/check_bot_pr_diff.py yet; running the pull request's copy" fi - python3 -E -s "$guard" "$HEAD_REF" "$BASE_REF" + $OFFLINE python3 -E -s "$guard" "$HEAD_REF" "$BASE_REF" + # Online: a new network namespace has loopback down, and the image has no ip to bring it up for the fake registry. - name: Test the repository scripts run: | export PATH="/opt/venv/bin:$PATH" @@ -125,7 +129,7 @@ jobs: echo "gitleaks binary not found in the pre-commit cache" >&2 exit 1 fi - "$GITLEAKS" git --verbose --redact --log-opts="origin/main..$SHA" + $OFFLINE "$GITLEAKS" git --verbose --redact --log-opts="origin/main..$SHA" # commit-msg stage hooks do not run under --all-files, so each commit's message is given to # every commit-msg hook (Conventional Commits, refuse-agent-trailers); --no-verify skips them locally. @@ -139,5 +143,5 @@ jobs: for sha in $(git rev-list --no-merges "origin/main..$SHA"); do git log -1 --format=%B "$sha" > "$MSG_FILE" echo "Checking $sha" - pre-commit run --hook-stage commit-msg --commit-msg-filename "$MSG_FILE" + $OFFLINE pre-commit run --hook-stage commit-msg --commit-msg-filename "$MSG_FILE" done diff --git a/docs/images/ci.md b/docs/images/ci.md index 5e15584..2d293ed 100644 --- a/docs/images/ci.md +++ b/docs/images/ci.md @@ -66,7 +66,8 @@ Read `.gitea/workflows/molecule.yml` for the full command. `/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 -collections are used as they are. When a pull request changes a pin the check fails and the job installs the pinned +collections are used as they are, and Lint and Build run their tools without network, 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 (slower, same result), until the image is rebuilt from `main`. `lint.yml`, `build.yml`, `molecule.yml` and `gitea-release-key.yml` are the real consumers. diff --git a/images/AGENTS.md b/images/AGENTS.md index cfc8e02..463b47b 100644 --- a/images/AGENTS.md +++ b/images/AGENTS.md @@ -61,8 +61,9 @@ it to this repository's organisation in the Gitea registry as `` and `l - **Bake in:** every tool, collection, hook environment and package a CI job uses is in its image; a job downloads at run time only on the slow path (a pull request that changes a pin - file). *Why:* a run that downloads is slower and depends on the network. *Held:* review until - the network-off check (#168) lands. + file). *Why:* a run that downloads is slower and depends on the network. *Held:* control: on + the fast path the Lint and Build tool steps run without network, so a download fails the job; + review for the script tests, which keep network, and for Molecule. - **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. From 7c148e858d042cf9dba12cd0f83e60b864a1464c Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Thu, 26 Nov 2026 22:20:17 +0000 Subject: [PATCH 03/11] docs: say what the network-off fast path does not hold A step without the $OFFLINE prefix runs online unchecked, and the script tests keep network; both stay held by review. Assisted-by: Claude Code --- .gitea/workflows/AGENTS.md | 5 +++-- docs/images/ci.md | 4 ++-- images/AGENTS.md | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/AGENTS.md b/.gitea/workflows/AGENTS.md index cc34b0b..c62780d 100644 --- a/.gitea/workflows/AGENTS.md +++ b/.gitea/workflows/AGENTS.md @@ -60,8 +60,9 @@ issue. - **On the fast path the tool steps run in a network namespace without network** (`unshare -rn` through `$OFFLINE`), except "Test the repository scripts", whose fake registry needs loopback; the slow path keeps network. *Why:* a runtime download is a bake-in defect and must fail the - job, not silently slow it. *Held:* control: the `$OFFLINE` prefix set by the "Check the baked - tooling against the pins" step. + job, not silently slow it. *Held:* control for the steps that carry the `$OFFLINE` prefix set + by the "Check the baked tooling against the pins" step; review that every new tool step + carries it. - **Triggers:** both run on pull requests to `main` and on manual dispatch; Build also runs on `v*` tags, where it checks the tag against `galaxy.yml`. *Why:* the tag is what consumers install. *Held:* review. diff --git a/docs/images/ci.md b/docs/images/ci.md index 2d293ed..d429449 100644 --- a/docs/images/ci.md +++ b/docs/images/ci.md @@ -66,8 +66,8 @@ Read `.gitea/workflows/molecule.yml` for the full command. `/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 -collections are used as they are, and Lint and Build run their tools without network, 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 +collections are used as they are, and Lint and Build run their tools (all but the script tests) without +network, 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 (slower, same result), until the image is rebuilt from `main`. `lint.yml`, `build.yml`, `molecule.yml` and `gitea-release-key.yml` are the real consumers. diff --git a/images/AGENTS.md b/images/AGENTS.md index 463b47b..b0e0b31 100644 --- a/images/AGENTS.md +++ b/images/AGENTS.md @@ -63,7 +63,8 @@ it to this repository's organisation in the Gitea registry as `` and `l image; a job downloads at run time only on the slow path (a pull request that changes a pin file). *Why:* a run that downloads is slower and depends on the network. *Held:* control: on the fast path the Lint and Build tool steps run without network, so a download fails the job; - review for the script tests, which keep network, and for Molecule. + review for a new tool step without the prefix, for the script tests, which keep network, and + for Molecule. - **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. From d5a91520df720c5a237d03fdf6fa4beef1a0fb96 Mon Sep 17 00:00:00 2001 From: Dragonish Date: Thu, 26 Nov 2026 22:01:43 +0000 Subject: [PATCH 04/11] feat(system_baseline): add inputs that append packages to the profile's lists system_baseline_essential_packages and system_baseline_remove_packages replace the whole list, and so does a list inside system_baseline_profile_overrides, so adding one package meant repeating the profile's list and keeping it in step with every release. system_baseline_extra_packages and system_baseline_extra_remove_packages (lists, default empty) append to the resolved lists. The tmux and unattended-upgrades checks read the combined list, so an extra tmux or unattended-upgrades enables the matching task like a profile package. Items must be Debian package names: a null item would have become the package "None", and apt reads a trailing minus (jq-) as a removal. A package that one input installs and another purges stops the run before any change; only overlaps that involve an extra are checked, so a consumer's own overlap between the resolved lists behaves as before. A flat input that is a plain string still counts as a one-item list. With both inputs left at their default the role behaves as before. Closes #399 Assisted-by: Claude Code:claude-sonnet-5-5 --- changelogs/fragments/399-extra-packages.yml | 8 ++ roles/system_baseline/README.md | 20 ++++- roles/system_baseline/defaults/main.yml | 16 +++- roles/system_baseline/meta/argument_specs.yml | 24 +++++- .../molecule/default/converge.yml | 75 +++++++++++++++++++ .../molecule/default/prepare.yml | 10 ++- .../default/tasks/refuse_extra_packages.yml | 21 ++++++ .../molecule/default/verify.yml | 55 ++++++++++++++ roles/system_baseline/tasks/main.yml | 2 +- roles/system_baseline/tasks/packages.yml | 4 +- roles/system_baseline/tasks/tmux.yml | 11 +-- roles/system_baseline/tasks/validate.yml | 37 +++++++++ 12 files changed, 269 insertions(+), 14 deletions(-) create mode 100644 changelogs/fragments/399-extra-packages.yml create mode 100644 roles/system_baseline/molecule/default/tasks/refuse_extra_packages.yml diff --git a/changelogs/fragments/399-extra-packages.yml b/changelogs/fragments/399-extra-packages.yml new file mode 100644 index 0000000..3e1c6ae --- /dev/null +++ b/changelogs/fragments/399-extra-packages.yml @@ -0,0 +1,8 @@ +--- +minor_changes: + - >- + system_baseline - Add ``system_baseline_extra_packages`` and ``system_baseline_extra_remove_packages`` (lists, default empty), which + append to the resolved package lists, where setting ``system_baseline_essential_packages`` or ``system_baseline_remove_packages`` + replaces the profile's whole list. An extra ``tmux`` or ``unattended-upgrades`` enables the matching task like a profile package. + A package that one input installs and another purges stops the run before any change. With both inputs left at their default the + role behaves as before. diff --git a/roles/system_baseline/README.md b/roles/system_baseline/README.md index 480678a..4878c11 100644 --- a/roles/system_baseline/README.md +++ b/roles/system_baseline/README.md @@ -35,6 +35,8 @@ templating error instead of the role's own message. | `system_baseline_profile` | derived | no | Active profile after overrides | | `system_baseline_essential_packages` | from profile | no | Packages to install | | `system_baseline_remove_packages` | from profile | no | Packages to purge when present | +| `system_baseline_extra_packages` | `[]` | no | Packages to install in addition to the resolved list; appends, see "Adding packages to a profile" | +| `system_baseline_extra_remove_packages` | `[]` | no | Packages to purge in addition to the resolved list; appends | | `system_baseline_apt_periodic_settings` | from profile | no | Keys for `20auto-upgrades` | | `system_baseline_apt_upgrade` | from profile | no | `safe` or `dist`: how the role upgrades packages (`pve`: `dist`, the Ubuntu profiles: `safe`); see "Apt upgrade mode" | | `system_baseline_unattended_upgrade_settings` | from profile | no | Keys for `50unattended-upgrades` | @@ -130,6 +132,7 @@ The scenario `molecule/default/` runs in CI only, on two platforms: `${MOLECULE_ - Converge then applies the `ubuntu_lxc` profile, with tmux autostart and `system_baseline_apt_daily_timeout: 1h`, and only resolves the `pve` and `ubuntu_vm` profiles and a consumer override, 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. +- Converge 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, then 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. - Converge 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. Verify reads `tasks/update.yml` and checks that the scratch directory is created with mode `0700`, that both apt tasks set `TMPDIR` to it, and that the connection is reset afterwards: the scenario skips the `update` tag, so the upgrade itself never runs there. - 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. @@ -145,9 +148,22 @@ Not covered: Molecule skips `sysctl`, `secure_tmp`, `update` and `timezone` (no - Policy lives in defaults, not `vars/`, so group_vars and host_vars can override it. - `no_log` is not used: the role handles no secrets. +### Adding packages to a profile + +`system_baseline_essential_packages` and `system_baseline_remove_packages` replace the profile's whole list, and so does a list inside `system_baseline_profile_overrides`. To add or drop a few packages and keep the profile's own, use the two extra lists, which append: + +```yaml +system_baseline_extra_packages: [jq] +system_baseline_extra_remove_packages: [telnet] +``` + +- Each item is a Debian package name: lower-case letters, digits, `+`, `-` and `.`, two or more characters, starting with a letter or digit and not ending in `-` (apt reads a trailing minus as a removal). Anything else stops the run. Duplicates of the profile list are harmless. +- An extra counts wherever the role looks for a package in the list: an extra `tmux` enables the tmux snippet and an extra `unattended-upgrades` the unattended-upgrades tasks, as a profile package does. +- A package that one input installs and another purges stops the run before any change: `system_baseline_extra_packages` against `system_baseline_remove_packages` or `system_baseline_extra_remove_packages`, and `system_baseline_extra_remove_packages` against `system_baseline_essential_packages`. The resolved lists are not checked against each other, so a consumer's own overlap there behaves as before. + ### tmux on SSH login -With `system_baseline_tmux_autostart: true` an interactive SSH login attaches to the session `system_baseline_tmux_session` (created when missing), so a dropped connection loses nothing. The `ubuntu_lxc` and `ubuntu_vm` profiles install `tmux`; `pve` never gets the snippet. +With `system_baseline_tmux_autostart: true` an interactive SSH login attaches to the session `system_baseline_tmux_session` (created when missing), so a dropped connection loses nothing. The `ubuntu_lxc` and `ubuntu_vm` profiles install `tmux`; the `pve` profile has none, so it gets the snippet only if `system_baseline_extra_packages` adds `tmux`. ```yaml system_baseline_tmux_autostart: true @@ -157,7 +173,7 @@ system_baseline_tmux_windows: ``` - It is `/etc/profile.d/tmux-autostart.sh`. Every login shell reads that directory, so the snippet itself acts only for an interactive shell (`case $-`) with a terminal and an SSH connection, outside tmux, and without `~/.no-tmux`. `scp`, `sftp`, `ssh host command`, Ansible and `ssh -t host 'bash -lc cmd'` never trigger it. sshd's `ForceCommand` is not used: it applies to every session type and a broken tmux would lock all of them out. Users whose login shell is zsh or fish are not affected, because those shells do not read `/etc/profile.d`. -- The snippet is installed when autostart is on and the resolved package list contains `tmux` (the `ubuntu_lxc` and `ubuntu_vm` profiles). If you override `system_baseline_essential_packages` without it, nothing is installed. +- The snippet is installed when autostart is on and the packages to install contain `tmux`: the `ubuntu_lxc` and `ubuntu_vm` profiles have it, and `system_baseline_extra_packages` can add it. If you override `system_baseline_essential_packages` without it and add no extra `tmux`, nothing is installed. - A failed attach (for example a client `TERM` such as `xterm-kitty` or `wezterm` without a terminfo entry on the host) prints a line and leaves a plain shell. Detaching (`Ctrl-b d`) ends the SSH connection, as `exit` would. - Turn it off for one login with `ssh -t host bash` (a non-login shell does not read `/etc/profile.d`), for one user with `touch ~/.no-tmux`, and for the host by setting the variable to `false` and running the role (it removes the snippet). - The windows are made when the session is created; a login that re-attaches adds none, so a change applies from the next new session. A window closes when its command exits. A window command runs with `sh -c` from the tmux server of the first login, before `~/.profile` is read, so it does not see `~/.local/bin` and other additions made there: use absolute paths. diff --git a/roles/system_baseline/defaults/main.yml b/roles/system_baseline/defaults/main.yml index 53ab949..1a39db4 100644 --- a/roles/system_baseline/defaults/main.yml +++ b/roles/system_baseline/defaults/main.yml @@ -21,7 +21,8 @@ system_baseline_update: true # Upper bound of the persistent journal (journald SystemMaxUse); older archived files are removed above it. system_baseline_journal_max_use: 200M # Attach an interactive SSH login to a tmux session (see tasks/tmux.yml). Off by default: it changes what every login does. -# Only the ubuntu_lxc and ubuntu_vm profiles honour it; pve never installs the snippet. +# 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. system_baseline_tmux_autostart: false # Name of the session an SSH login attaches to. system_baseline_tmux_session: main @@ -246,6 +247,19 @@ system_baseline_profile: >- # Inputs the tasks read system_baseline_essential_packages: "{{ system_baseline_profile.essential_packages }}" system_baseline_remove_packages: "{{ system_baseline_profile.remove_packages }}" +# Packages installed and purged in addition to the two resolved lists above. They append: a flat essential or remove input replaces its +# list, so adding one package that way means repeating the whole profile list. +system_baseline_extra_packages: [] +system_baseline_extra_remove_packages: [] +# What the role acts on: each resolved list plus its extras, without duplicates. Internal, read by tasks/packages.yml, tasks/tmux.yml and +# tasks/main.yml, so that an extra `tmux` or `unattended-upgrades` enables the matching task like a profile package does. +# A flat input that is a plain string (`system_baseline_essential_packages: vim`, which the package module accepts) counts as a one-item list. +__system_baseline_install_packages: >- + {{ (([system_baseline_essential_packages] if system_baseline_essential_packages is string else system_baseline_essential_packages) + + system_baseline_extra_packages) | unique | list }} +__system_baseline_purge_packages: >- + {{ (([system_baseline_remove_packages] if system_baseline_remove_packages is string else system_baseline_remove_packages) + + system_baseline_extra_remove_packages) | unique | list }} system_baseline_apt_periodic_settings: "{{ system_baseline_profile.apt_periodic_settings }}" # safe or dist (see the profiles). Guarded: the tasks_from: update entry point needs no system_baseline_system_type, and without one it # stays on a safe upgrade instead of failing on the profile lookup. default('safe'): a system_baseline_profiles written before this key diff --git a/roles/system_baseline/meta/argument_specs.yml b/roles/system_baseline/meta/argument_specs.yml index 6f36c6b..9f0e417 100644 --- a/roles/system_baseline/meta/argument_specs.yml +++ b/roles/system_baseline/meta/argument_specs.yml @@ -63,7 +63,8 @@ argument_specs: Attach an interactive SSH login to a tmux session, creating it when it does not exist. Installs C(/etc/profile.d/tmux-autostart.sh), which acts only for an interactive login shell with a terminal, so scp, sftp, C(ssh host command) and automation are unaffected. Shells that do not read C(/etc/profile.d) (zsh, fish) are unaffected too. A user opts out with C(~/.no-tmux). Installed only when - C(tmux) is in the resolved package list (the C(ubuntu_lxc) and C(ubuntu_vm) profiles); with false, or without tmux, the file is + C(tmux) is among the packages to install (the C(ubuntu_lxc) and C(ubuntu_vm) profiles have it, and C(system_baseline_extra_packages) + can add it to any profile, C(pve) included); with false, or without tmux, the file is removed. A failed attach leaves a plain shell; detaching ends the SSH connection. system_baseline_tmux_session: type: str @@ -152,6 +153,27 @@ argument_specs: A non-empty list is written to C(/etc/apt/apt.conf.d/90unattended-upgrades-blacklist) as C(Unattended-Upgrade::Package-Blacklist). apt appends list entries across files, so these are added to those of C(50unattended-upgrades). An empty list removes the file. An entry may not hold a double quote, a backslash or a line break. + system_baseline_extra_packages: + type: list + elements: str + default: [] + description: + - >- + Packages installed in addition to the resolved C(system_baseline_essential_packages). The list appends: setting + C(system_baseline_essential_packages) itself replaces the profile's list. A package named here also counts for the checks that read + the package list (C(tmux) for the tmux snippet, C(unattended-upgrades) for the unattended-upgrades tasks). Each item is a Debian + package name: lower-case letters, digits, C(+), C(-) and C(.), two or more characters, starting with a letter or digit and not + ending in C(-) (apt reads a trailing minus as a removal). A package that is also in C(system_baseline_remove_packages) or + C(system_baseline_extra_remove_packages) stops the run before any change. + system_baseline_extra_remove_packages: + type: list + elements: str + default: [] + description: + - >- + Packages purged, when installed, in addition to the resolved C(system_baseline_remove_packages). The list appends. Each item is a + Debian package name, as for C(system_baseline_extra_packages). A package that is also in C(system_baseline_essential_packages) + stops the run before any change. system_baseline_update: type: bool default: true diff --git a/roles/system_baseline/molecule/default/converge.yml b/roles/system_baseline/molecule/default/converge.yml index 437f61b..0a0b4d8 100644 --- a/roles/system_baseline/molecule/default/converge.yml +++ b/roles/system_baseline/molecule/default/converge.yml @@ -133,11 +133,38 @@ - [null] - linux-image-.* +# Items that are not Debian package names (whitespace, null, empty, a trailing minus that apt reads as a removal, an option, upper case, a +# version pin), and a package that one input installs and another purges, each stop the run before any change. +# The overlaps are: an extra install against the profile's remove list (telnet), an extra install against an extra remove, and an extra +# remove against the profile's install list (tmux). +- name: A bad extra package list is refused + hosts: all + gather_facts: false + tasks: + - name: Refuse each bad value + ansible.builtin.include_tasks: tasks/refuse_extra_packages.yml + vars: + system_baseline_refused_case: "{{ item }}" + loop: + - { install: ['bad name'], expect: 'must be lists of package names' } + - { install: [null], expect: 'must be lists of package names' } + - { install: jq, expect: 'must be lists of package names' } + - { remove: [''], expect: 'must be lists of package names' } + - { install: ['jq-'], expect: 'must be lists of package names' } + - { install: ['-y'], expect: 'must be lists of package names' } + - { remove: ['Telnet'], expect: 'must be lists of package names' } + - { remove: ['ed=1.0'], expect: 'must be lists of package names' } + - { install: [telnet], expect: 'is both installed and purged' } + - { install: [jq], remove: [jq], expect: 'is both installed and purged' } + - { remove: [tmux], expect: 'is both installed and purged' } + - name: Converge the LXC profile hosts: all gather_facts: true vars: system_baseline_system_type: ubuntu_lxc + system_baseline_extra_packages: [jq] + system_baseline_extra_remove_packages: [ed] system_baseline_tmux_autostart: true system_baseline_apt_daily_timeout: 1h system_baseline_tmux_session: molecule @@ -172,6 +199,8 @@ - system_baseline_apt_upgrade == 'dist' - system_baseline_unattended_upgrade_origins | length == 3 - system_baseline_unattended_upgrade_origins | select('search', 'Proxmox') | list == [] + - __system_baseline_install_packages == system_baseline_essential_packages + - __system_baseline_purge_packages == system_baseline_remove_packages quiet: true - name: The ubuntu_vm profile resolves @@ -195,6 +224,8 @@ - system_baseline_sysctl_hardening | selectattr('name', 'equalto', 'net.ipv4.conf.all.log_martians') | list | length == 1 - system_baseline_apt_upgrade == 'safe' - system_baseline_unattended_upgrade_origins == [] + - __system_baseline_install_packages == system_baseline_essential_packages + - __system_baseline_purge_packages == system_baseline_remove_packages quiet: true # Consumer play vars override the profile. @@ -224,3 +255,47 @@ - system_baseline_unattended_upgrade_settings['Unattended-Upgrade::Automatic-Reboot-Time'] == '04:00' - "'qemu-guest-agent' in system_baseline_essential_packages" quiet: true + +# The extras append to the resolved lists, whether the profile's list or a flat input supplies them, and a name that is in both is listed once. +- name: Extra packages append to the resolved lists + hosts: all + gather_facts: false + vars: + system_baseline_system_type: ubuntu_lxc + system_baseline_essential_packages: [vim, curl] + system_baseline_extra_packages: [jq, vim, unattended-upgrades] + system_baseline_extra_remove_packages: [ed, telnet] + tasks: + - name: Load the role defaults + ansible.builtin.include_role: + name: mortis.kamino.system_baseline + tasks_from: validate.yml + public: true + - name: Assert the lists the role acts on + ansible.builtin.assert: + that: + - __system_baseline_install_packages == ['vim', 'curl', 'jq', 'unattended-upgrades'] + - "'ed' in __system_baseline_purge_packages" + - __system_baseline_purge_packages | select('equalto', 'telnet') | list | length == 1 + - system_baseline_remove_packages | difference(__system_baseline_purge_packages) | length == 0 + quiet: true + +# A flat input that is a plain string (the package module accepts one) still counts as a one-item list, with and without extras. +- name: A flat string package list still resolves + hosts: all + gather_facts: false + vars: + system_baseline_system_type: ubuntu_lxc + system_baseline_essential_packages: vim + system_baseline_extra_packages: [jq] + tasks: + - name: Load the role defaults + ansible.builtin.include_role: + name: mortis.kamino.system_baseline + tasks_from: validate.yml + public: true + - name: Assert the lists the role acts on + ansible.builtin.assert: + that: + - __system_baseline_install_packages == ['vim', 'jq'] + quiet: true diff --git a/roles/system_baseline/molecule/default/prepare.yml b/roles/system_baseline/molecule/default/prepare.yml index 3b41e7b..c7b6152 100644 --- a/roles/system_baseline/molecule/default/prepare.yml +++ b/roles/system_baseline/molecule/default/prepare.yml @@ -1,12 +1,18 @@ --- # A package the role must remove, and the locales tool the role assumes exists -# (it does on a stock Ubuntu host). +# (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. - name: Prepare hosts: all gather_facts: false tasks: - name: Install a package on the role's remove list and locale-gen ansible.builtin.apt: - name: [telnet, locales] + name: [telnet, locales, ed] state: present update_cache: true + + - name: Make sure jq is not installed + ansible.builtin.apt: + name: jq + state: absent diff --git a/roles/system_baseline/molecule/default/tasks/refuse_extra_packages.yml b/roles/system_baseline/molecule/default/tasks/refuse_extra_packages.yml new file mode 100644 index 0000000..bf3ac1c --- /dev/null +++ b/roles/system_baseline/molecule/default/tasks/refuse_extra_packages.yml @@ -0,0 +1,21 @@ +--- +# One refusal per call: the role must stop on validation, before it changes anything, with a message that names the inputs. +# The case comes in as system_baseline_refused_case: {install, remove, expect}. +- name: Run the role with a bad extra package list + block: + - name: Include system_baseline + ansible.builtin.include_role: + name: mortis.kamino.system_baseline + vars: + system_baseline_system_type: ubuntu_lxc + system_baseline_extra_packages: "{{ system_baseline_refused_case.install | default([]) }}" + system_baseline_extra_remove_packages: "{{ system_baseline_refused_case.remove | default([]) }}" + - name: Unreachable when validation works + ansible.builtin.fail: + msg: system_baseline ran with a bad extra package list + rescue: + - name: The validation stopped the play with the expected message + ansible.builtin.assert: + that: system_baseline_refused_case.expect in ansible_failed_result.msg | default('') + fail_msg: "Expected '{{ system_baseline_refused_case.expect }}', got: {{ ansible_failed_result.msg | default('') }}" + quiet: true diff --git a/roles/system_baseline/molecule/default/verify.yml b/roles/system_baseline/molecule/default/verify.yml index d2eb81a..bc0dca2 100644 --- a/roles/system_baseline/molecule/default/verify.yml +++ b/roles/system_baseline/molecule/default/verify.yml @@ -17,6 +17,16 @@ - "'telnet' not in ansible_facts.packages" quiet: true + # jq was absent before the role ran and is on no profile list: the extra list installed it, and the profile's own packages (tmux, + # curl above) are still there. ed was present and is on no profile list: the extra remove list purged it. + - name: The extra packages were installed and the extra removal purged + ansible.builtin.assert: + that: + - "'jq' in ansible_facts.packages" + - "'curl' in ansible_facts.packages" + - "'ed' not in ansible_facts.packages" + quiet: true + - name: Read the journald drop-in ansible.builtin.slurp: src: /etc/systemd/journald.conf.d/50-system-baseline.conf @@ -254,6 +264,51 @@ that: not system_baseline_verify_removed.stat.exists quiet: true + # An extra tmux counts like a profile tmux: a flat package list without it installs no snippet, the same list plus the extra does. + - name: Run the tmux tasks with a flat package list that lacks tmux + ansible.builtin.include_role: + name: mortis.kamino.system_baseline + tasks_from: tmux + vars: + system_baseline_system_type: ubuntu_lxc + system_baseline_tmux_autostart: true + system_baseline_essential_packages: [vim] + + - name: Stat the snippet without the extra + ansible.builtin.stat: + path: /etc/profile.d/tmux-autostart.sh + register: system_baseline_verify_no_extra + + - name: Run the tmux tasks with tmux as an extra package + ansible.builtin.include_role: + name: mortis.kamino.system_baseline + tasks_from: tmux + vars: + system_baseline_system_type: ubuntu_lxc + system_baseline_tmux_autostart: true + system_baseline_essential_packages: [vim] + system_baseline_extra_packages: [tmux] + + - name: Stat the snippet with the extra + ansible.builtin.stat: + path: /etc/profile.d/tmux-autostart.sh + register: system_baseline_verify_with_extra + + - name: Only the extra tmux installs the snippet + ansible.builtin.assert: + that: + - not system_baseline_verify_no_extra.stat.exists + - system_baseline_verify_with_extra.stat.exists + quiet: true + + - name: Remove the snippet again + ansible.builtin.include_role: + name: mortis.kamino.system_baseline + tasks_from: tmux + vars: + system_baseline_system_type: ubuntu_lxc + system_baseline_tmux_autostart: false + # The pve origins pin, run on this Ubuntu host: Ubuntu's 50unattended-upgrades sets Allowed-Origins, so the merged # configuration showing only the pinned patterns proves the drop-in clears the earlier lists instead of appending to them. # The patterns match no Ubuntu origin, which only means nothing would be upgraded; the role's dry run still passes. Here diff --git a/roles/system_baseline/tasks/main.yml b/roles/system_baseline/tasks/main.yml index 46bb026..0917c46 100644 --- a/roles/system_baseline/tasks/main.yml +++ b/roles/system_baseline/tasks/main.yml @@ -17,7 +17,7 @@ - name: Configure unattended-upgrades ansible.builtin.import_tasks: unattended_upgrades.yml - when: "'unattended-upgrades' in system_baseline_essential_packages" + when: "'unattended-upgrades' in __system_baseline_install_packages" tags: unattended-upgrades - name: Set locale diff --git a/roles/system_baseline/tasks/packages.yml b/roles/system_baseline/tasks/packages.yml index a10df06..1439741 100644 --- a/roles/system_baseline/tasks/packages.yml +++ b/roles/system_baseline/tasks/packages.yml @@ -1,7 +1,7 @@ --- - name: Install essential packages ansible.builtin.package: - name: "{{ system_baseline_essential_packages }}" + name: "{{ __system_baseline_install_packages }}" state: present update_cache: true become: true @@ -16,6 +16,6 @@ name: "{{ item }}" state: absent purge: true - loop: "{{ system_baseline_remove_packages }}" + loop: "{{ __system_baseline_purge_packages }}" when: item in ansible_facts.packages become: true diff --git a/roles/system_baseline/tasks/tmux.yml b/roles/system_baseline/tasks/tmux.yml index fde0c8c..27e1758 100644 --- a/roles/system_baseline/tasks/tmux.yml +++ b/roles/system_baseline/tasks/tmux.yml @@ -4,9 +4,10 @@ # connection, so scp, sftp, `ssh host command` and automation never trigger it. # sshd's ForceCommand is deliberately not used: it applies to every session type and a broken tmux would lock out all of them. # -# Installed when autostart is on and the resolved package list holds tmux (the ubuntu_lxc and ubuntu_vm profiles); the inputs are -# checked in validate.yml. Security: the session name, window names and commands are role inputs (inventory), never read from a user -# or a fact. They are validated and shell-quoted in the template. The script is root-owned and not writable by the users it runs for. +# Installed when autostart is on and the packages to install hold tmux (the ubuntu_lxc and ubuntu_vm profiles, or +# system_baseline_extra_packages); the inputs are checked in validate.yml. Security: the session name, window names and commands are +# role inputs (inventory), never read from a user or a fact. They are validated and shell-quoted in the template. The script is +# root-owned and not writable by the users it runs for. # It is world-readable and the commands show in `ps`, so a command must hold no secret. Commands run as the user who logs in. - name: Install the tmux auto-start snippet ansible.builtin.template: @@ -16,12 +17,12 @@ group: root mode: "0644" validate: /bin/sh -n %s - when: system_baseline_tmux_autostart | bool and 'tmux' in system_baseline_essential_packages + when: system_baseline_tmux_autostart | bool and 'tmux' in __system_baseline_install_packages become: true - name: Remove the tmux auto-start snippet ansible.builtin.file: path: /etc/profile.d/tmux-autostart.sh state: absent - when: not (system_baseline_tmux_autostart | bool and 'tmux' in system_baseline_essential_packages) + when: not (system_baseline_tmux_autostart | bool and 'tmux' in __system_baseline_install_packages) become: true diff --git a/roles/system_baseline/tasks/validate.yml b/roles/system_baseline/tasks/validate.yml index 20d78c3..b9d054b 100644 --- a/roles/system_baseline/tasks/validate.yml +++ b/roles/system_baseline/tasks/validate.yml @@ -75,6 +75,43 @@ quiet: true tags: always +# The extras are appended to the resolved lists. An item must be a Debian package name (policy: lower-case letters, digits, + - . , two or +# more characters, starting with a letter or digit), and not end in a minus: apt reads `jq-` as "remove jq", and a null item would become the +# package "None". A bare string is rejected here as it is for the blacklist. A package that one input installs and another purges would be +# installed and removed on every run, so it stops the run; only overlaps that involve an extra are checked, the resolved lists themselves +# are the consumer's. +- name: Validate the extra packages + ansible.builtin.assert: + that: + - system_baseline_extra_packages is sequence + - system_baseline_extra_packages is not string + - system_baseline_extra_packages is not mapping + - system_baseline_extra_packages | select('string') | select('match', '^[a-z0-9][a-z0-9+.-]*[a-z0-9+.]\Z') | list | length + == system_baseline_extra_packages | length + - system_baseline_extra_remove_packages is sequence + - system_baseline_extra_remove_packages is not string + - system_baseline_extra_remove_packages is not mapping + - system_baseline_extra_remove_packages | select('string') | select('match', '^[a-z0-9][a-z0-9+.-]*[a-z0-9+.]\Z') | list | length + == system_baseline_extra_remove_packages | length + fail_msg: >- + system_baseline_extra_packages and system_baseline_extra_remove_packages must be lists of package names: lower-case letters, + digits, + - . only, two or more characters, starting with a letter or digit and not ending in a minus. + quiet: true + tags: always + +- name: Refuse a package that is both installed and purged + ansible.builtin.assert: + that: + - system_baseline_extra_packages | intersect(__system_baseline_purge_packages) | length == 0 + - system_baseline_extra_remove_packages | intersect(__system_baseline_install_packages) | length == 0 + fail_msg: >- + A package is both installed and purged. system_baseline_extra_packages must not name a package of system_baseline_remove_packages or + system_baseline_extra_remove_packages, and system_baseline_extra_remove_packages must not name a package of + system_baseline_essential_packages. Found: {{ (system_baseline_extra_packages | intersect(__system_baseline_purge_packages)) + + (system_baseline_extra_remove_packages | intersect(__system_baseline_install_packages)) }}. + quiet: true + tags: always + # Each origin is written inside a double-quoted apt.conf string: a quote or a line break would end it, a backslash could escape. - name: Validate the unattended-upgrades origins ansible.builtin.assert: From 4d5042a31fd53e8ec9f25673855a37a5cd5a8bac Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Thu, 26 Nov 2026 22:48:51 +0000 Subject: [PATCH 05/11] ci: cut the fast-path network by environment, not unshare The runner's job container refuses unshare, even with a user namespace, so the fast path sets PIP_NO_INDEX and a dead proxy instead; a raw socket is not caught. Assisted-by: Claude Code --- .gitea/workflows/AGENTS.md | 14 ++++++++------ .gitea/workflows/build.yml | 18 ++++++++++-------- .gitea/workflows/lint.yml | 21 ++++++++++++--------- docs/images/ci.md | 4 ++-- images/AGENTS.md | 6 +++--- 5 files changed, 35 insertions(+), 28 deletions(-) diff --git a/.gitea/workflows/AGENTS.md b/.gitea/workflows/AGENTS.md index c62780d..9250962 100644 --- a/.gitea/workflows/AGENTS.md +++ b/.gitea/workflows/AGENTS.md @@ -57,12 +57,14 @@ issue. `.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 tool steps run in a network namespace without network** (`unshare -rn` - through `$OFFLINE`), except "Test the repository scripts", whose fake registry needs loopback; - the slow path keeps network. *Why:* a runtime download is a bake-in defect and must fail the - job, not silently slow it. *Held:* control for the steps that carry the `$OFFLINE` prefix set - by the "Check the baked tooling against the pins" step; review that every new tool step - carries it. +- **On the fast path the network is cut by environment**: `PIP_NO_INDEX=1`, the proxy variables + set to a dead local port and `no_proxy` empty, for every later step except "Test the repository + scripts", which unsets them for its fake registry on loopback; the slow path keeps network. + *Why:* a runtime download is a bake-in defect and must fail the job, not silently slow it. + *Held:* control, set by the "Check the baked tooling against the pins" step, for pip, curl, git + over HTTPS and Python's urllib or requests (anything honouring `PIP_NO_INDEX` or the proxy + variables); review for a raw socket or a tool that ignores the proxy variables, and for the + script tests. - **Triggers:** both run on pull requests to `main` and on manual dispatch; Build also runs on `v*` tags, where it checks the tag against `galaxy.yml`. *Why:* the tag is what consumers install. *Held:* review. diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index a71904c..3ac55be 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -60,9 +60,11 @@ jobs: run: | if sha256sum --quiet -c /opt/ci-pins.sha256; then echo "The pin files match the ci image; using the baked tools." - # -r adds a user namespace: a job container lacks CAP_SYS_ADMIN for a plain unshare -n. - echo "OFFLINE=unshare -rn --" >> "$GITHUB_ENV" - echo "::notice::The tool steps run without network; a download fails the job (bake it into images/ci)." + # A job container may not unshare, so the network is cut by environment: pip, curl, + # git over HTTPS and Python's urllib fail; a raw socket is not caught. + printf '%s\n' PIP_NO_INDEX=1 http_proxy=http://127.0.0.1:9 https_proxy=http://127.0.0.1:9 \ + 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;" \ @@ -82,7 +84,7 @@ jobs: echo "::error::$TAG is a lightweight tag; releases must be annotated (git tag -a)" exit 1 fi - version="$($OFFLINE python3 -c 'import sys, yaml; print(yaml.safe_load(open("galaxy.yml"))["version"])')" + version="$(python3 -c 'import sys, yaml; print(yaml.safe_load(open("galaxy.yml"))["version"])')" if [ "$TAG" != "v$version" ]; then echo "::error::tag $TAG does not match galaxy.yml version $version (expected v$version)" exit 1 @@ -109,7 +111,7 @@ jobs: run: | export PATH="/opt/venv/bin:$PATH" mkdir -p /tmp/dist - $OFFLINE ansible-galaxy collection build --force --output-path /tmp/dist . + ansible-galaxy collection build --force --output-path /tmp/dist . ls -l /tmp/dist sha256sum /tmp/dist/*.tar.gz @@ -122,7 +124,7 @@ jobs: echo "::error::expected exactly one tarball in /tmp/dist, found $# match(es): $*" exit 1 fi - $OFFLINE python3 scripts/check_tarball.py "$1" + python3 scripts/check_tarball.py "$1" # galaxy-importer without ansible-test and without Docker. The importer reads its # configuration from this file. @@ -141,7 +143,7 @@ jobs: exit 1 fi GALAXY_IMPORTER_CONFIG=/tmp/galaxy-importer.cfg \ - $OFFLINE python3 -m galaxy_importer.main "$1" + python3 -m galaxy_importer.main "$1" # Sanity tests need the collection at ansible_collections//. - name: Run ansible-test sanity @@ -162,4 +164,4 @@ jobs: { cat tests/sanity/ignore-common.txt; if [ -f "$ignore" ]; then cat "$ignore"; fi; } > /tmp/ignore.new mv /tmp/ignore.new "$ignore" echo "Sanity ignore list for ansible-core ${core}: $(wc -l < "$ignore") lines" - $OFFLINE ansible-test sanity --requirements --color no + ansible-test sanity --requirements --color no diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml index a6f65a2..a069946 100644 --- a/.gitea/workflows/lint.yml +++ b/.gitea/workflows/lint.yml @@ -59,9 +59,11 @@ jobs: run: | if sha256sum --quiet -c /opt/ci-pins.sha256; then echo "The pin files match the ci image; using the baked tools." - # -r adds a user namespace: a job container lacks CAP_SYS_ADMIN for a plain unshare -n. - echo "OFFLINE=unshare -rn --" >> "$GITHUB_ENV" - echo "::notice::The tool steps run without network; a download fails the job (bake it into images/ci)." + # A job container may not unshare, so the network is cut by environment: pip, curl, + # git over HTTPS and Python's urllib fail; a raw socket is not caught. + printf '%s\n' PIP_NO_INDEX=1 http_proxy=http://127.0.0.1:9 https_proxy=http://127.0.0.1:9 \ + 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;" \ @@ -74,7 +76,7 @@ jobs: - name: Run pre-commit on all files run: | export PATH="/opt/venv/bin:$PATH" - $OFFLINE pre-commit run --all-files --show-diff-on-failure + pre-commit run --all-files --show-diff-on-failure # Image pins (scripts/check_image_versions.py): a pin in a workflow must name an # image of the matrix. Not a pre-commit hook: a change to .pre-commit-config.yaml @@ -82,7 +84,7 @@ jobs: - name: Check image pins run: | export PATH="/opt/venv/bin:$PATH" - $OFFLINE python3 scripts/check_image_versions.py pins + python3 scripts/check_image_versions.py pins # A pull request from a renovate/ branch may only move version, tag, digest and pin # lines (scripts/check_bot_pr_diff.py), so the bot's automerge cannot change workflow @@ -109,11 +111,12 @@ jobs: else echo "::notice::$BASE_REF has no scripts/check_bot_pr_diff.py yet; running the pull request's copy" fi - $OFFLINE python3 -E -s "$guard" "$HEAD_REF" "$BASE_REF" + python3 -E -s "$guard" "$HEAD_REF" "$BASE_REF" - # Online: a new network namespace has loopback down, and the image has no ip to bring it up for the fake registry. + # Without the guard: an empty no_proxy would send the fake registry on 127.0.0.1 to the dead proxy. - name: Test the repository scripts run: | + unset PIP_NO_INDEX http_proxy https_proxy HTTP_PROXY HTTPS_PROXY export PATH="/opt/venv/bin:$PATH" python3 -m unittest discover -s tests/scripts @@ -129,7 +132,7 @@ jobs: echo "gitleaks binary not found in the pre-commit cache" >&2 exit 1 fi - $OFFLINE "$GITLEAKS" git --verbose --redact --log-opts="origin/main..$SHA" + "$GITLEAKS" git --verbose --redact --log-opts="origin/main..$SHA" # commit-msg stage hooks do not run under --all-files, so each commit's message is given to # every commit-msg hook (Conventional Commits, refuse-agent-trailers); --no-verify skips them locally. @@ -143,5 +146,5 @@ jobs: for sha in $(git rev-list --no-merges "origin/main..$SHA"); do git log -1 --format=%B "$sha" > "$MSG_FILE" echo "Checking $sha" - $OFFLINE pre-commit run --hook-stage commit-msg --commit-msg-filename "$MSG_FILE" + pre-commit run --hook-stage commit-msg --commit-msg-filename "$MSG_FILE" done diff --git a/docs/images/ci.md b/docs/images/ci.md index d429449..ad9b1bd 100644 --- a/docs/images/ci.md +++ b/docs/images/ci.md @@ -66,8 +66,8 @@ Read `.gitea/workflows/molecule.yml` for the full command. `/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 -collections are used as they are, and Lint and Build run their tools (all but the script tests) without -network, 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 +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 (slower, same result), until the image is rebuilt from `main`. `lint.yml`, `build.yml`, `molecule.yml` and `gitea-release-key.yml` are the real consumers. diff --git a/images/AGENTS.md b/images/AGENTS.md index b0e0b31..c22eb58 100644 --- a/images/AGENTS.md +++ b/images/AGENTS.md @@ -62,9 +62,9 @@ it to this repository's organisation in the Gitea registry as `` and `l - **Bake in:** every tool, collection, hook environment and package a CI job uses is in its image; a job downloads at run time only on the slow path (a pull request that changes a pin file). *Why:* a run that downloads is slower and depends on the network. *Held:* control: on - the fast path the Lint and Build tool steps run without network, so a download fails the job; - review for a new tool step without the prefix, for the script tests, which keep network, and - for Molecule. + 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. - **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. From 2eb7da3563714104a346b90d85194286ea78f6f6 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 27 Nov 2026 03:18:31 +0000 Subject: [PATCH 06/11] chore(deps): update dependency apm-cli to v0.38.1 --- requirements-dev.lock | 6 +++--- requirements-dev.txt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/requirements-dev.lock b/requirements-dev.lock index 9917e06..01494c7 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -240,9 +240,9 @@ anyio==4.16.0 \ # via # httpx2 # openai -apm-cli==0.38.0 \ - --hash=sha256:6dfac2fdc8ab68586afb2b1a5a6db3c1b7ab569ff0edc525448aa85d0f92bd38 \ - --hash=sha256:aa51a98867ae6aef11e92143dd9ca2a994d3dd6cbd7224eae58fb7b8078fc3b1 +apm-cli==0.38.1 \ + --hash=sha256:c2a0394643e54d3516efefcd78bb043509ac48b65cca1f40166023789b8eb89a \ + --hash=sha256:c2ddd1ea95f7223de2ced83c1bbb61b756a10de2651edc76b93346c925dc162b # via -r requirements-dev.txt attrs==23.2.0 \ --hash=sha256:935dc3b529c262f6cf76e50877d35a4bd3c1de194fd41f47a2b7ae8f19971f30 \ diff --git a/requirements-dev.txt b/requirements-dev.txt index 0aa4b6f..d8d8ec5 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -19,4 +19,4 @@ molecule-plugins[docker]==26.11.0 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. -apm-cli==0.38.0 +apm-cli==0.38.1 From c51fa998b9ff2c5176b5eaf9d6591352871583b7 Mon Sep 17 00:00:00 2001 From: Dragonish Date: Fri, 27 Nov 2026 06:00:04 +0000 Subject: [PATCH 07/11] feat(system_baseline): let system_baseline_journal_max_use be empty to leave journald alone The role capped the persistent journal on every host with no way to opt out, and wrote the value into the drop-in unchecked: an empty value produced an empty SystemMaxUse=, and a bare number, a typo or a line break went into the file as it was. An empty system_baseline_journal_max_use now skips the journald task, as an empty system_baseline_apt_daily_timeout skips its task: no drop-in directory, no drop-in file and no restart of systemd-journald. A file an earlier run wrote stays. Any other value is checked before any change: infinity, or a number followed by K, M, G or T. A bare number, a space and a line break stop the run with a message that names the input. The default stays 200M. Closes #401 Assisted-by: Claude Code:claude-sonnet-5-5 --- .../fragments/401-journal-max-use-empty.yml | 9 ++++ roles/system_baseline/README.md | 9 +++- roles/system_baseline/defaults/main.yml | 3 +- roles/system_baseline/meta/argument_specs.yml | 4 ++ .../molecule/default/converge.yml | 18 ++++++++ .../default/tasks/refuse_journal_max_use.yml | 18 ++++++++ .../molecule/default/verify.yml | 45 +++++++++++++++++++ roles/system_baseline/tasks/main.yml | 1 + roles/system_baseline/tasks/validate.yml | 13 ++++++ 9 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/401-journal-max-use-empty.yml create mode 100644 roles/system_baseline/molecule/default/tasks/refuse_journal_max_use.yml diff --git a/changelogs/fragments/401-journal-max-use-empty.yml b/changelogs/fragments/401-journal-max-use-empty.yml new file mode 100644 index 0000000..0fd9461 --- /dev/null +++ b/changelogs/fragments/401-journal-max-use-empty.yml @@ -0,0 +1,9 @@ +--- +minor_changes: + - >- + system_baseline - ``system_baseline_journal_max_use`` can be empty to leave journald alone: the role then writes no drop-in and does not + restart ``systemd-journald``. The default stays ``200M``. + - >- + system_baseline - ``system_baseline_journal_max_use`` is checked before any change: it must be empty, ``infinity`` or a number followed by + ``K``, ``M``, ``G`` or ``T``. A value in any other form, which the role used to write into the drop-in as it was (a bare number, ``1.5G``, + a typo, a line break), now stops the run; an empty value used to write an empty ``SystemMaxUse=``. diff --git a/roles/system_baseline/README.md b/roles/system_baseline/README.md index 4878c11..99e78e0 100644 --- a/roles/system_baseline/README.md +++ b/roles/system_baseline/README.md @@ -44,7 +44,7 @@ templating error instead of the role's own message. | `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_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`). | +| `system_baseline_journal_max_use` | `200M` | no | Upper bound of the persistent journal (journald `SystemMaxUse`): a number and `K`, `M`, `G` or `T`, or `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) | | `system_baseline_tmux_session` | `main` | no | Session name, `A-Za-z0-9_-`, up to 32 characters | | `system_baseline_tmux_windows` | `[]` | no | `{name, command}` windows made when the session is created | @@ -128,12 +128,13 @@ 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). -- Converge first checks 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`, and a bad package blacklist (a quote, a null item, a bare string). +- Converge first checks 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` (a bare number, a space, a line break, a number), and a bad package blacklist (a quote, a null item, a bare string). - Converge then applies the `ubuntu_lxc` profile, with tmux autostart and `system_baseline_apt_daily_timeout: 1h`, and only resolves the `pve` and `ubuntu_vm` profiles and a consumer override, 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. - Converge 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, then 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. - Converge 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. Verify reads `tasks/update.yml` and checks that the scratch directory is created with mode `0700`, that both apt tasks set `TMPDIR` to it, and that the connection is reset afterwards: the scenario skips the `update` tag, so the upgrade itself never runs there. +- 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. @@ -211,6 +212,10 @@ The profile key `apt_upgrade` (`safe` or `dist`, resolved to `system_baseline_ap - The `update` entry point follows the same input: it upgrades with `dist` when `system_baseline_system_type` is `pve`. Without a `system_baseline_system_type` (the entry point does not require one) it stays on `safe`. - Only the apt upgrade changes. Autoremove and autoclean, the check-mode skip and unattended-upgrades are as before; the example blacklist below keeps unattended-upgrades away from the Proxmox packages. +### Leaving journald alone + +`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 (`300`, `0`, `10 M`, one with a line break) stops the run before any change, in the same way as the apt-daily value. + ### 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`. diff --git a/roles/system_baseline/defaults/main.yml b/roles/system_baseline/defaults/main.yml index 1a39db4..87a2e49 100644 --- a/roles/system_baseline/defaults/main.yml +++ b/roles/system_baseline/defaults/main.yml @@ -18,7 +18,8 @@ system_baseline_apt_tmpdir: /var/cache/system-baseline-apt-tmp # Run the package update (tasks/update.yml) in the main flow. false skips it, for hosts that are patched by a separate, # operator-run flow; the tasks_from: update entry point does not read it. system_baseline_update: true -# Upper bound of the persistent journal (journald SystemMaxUse); older archived files are removed above it. +# 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 # 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 diff --git a/roles/system_baseline/meta/argument_specs.yml b/roles/system_baseline/meta/argument_specs.yml index 9f0e417..04ba64f 100644 --- a/roles/system_baseline/meta/argument_specs.yml +++ b/roles/system_baseline/meta/argument_specs.yml @@ -55,6 +55,10 @@ argument_specs: description: - Upper bound of the persistent systemd journal (journald C(SystemMaxUse), for example C(200M)). - Written to a drop-in under C(/etc/systemd/journald.conf.d). + - >- + A number and one of C(K), C(M), C(G), C(T), or C(infinity); anything else (a bare number, a space, 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_tmux_autostart: type: bool default: false diff --git a/roles/system_baseline/molecule/default/converge.yml b/roles/system_baseline/molecule/default/converge.yml index 0a0b4d8..11bb7b4 100644 --- a/roles/system_baseline/molecule/default/converge.yml +++ b/roles/system_baseline/molecule/default/converge.yml @@ -118,6 +118,24 @@ that: "'system_baseline_apt_daily_timeout must be' in ansible_failed_result.msg | default('')" quiet: true +# The journal cap is a number and a unit letter, or empty: a bare number (journald would read bytes), a zero, a space, a line break, a +# lower-case unit and a number that is not a string each stop the run before any change. +- name: A bad journal size cap is refused + hosts: all + gather_facts: false + tasks: + - name: Refuse each bad value + ansible.builtin.include_tasks: tasks/refuse_journal_max_use.yml + vars: + system_baseline_refused_journal: "{{ item }}" + loop: + - "300" + - "0" + - 10 M + - "10m" + - "200M\nStorage=none" + - 300 + # 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 diff --git a/roles/system_baseline/molecule/default/tasks/refuse_journal_max_use.yml b/roles/system_baseline/molecule/default/tasks/refuse_journal_max_use.yml new file mode 100644 index 0000000..c0b421a --- /dev/null +++ b/roles/system_baseline/molecule/default/tasks/refuse_journal_max_use.yml @@ -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_journal_max_use + block: + - name: Include system_baseline + ansible.builtin.include_role: + name: mortis.kamino.system_baseline + vars: + system_baseline_system_type: ubuntu_lxc + system_baseline_journal_max_use: "{{ system_baseline_refused_journal }}" + - name: Unreachable when validation works + ansible.builtin.fail: + msg: system_baseline ran with an invalid system_baseline_journal_max_use + rescue: + - name: The validation stopped the play + ansible.builtin.assert: + that: "'system_baseline_journal_max_use must be' in ansible_failed_result.msg | default('')" + quiet: true diff --git a/roles/system_baseline/molecule/default/verify.yml b/roles/system_baseline/molecule/default/verify.yml index bc0dca2..7afc4b2 100644 --- a/roles/system_baseline/molecule/default/verify.yml +++ b/roles/system_baseline/molecule/default/verify.yml @@ -450,3 +450,48 @@ - system_baseline_verify_blacklist_dump_removed.stdout_lines | select('match', 'Unattended-Upgrade::Package-Blacklist::\s') | list == [] quiet: true tags: always + +# 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. +# It removes what the converge wrote, so a second `molecule verify` needs a converge first. +- name: An empty journal size cap leaves journald alone + hosts: all + gather_facts: true + tasks: + - name: Remove the drop-in and its directory + ansible.builtin.file: + path: /etc/systemd/journald.conf.d + state: absent + + - name: Note when journald last started + ansible.builtin.command: + argv: [systemctl, show, systemd-journald, --property=ActiveEnterTimestampMonotonic, --value] + register: system_baseline_verify_journald_before + changed_when: false + + - name: Run the role with an empty cap + ansible.builtin.include_role: + name: mortis.kamino.system_baseline + vars: + system_baseline_system_type: ubuntu_lxc + system_baseline_journal_max_use: "" + + - name: Look for the drop-in directory + ansible.builtin.stat: + path: /etc/systemd/journald.conf.d + register: system_baseline_verify_journald_dir + + - name: Note when journald last started, after the run + ansible.builtin.command: + argv: [systemctl, show, systemd-journald, --property=ActiveEnterTimestampMonotonic, --value] + register: system_baseline_verify_journald_after + changed_when: false + + - name: Nothing was written and journald was not restarted + ansible.builtin.assert: + that: + - not system_baseline_verify_journald_dir.stat.exists + - system_baseline_verify_journald_before.stdout | length > 0 + - system_baseline_verify_journald_after.stdout == system_baseline_verify_journald_before.stdout + quiet: true diff --git a/roles/system_baseline/tasks/main.yml b/roles/system_baseline/tasks/main.yml index 0917c46..0745c00 100644 --- a/roles/system_baseline/tasks/main.yml +++ b/roles/system_baseline/tasks/main.yml @@ -30,6 +30,7 @@ - name: Cap the journal size ansible.builtin.import_tasks: journald.yml + when: system_baseline_journal_max_use | length > 0 tags: journald - name: Bound a hung apt-daily.service diff --git a/roles/system_baseline/tasks/validate.yml b/roles/system_baseline/tasks/validate.yml index b9d054b..ac4d754 100644 --- a/roles/system_baseline/tasks/validate.yml +++ b/roles/system_baseline/tasks/validate.yml @@ -47,6 +47,19 @@ ansible.builtin.import_tasks: validate_reboot.yml tags: always +# The value is written into a journald drop-in: a number and a unit letter, so a bare number (journald reads it as bytes), a space or a line +# break (a second directive) never reaches the file. Empty leaves the host alone, as for the apt-daily timeout. +- name: Validate the journal size cap + ansible.builtin.assert: + that: + - system_baseline_journal_max_use is string + - system_baseline_journal_max_use == '' or system_baseline_journal_max_use is match('^(infinity|[0-9]+[KMGT])\Z') + fail_msg: >- + system_baseline_journal_max_use must be empty (leave journald alone), infinity or a size such as 200M or 2G + (a number and one of K, M, G, T; a bare number is refused, journald would read it as bytes). + 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 From 19449f7e93b95c550fe4a0ce474465e51c875555 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 27 Nov 2026 07:50:27 +0000 Subject: [PATCH 08/11] chore(deps): update ubuntu:24.04 docker digest to 562111b --- images/molecule-ubuntu2404/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/molecule-ubuntu2404/Dockerfile b/images/molecule-ubuntu2404/Dockerfile index 4161b44..3946f10 100644 --- a/images/molecule-ubuntu2404/Dockerfile +++ b/images/molecule-ubuntu2404/Dockerfile @@ -25,7 +25,7 @@ # 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:9c7f200c07e3d4a03e7249d2c16bf66a51120fb876aa2242cf31451412543289 +FROM ubuntu:24.04@sha256:562111b88caa79c71391c0c4d3c2114a7d5c35915c20561fd893cb1e07929e6b LABEL org.opencontainers.image.title="molecule-ubuntu2404" \ org.opencontainers.image.description="Disposable Ubuntu 24.04 test target for the molecule scenarios of the mortis.kamino Ansible Collection. systemd runs as PID 1 with D-Bus, sudo, python3 and the packages the roles manage (iptables, ufw, fail2ban, openssh-server) preinstalled, so a converge makes no network calls. Start it as a molecule platform (usage label); it carries throwaway SSH host keys and is a test target only, never to be exposed." \ From 2e92b11cbccd57a7d70c0254c74bf13fec7b381d Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Fri, 27 Nov 2026 08:15:18 +0000 Subject: [PATCH 09/11] remove image.yml timeout --- .gitea/workflows/image.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitea/workflows/image.yml b/.gitea/workflows/image.yml index 07ab4a3..7e212c9 100644 --- a/.gitea/workflows/image.yml +++ b/.gitea/workflows/image.yml @@ -62,7 +62,6 @@ jobs: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' runs-on: kamino-docker - timeout-minutes: 45 # max-parallel: 1 keeps the builds to one at a time. The runner takes two jobs, so a build # may share it with one other job (Lint, Build or Molecule). An empty subpath means the # repository root is the build context. From e2df672be72f04a276dd19701cc4bbaf7b9c14a2 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Fri, 27 Nov 2026 08:15:45 +0000 Subject: [PATCH 10/11] remove molecule.yml timeout --- .gitea/workflows/molecule.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.gitea/workflows/molecule.yml b/.gitea/workflows/molecule.yml index ced0649..252742b 100644 --- a/.gitea/workflows/molecule.yml +++ b/.gitea/workflows/molecule.yml @@ -47,10 +47,6 @@ jobs: (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) runs-on: [kamino-molecule] - # Two full runs sharing the runner (a nightly run and a dispatch) take more than 30 minutes. - # Also the age past which the sweep step removes a run's containers; a script test holds the - # two equal. - timeout-minutes: 45 env: # The tools and collections molecule runs with: the image Lint and Build use. CI_IMAGE: >- From 18475ea0a50a1a8cd3d1e1d7106f061e97a4a800 Mon Sep 17 00:00:00 2001 From: Dragonish Date: Fri, 27 Nov 2026 08:47:25 +0000 Subject: [PATCH 11/11] fix(ci): give the molecule job a 90 minute timeout Removing timeout-minutes left the sweep step's 45 minute bound without the job timeout it must equal, and the script test that holds the two equal failed with a KeyError. Restore the key at 90 minutes, which also leaves a full run under load (PR #405 took 44m53s) real margin, and move the sweep bound to match so a live run's containers are never removed. Assisted-by: Claude Code --- .gitea/workflows/molecule.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/molecule.yml b/.gitea/workflows/molecule.yml index 252742b..6358ab5 100644 --- a/.gitea/workflows/molecule.yml +++ b/.gitea/workflows/molecule.yml @@ -47,6 +47,9 @@ jobs: (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) runs-on: [kamino-molecule] + # A full run under load takes about 45 minutes (PR #405: 44m53s), so 45 left no margin. Also the + # age past which the sweep step removes a run's containers; a script test holds the two equal. + timeout-minutes: 90 env: # The tools and collections molecule runs with: the image Lint and Build use. CI_IMAGE: >- @@ -94,7 +97,7 @@ jobs: ids="$(docker ps -aq --filter 'label=net.rkdr.mortis.molecule-run')" # The job's timeout-minutes (a script test holds them equal): a shorter bound would remove a # live run's containers. - cutoff="$(date -d '45 minutes ago' +%s)" + cutoff="$(date -d '90 minutes ago' +%s)" old="" for id in $ids; do # a container removed since the listing, by its run or another run's sweep, is skipped