fix(system_baseline): run the apt upgrade with TMPDIR outside /tmp and /var/tmp
Build / build (pull_request) Successful in 31s
Lint / lint (pull_request) Canceled after 1m40s
Molecule / molecule (pull_request) Canceled after 1m13s

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:
Dragonish committed 2026-11-25 19:21:01 +00:00
1 parent 008c5ab8a4
commit 1bbf3368ee
11 files changed
+151 -1

No files matched your search

@@ -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.