Skip to content

Commit 70ce378

Browse files
committed
tests: cover the snapd no-recovery-needed security event
1 parent 654702b commit 70ce378

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

‎tests/main/security-logging/task.yaml‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ details: |
1717
produces a "sys_startup_snapd" event with snapd_version and boot_id
1818
fields. Sideloading a new snapd snap revision produces a
1919
"sys_restart_snapd" event with reason "snapd-update" and a
20-
snapd_version field. On classic, reseeding with no snaps produces a
21-
"sys_standby_snapd" event with reason "snapd-idle". A root GET
20+
snapd_version field. Starting snapd with SNAPD_REVERT_TO_REV set and
21+
no snapd refresh to recover produces a "sys_restart_snapd" event
22+
with reason "snapd-no-recovery-needed". On classic, reseeding
23+
with no snaps produces a "sys_standby_snapd" event with reason
24+
"snapd-idle". A root GET
2225
/v2/users produces an "authz_admin" event with reason "root-auth",
2326
and the same request from an unprivileged user produces an
2427
"authz_fail" event with reason "root-auth-denied".
@@ -44,11 +47,17 @@ prepare: |
4447
systemctl restart snapd.service
4548
4649
restore: |
50+
# Restore the unit override before starting snapd. A process
51+
# started while SNAPD_STANDBY_WAIT=1s is still installed keeps
52+
# that environment; daemon-reload does not update it.
4753
if [ -f "$OVERRIDES_FILE.bak" ]; then
4854
mv "$OVERRIDES_FILE.bak" "$OVERRIDES_FILE"
4955
systemctl daemon-reload
56+
systemctl try-restart snapd.service || true
5057
fi
5158
59+
systemctl start snapd.socket snapd.service || true
60+
5261
if [ -f audit-socket-was-inactive ]; then
5362
systemctl stop systemd-journald-audit.socket
5463
systemctl restart systemd-journald.service
@@ -228,6 +237,20 @@ execute: |
228237
journal_match '"category":"USER","event":"user_removed_system".*"system_user":"'"$system_username"'".*"force":false.*"remove_reason":"api-remove-user"'
229238
fi
230239
240+
echo "Checking that a failure-recovery start with nothing to recover produces a sys_restart_snapd audit event"
241+
snapd_pid=$(systemctl show -p MainPID snapd.service | cut -d= -f2)
242+
test "$snapd_pid" -gt 0
243+
snapd_bin=$(readlink -f "/proc/${snapd_pid}/exe")
244+
tests.systemd stop-unit snapd.service snapd.socket
245+
pin_logs
246+
# snap-failure sets SNAPD_REVERT_TO_REV before it runs snapd. With no
247+
# snapd refresh in progress, snapd records the restart and exits 0.
248+
SNAPD_REVERT_TO_REV=999 timeout 120 "$snapd_bin"
249+
security_event_match '"level":"INFO","description":"Snapd restart with reason snapd-no-recovery-needed","app_id":"canonical.snapd.snapd","type":"security","category":"SYS","event":"sys_restart_snapd","snapd_version":"[^"]+","reason":"snapd-no-recovery-needed"'
250+
systemctl reset-failed snapd.service snapd.socket || true
251+
systemctl start snapd.socket snapd.service
252+
snap wait system seed.loaded
253+
231254
echo "Checking that snapd-idle socket-activation standby produces a sys_standby_snapd audit event"
232255
if ! os.query is-classic; then
233256
echo "non-classic systems always have snaps; skipping sys_standby_snapd check"

0 commit comments

Comments
 (0)