re-sweep a replaced media volume despite the ownership sentinel

The boot sweep skipped whenever the sentinel in /config matched, so wiping or swapping /media/frigate while keeping the config volume left the new root-owned folder unswept and Frigate failed to create /media/frigate/recordings. The sentinel is now honored only when each volume root is still owned by the runtime user. Filesystems that accept chown without applying it (CIFS without setuids) get an unmanaged sentinel after a clean sweep so they don't re-sweep on every boot.
This commit is contained in:
Josh Hawkins
2026-11-27 07:09:53 -06:00
parent 8c773c2e2e
commit 19a212dfb1
3 changed files with 38 additions and 11 deletions
+25 -10
View File
@@ -70,16 +70,6 @@ if [[ -n "$mode" ]]; then
sentinel_content="${sentinel_content}:${mode}"
fi
# safe-sentinel reports only a root-owned regular file, so a forged or
# symlinked sentinel in the runtime-user-owned /config can't suppress the sweep
if [[ "$dry_run" -eq 0 && -n "$sentinel" ]]; then
if existing=$(/usr/local/bin/safe-sentinel read "$sentinel" 2>/dev/null) && \
[[ "$existing" == "$sentinel_content" ]]; then
echo "[INFO] fix-ownership: ${target_uid}:${target_gid} (schema ${schema}) already applied, skipping"
exit 0
fi
fi
# A sweep that could not chown everything must not be recorded as complete:
# the sentinel would make every later boot skip it and the entries would stay
# unreachable once services run unprivileged.
@@ -102,6 +92,24 @@ mismatch_expr=(
-a ! -path /config/.permissions_version
)
first_mismatched_root() {
find "$@" -maxdepth 0 "${mismatch_expr[@]}" -print -quit 2>/dev/null || true
}
# safe-sentinel reports only a root-owned regular file, so a forged or
# symlinked sentinel in the runtime-user-owned /config can't suppress the sweep.
# A mismatched volume root means the volume was replaced or wiped since the
# sweep (Docker recreates a missing bind source as root), so it sweeps again,
# unless the sentinel records a filesystem that ignores chown.
if [[ "$dry_run" -eq 0 && -n "$sentinel" ]]; then
if existing=$(/usr/local/bin/safe-sentinel read "$sentinel" 2>/dev/null) && \
{ [[ "$existing" == "${sentinel_content}:unmanaged" ]] || \
{ [[ "$existing" == "$sentinel_content" ]] && [[ -z "$(first_mismatched_root "$@")" ]]; }; }; then
echo "[INFO] fix-ownership: ${target_uid}:${target_gid} (schema ${schema}) already applied, skipping"
exit 0
fi
fi
exec 3>&1
for path in "$@"; do
@@ -199,6 +207,13 @@ if [[ "$dry_run" -eq 0 && -d /config ]]; then
fi
if [[ "$dry_run" -eq 0 && -n "$sentinel" && "$swept_clean" -eq 1 ]]; then
# CIFS without the setuids option accepts chown and changes nothing, so
# the root can never match. Without this every boot would sweep again.
unmanaged_root=$(first_mismatched_root "$@")
if [[ -n "$unmanaged_root" ]]; then
echo "[WARN] fix-ownership: ${unmanaged_root} kept its owner after chown; its filesystem ignores ownership changes, so set the owner through its mount options"
sentinel_content="${sentinel_content}:unmanaged"
fi
/usr/local/bin/safe-sentinel write "$sentinel" "$sentinel_content" || \
echo "[WARN] fix-ownership: could not write ${sentinel}; the sweep will run again on next boot"
fi