fix(system_baseline): run the apt upgrade with TMPDIR outside /tmp and /var/tmp
An openssh-server upgrade restarts ssh.service. With PrivateTmp=yes systemd then deletes that unit's /tmp and /var/tmp, which removes the files apt staged there while the upgrade is still running, so dpkg fails and leaves packages unpacked but not configured. The update flow now 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. The input is validated in the main flow and in the update entry point: absolute, no "..", not under /tmp or /var/tmp. Closes #374 Assisted-by: Claude Code:claude-sonnet-5-5
This commit is contained in:
1 parent
008c5ab8a4
commit
1bbf3368ee
11 files changed
+151
-1
No files matched your search
@@ -64,6 +64,23 @@
|
||||
that: "'system_baseline_apt_upgrade is' in ansible_failed_result.msg | default('')"
|
||||
quiet: true
|
||||
|
||||
# The apt scratch directory becomes TMPDIR of the upgrade: a path under /tmp or /var/tmp (which a restart of ssh.service can delete), a relative
|
||||
# path and a `..` each stop the run before any change, in the main flow and in the update entry point (which does not run validate.yml).
|
||||
- name: A bad apt scratch directory is refused
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Refuse each bad value
|
||||
ansible.builtin.include_tasks: tasks/refuse_apt_tmpdir_entries.yml
|
||||
vars:
|
||||
system_baseline_refused_tmpdir: "{{ item }}"
|
||||
loop:
|
||||
- /tmp
|
||||
- /var/tmp/apt
|
||||
- /var/cache/../../tmp/x
|
||||
- var/cache/apt-tmp
|
||||
- ""
|
||||
|
||||
# The reboot inputs are whole numbers, 0 or more: a negative number and a boolean each stop the run before a host reboots,
|
||||
# in the main flow and in the reboot entry point (which does not run validate.yml).
|
||||
- name: A bad reboot throttle or post-reboot delay is refused
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
---
|
||||
# One refusal per entry point: the main flow and the update entry point must both stop on validation, with a message that names the variable.
|
||||
- name: Run the role with a bad apt scratch directory
|
||||
block:
|
||||
- name: Include system_baseline
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.system_baseline
|
||||
tasks_from: "{{ system_baseline_refused_entry }}"
|
||||
vars:
|
||||
system_baseline_system_type: ubuntu_lxc
|
||||
system_baseline_apt_tmpdir: "{{ system_baseline_refused_tmpdir }}"
|
||||
- name: Unreachable when validation works
|
||||
ansible.builtin.fail:
|
||||
msg: system_baseline ran with an invalid system_baseline_apt_tmpdir
|
||||
rescue:
|
||||
- name: The validation stopped the play
|
||||
ansible.builtin.assert:
|
||||
that: "'system_baseline_apt_tmpdir must be' in ansible_failed_result.msg | default('')"
|
||||
quiet: true
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
- name: Refuse the value in the main flow and in the update entry point
|
||||
ansible.builtin.include_tasks: refuse_apt_tmpdir.yml
|
||||
vars:
|
||||
system_baseline_refused_entry: "{{ entry }}"
|
||||
loop:
|
||||
- main
|
||||
- update
|
||||
loop_control:
|
||||
loop_var: entry
|
||||
@@ -101,6 +101,26 @@
|
||||
- system_baseline_verify_apt_daily_show.stdout_lines is contains('TimeoutStartUSec=1h')
|
||||
quiet: true
|
||||
|
||||
# The scenario skips the `update` tag (molecule.yml), so the upgrade never runs here and its scratch directory is never created. This reads the
|
||||
# task file on the controller and checks that the directory is private and that both apt tasks use it as TMPDIR.
|
||||
- name: The update tasks give the apt upgrade a private scratch directory
|
||||
hosts: localhost
|
||||
connection: local
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Read the update tasks
|
||||
ansible.builtin.set_fact:
|
||||
system_baseline_verify_update_tasks: "{{ lookup('ansible.builtin.file', playbook_dir ~ '/../../tasks/update.yml') }}"
|
||||
|
||||
- name: The scratch directory is created private and both apt tasks use it
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- system_baseline_verify_update_tasks is search('(?m)^ path:\s"\{\{ system_baseline_apt_tmpdir \}\}"$')
|
||||
- system_baseline_verify_update_tasks is search('(?m)^ mode:\s"0700"$')
|
||||
- system_baseline_verify_update_tasks | regex_findall('(?m)^ TMPDIR:\s"\{\{ system_baseline_apt_tmpdir \}\}"$') | length == 2
|
||||
- system_baseline_verify_update_tasks is search('(?m)^ ansible.builtin.meta:\sreset_connection$')
|
||||
quiet: true
|
||||
|
||||
# The reboot entry point is a supported interface: with system_baseline_reboot_if_required
|
||||
# false it only sets system_baseline_reboot_required. Here and not in converge, because it
|
||||
# creates and removes the marker file, which the idempotence run would report as a change.
|
||||
|
||||
Reference in new issue
Block a user