Name the roles under roles/ in the README intro and the Galaxy description, and drop the NOTICE and REUSE.toml entries and licence texts (Apache-2.0, EUPL-1.2, MIT) of roles that are not in the Collection. The reuse_lint.py wrapper only tolerated those unused texts, so the hook runs plain `reuse lint`. The GPL-3.0-only reason is ufw's before.rules.j2. Remove HANDOFF.md and .reuse from build_ignore (neither has existed), correct the galaxy.yml comment on dependency bounds, and bump the ci image to 0.2.33 (.pre-commit-config.yaml is an image input). Part of #164 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
140 lines
12 KiB
Markdown
140 lines
12 KiB
Markdown
# system_baseline
|
|
|
|
Applies an OS baseline chosen by `system_baseline_system_type`: apt upgrade, package install and removal, unattended-upgrades, locale, timezone, a journal size cap, sysctl hardening, tmpfs mounts, an optional tmux session on SSH login and an optional reboot. Variables and their types are defined in [`meta/argument_specs.yml`](meta/argument_specs.yml), which is the source of truth.
|
|
|
|
## Supported platforms
|
|
|
|
Ubuntu 24.04 (noble, covered by the molecule scenario) and Debian 13 (trixie, Proxmox hosts). The tasks use apt and the reboot check is limited to the Debian family. See `meta/main.yml`. The molecule scenario (`molecule/default/`, CI only) converges the `ubuntu_lxc` profile on Ubuntu 24.04 and only resolves the `pve` and `ubuntu_vm` profiles; Debian 13 is not verified by a test, and Ubuntu 22.04 (jammy) is listed in `meta/main.yml` but neither supported nor tested.
|
|
|
|
## Requirements and run order
|
|
|
|
- Facts must be gathered (`gather_facts: true`); `reboot.yml` reads `ansible_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).
|
|
- 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.
|
|
- The role has no declared dependencies.
|
|
|
|
## Role variables
|
|
|
|
The resolved `system_baseline_*` inputs derived from the active profile (`_profile`, `_essential_packages`, `_remove_packages`, `_apt_periodic_settings`,
|
|
`_unattended_upgrade_settings`, `_unattended_upgrade_origins`, `_sysctl_hardening`, `_secure_tmp_mounts`) are listed below but
|
|
deliberately not in the spec: their defaults index the profile by `system_baseline_system_type`, and the spec is
|
|
templated before `validate.yml` runs, so an invalid `system_baseline_system_type` would otherwise fail with a
|
|
templating error instead of the role's own message.
|
|
|
|
| Name | Default | Required | Description |
|
|
| --- | --- | --- | --- |
|
|
| `system_baseline_system_type` | none | yes | Profile selector, validated by `tasks/validate.yml` |
|
|
| `system_baseline_profiles` | see `defaults/main.yml` | no | Policy per system type; overriding replaces all profiles |
|
|
| `system_baseline_profile_overrides` | `{}` | no | Per-system-type overrides, merged recursively into the active profile |
|
|
| `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_apt_periodic_settings` | from profile | no | Keys for `20auto-upgrades` |
|
|
| `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_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_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 |
|
|
| `system_baseline_timezone` | `Etc/UTC` | no | Timezone |
|
|
| `system_baseline_locale` | `en_US.UTF-8` | no | Locale |
|
|
| `system_baseline_reboot_if_required` | `true` | no | Reboot when `/var/run/reboot-required` exists |
|
|
| `system_baseline_update` | `true` | no | Run the package update in the main flow; `false` skips it (the `update` entry point ignores it) |
|
|
|
|
A flat `system_baseline_*` input replaces that value entirely. To change one key of a profile dict, use `system_baseline_profile_overrides`, for example to let unattended-upgrades reboot a group on its own:
|
|
|
|
```yaml
|
|
system_baseline_profile_overrides:
|
|
ubuntu_vm:
|
|
unattended_upgrade_settings:
|
|
"Unattended-Upgrade::Automatic-Reboot": true
|
|
```
|
|
|
|
## Entry points
|
|
|
|
Besides `main`, two task files are a supported interface, for a caller that drives its own reboot (for example a Kubernetes node patch flow that cordons and drains first). Their names, the fact name and the behaviour below follow the Collection's semantic versioning: changing them is a breaking change.
|
|
|
|
- `tasks_from: update`: apt update, upgrade, autoremove and autoclean, nothing else. It does not read `system_baseline_update`: calling the entry point is the request to update.
|
|
- `tasks_from: reboot`: sets the fact `system_baseline_reboot_required` (bool, from `/var/run/reboot-required`) on Debian family hosts, then reboots when `system_baseline_reboot_if_required` is true and the fact is true. With `system_baseline_reboot_if_required: false` it only computes the fact. On other families the fact is not set, so read it with `default(false)`.
|
|
|
|
```yaml
|
|
- name: Upgrade packages
|
|
ansible.builtin.import_role:
|
|
name: mortis.kamino.system_baseline
|
|
tasks_from: update
|
|
|
|
- name: Check whether a reboot is required
|
|
ansible.builtin.import_role:
|
|
name: mortis.kamino.system_baseline
|
|
tasks_from: reboot
|
|
vars:
|
|
system_baseline_reboot_if_required: false
|
|
|
|
- name: Reboot after draining
|
|
ansible.builtin.reboot:
|
|
when: system_baseline_reboot_required | default(false)
|
|
```
|
|
|
|
`validate.yml` has no spec and is not an entry point; the molecule scenario calls it to load the defaults.
|
|
|
|
## Tags
|
|
|
|
`always` (validation), `update` (apt upgrade and the reboot), `packages`, `unattended-upgrades`, `locale`, `timezone`, `journald`, `sysctl`, `secure_tmp`, `tmux`.
|
|
|
|
## Example play
|
|
|
|
```yaml
|
|
- name: Baseline LXC guests
|
|
hosts: lxc_guests
|
|
gather_facts: true
|
|
vars:
|
|
system_baseline_system_type: ubuntu_lxc
|
|
roles:
|
|
- role: mortis.kamino.system_baseline
|
|
```
|
|
|
|
## 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.
|
|
|
|
```yaml
|
|
system_baseline_tmux_autostart: true
|
|
system_baseline_tmux_session: ops
|
|
system_baseline_tmux_windows:
|
|
- { name: logs, command: "journalctl -f" }
|
|
```
|
|
|
|
- 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.
|
|
- 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.
|
|
- Security: the name and commands are validated (`A-Za-z0-9_-`, one line) and shell-quoted, and come from the inventory, never from a user. The file is root-owned and not writable by its users. The commands run as the user who logs in, are readable by every user and show in `ps`: no secrets in a command. A session outlives the SSH connection, so a root session stays open until it is closed.
|
|
|
|
## Skipping the package update
|
|
|
|
`system_baseline_update: false` skips the package update of the main flow, for hosts patched by a separate, operator-run flow (for example a full upgrade with a rolling reboot). Everything else, unattended-upgrades included, still runs. The reboot check still runs as well, so set `system_baseline_reboot_if_required: false` too when that flow owns the reboot. Running the play with `--skip-tags update` skips the same task for one run only, and also the reboot.
|
|
|
|
## Unattended-upgrades origins
|
|
|
|
A profile's `unattended_upgrade_origins` list pins the origins unattended-upgrades may install from. apt merges every file in `/etc/apt/apt.conf.d` and appends list entries across files, so a later file that only lists origins would widen the distribution's `50unattended-upgrades`, never narrow it. A non-empty list is therefore written to `/etc/apt/apt.conf.d/90unattended-upgrades-origins`, which sorts after `50unattended-upgrades`, clears `Unattended-Upgrade::Allowed-Origins` and `Unattended-Upgrade::Origins-Pattern` (apt's `#clear` directive) and sets only the listed patterns. The origin lists in `50unattended-upgrades` itself are not edited. An empty or missing list removes the drop-in.
|
|
|
|
- `pve` pins Debian's own default set: `origin=Debian,codename=${distro_codename},label=Debian` (point releases) and the two `Debian-Security` patterns. The Proxmox repository is never allowed, and a future Debian default cannot widen the set.
|
|
- `ubuntu_lxc` and `ubuntu_vm` pin nothing (`[]`): Ubuntu's default origins apply.
|
|
- `${distro_codename}` is expanded by unattended-upgrades, not by Ansible. An entry may not hold a double quote, a backslash or a line break.
|
|
- A file in `/etc/apt/apt.conf.d` that sorts after `90unattended-upgrades-origins` can still add origins, and so can `/etc/apt/apt.conf`, which apt reads after `apt.conf.d`.
|
|
- Check the merged result on a host with `apt-config dump | grep -E 'Unattended-Upgrade::(Origins-Pattern|Allowed-Origins)'`.
|
|
|
|
## Notes
|
|
|
|
- The `pve` profile has no `ufw`; the `ubuntu_*` profiles install it and `fail2ban`.
|
|
- No profile lets unattended-upgrades reboot on its own (`Automatic-Reboot: false`); a host opts in through `system_baseline_profile_overrides`.
|
|
- Set `system_baseline_reboot_if_required: false` for hosts whose reboot takes other machines down (hypervisors) or needs a drain first (cluster nodes).
|
|
- 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. The `pve` origins pin is applied to the Ubuntu container and read back with `apt-config dump`.
|
|
- 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.
|