fix(system_baseline): run the apt upgrade with TMPDIR outside /tmp and /var/tmp #377

Merged
Defame1297 merged 2 commits from fix/374-apt-tmpdir into main 2026-11-25 19:42:15 +00:00
Collaborator

What and why

Closes #374.

The update flow upgrades packages over the SSH connection Ansible uses. An openssh-server upgrade restarts ssh.service; when that unit has PrivateTmp=yes, systemd then deletes its /tmp and /var/tmp while the upgrade still needs the files apt staged there. dpkg fails with "cannot access archive" and leaves packages unpacked but not configured.

  • New input system_baseline_apt_tmpdir (default /var/cache/system-baseline-apt-tmp). The role creates it (root, mode 0700) and runs the upgrade and the autoremove with TMPDIR set to it, then opens a new connection (meta: reset_connection), so later tasks get a fresh private /tmp.
  • Validated in the main flow and in the update entry point (which does not run validate.yml): an absolute path of letters, digits, ., _, - and /, without .., and not /tmp, /var/tmp or a path below them.
  • README ("Apt scratch directory"), argument spec, defaults and a changelog fragment.

Differences from the issue

  • The fragment has bugfixes (the fix) and minor_changes (the new input), because roles/AGENTS.md makes a new input a minor change; the issue said bugfixes.
  • The directory is created in check mode too, not only when an upgrade runs: the autoremove runs in check mode with the same TMPDIR, which would otherwise point at a missing directory. A dry run reports it once, on a host that does not have it yet. The README says so.

Verified

  • yamllint and every pre-commit hook pass, including ansible-lint and the changelog fragment lint.
  • Through Ansible on localhost (no change made): the validation accepts 4 good paths (including /tmpfoo/ok, which is not /tmp) and refuses 10 bad ones (empty, relative, .., /tmp, /tmp/x, /var/tmp, /var/tmp/apt, a space, a line break, /), each with the message that names the input.
  • The static check that verify uses passes against the real tasks/update.yml.

Not verified

  • The Molecule scenario has not run on this change. Its first CI run may fail.
  • The scenario skips the update tag (molecule/default/molecule.yml), so the upgrade never runs there and the directory is never created. Verify only reads tasks/update.yml and checks the mode, the two TMPDIR settings and the connection reset, which is a text check.
  • A real openssh-server upgrade on a host whose ssh.service has PrivateTmp=yes was not run.

  • I confirm third-party material is recorded in NOTICE and REUSE.toml, or there is none.

Assisted-by: Claude Code:claude-sonnet-5-5

## What and why Closes #374. The `update` flow upgrades packages over the SSH connection Ansible uses. An `openssh-server` upgrade restarts `ssh.service`; when that unit has `PrivateTmp=yes`, systemd then deletes its `/tmp` and `/var/tmp` while the upgrade still needs the files apt staged there. dpkg fails with "cannot access archive" and leaves packages unpacked but not configured. - New input `system_baseline_apt_tmpdir` (default `/var/cache/system-baseline-apt-tmp`). The role creates it (root, mode `0700`) and runs the upgrade and the autoremove with `TMPDIR` set to it, then opens a new connection (`meta: reset_connection`), so later tasks get a fresh private `/tmp`. - Validated in the main flow and in the `update` entry point (which does not run `validate.yml`): an absolute path of letters, digits, `.`, `_`, `-` and `/`, without `..`, and not `/tmp`, `/var/tmp` or a path below them. - README ("Apt scratch directory"), argument spec, defaults and a changelog fragment. ## Differences from the issue - The fragment has `bugfixes` (the fix) and `minor_changes` (the new input), because `roles/AGENTS.md` makes a new input a minor change; the issue said `bugfixes`. - The directory is created in check mode too, not only when an upgrade runs: the autoremove runs in check mode with the same `TMPDIR`, which would otherwise point at a missing directory. A dry run reports it once, on a host that does not have it yet. The README says so. ## Verified - `yamllint` and every pre-commit hook pass, including `ansible-lint` and the changelog fragment lint. - Through Ansible on localhost (no change made): the validation accepts 4 good paths (including `/tmpfoo/ok`, which is not `/tmp`) and refuses 10 bad ones (empty, relative, `..`, `/tmp`, `/tmp/x`, `/var/tmp`, `/var/tmp/apt`, a space, a line break, `/`), each with the message that names the input. - The static check that verify uses passes against the real `tasks/update.yml`. ## Not verified - The Molecule scenario has not run on this change. Its first CI run may fail. - The scenario skips the `update` tag (`molecule/default/molecule.yml`), so the upgrade never runs there and the directory is never created. Verify only reads `tasks/update.yml` and checks the mode, the two `TMPDIR` settings and the connection reset, which is a text check. - A real `openssh-server` upgrade on a host whose `ssh.service` has `PrivateTmp=yes` was not run. --- - [ ] I confirm third-party material is recorded in `NOTICE` and `REUSE.toml`, or there is none. Assisted-by: Claude Code:claude-sonnet-5-5
Dragonish added 1 commit 2026-11-25 19:36:53 +00:00
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
1bbf3368ee
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
Defame1297 added 1 commit 2026-11-25 19:38:26 +00:00
Merge branch 'main' into fix/374-apt-tmpdir
Build / build (pull_request) Successful in 25s
Lint / lint (pull_request) Successful in 1m48s
Molecule / molecule (pull_request) Successful in 3m11s
ebac95e51d
Defame1297 approved these changes 2026-11-25 19:39:34 +00:00
Defame1297 scheduled this pull request to auto merge when all checks succeed 2026-11-25 19:39:44 +00:00
Defame1297 merged commit 3149c22f93 into main 2026-11-25 19:42:15 +00:00
Defame1297 deleted branch fix/374-apt-tmpdir 2026-11-25 19:42:15 +00:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Kamino#377