Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c51fa998b9 |
No files matched your search
@@ -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=``.
|
||||
@@ -240,9 +240,9 @@ anyio==4.16.0 \
|
||||
# via
|
||||
# httpx2
|
||||
# openai
|
||||
apm-cli==0.38.1 \
|
||||
--hash=sha256:c2a0394643e54d3516efefcd78bb043509ac48b65cca1f40166023789b8eb89a \
|
||||
--hash=sha256:c2ddd1ea95f7223de2ced83c1bbb61b756a10de2651edc76b93346c925dc162b
|
||||
apm-cli==0.38.0 \
|
||||
--hash=sha256:6dfac2fdc8ab68586afb2b1a5a6db3c1b7ab569ff0edc525448aa85d0f92bd38 \
|
||||
--hash=sha256:aa51a98867ae6aef11e92143dd9ca2a994d3dd6cbd7224eae58fb7b8078fc3b1
|
||||
# via -r requirements-dev.txt
|
||||
attrs==23.2.0 \
|
||||
--hash=sha256:935dc3b529c262f6cf76e50877d35a4bd3c1de194fd41f47a2b7ae8f19971f30 \
|
||||
|
||||
@@ -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.1
|
||||
apm-cli==0.38.0
|
||||
@@ -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`.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user