Boot ownership and device grant fixes (#25085)

* fix boot sentinel and usb device grant edge cases

- Exclude /config/.permissions_version from every fix-ownership sweep. The granular root per-boot /config sweep ran without --sentinel and chowned the root-owned sentinel to PUID, so safe-sentinel rejected it on the next boot and /config and /media/frigate were fully re-swept on every boot
- Only grant real directories and char devices under /dev/bus/usb, and pass -P when setting the default ACLs, so a symlink in a host-backed usb tree is never followed by root
- Open the sentinel with O_NONBLOCK on read so a FIFO at that path fails the regular-file check instead of hanging the boot
- Assert in CI that the sentinel stays root-owned across a granular restart and that a symlink under /dev/bus/usb is not followed

* tweak ci
This commit is contained in:
Josh Hawkins
2026-11-25 05:06:48 -07:00
committed by GitHub
parent 304dd6dda8
commit 08dcb63a9b
4 changed files with 23 additions and 12 deletions
@@ -88,22 +88,19 @@ swept_clean=1
# Entries another mechanism deliberately owns. Chowning them undoes that work
# and leaves the same "mismatch" waiting for the next boot, so /config could
# never report itself clean: /config is chgrp'd to frigate-data below so go2rtc
# can traverse it, and the HomeKit file is handed to the go2rtc user by the
# go2rtc service. Only the GROUP on /config is exempt; a root-owned /config
# must still be chowned or the runtime user cannot write there at all.
# can traverse it, the HomeKit file is handed to the go2rtc user by the go2rtc
# service, and safe-sentinel only trusts a root-owned sentinel. The sentinel is
# excluded on every call, including the granular per-boot /config sweep that
# runs without --sentinel. Only the GROUP on /config is exempt; a root-owned
# /config must still be chowned or the runtime user cannot write there at all.
# Shared by the counting and the chowning walk so the two cannot disagree.
mismatch_expr=(
"(" -not -uid "$target_uid"
-o "(" -not -gid "$target_gid" -a ! -path /config ")"
")"
-a ! -path /config/go2rtc_homekit.yml
-a ! -path /config/.permissions_version
)
if [[ -n "$sentinel" ]]; then
# safe-sentinel keeps the sentinel root-owned on purpose and rejects one
# owned by anybody else, so chowning it here would suppress the skip and
# make every boot re-sweep. Only the trailing write puts it back today.
mismatch_expr+=(-a ! -path "$sentinel")
fi
exec 3>&1
@@ -20,7 +20,8 @@ MODE = 0o644
def do_read(path: str) -> int:
try:
fd = os.open(path, os.O_RDONLY | os.O_NOFOLLOW)
# O_NONBLOCK so a fifo opens at once and fails the regular-file check
fd = os.open(path, os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK)
except OSError:
return 1
try: