Author SHA1 Message Date
Defame1297 595f517b49 chore(apm): pin apm with uv
Build / build (pull_request) Successful in 28s
Molecule / select (pull_request) Successful in 5s
Lint / lint (pull_request) Successful in 4m16s
Molecule / scenarios (pull_request) Successful in 34m33s
Molecule / Result (pull_request) Successful in 1s
A bare `apm` is whatever version a machine has. apm 0.37.0 to 0.39.1
refuse an apm.lock.yaml rewritten by 0.39.2 or later, and versions before
0.39.0 drop `disable-model-invocation` from the deployed Claude commands.
uv now runs one pinned version, from a .venv of its own.

apm-cli leaves requirements-dev.txt, so there is one pin. Its lock loses 40
packages and no other version moves. apm.lock.yaml is regenerated with the
pinned apm.

Refs: #517
Assisted-by: Claude Code
2026-12-04 21:48:53 +00:00
Defame1297 d732ac0a71 Merge pull request 'chore(dev): move the dev tools from .venv to .venv-dev' (#519) from chore/516-venv-dev into main
Reviewed-on: #519
Reviewed-by: Defame1297 <[email protected]>
2026-12-04 21:16:58 +00:00
Defame1297 f62097a748 chore(dev): move the dev tools from .venv to .venv-dev
Build / build (pull_request) Successful in 34s
Molecule / select (pull_request) Successful in 3s
Molecule / scenarios (pull_request) Skipped
Molecule / Result (pull_request) Successful in 1s
Lint / lint (pull_request) Successful in 1m49s
uv uses .venv as its project environment, and `uv sync --frozen` removes
every package that is not in uv.lock. The tools the git hooks need would
go with it, so they get a directory of their own.

Re-running scripts/dev-setup.sh switches the hooks of an older clone and
leaves its .venv alone. Ignore rules and prunes cover both directories.

Refs: #516
Assisted-by: Claude Code
2026-12-04 20:45:49 +00:00
Defame1297 b7b763e1fa Merge pull request 'chore(release): 3.4.0' (#515) from chore/512-release-3.4.0 into main
Build / build (push) Successful in 16s
Reviewed-on: #515
2026-12-04 19:33:54 +00:00
Defame1297 1dfdaf48ec chore(release): 3.4.0
Build / build (pull_request) Successful in 41s
Molecule / select (pull_request) Successful in 8s
Molecule / scenarios (pull_request) Skipped
Molecule / Result (pull_request) Successful in 1s
Lint / lint (pull_request) Successful in 2m10s
Minor release: system_baseline persists its sysctl hardening in its own
sysctl.d drop-in, so it survives a reboot on Debian 13, and refuses ICMP
redirects on every interface.

Refs #512

Assisted-by: Claude Code:claude-opus-5-5
2026-12-03 19:21:05 +00:00
Defame1297 3d7b66072e Merge pull request 'fix(system_baseline): refuse ICMP redirects on every interface' (#514) from fix/511-icmp-redirects into main
Reviewed-on: #514
2026-12-03 19:15:06 +00:00
Defame1297 83f4cc2c5b Merge branch 'main' into fix/511-icmp-redirects
Build / build (pull_request) Successful in 32s
Molecule / select (pull_request) Successful in 6s
Lint / lint (pull_request) Successful in 2m56s
Molecule / scenarios (pull_request) Successful in 5m33s
Molecule / Result (pull_request) Successful in 1s
2026-12-03 19:08:37 +00:00
Defame1297 eaece480c8 Merge pull request 'fix(system_baseline): persist sysctls in an own sysctl.d drop-in' (#513) from fix/510-sysctl-dropin into main
Reviewed-on: #513
2026-12-03 18:52:01 +00:00
Defame1297 191431a8e4 Merge branch 'main' into fix/510-sysctl-dropin
Build / build (pull_request) Successful in 32s
Molecule / select (pull_request) Successful in 4s
Lint / lint (pull_request) Successful in 3m2s
Molecule / scenarios (pull_request) Successful in 5m18s
Molecule / Result (pull_request) Successful in 1s
2026-12-03 18:45:52 +00:00
Defame1297 2158233241 Merge pull request 'chore(deps): update own ci images' (#507) from renovate/own-ci-images into main
Reviewed-on: #507
2026-12-03 17:48:32 +00:00
Defame1297 74e574ee80 fix(system_baseline): refuse ICMP redirects on every interface
Build / build (pull_request) Successful in 28s
Molecule / select (pull_request) Successful in 8s
Lint / lint (pull_request) Successful in 2m23s
Molecule / scenarios (pull_request) Successful in 10m38s
Molecule / Result (pull_request) Successful in 1s
With forwarding off the kernel accepts redirects when either `all` or the
interface's own value is 1, and over IPv6 only the interface's value counts.
The profiles now also set `default` and, with a wildcard, every existing
interface, over IPv4 and IPv6.

Refs #511

Assisted-by: Claude Code:claude-opus-5-5
2026-12-03 17:44:02 +00:00
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
39 changed files with 2513 additions and 1243 deletions

No files matched your search

+1
View File
@@ -6,6 +6,7 @@ profile: production
exclude_paths:
- .gitea
- .venv
- .venv-dev
- apm_modules
- apm.lock.yaml
- changelogs
+3 -3
View File
@@ -94,13 +94,13 @@ jobs:
# ansible-galaxy dereferences symlinks when it builds, so a symlink in the source tree
# reaches the archive as a regular file with the target's content, where
# scripts/check_tarball.py cannot see it. Refuse them in the tree instead: this step
# is the only guard against a file symlink. The two -prune paths below (./.venv,
# ./.git) are skipped only because the build skips them too (galaxy.yml build_ignore,
# is the only guard against a file symlink. The -prune paths below (./.git, ./.venv,
# ./.venv-dev) are skipped only because the build skips them too (galaxy.yml build_ignore,
# and ansible-galaxy's own .git exclusion): the two lists must stay in step, and
# tests/scripts/test_check_tarball.py fails when a pruned directory is not ignored.
- name: Refuse symlinks in the source tree
run: |
links="$(find . -path ./.git -prune -o -path ./.venv -prune -o -type l -print)"
links="$(find . -path ./.git -prune -o -path ./.venv -prune -o -path ./.venv-dev -prune -o -type l -print)"
if [ -n "$links" ]; then
echo "::error::symlinks in the source tree would be dereferenced into the Collection archive:"
echo "$links"
+1
View File
@@ -1,6 +1,7 @@
# Built collection archives and local tooling
*.tar.gz
/.venv/
/.venv-dev/
/venv/
__pycache__/
*.pyc
+1
View File
@@ -3,6 +3,7 @@ extends: default
ignore: |
.venv/**
.venv-dev/**
apm_modules/**
# Generated by apm install; its list indentation fails the rules below.
apm.lock.yaml
+19
View File
@@ -4,6 +4,25 @@ mortis.kamino Release Notes
.. contents:: Topics
v3.4.0
======
Minor Changes
-------------
- system_baseline - A name in ``system_baseline_sysctl_hardening`` may contain ``*``, which sets the key on every interface.
- system_baseline - New input ``system_baseline_sysctl_file``, the path of the drop-in that persists the sysctl hardening.
Security Fixes
--------------
- system_baseline - Every profile now refuses ICMP redirects on every interface, over IPv4 and IPv6. Before, only ``net.ipv4.conf.all`` was set, so a host that does not forward still accepted them on its interfaces.
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.
v3.3.0
======
+2
View File
@@ -34,4 +34,6 @@ GLOSSARY\\.md @Defame1297
\\.claude/.* @Defame1297
apm\\.yml @Defame1297
apm\\.lock\\.yaml @Defame1297
pyproject\\.toml @Defame1297
uv\\.lock @Defame1297
\\.mcp\\.json @Defame1297
+2 -2
View File
@@ -5,7 +5,7 @@ An Ansible Collection of reusable, hardened roles for a self-hosted home lab:
`nfs_client`, `pihole`, `pve_lxc`, `pve_vm`, `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.3.0 holds the `cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, `nfs_client`, `pihole`, `pve_lxc`, `pve_vm`, `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).
Status: roles arrive in waves. Release 3.4.0 holds the `cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, `nfs_client`, `pihole`, `pve_lxc`, `pve_vm`, `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.<role>`:
collections:
- name: https://git.rkdr.net/mortis/kamino.git
type: git
version: v3.3.0
version: v3.4.0
```
Its dependencies (`community.general`, `ansible.posix`, `community.proxmox`) are declared in `galaxy.yml`, so
+6 -6
View File
@@ -1,6 +1,6 @@
lockfile_version: '4'
generated_at: '2026-11-29T13:12:37.842657+00:00'
apm_version: 0.38.1
generated_at: '2026-12-04T21:33:07.493501+00:00'
apm_version: 0.39.3
manifest_targets:
- claude
dependencies:
@@ -220,8 +220,8 @@ dependencies:
.claude/agents/plan-researcher.md: sha256:eda0457d2007cf0c6cb4745383a0369d03a26ed252d7251a1f5250003a89ef85
.claude/agents/plan-validator.md: sha256:a56e7a710fd9e7a9dd9e2601f1f2701b98fd229f3e014bba4bda4dfe5977ecae
.claude/commands/next.md: sha256:8e16330ec0f16dbbc86d44fca94699e33e393c9a8af76f45d3f3bd2b9c8bfa1f
.claude/commands/plan.md: sha256:2538b3dbb3860ebe93a39cad95cd5a1adcbeded19f404a84201b3e8aa7ce91c7
.claude/commands/ship.md: sha256:f108f73e60a884f46285955027fba47d6309fed6a89812948f577e27be180af8
.claude/commands/plan.md: sha256:c5216fb6c443ca9de45ad5cb69351a4e3193bcb5ffca4d59567495fcb5d7ec71
.claude/commands/ship.md: sha256:c3c9f516b9b01cb7f879d7d331187b12f697f73104b0eafdc813d64b73091284
.claude/skills/plan-track/LICENSE: sha256:9d3692e6b35e0e43b81e096352f11c6b884e7004d78d3dcd92768232c6704525
.claude/skills/plan-track/SKILL.md: sha256:fee5062c8c63b49f66368b290c8ebd8cfff744137670d0c037da1a49c455c047
.claude/skills/research-docs/LICENSE: sha256:9d3692e6b35e0e43b81e096352f11c6b884e7004d78d3dcd92768232c6704525
@@ -843,7 +843,7 @@ deployments:
owners:
- git.rkdr.net/Mortis/Holocron/plugins/plan
active_owner: git.rkdr.net/Mortis/Holocron/plugins/plan
content_hash: sha256:2538b3dbb3860ebe93a39cad95cd5a1adcbeded19f404a84201b3e8aa7ce91c7
content_hash: sha256:c5216fb6c443ca9de45ad5cb69351a4e3193bcb5ffca4d59567495fcb5d7ec71
- kind: project-relative
target: claude
value: .claude/commands/ship.md
@@ -852,7 +852,7 @@ deployments:
owners:
- git.rkdr.net/Mortis/Holocron/plugins/plan
active_owner: git.rkdr.net/Mortis/Holocron/plugins/plan
content_hash: sha256:f108f73e60a884f46285955027fba47d6309fed6a89812948f577e27be180af8
content_hash: sha256:c3c9f516b9b01cb7f879d7d331187b12f697f73104b0eafdc813d64b73091284
- kind: project-relative
target: claude
value: .claude/skills/code-review
+1 -1
View File
@@ -93,4 +93,4 @@ plugins:
strategy: {}
test: {}
vars: {}
version: 3.3.0
version: 3.4.0
+23
View File
@@ -576,3 +576,26 @@ releases:
- 482-pve-vm.yml
- system-baseline-internal-registers.yml
release_date: '2026-12-01'
3.4.0:
changes:
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.
minor_changes:
- system_baseline - A name in ``system_baseline_sysctl_hardening`` may contain
``*``, which sets the key on every interface.
- system_baseline - New input ``system_baseline_sysctl_file``, the path of the
drop-in that persists the sysctl hardening.
security_fixes:
- system_baseline - Every profile now refuses ICMP redirects on every interface,
over IPv4 and IPv6. Before, only ``net.ipv4.conf.all`` was set, so a host
that does not forward still accepted them on its interfaces.
fragments:
- 505-ufw-check-mode-probe.yml
- 510-system-baseline-sysctl-dropin.yml
- 510-system-baseline-sysctl-file.yml
- 511-system-baseline-icmp-redirects.yml
- 511-system-baseline-sysctl-wildcard.yml
release_date: '2026-12-03'
@@ -1,5 +0,0 @@
---
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.
+7 -1
View File
@@ -9,7 +9,7 @@ held by review until an offline link check exists.
## The clone
- **Run `scripts/dev-setup.sh` once per clone, and again after a change to `requirements-dev.txt`, its
lock `requirements-dev.lock`, `requirements.yml` or the hook types.** It creates `.venv` with the
lock `requirements-dev.lock`, `requirements.yml` or the hook types.** It creates `.venv-dev` with the
pinned tools on the Python named in `.python-version`, installs the collections of `requirements.yml`
into `.ansible/collections`, and installs the git hooks (pre-commit, commit-msg, pre-push) with the
virtualenv first on their `PATH`.
@@ -63,6 +63,12 @@ held by review until an offline link check exists.
pushed on an unmerged branch lets that branch's commands run without a prompt before anyone has
reviewed it, while a `deny` or `ask` rule can only add prompts.
*Held by:* review (`.claude/` is under `CODEOWNERS`).
- **Install [uv](https://docs.astral.sh/uv/getting-started/installation/), run `uv sync --frozen` once per
clone and again after a change to `uv.lock`, and run apm only as `uv run --frozen apm ...`** (for example
`uv run --frozen apm install`). uv keeps apm in `.venv`, apart from the tools in `.venv-dev`.
*Reason:* a bare `apm` is whatever version your machine has, and versions differ in which
`apm.lock.yaml` they accept and in what they deploy.
*Held by:* aspirational.
- **Every hook in the tracked `.claude/settings.json` arrives through apm; personal hooks go in
`.claude/settings.local.json`.**
*Reason:* a hook nobody owns is checked by nothing.
+4 -1
View File
@@ -1,7 +1,7 @@
---
namespace: mortis
name: kamino
version: 3.3.0
version: 3.4.0
readme: README.md
authors:
- Defame1297
@@ -46,6 +46,7 @@ build_ignore:
- .python-version
- .ruff_cache
- .venv
- .venv-dev
- .yamllint
- docs
- .ansible-lint
@@ -59,6 +60,7 @@ build_ignore:
- images
- scripts
- tests/scripts
- pyproject.toml
- renovate.json
- ruff.toml
- requirements-dev.txt
@@ -66,6 +68,7 @@ build_ignore:
- requirements-molecule.txt
- requirements-molecule.lock
- requirements.yml
- uv.lock
- gitleaks-report.json
- importer_result.json
- 'roles/*/molecule'
+2 -2
View File
@@ -14,7 +14,7 @@
# 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, proxmoxer), on the Python of
# .python-version (PYTHON_VERSION below), the one the lock was resolved on and a clone's .venv uses.
# .python-version (PYTHON_VERSION below), the one the lock was resolved on and a clone's .venv-dev 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
@@ -71,7 +71,7 @@ COPY requirements-dev.txt requirements-dev.lock requirements.yml .pre-commit-con
# 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
# python3, so the tools run on the Python the lock was resolved on and a clone's .venv uses.
# python3, so the tools run on the Python the lock was resolved on and a clone's .venv-dev uses.
# uv only lives in the build stage (its own venv): the final image keeps the interpreters it
# downloaded, not the installer. The distribution's python3 only bootstraps uv.
RUN python3 -m venv /opt/uv-venv \
+12
View File
@@ -0,0 +1,12 @@
# Pins apm for contributors (docs/contributing/setup.md). The Lint and Build tools are pinned in requirements-dev.txt.
[project]
name = "kamino"
version = "0"
# ruff reads this floor too: a higher one makes it reformat existing files.
requires-python = ">=3.11"
[dependency-groups]
dev = ["apm-cli==0.39.3"]
[tool.uv]
package = false
-1
View File
@@ -196,7 +196,6 @@
"pypi"
],
"matchPackageNames": [
"apm-cli",
"antsibull-changelog",
"galaxy-importer",
"reuse",
+6 -1180
View File
File diff suppressed because it is too large. Load diff
+1 -4
View File
@@ -1,5 +1,5 @@
# 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
# python3 -m venv .venv-dev && . .venv-dev/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
# install in which the two files disagree. Renovate bumps a pin here and regenerates the lock
@@ -18,6 +18,3 @@ molecule==26.11.1
# proxmoxer: the controller-side library community.proxmox's modules import (they refuse anything below 2.3),
# 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.
apm-cli==0.39.1
+20 -4
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.
@@ -43,7 +43,8 @@ templating error instead of the role's own message.
| `system_baseline_unattended_upgrade_settings` | from profile | no | Keys for `50unattended-upgrades` |
| `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_hardening` | from profile | no | List of `name` and `value` sysctl pairs; `*` in a name matches every interface (see "Sysctl hardening") |
| `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, each for a plain key and for a `*`, and a failure for a `*` that matches no key.
- 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, runs without IPv6 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,20 @@ 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.
- Every profile refuses ICMP redirects on every interface: `accept_redirects` is `0` for `all`, `default` and `*` (each interface that exists) over IPv4 and IPv6. `secure_redirects` is `0` for `all` and `default` over IPv4; the kernel reads it only for an interface that accepts redirects. An inventory that overrides the list or a profile's `sysctl_hardening` has to add these keys itself.
- A `*` sets every matching key except those with an entry of their own, so `net.ipv4.conf.eth1.accept_redirects` in the list keeps its value. At boot an entry in any other `sysctl.d` file also wins over a `*`. Write names with dots, and a dot in an interface name as a slash: `net.ipv4.conf.eth0/100.accept_redirects`. Use a `*` only for keys with a single-word value, and no two patterns that match the same key.
- Without IPv6 in the kernel the role skips the `net.ipv6` keys on the running kernel and still persists them. `systemd-sysctl` ignores them at boot; `sysctl -p` on the drop-in reports them as missing and exits 1.
- 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`.
+25
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.
@@ -107,7 +110,13 @@ system_baseline_profiles:
- { name: "kernel.randomize_va_space", value: 2 }
- { name: "net.ipv4.conf.all.accept_source_route", value: 0 }
- { name: "net.ipv4.conf.all.accept_redirects", value: 0 }
- { name: "net.ipv4.conf.default.accept_redirects", value: 0 }
- { name: "net.ipv4.conf.*.accept_redirects", value: 0 }
- { name: "net.ipv4.conf.all.secure_redirects", value: 0 }
- { name: "net.ipv4.conf.default.secure_redirects", value: 0 }
- { name: "net.ipv6.conf.all.accept_redirects", value: 0 }
- { name: "net.ipv6.conf.default.accept_redirects", value: 0 }
- { name: "net.ipv6.conf.*.accept_redirects", value: 0 }
- { name: "net.ipv4.icmp_echo_ignore_broadcasts", value: 1 }
- { name: "net.ipv4.icmp_ignore_bogus_error_responses", value: 1 }
- { name: "net.ipv4.conf.all.log_martians", value: 1 }
@@ -170,7 +179,13 @@ system_baseline_profiles:
- { name: "net.ipv4.tcp_syncookies", value: 1 }
- { name: "net.ipv4.conf.all.accept_source_route", value: 0 }
- { name: "net.ipv4.conf.all.accept_redirects", value: 0 }
- { name: "net.ipv4.conf.default.accept_redirects", value: 0 }
- { name: "net.ipv4.conf.*.accept_redirects", value: 0 }
- { name: "net.ipv4.conf.all.secure_redirects", value: 0 }
- { name: "net.ipv4.conf.default.secure_redirects", value: 0 }
- { name: "net.ipv6.conf.all.accept_redirects", value: 0 }
- { name: "net.ipv6.conf.default.accept_redirects", value: 0 }
- { name: "net.ipv6.conf.*.accept_redirects", value: 0 }
- { name: "net.ipv4.icmp_echo_ignore_broadcasts", value: 1 }
- { name: "net.ipv4.icmp_ignore_bogus_error_responses", value: 1 }
@@ -231,7 +246,13 @@ system_baseline_profiles:
- { name: "kernel.randomize_va_space", value: 2 }
- { name: "net.ipv4.conf.all.accept_source_route", value: 0 }
- { name: "net.ipv4.conf.all.accept_redirects", value: 0 }
- { name: "net.ipv4.conf.default.accept_redirects", value: 0 }
- { name: "net.ipv4.conf.*.accept_redirects", value: 0 }
- { name: "net.ipv4.conf.all.secure_redirects", value: 0 }
- { name: "net.ipv4.conf.default.secure_redirects", value: 0 }
- { name: "net.ipv6.conf.all.accept_redirects", value: 0 }
- { name: "net.ipv6.conf.default.accept_redirects", value: 0 }
- { name: "net.ipv6.conf.*.accept_redirects", value: 0 }
- { name: "net.ipv4.icmp_echo_ignore_broadcasts", value: 1 }
- { name: "net.ipv4.icmp_ignore_bogus_error_responses", value: 1 }
- { name: "net.ipv4.conf.all.log_martians", value: 1 }
@@ -276,4 +297,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,208 @@
- {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.default.accept_redirects=0
- net.ipv4.conf.*.accept_redirects=0
- net.ipv4.conf.all.secure_redirects=0
- net.ipv4.conf.default.secure_redirects=0
- net.ipv6.conf.all.accept_redirects=0
- net.ipv6.conf.default.accept_redirects=0
- net.ipv6.conf.*.accept_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
# The container can inherit the runner host's values. The interfaces share the value of `default`; `all` has its own.
- name: Read the live arp_accept values
ansible.builtin.command:
argv: [cat, /proc/sys/net/ipv4/conf/all/arp_accept, /proc/sys/net/ipv4/conf/default/arp_accept]
register: system_baseline_verify_sysctl_arp
changed_when: false
- name: Apply a wildcard value that every interface already has
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
tasks_from: sysctl_apply
vars:
system_baseline_sysctl_hardening:
- { name: net.ipv4.conf.all.arp_accept, value: "{{ system_baseline_verify_sysctl_arp.stdout_lines[0] }}" }
- { name: "net.ipv4.conf.*.arp_accept", value: "{{ system_baseline_verify_sysctl_arp.stdout_lines[1] }}" }
- name: No interface was changed
ansible.builtin.assert:
that: __system_baseline_sysctl_wildcard_apply is not changed
quiet: true
- name: Preview a different wildcard 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.conf.all.arp_accept, value: "{{ system_baseline_verify_sysctl_arp.stdout_lines[0] }}" }
- { name: "net.ipv4.conf.*.arp_accept", value: "{{ (system_baseline_verify_sysctl_arp.stdout_lines[1] == '0') | ternary(1, 0) }}" }
- name: The pending change covers the interfaces and not the key with its own entry
ansible.builtin.assert:
that:
- __system_baseline_sysctl_wildcard_apply is changed
- system_baseline_verify_sysctl_cmd is search('net.ipv4.conf.lo.arp_accept=')
- system_baseline_verify_sysctl_cmd is not search('net.ipv4.conf.all.arp_accept=')
quiet: true
vars:
system_baseline_verify_sysctl_cmd: "{{ __system_baseline_sysctl_wildcard_apply.results[0].cmd | join(' ') }}"
- name: Apply a wildcard 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.conf.*.arp_accept", value: "{{ (system_baseline_verify_sysctl_arp.stdout_lines[1] == '0') | ternary(1, 0) }}" }
- name: Unreachable when a refused wildcard value fails
ansible.builtin.fail:
msg: system_baseline ignored a sysctl wildcard that could not be set
rescue:
- name: The refused wildcard write stopped the play
ansible.builtin.assert:
that: ansible_failed_task.name is search('Apply the sysctl wildcards')
quiet: true
- name: Apply a wildcard that matches no key
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.conf.*.accept_redirect", value: 0 }
- name: Unreachable when a wildcard without a match fails
ansible.builtin.fail:
msg: system_baseline ignored a sysctl wildcard that matches no key
rescue:
- name: The wildcard without a match stopped the play
ansible.builtin.assert:
that: ansible_failed_task.name is search('Read the live values a wildcard matches')
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,73 @@
---
# 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 | rejectattr('key', 'search', '[*]') }}"
register: __system_baseline_sysctl_live
changed_when: false
failed_when: false
check_mode: false
become: true
# The directory is missing when the kernel runs without IPv6; a mistyped IPv6 key still fails when it exists.
- name: Check that the kernel has IPv6
ansible.builtin.stat:
path: /proc/sys/net/ipv6/conf
register: __system_baseline_sysctl_ipv6
# `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
- __system_baseline_sysctl_ipv6.stat.exists or item.item.key is not match('net[.]ipv6[.]')
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
# After the plain keys: an interface created from here on inherits the new `default`. A wildcard without a match is a typo, as
# an unknown plain key is, unless the kernel has no IPv6. sysctl exits 0 when an interface disappears while it lists them.
- name: Read the live values a wildcard matches
ansible.builtin.command:
argv: [/usr/sbin/sysctl, -a, -e, -r, "^{{ item.key | replace('.', '[.]') | replace('*', '[^.]*') }}$"]
loop: "{{ __system_baseline_sysctl | dict2items | selectattr('key', 'search', '[*]') }}"
register: __system_baseline_sysctl_wildcard
changed_when: false
failed_when: >-
__system_baseline_sysctl_wildcard.rc != 0
or (__system_baseline_sysctl_wildcard.stdout | length == 0
and (__system_baseline_sysctl_ipv6.stat.exists or item.key is not match('net[.]ipv6[.]')))
check_mode: false
become: true
# A key with its own entry keeps that value, as at boot. -e skips an interface that is gone, unless it goes during the write itself.
- name: Apply the sysctl wildcards
ansible.builtin.command:
argv: "{{ ['/usr/sbin/sysctl', '-e', '-w'] + (__system_baseline_sysctl_pending | product([item.item.value]) | map('join', '=')) }}"
removes: /proc/sys
environment:
LC_ALL: C
vars:
__system_baseline_sysctl_pending: >-
{{ item.stdout_lines | reject('search', ' = ' ~ (item.item.value | regex_escape) ~ '$')
| map('regex_replace', ' = .*', '') | difference(__system_baseline_sysctl.keys() | list) }}
loop: "{{ __system_baseline_sysctl_wildcard.results }}"
loop_control:
label: "{{ item.item.key }}={{ item.item.value }}"
when: __system_baseline_sysctl_pending | length > 0
register: __system_baseline_sysctl_wildcard_apply
failed_when: >-
__system_baseline_sysctl_wildcard_apply.stderr_lines | default([]) | reject('search', 'No such file or directory') | length > 0
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
@@ -19,7 +19,7 @@ cd "$root"
for tool in ansible ansible-test; do
if ! command -v "$tool" >/dev/null 2>&1; then
echo "error: $tool is not on PATH; run scripts/dev-setup.sh and use its virtualenv (.venv/bin)" >&2
echo "error: $tool is not on PATH; run scripts/dev-setup.sh and use its virtualenv (.venv-dev/bin)" >&2
exit 1
fi
done
+1 -1
View File
@@ -27,7 +27,7 @@ allow list. It fails the build for:
ansible-galaxy dereferences FILE symlinks while building, so a symlink to a file reaches
the archive as a regular file with the target's content and this check cannot see it. The
`Refuse symlinks in the source tree` step of .gitea/workflows/build.yml is the only guard
against that. Its `find` prunes ./.venv and ./.git only because both are in galaxy.yml
against that. Its `find` prunes ./.git, ./.venv and ./.venv-dev only because they are in galaxy.yml
`build_ignore` (or excluded by ansible-galaxy itself, as .git is): the two lists must stay
in step, and tests/scripts/test_check_tarball.py fails when a pruned directory is not
ignored by the build.
+9 -9
View File
@@ -26,7 +26,7 @@ set -euo pipefail
# The repository is derived from this script's own location (symlinks resolved), never
# from the caller's working directory: running it from another repository must not
# create or remove that repository's .venv.
# create or remove that repository's .venv-dev.
script="$(readlink -f "${BASH_SOURCE[0]}")"
root="$(git -C "$(dirname "$script")/.." rev-parse --show-toplevel)"
cd "$root"
@@ -122,19 +122,19 @@ if still="$(git -C "$root" config --get core.hooksPath)" && [ -n "$still" ]; the
fi
# A virtualenv made by an older Python is rebuilt rather than reused.
if [ -x .venv/bin/python ] && ! .venv/bin/python -c "$py_ok" 2>/dev/null; then
rm -rf "$root/.venv"
if [ -x .venv-dev/bin/python ] && ! .venv-dev/bin/python -c "$py_ok" 2>/dev/null; then
rm -rf "$root/.venv-dev"
fi
[ -x .venv/bin/python ] || "$python" -m venv .venv
.venv/bin/pip install --quiet --disable-pip-version-check --require-hashes -r requirements-dev.lock -r requirements-dev.txt
.venv/bin/pre-commit install --install-hooks
[ -x .venv-dev/bin/python ] || "$python" -m venv .venv-dev
.venv-dev/bin/pip install --quiet --disable-pip-version-check --require-hashes -r requirements-dev.lock -r requirements-dev.txt
.venv-dev/bin/pre-commit install --install-hooks
# The collections of requirements.yml, exactly as pinned, into this clone (.ansible/ is ignored by
# git and by the Collection build). ANSIBLE_COLLECTIONS_PATH is set to the target for the install:
# a copy found elsewhere (~/.ansible/collections) would be skipped as already installed.
collections="$root/.ansible/collections"
mkdir -p "$collections"
ANSIBLE_COLLECTIONS_PATH="$collections" .venv/bin/ansible-galaxy collection install \
ANSIBLE_COLLECTIONS_PATH="$collections" .venv-dev/bin/ansible-galaxy collection install \
-r requirements.yml -p "$collections"
marker="# kamino-dev-setup: virtualenv first on PATH"
@@ -150,7 +150,7 @@ for hook in pre-commit commit-msg pre-push; do
{
head -n 1 "$file"
# %q shell-quotes the path: a repository path with spaces, quotes or $(...) is data.
printf '%s\n' "$marker" "export PATH=$(printf '%q' "$root/.venv/bin"):\"\$PATH\""
printf '%s\n' "$marker" "export PATH=$(printf '%q' "$root/.venv-dev/bin"):\"\$PATH\""
tail -n +2 "$file"
} > "$tmp"
cat "$tmp" > "$file" # keeps the file mode of the hook
@@ -179,4 +179,4 @@ else
fi
fi
echo "Done: git commit now runs the hooks with the tools in $root/.venv/bin and the collections in $collections."
echo "Done: git commit now runs the hooks with the tools in $root/.venv-dev/bin and the collections in $collections."
+1 -1
View File
@@ -11,7 +11,7 @@
# Needs the network (PyPI) and the Python of .python-version (python<MINOR>; KAMINO_PYTHON overrides it): the
# header of the lock records it, and check_image_versions.py pins fails when it differs.
# pip and pip-tools are installed, at the pinned versions below, into a throwaway virtualenv, never
# into the project's .venv. pip is pinned too: pip-tools breaks on newer pip releases (7.5.2 on pip 26). Commit
# into the project's .venv-dev. pip is pinned too: pip-tools breaks on newer pip releases (7.5.2 on pip 26). Commit
# the lock with its requirements file; pip refuses an install of the two when they disagree
# (`pip install --require-hashes -r requirements-dev.lock -r requirements-dev.txt`).
# The pins are not hash-checked themselves: they come from PyPI over TLS, like the pip that
+2
View File
@@ -92,6 +92,8 @@ IGNORED = (
"ruff.toml",
"apm.yml",
"apm.lock.yaml",
"pyproject.toml",
"uv.lock",
".claude/*",
"tests/sanity/*",
"tests/scripts/*",
+1 -1
View File
@@ -267,7 +267,7 @@ class CraftedTarballTest(unittest.TestCase):
REPO,
src,
ignore=shutil.ignore_patterns(
".git", ".venv", "__pycache__", "output", "*.tar.gz"
".git", ".venv", ".venv-dev", "__pycache__", "output", "*.tar.gz"
),
)
out = pathlib.Path(self.tmp.name) / "dist"
+30 -6
View File
@@ -192,7 +192,7 @@ class DevSetupTest(unittest.TestCase):
proc = self.run_setup(repo, KAMINO_PYTHON=str(wrong))
self.assertNotEqual(proc.returncode, 0)
self.assertIn("is not Python 3.13 (.python-version)", proc.stderr)
self.assertFalse((repo / ".venv").exists())
self.assertFalse((repo / ".venv-dev").exists())
def test_an_interpreter_of_another_minor_is_refused_and_the_pinned_one_accepted(
self,
@@ -201,10 +201,10 @@ class DevSetupTest(unittest.TestCase):
proc = self.run_setup(repo, STUB_PY_MINOR="3.12")
self.assertNotEqual(proc.returncode, 0)
self.assertIn("is not Python 3.13 (.python-version)", proc.stderr)
self.assertFalse((repo / ".venv").exists())
self.assertFalse((repo / ".venv-dev").exists())
proc = self.run_setup(repo, STUB_PY_MINOR="3.13")
self.assertEqual(proc.returncode, 0, proc.stderr)
self.assertTrue((repo / ".venv").is_dir())
self.assertTrue((repo / ".venv-dev").is_dir())
def test_a_missing_pin_file_is_refused_with_a_message(self) -> None:
repo = self.make_repo()
@@ -228,6 +228,30 @@ class DevSetupTest(unittest.TestCase):
text = self.hook(repo, name).read_text()
self.assertIn("# kamino-dev-setup: virtualenv first on PATH", text)
self.assertEqual(self.hooks_z(repo), b"")
self.assertFalse((repo / ".venv").exists())
def test_a_rerun_moves_the_hooks_of_an_older_setup_to_venv_dev(self) -> None:
repo = self.make_repo()
kept = repo / ".venv" / "kept"
kept.parent.mkdir()
kept.write_text("")
names = ("pre-commit", "commit-msg", "pre-push")
for name in names:
hook = self.hook(repo, name)
hook.parent.mkdir(exist_ok=True)
hook.write_text(
"#!/usr/bin/env bash\n"
"# kamino-dev-setup: virtualenv first on PATH\n"
f'export PATH={repo}/.venv/bin:"$PATH"\n'
)
hook.chmod(0o755)
result = self.run_setup(repo)
self.assertEqual(result.returncode, 0, result.stderr)
for name in names:
text = self.hook(repo, name).read_text()
self.assertIn(f'export PATH={repo}/.venv-dev/bin:"$PATH"\n', text)
self.assertNotIn("/.venv/bin", text)
self.assertTrue(kept.exists())
def test_a_missing_tea_warns_and_setup_succeeds(self) -> None:
repo = self.make_repo()
@@ -403,12 +427,12 @@ class DevSetupTest(unittest.TestCase):
self.git(other, "init", "--quiet")
result = self.run_setup(repo, cwd=other)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertFalse((other / ".venv").exists())
self.assertFalse((other / ".venv-dev").exists())
self.assertEqual(
os.listdir(other / ".git" / "hooks"),
[n for n in os.listdir(other / ".git" / "hooks") if n.endswith(".sample")],
)
self.assertTrue((repo / ".venv").is_dir())
self.assertTrue((repo / ".venv-dev").is_dir())
self.assertTrue(self.hook(repo).exists())
def test_crafted_repository_path_is_not_executed(self) -> None:
@@ -428,7 +452,7 @@ class DevSetupTest(unittest.TestCase):
self.assertEqual(hook.returncode, 0, hook.stderr)
lines = hook.stdout.splitlines()
self.assertEqual(lines[0], "hook-ran")
self.assertTrue(lines[1].startswith(f"{repo}/.venv/bin:"), lines[1])
self.assertTrue(lines[1].startswith(f"{repo}/.venv-dev/bin:"), lines[1])
for place in (workdir, repo, self.tmp, Path.cwd()):
self.assertFalse((place / "PWNED").exists(), place)
self.assertFalse((place / "PWNED2").exists(), place)
@@ -217,6 +217,10 @@ class SelectTest(unittest.TestCase):
chosen, _reason = self.select(["requirements-dev.txt", "requirements-dev.lock"])
self.assertEqual(chosen, [])
def test_the_apm_pin_selects_nothing(self):
chosen, _reason = self.select(["pyproject.toml", "uv.lock"])
self.assertEqual(chosen, [])
def test_molecule_requirements_select_everything(self):
# An ansible-core or molecule bump there changes the tools every scenario runs with.
for path in ("requirements-molecule.txt", "requirements-molecule.lock"):
Generated
+1951
View File
File diff suppressed because it is too large. Load diff