Enhancement: Add PUID/PGID support (Still #22837
Unanswered
TCS-UK
asked this question in
Ask A Question
Replies: 1 comment
-
|
What you've proposed is not all that different than what we had in mind, with some slight differences. We've planned this and other container hardening work for a future version of Frigate. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
UPDATED:
Add PUID/PGID support for running Frigate as a non-root user
Problem
Users who run Frigate on NAS devices, Unraid, or any shared host care about
which uid/gid owns the files created inside their mounted volumes (
/config,/media, recordings, etc.). Currently Frigate always runs as root inside thecontainer, so every recorded clip and database file ends up owned by
rootonthe host — requiring
chmod 777hacks or making files inaccessible to the hostuser.
The two obvious workarounds both fail:
user: "1000:1000"in Compose — breaks startup entirely. s6-overlay'slog-prepareruns as that uid and cannotchown /dev/shm/logs/* nobody:nogroup,stalling all services before any app process starts.
PUID/PGIDenv vars — silently ignored; Frigate has no such mechanism.Solution
Adds opt-in
PUID/PGIDsupport using the same pattern as LinuxServer.ioimages, which the self-hosted community already understands well.
How it works
A new
user-setups6-rc oneshot service runs as root immediately after thebasebundle — beforeprepareorlog-prepare— and exits. It:frigategroup to matchPGIDviagroupmodfrigateuser to matchPUIDviausermodvideo,render,coralfromgroup_add:in Compose) to thefrigateuser, so that ffmpegprocesses spawned by both Frigate and go2rtc retain device access
chowns/config,/media,/tmp/cache,/db(skips dirs that aren'tmounted)
HOME,HF_HOME, andXDG_CACHE_HOMEinto/run/s6/container_environment/— the idiomatic s6-overlay way to propagateenv vars to all subsequent
with-contenvservice scripts, eliminatingspurious cache-write warnings
The
frigateandgo2rtcservicerunscripts uses6-setuidgid frigatetodrop privileges before
exec-ing the process. Becauses6-setuidgidis passeda username rather than a raw uid, it reads the full group membership of
frigatefrom
/etc/groupat exec time — picking up the supplementary groups added instep 3.
nginxandcertsyncremain root — nginx needs root to bind port 443 andgenerate TLS certificates; it drops its workers to
nobodyitself.Startup sequence with PUID/PGID set
Supplementary group handling
Hardware acceleration and devices (VAAPI, NVENC, Coral USB) require the app
process to be a member of specific groups (e.g.
video,render). Docker'sgroup_add:injects these into the container's init process. Without explicitpropagation,
s6-setuidgidwould reset to only thefrigateuser's own groups,breaking device access.
user-setupiteratesid -G(skipping gid 0 / root) and callsusermod -aG <group> frigatefor each, so they are in place before anys6-setuidgid frigatecall. The underlying gid numbers are preserved exactly —no remapping occurs.
Backward compatibility
When
PUID/PGIDare not set,user-setupexits immediately (no-op).All behaviour is identical to today — Frigate runs as root. This is a fully
opt-in change.
Files changed
docker/main/Dockerfilefrigateuser/group (uid/gid 1000 as placeholder)rootfs/…/user-setup/runrootfs/…/user-setup/typeoneshotrootfs/…/user-setup/uprootfs/…/user-setup/dependencies.d/baserootfs/…/prepare/dependencies.d/user-setuprootfs/…/log-prepare/dependencies.d/user-setuprootfs/…/frigate/runs6-setuidgid frigatewhenPUID≠0rootfs/…/go2rtc/runUsage
Files created by Frigate (recordings, clips, database) will be owned by
uid/gid 1000 on the host. Hardware-accelerated ffmpeg processes retain access
to
/dev/dri/*and other devices via the propagated supplementary groups.Testing
Verified against Frigate stable (
0.17.1-416a9b7):healthywithPUID=1000 PGID=1000python3 -m frigateand all child processes run as uid/gid 1000go2rtcbinary runs as uid/gid 1000; its ffmpeg children inherit the samegroup_add:(e.g.videogid 44) are correctlypropagated — verified via
/proc/<pid>/status Groups:field/config,/media,/db,/tmp/cachecorrectly owned after startupHOME/HuggingFace/OpenVINO cache warnings in logsPUID/PGID: zero behaviour change — runs as root as beforepuid-pgid-support-git.patch
Beta Was this translation helpful? Give feedback.
All reactions