31 lines
3.0 KiB
Bash
31 lines
3.0 KiB
Bash
# 03-refresh.sh — demo-hp. The repair candidate: load every profile from a FRESH compile, cache ignored and rewritten.
|
|
set -u
|
|
P=/sys/kernel/security/apparmor/policy/profiles; CUR=/var/cache/apparmor/f6da0254.0
|
|
snap() { # name -> loaded hash, every profile
|
|
for d in $P/*/; do echo "$(cat $d/name) $(cat $d/raw_sha256 2>/dev/null) $(cat $d/mode 2>/dev/null)"; done | sort
|
|
}
|
|
guests() {
|
|
for v in 9201 9202; do
|
|
ip=$(lxc-info -n $v -p -H); echo "guest $v: $(pct status $v) init pid $ip confinement=$(cat /proc/$ip/attr/current)"
|
|
echo " containers: $(pct exec $v -- docker ps -q | wc -l) running, $(pct exec $v -- docker ps --filter health=unhealthy -q | wc -l) unhealthy, started-at-newest=$(pct exec $v -- sh -c 'docker inspect --format "{{.State.StartedAt}}" $(docker ps -q) | sort | tail -1')"
|
|
cp=$(pct exec $v -- sh -c 'docker inspect --format "{{.State.Pid}}" felhom-controller'); hp=$(grep -l "NSpid:.*[[:space:]]$cp$" /proc/[0-9]*/status 2>/dev/null | head -1 | cut -d/ -f3)
|
|
echo " the controller container's process (host pid ${hp:-?}): confinement=$(cat /proc/${hp:-0}/attr/current 2>/dev/null)"
|
|
done
|
|
echo "VM 341 (Tester 1): $(qm status 341)"
|
|
}
|
|
echo "#### $(hostname) $(date -u +%FT%TZ)"
|
|
echo "## BEFORE"; guests; snap > /root/spike-loaded-before.txt; echo "loaded profiles: $(wc -l < /root/spike-loaded-before.txt)"
|
|
echo "chrony: $(systemctl is-active chrony); loaded chrony profile $(cat $P/usr.sbin.chronyd*/raw_sha256 | cut -c1-12); cache $(sha256sum < $CUR/usr.sbin.chronyd | cut -c1-12)"
|
|
echo "disabled profiles (must stay unloaded): $(ls /etc/apparmor.d/disable 2>/dev/null | tr '\n' ' ')"
|
|
T=$(date +"%Y-%m-%d %H:%M:%S"); date +%s > /root/spike-refresh-at
|
|
echo "## THE COMMAND: apparmor_parser --replace --skip-read-cache --write-cache -- /etc/apparmor.d"
|
|
s=$(date +%s.%N); apparmor_parser --replace --skip-read-cache --write-cache -- /etc/apparmor.d; rc=$?; e=$(date +%s.%N)
|
|
echo "rc=$rc seconds=$(echo "$e - $s" | bc)"
|
|
echo "## AFTER"; guests; snap > /root/spike-loaded-after.txt; echo "loaded profiles: $(wc -l < /root/spike-loaded-after.txt)"
|
|
echo "profiles whose loaded hash changed:"; diff <(cut -d' ' -f1,2 /root/spike-loaded-before.txt) <(cut -d' ' -f1,2 /root/spike-loaded-after.txt) | grep '^>' | sed 's/^> / /'
|
|
echo "profiles added or gone (names):"; diff <(cut -d' ' -f1 /root/spike-loaded-before.txt) <(cut -d' ' -f1 /root/spike-loaded-after.txt) | grep '^[<>]' || echo " none"
|
|
echo "modes changed:"; diff <(cut -d' ' -f1,3 /root/spike-loaded-before.txt) <(cut -d' ' -f1,3 /root/spike-loaded-after.txt) | grep '^[<>]' || echo " none"
|
|
echo "chrony profile: loaded $(cat $P/usr.sbin.chronyd*/raw_sha256 | cut -c1-12); cache $(sha256sum < $CUR/usr.sbin.chronyd | cut -c1-12) mtime $(stat -c %y $CUR/usr.sbin.chronyd | cut -c1-19); fresh $(apparmor_parser -S -K /etc/apparmor.d/usr.sbin.chronyd | sha256sum | cut -c1-12)"
|
|
echo "chrony unit, NOT restarted by the command: $(systemctl is-active chrony)"
|
|
echo "kernel lines since the command:"; journalctl -k --since "$T" --no-pager -o short-iso | grep -i apparmor | tail -5; echo "(end)"
|