From 19a212dfb16fd913e7ff68a91f21f9b35b99fe90 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Fri, 27 Nov 2026 07:09:53 -0600 Subject: [PATCH] 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. --- .github/workflows/ci.yml | 12 +++++++ .../main/rootfs/usr/local/bin/fix-ownership | 35 +++++++++++++------ docs/docs/configuration/non_root.md | 2 +- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9682eeb34f..d7396a1ac9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -314,6 +314,18 @@ jobs: sleep 2 done if [ "$ok" -ne 1 ]; then echo "sentinel skip never logged"; docker logs frigate-puid; exit 1; fi + # a replaced media volume re-sweeps despite the sentinel + docker stop frigate-puid + sudo rm -rf /tmp/frigate-media-puid + sudo mkdir /tmp/frigate-media-puid + docker start frigate-puid + up=0 + for i in $(seq 1 60); do + docker exec frigate-puid curl -fs http://127.0.0.1:5000/api/version && up=1 && break + sleep 5 + done + if [ "$up" -ne 1 ]; then echo "replaced media volume was not swept"; docker logs frigate-puid; exit 1; fi + docker exec frigate-puid stat -c %u:%g /media/frigate | grep -qx 1500:1500 docker rm -f frigate-puid - name: Assert read-only rootfs with --user works run: | diff --git a/docker/main/rootfs/usr/local/bin/fix-ownership b/docker/main/rootfs/usr/local/bin/fix-ownership index 787779a1ba..98e4a550d4 100755 --- a/docker/main/rootfs/usr/local/bin/fix-ownership +++ b/docker/main/rootfs/usr/local/bin/fix-ownership @@ -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 diff --git a/docs/docs/configuration/non_root.md b/docs/docs/configuration/non_root.md index 0347900616..bdef2d9001 100644 --- a/docs/docs/configuration/non_root.md +++ b/docs/docs/configuration/non_root.md @@ -94,7 +94,7 @@ Recordings on a NAS behave differently, so check what you have before migrating: findmnt -T /path/to/your/storage -o TARGET,FSTYPE,OPTIONS ``` -**SMB and CIFS** don't store per-file ownership at all. It's synthesized from the mount options, so a per-file `chown` fails and isn't needed. Mount the share as the uid and gid Frigate runs as, and every file already looks correct to the sweep: +**SMB and CIFS** don't store per-file ownership at all. It's synthesized from the mount options, so a per-file `chown` has no effect and isn't needed. Mount the share as the uid and gid Frigate runs as, and every file already looks correct to the sweep: ``` //nas/frigate /media/frigate cifs credentials=/root/.smb,uid=1000,gid=1000,file_mode=0664,dir_mode=0775 0 0