Merge branch 'main' into ci/refuse-claude-md-any-case
This commit is contained in:
commit
f21a535a87
10 files changed
+197
No files matched your search
@@ -0,0 +1,6 @@
|
||||
---
|
||||
minor_changes:
|
||||
- >-
|
||||
system_baseline - Add ``system_baseline_unattended_upgrade_package_blacklist`` (list of regular expressions, default empty). A non-empty
|
||||
list is written to ``/etc/apt/apt.conf.d/90unattended-upgrades-blacklist`` as ``Unattended-Upgrade::Package-Blacklist``, so unattended-upgrades
|
||||
leaves those packages alone on a host whose kernel or drivers must not change. An empty list removes the file.
|
||||
@@ -34,6 +34,7 @@ templating error instead of the role's own message.
|
||||
| `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_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`). |
|
||||
@@ -133,6 +134,26 @@ A profile's `unattended_upgrade_origins` list pins the origins unattended-upgrad
|
||||
- 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)'`.
|
||||
|
||||
## Unattended-upgrades package blacklist
|
||||
|
||||
`system_baseline_unattended_upgrade_package_blacklist` keeps individual packages out of unattended-upgrades, for a host whose kernel or drivers must not change (for example one with hardware passthrough). Each entry is a regular expression matched against the package name, so `linux-image-.*` covers every kernel image; anchor an entry (`^name$`) when it must not match longer names too. A non-empty list is written to `/etc/apt/apt.conf.d/90unattended-upgrades-blacklist` as `Unattended-Upgrade::Package-Blacklist`. apt appends list entries across files, so the entries are added to those of `50unattended-upgrades`, which is not edited. An empty list removes the file. An entry may not hold a double quote, a backslash or a line break.
|
||||
|
||||
- Example for Proxmox VE hosts: packages that should only ever change through a deliberate `apt dist-upgrade` (Proxmox's documented way to update, because its packages add and remove dependencies). The `pve` profile already pins unattended-upgrades to Debian's origins, so these never come from the Proxmox repository through unattended-upgrades; the list keeps that true if the pin is ever removed or widened. Adjust it to the repositories you use:
|
||||
|
||||
```yaml
|
||||
system_baseline_unattended_upgrade_package_blacklist:
|
||||
- "^pve-.*" # pve-manager, pve-kernel-*, pve-qemu-kvm, pve-container ...
|
||||
- "^libpve-.*"
|
||||
- "^proxmox-.*" # proxmox-ve, proxmox-kernel-*, proxmox-backup-client ...
|
||||
- "^qemu-server$"
|
||||
- "^ceph.*"
|
||||
- "^corosync$"
|
||||
```
|
||||
|
||||
- Like the other unattended-upgrades settings, it is applied only when `unattended-upgrades` is in the profile's packages.
|
||||
- This is unattended-upgrades only. The role's own apt upgrade (`update` tag, and the `update` entry point) is not limited by it; set `system_baseline_update: false` for a host that is patched by a separate flow.
|
||||
- Check the merged result on a host with `apt-config dump | grep Package-Blacklist`.
|
||||
|
||||
## Notes
|
||||
|
||||
- The `pve` profile has no `ufw`; the `ubuntu_*` profiles install it and `fail2ban`.
|
||||
|
||||
@@ -230,5 +230,8 @@ system_baseline_apt_periodic_settings: "{{ system_baseline_profile.apt_periodic_
|
||||
system_baseline_unattended_upgrade_settings: "{{ system_baseline_profile.unattended_upgrade_settings }}"
|
||||
# default([]): a system_baseline_profiles written before this key existed keeps the distribution default.
|
||||
system_baseline_unattended_upgrade_origins: "{{ system_baseline_profile.unattended_upgrade_origins | default([]) }}"
|
||||
# Packages unattended-upgrades must not touch, on top of the profile: a per-host list, empty by default (see README, "Unattended-upgrades
|
||||
# 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 }}"
|
||||
system_baseline_secure_tmp_mounts: "{{ system_baseline_profile.secure_tmp_mounts }}"
|
||||
@@ -102,6 +102,19 @@ argument_specs:
|
||||
default: true
|
||||
description:
|
||||
- Reboot when C(/var/run/reboot-required) exists after the run.
|
||||
system_baseline_unattended_upgrade_package_blacklist:
|
||||
type: list
|
||||
elements: str
|
||||
default: []
|
||||
description:
|
||||
- >-
|
||||
Packages unattended-upgrades must leave alone, for a host whose kernel or drivers must not change. Entries are regular
|
||||
expressions matched against the package name, so C(linux-image-.*) covers every kernel image; anchor an entry (C(^name$))
|
||||
when it must not match longer names too.
|
||||
- >-
|
||||
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_update:
|
||||
type: bool
|
||||
default: true
|
||||
|
||||
@@ -19,6 +19,21 @@
|
||||
that: "'is invalid' in ansible_failed_result.msg | default('')"
|
||||
quiet: true
|
||||
|
||||
# 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
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Refuse each bad value
|
||||
ansible.builtin.include_tasks: tasks/refuse_blacklist.yml
|
||||
vars:
|
||||
system_baseline_refused_blacklist: "{{ item }}"
|
||||
loop:
|
||||
- ['bad"name']
|
||||
- [null]
|
||||
- linux-image-.*
|
||||
|
||||
- name: Converge the LXC profile
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
|
||||
@@ -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 package blacklist
|
||||
block:
|
||||
- name: Include system_baseline
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.system_baseline
|
||||
vars:
|
||||
system_baseline_system_type: ubuntu_lxc
|
||||
system_baseline_unattended_upgrade_package_blacklist: "{{ system_baseline_refused_blacklist }}"
|
||||
- name: Unreachable when validation works
|
||||
ansible.builtin.fail:
|
||||
msg: system_baseline ran with an invalid package blacklist
|
||||
rescue:
|
||||
- name: The validation stopped the play
|
||||
ansible.builtin.assert:
|
||||
that: "'system_baseline_unattended_upgrade_package_blacklist must be' in ansible_failed_result.msg | default('')"
|
||||
quiet: true
|
||||
@@ -270,3 +270,84 @@
|
||||
- system_baseline_verify_apt_config_restored.stdout_lines | select('match', 'Unattended-Upgrade::Allowed-Origins::\s') | list | length > 0
|
||||
- system_baseline_verify_apt_config_restored.stdout is not search('origin=Debian')
|
||||
quiet: true
|
||||
|
||||
# The package blacklist: written and parsed by apt as a list, left alone by a second run, removed by an empty list. Here and not in
|
||||
# converge, because converge runs the default (empty) list.
|
||||
- name: The unattended-upgrades package blacklist is written, kept and removed
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
vars:
|
||||
system_baseline_verify_blacklist: ["linux-image-.*", "nvidia-.*"]
|
||||
tasks:
|
||||
- name: Run the unattended-upgrades tasks with a blacklist
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.system_baseline
|
||||
tasks_from: unattended_upgrades
|
||||
vars:
|
||||
system_baseline_system_type: ubuntu_lxc
|
||||
system_baseline_unattended_upgrade_package_blacklist: "{{ system_baseline_verify_blacklist }}"
|
||||
|
||||
- name: Stat the blacklist drop-in
|
||||
ansible.builtin.stat:
|
||||
path: /etc/apt/apt.conf.d/90unattended-upgrades-blacklist
|
||||
register: system_baseline_verify_blacklist_first
|
||||
|
||||
- name: Dump the merged apt configuration
|
||||
ansible.builtin.command: apt-config dump
|
||||
register: system_baseline_verify_blacklist_dump
|
||||
changed_when: false
|
||||
|
||||
- name: Apt reads both entries as a list
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- system_baseline_verify_blacklist_first.stat.exists
|
||||
- >-
|
||||
system_baseline_verify_blacklist_dump.stdout_lines | select('match', 'Unattended-Upgrade::Package-Blacklist::\s') | list ==
|
||||
['Unattended-Upgrade::Package-Blacklist:: "linux-image-.*";', 'Unattended-Upgrade::Package-Blacklist:: "nvidia-.*";']
|
||||
quiet: true
|
||||
|
||||
- name: Run the same tasks again
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.system_baseline
|
||||
tasks_from: unattended_upgrades
|
||||
vars:
|
||||
system_baseline_system_type: ubuntu_lxc
|
||||
system_baseline_unattended_upgrade_package_blacklist: "{{ system_baseline_verify_blacklist }}"
|
||||
|
||||
- name: Stat the blacklist drop-in again
|
||||
ansible.builtin.stat:
|
||||
path: /etc/apt/apt.conf.d/90unattended-upgrades-blacklist
|
||||
register: system_baseline_verify_blacklist_second
|
||||
|
||||
- name: A second run does not rewrite the file
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- system_baseline_verify_blacklist_second.stat.checksum == system_baseline_verify_blacklist_first.stat.checksum
|
||||
- system_baseline_verify_blacklist_second.stat.mtime == system_baseline_verify_blacklist_first.stat.mtime
|
||||
quiet: true
|
||||
|
||||
- name: Run the same tasks with an empty blacklist
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.system_baseline
|
||||
tasks_from: unattended_upgrades
|
||||
vars:
|
||||
system_baseline_system_type: ubuntu_lxc
|
||||
system_baseline_unattended_upgrade_package_blacklist: []
|
||||
|
||||
- name: Stat the blacklist drop-in after the empty list
|
||||
ansible.builtin.stat:
|
||||
path: /etc/apt/apt.conf.d/90unattended-upgrades-blacklist
|
||||
register: system_baseline_verify_blacklist_removed
|
||||
|
||||
- name: Dump the merged apt configuration after the empty list
|
||||
ansible.builtin.command: apt-config dump
|
||||
register: system_baseline_verify_blacklist_dump_removed
|
||||
changed_when: false
|
||||
|
||||
- name: The file is gone and apt lists no blacklisted package
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- not system_baseline_verify_blacklist_removed.stat.exists
|
||||
- system_baseline_verify_blacklist_dump_removed.stdout_lines | select('match', 'Unattended-Upgrade::Package-Blacklist::\s') | list == []
|
||||
quiet: true
|
||||
tags: always
|
||||
@@ -40,6 +40,23 @@
|
||||
state: absent
|
||||
when: system_baseline_unattended_upgrade_origins | length == 0
|
||||
|
||||
- name: Keep packages out of unattended-upgrades
|
||||
become: true
|
||||
ansible.builtin.template:
|
||||
src: unattended-upgrades-blacklist.j2
|
||||
dest: /etc/apt/apt.conf.d/90unattended-upgrades-blacklist
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
when: system_baseline_unattended_upgrade_package_blacklist | length > 0
|
||||
|
||||
- name: Remove the package blacklist when none is set
|
||||
become: true
|
||||
ansible.builtin.file:
|
||||
path: /etc/apt/apt.conf.d/90unattended-upgrades-blacklist
|
||||
state: absent
|
||||
when: system_baseline_unattended_upgrade_package_blacklist | length == 0
|
||||
|
||||
- name: Validate unattended-upgrades config
|
||||
become: true
|
||||
ansible.builtin.command: unattended-upgrades --dry-run --debug
|
||||
|
||||
@@ -35,6 +35,21 @@
|
||||
when: system_baseline_tmux_autostart | bool
|
||||
tags: always
|
||||
|
||||
# Each package pattern is written inside a double-quoted apt.conf string, like the origins below: the same characters are refused.
|
||||
- name: Validate the unattended-upgrades package blacklist
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- system_baseline_unattended_upgrade_package_blacklist is sequence
|
||||
- system_baseline_unattended_upgrade_package_blacklist is not string
|
||||
- system_baseline_unattended_upgrade_package_blacklist is not mapping
|
||||
- system_baseline_unattended_upgrade_package_blacklist | select('string') | select('match', '^[^"\\\\\n\r]+\Z') | list | length
|
||||
== system_baseline_unattended_upgrade_package_blacklist | length
|
||||
fail_msg: >-
|
||||
system_baseline_unattended_upgrade_package_blacklist must be a list of non-empty one-line strings without a double quote
|
||||
or a backslash.
|
||||
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:
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// Managed by Ansible (mortis.kamino.system_baseline, tasks/unattended_upgrades.yml). Do not edit: the next run overwrites it.
|
||||
// apt appends list entries across apt.conf.d files, so these packages are added to Unattended-Upgrade::Package-Blacklist of
|
||||
// 50unattended-upgrades. Entries are regular expressions matched against the package name.
|
||||
Unattended-Upgrade::Package-Blacklist {
|
||||
{% for package in system_baseline_unattended_upgrade_package_blacklist %}
|
||||
"{{ package }}";
|
||||
{% endfor %}
|
||||
};
|
||||
Reference in new issue
Block a user