Skip to content

feat(apt): report unattended-upgrades status - #807

Merged
vladimirrott merged 10 commits into
lacs-project:mainfrom
dannyward630:fix/680-unattended-upgrades-status
Nov 18, 2026
Merged

vladimirrott merged 10 commits into
lacs-project:mainfrom
dannyward630:fix/680-unattended-upgrades-status

Conversation

@dannyward630

Copy link
Copy Markdown
Contributor

Summary

Adds UnattendedUpgradesStatus, a Low-risk Ubuntu Observer action reporting both APT::Periodic values, last and next runs for both apt-daily timers, and the newest timestamped unattended-upgrades log entry. Missing settings, timers, and logs remain unknown and identify the missing path or unit. It is read-only and does not run a dry-run.

Wires the action into the catalogue, executor, Ubuntu-only prompt, preview policy, and MCP Observer allow-list.

Related Issue

Closes #680.

Validation

  • Parser regression cases added for the captured config/timer output, zero setting, disabled timer, and missing log directory.
  • Documentation updated.
  • Security impact considered; the action only reads configuration, timer state, and logs.
  • Trust boundary preserved; the daemon remains the only executor and no privileged command is used.
  • CI passes; hosted Linux checks are pending.
  • Commit signed off with git commit -s.

Local checks: cargo fmt --all --check and Bash -n passed. The focused cargo nextest command could not reach tests on this Windows host because the workspace's vsock dependency fails to compile against Unix-only APIs. The repository CI runs on Linux.

Notes for Reviewers

The parser reports missing inputs as unknown with their path or timer name. No apt-locking dry-run is performed.

Assisted by Codex (GPT-6). The full diff was reviewed.

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for #680. The fence-test exception is the part I'd have worried about, and you closed it off: UBUNTU_ONLY_SHARED_DEBIAN_ACTIONS fails unless its member is Debian-shaped, sits in UBUNTU_ONLY_ACTIONS and stays out of DEBIAN_ONLY_ACTIONS, so nobody can widen the exception without the test noticing. Keeping the prompt block inside the Ubuntu branch of render_debian_prompt, and leaving out the dry run that takes the apt lock, both match the issue.

Reviewed at ec72aa9246ae3faf03abc7f9c0caf398257938bc. I ran nothing from this branch on my own machine; everything below ran in containers with --network=none. The baseline is right (2150 = main's 2145 + your 5 tests) and all six commits carry a sign-off.

I ran the parser tests (cargo test -p sysknife-daemon --lib --locked --offline unattended_upgrades, 6 selected) against one mutant at a time:

[pristine]                            6 passed  rc=0
[M1-missing-log-reads-ok]             unattended_upgrades_parser_reports_missing_log_directory_as_unknown ... FAILED  rc=101
[M2-missing-config-defaults-enabled]  6 passed  rc=0
[M3-zero-reads-enabled]               unattended_upgrades_parser_reports_zero_as_off ... FAILED  rc=101
[M4-disabled-branch-skipped]          6 passed  rc=0
[pristine-again]                      6 passed  rc=0

Blocking, two items.

  1. On a packaged install the log line always reads "no timestamped log entry". The daemon runs as User=sysknife (packaging/sysknife-daemon.service:8), and packaging/sysknife-sysusers.conf adds that user to systemd-journal only. Ubuntu ships the log directory as drwxr-x--- root:adm. I ran your script's text, copied verbatim from UNATTENDED_UPGRADES_STATUS_SCRIPT, in a container with that layout, once as root and once as a sysknife user outside adm:

    drwxr-x--- root:adm /var/log/unattended-upgrades
    uid=999(sysknife) gid=999(sysknife) groups=999(sysknife)
    === as root
    __SYSKNIFE_LOG_BEGIN__
    2026-11-17 06:05:00,123 INFO Starting unattended upgrades script
    __SYSKNIFE_LOG_END__
    === as sysknife (not in adm)
    __SYSKNIFE_LOG_BEGIN__
    __SYSKNIFE_LOG_END__
    

    The directory exists, the glob cannot list it, zcat fails into /dev/null, and the parser turns the empty section into unknown (/var/log/unattended-upgrades: no timestamped log entry). "Unknown" is right, but the reason sends the operator looking for a log problem when the daemon lacked permission to read it. Please have the script check [ -r "$log_dir" ] && [ -x "$log_dir" ] and print a marker of its own when that fails, have the parser report the directory as not readable by the daemon user, and add a test for that marker. The __NO_LOG_FILES__ arm in the parser has no producer in the script today, so this is a good moment to either emit it or drop it.

    Reading the entry itself would take adm membership for the daemon user, and that grants every adm-readable log on the host. That is a trust-boundary call I'd rather make separately, so leave it out of this PR.

  2. A missing 20auto-upgrades has no test. #680 asks for exactly this: "Make the parser default a missing value to 'enabled' and that test must go red." M2 does that (the None arm pushes 1 (enabled)), and all six tests pass. A fixture with __MISSING_CONFIG__ in the config section, asserting unknown (/etc/apt/apt.conf.d/20auto-upgrades: file missing or unreadable) for both keys, covers it.

Optional:

  • M4 survives because the general arm prints the same text for a disabled timer that list-timers still lists. The special arm only changes the output when list-timers has no row for the unit ("n/a" in place of "unknown"). Either test that case or drop the arm.
  • No test reaches the parse hook in execute_spec (if output.is_success() && spec.action_name == "UnattendedUpgradesStatus"); git grep finds the name in no executor test. Without that hook the operator gets the raw __SYSKNIFE_* sections. A test that runs execute_spec on an ActionSpec named UnattendedUpgradesStatus whose command prints your fixture would pin it.

Thanks again; once the two items are in I'll rerun the mutants at the new head.

The daemon runs as the sysknife user, which is not in adm, so on a packaged
Ubuntu install it cannot list /var/log/unattended-upgrades. The status script
now tests that the directory is readable and searchable and prints
__UNREADABLE_LOG_DIR__ when it is not. The parser turns that marker into
"directory not readable by the daemon user" instead of "no timestamped log
entry", which sent operators looking for a log problem. The daemon user gains
no new group membership.

The __NO_LOG_FILES__ arm had no producer in the script, so it is removed.

New tests cover the unreadable marker and the script's access check, a missing
20auto-upgrades for both keys, a disabled timer with no list-timers row, and
the UnattendedUpgradesStatus parse hook in execute_spec. docs/action-reference.md
is regenerated because it embeds the script text, and the workspace test count
moves from 2146 to 2156 (the PR's 5 tests plus these 5).

Signed-off-by: Vladimir Rotariu <[email protected]>
vladimirrott
vladimirrott previously approved these changes Nov 18, 2026

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dannyward630 Thank you for #807. Both blocking items from my last review are in, on your branch, so this could land without another round. Your commits are untouched.

Reviewed at 63ee30f6.

  • Unreadable log directory. The script now tests [ -r "$log_dir" ] && [ -x "$log_dir" ] and prints __UNREADABLE_LOG_DIR__ when the daemon cannot list it. The parser reports unknown (/var/log/unattended-upgrades: directory not readable by the daemon user). The __NO_LOG_FILES__ arm had no producer, so it is gone. I added no adm membership; that stays a separate decision.
  • Missing 20auto-upgrades. A new test feeds __MISSING_CONFIG__ and asserts unknown (...: file missing or unreadable) for both keys.
  • Optional items, both taken. A test for a disabled timer with no list-timers row, and an execute_spec test that pins the UnattendedUpgradesStatus parse hook.
  • docs/action-reference.md changed by one line because it embeds the script text. The workspace baseline is main's count plus your 5 tests and my 5.

I ran your script text from the new head in a debian:12-slim container, offline, with the real layout (drwxr-x--- root:adm):

ROOT:     2026-11-17 06:05:00,123 INFO x
SYSKNIFE: __UNREADABLE_LOG_DIR__

The gate ran the new parser test against one mutant:

receipt recorded for #807 at 63ee30f6 (observed: clean pass, mutated fail)

I'll merge once the board is green and write the CHANGELOG line myself.

Signed-off-by: Vladimir Rotariu <[email protected]>

# Conflicts:
#	tests/evidence/workspace-tests.json

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving at 0cb23e34. Main moved (#797, #806, #750, #748 landed), so I merged it into the branch and set tests/evidence/workspace-tests.json to 2160: main's 2150 plus the 10 tests this PR adds. When I merge the head I verified (63ee30f6) with today's main and diff that against this head, only the evidence file differs. The gate receipt from 63ee30f6 still applies. I'll merge when the board is green.

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving at 6cdc4551 after the last update from main. The gate reran the parser test against the same mutant at this head: receipt recorded for #807 at 6cdc4551 (observed: clean pass, mutated fail). Nothing else changed since 0cb23e34.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UnattendedUpgradesStatus: report whether automatic patching runs on schedule

2 participants