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

@@ -129,6 +129,16 @@ argument_specs:
C(/etc/systemd/system/apt-daily.service.d/10-timeout.conf), so a hung apt run is stopped. Empty leaves the host alone; clearing
the value later does not remove a file already written. A value of C(0) means no timeout to systemd.
C(apt-daily-upgrade.service) is not changed. Tag C(apt-daily-timeout).
system_baseline_apt_tmpdir:
type: str
default: /var/cache/system-baseline-apt-tmp
description:
- >-
Directory the apt upgrade and autoremove use as C(TMPDIR). It must be an absolute path made of letters, digits, C(.), C(_), C(-)
and C(/), without C(..), and not C(/tmp) or C(/var/tmp) or anything below them: an C(openssh-server) upgrade restarts
C(ssh.service), and when that unit has C(PrivateTmp=yes) systemd deletes its C(/tmp) and C(/var/tmp) while the upgrade still
needs the files apt staged there. The role creates it, owned by root with mode C(0700). An invalid value stops the run before
any change. Changing the value later does not remove the old directory.
system_baseline_unattended_upgrade_package_blacklist:
type: list
elements: str
@@ -162,6 +172,10 @@ argument_specs:
- >-
A supported entry point (C(tasks_from=update)) for a caller that drives its own reboot, for example a
Kubernetes node patch flow that drains the node first.
- >-
It creates C(system_baseline_apt_tmpdir), runs the upgrade and the autoremove with C(TMPDIR) set to it, and then opens a new
connection, so that a restart of C(ssh.service) during the upgrade does not remove the files apt needs. It reads that input
although the entry point has no argument specification of its own.
reboot:
short_description: Compute system_baseline_reboot_required and reboot when allowed
description: