Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions scripts/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,15 @@ verify_canary_check() {
esac
# ausearch reads stdin when it isn't a terminal, so --input-logs makes it read the audit logs.
# ausearch -ts takes the date and the time as two arguments. It parses the date with the C
# locale's %x, which has a two-digit year. The event time is never before this second.
verify_date=$(date '+%m/%d/%y')
verify_time=$(date '+%H:%M:%S')
verify_start="$verify_date $verify_time"
# locale's %x, which has a two-digit year. One date call gives both, so they are from the same
# moment.
verify_start=$(date '+%m/%d/%y %H:%M:%S')
verify_date=${verify_start% *}
verify_time=${verify_start#* }
# The kernel stamps an event with a clock that runs a few ms behind the one date reads. So an
# event written right after the start time can carry the second before it, and ausearch -ts
# would skip it. Waiting one second puts the event after the start time.
[ "$verify_poll" -eq 0 ] || sleep 1
if ! printf 'canary %s\n' "$verify_start" >"$verify_canary" 2>/dev/null; then
verify_report canary fail "cannot write $verify_canary"
return
Expand Down
11 changes: 11 additions & 0 deletions tests/bats/verify.bats
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,14 @@ lost 0'
[ "$status" -eq 0 ]
[[ "$output" == *"check=failure_mode result=warn"* ]]
}

@test "verify waits a second after it takes the start time, before it writes the canary" {
write_state
# The kernel's event clock runs a few ms behind date, so an event written right after the
# start time can carry the second before it, and ausearch -ts would then skip it.
export AKIT_VERIFY_POLL=1
akit_stub sleep '{ [ -e "$AKIT_ROOT/etc/auditd-kit/canary" ] && echo after || echo before; } >>"$AKIT_ROOT/sleeps"'
run sh "$verify"
[ "$status" -eq 0 ]
[ "$(sed -n 1p "$AKIT_ROOT/sleeps")" = before ]
}
Loading