fix(system_baseline): keep the apt upgrade's temporary files out of a directory that an ssh.service restart deletes #374

Closed
opened 2026-11-25 19:16:31 +00:00 by Dragonish · 0 comments
Collaborator

Problem

The update flow upgrades packages over the SSH connection Ansible is using. When the upgrade includes openssh-server, the package restarts ssh.service. If that unit has PrivateTmp=yes (the systemd_hardening role sets it), systemd deletes the unit's private /tmp and /var/tmp when the unit stops, and the session Ansible is still using sees an empty one. In the middle of the upgrade this removes the .deb files apt staged under /tmp/apt-dpkg-install-* and the apt module's own payload. dpkg then fails with "cannot access archive" and leaves packages unpacked but not configured (seen on systemd, docker-ce and containerd.io on ten hosts over three weeks).

Later tasks in the same play that use /tmp fail too ("No such file or directory"), until a new SSH connection gets a new private /tmp.

Out of scope: changing PrivateTmp on ssh.service, and the pve dist-upgrade path beyond using the same directory.

Proposal

  • New input system_baseline_apt_tmpdir (str, default /var/cache/system-baseline-apt-tmp, validated as an absolute path outside /tmp and /var/tmp).
  • update.yml creates it (owner root, mode 0700) and runs the upgrade and the autoremove with TMPDIR set to it.
  • After the upgrade, meta: reset_connection, so later tasks get a connection with a fresh private /tmp.
  • The directory is created only when an upgrade will run (not in the main flow's check mode, where the upgrade is skipped).

Acceptance criteria

  • Default run creates the directory with mode 0700 and a second run reports no change. Check: Molecule converge, idempotence and a stat assertion in verify.
  • The upgrade and autoremove tasks carry TMPDIR set to the input. Check: a lint-level test or Molecule verify that greps the task file, since the container cannot restart ssh.service.
  • A value inside /tmp or /var/tmp, or a relative path, is refused before any change. Check: a Molecule converge play that expects the failure.
  • argument_specs.yml, the README and a changelog fragment (bugfixes) cover the input. Check: ansible-doc, antsibull-changelog lint.
  • Not verified by CI: a real openssh-server upgrade on a host with PrivateTmp=yes. State it in the PR.

Assisted-by: Claude Code

## Problem The `update` flow upgrades packages over the SSH connection Ansible is using. When the upgrade includes `openssh-server`, the package restarts `ssh.service`. If that unit has `PrivateTmp=yes` (the `systemd_hardening` role sets it), systemd deletes the unit's private `/tmp` and `/var/tmp` when the unit stops, and the session Ansible is still using sees an empty one. In the middle of the upgrade this removes the `.deb` files apt staged under `/tmp/apt-dpkg-install-*` and the apt module's own payload. dpkg then fails with "cannot access archive" and leaves packages unpacked but not configured (seen on systemd, docker-ce and containerd.io on ten hosts over three weeks). Later tasks in the same play that use `/tmp` fail too ("No such file or directory"), until a new SSH connection gets a new private `/tmp`. Out of scope: changing `PrivateTmp` on `ssh.service`, and the `pve` dist-upgrade path beyond using the same directory. ## Proposal - New input `system_baseline_apt_tmpdir` (str, default `/var/cache/system-baseline-apt-tmp`, validated as an absolute path outside `/tmp` and `/var/tmp`). - `update.yml` creates it (owner root, mode 0700) and runs the upgrade and the autoremove with `TMPDIR` set to it. - After the upgrade, `meta: reset_connection`, so later tasks get a connection with a fresh private `/tmp`. - The directory is created only when an upgrade will run (not in the main flow's check mode, where the upgrade is skipped). ## Acceptance criteria - [ ] Default run creates the directory with mode 0700 and a second run reports no change. Check: Molecule converge, idempotence and a `stat` assertion in verify. - [ ] The upgrade and autoremove tasks carry `TMPDIR` set to the input. Check: a lint-level test or Molecule verify that greps the task file, since the container cannot restart ssh.service. - [ ] A value inside `/tmp` or `/var/tmp`, or a relative path, is refused before any change. Check: a Molecule converge play that expects the failure. - [ ] `argument_specs.yml`, the README and a changelog fragment (`bugfixes`) cover the input. Check: `ansible-doc`, `antsibull-changelog lint`. - [ ] Not verified by CI: a real openssh-server upgrade on a host with `PrivateTmp=yes`. State it in the PR. Assisted-by: Claude Code
Dragonish added the
Status
Ready for Agent
label 2026-11-25 19:17:16 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Kamino#374