mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-19 20:13:01 +03:00
The frigate and go2rtc run scripts probed "$ffmpeg_path" -version as root before dropping privileges, and resolve_ffmpeg_path only refused runtime-user-writable paths when frigate itself was a root service. In the default mode uid 1000 could set ffmpeg.path to a /config directory, plant bin/ffmpeg there, and get root on the next restart, and under FRIGATE_ROOT_SERVICES=go2rtc a root go2rtc used that path as its ffmpeg bin. The probe now runs as the service user whenever the service drops privileges, and resolve_ffmpeg_path refuses writable paths for whichever service will run the binary, returning the resolved path so a symlink can't be retargeted after the check. go2rtc falls back to the bundled build's libavformat version if its user can't run the custom build.
63 lines
2.1 KiB
Plaintext
Executable File
63 lines
2.1 KiB
Plaintext
Executable File
#!/command/with-contenv bash
|
|
# shellcheck shell=bash
|
|
# Start the Frigate service
|
|
|
|
set -o errexit -o nounset -o pipefail
|
|
|
|
runs_as_root=0
|
|
if [[ "$(id -u)" -eq 0 ]]; then
|
|
if [[ "${FRIGATE_RUN_AS_ROOT:-false}" == "true" ]] || /usr/local/bin/service-runs-as-root frigate; then
|
|
runs_as_root=1
|
|
fi
|
|
fi
|
|
|
|
# Tell S6-Overlay not to restart this service
|
|
s6-svc -O .
|
|
|
|
# The helper runs as root (-I skips user site-packages). The probe runs as the
|
|
# service user when the service drops privileges; a root probe relies on
|
|
# resolve_ffmpeg_path refusing runtime-user-writable paths.
|
|
function set_libva_version() {
|
|
local ffmpeg_path
|
|
local probe_as=()
|
|
if [[ "$(id -u)" -eq 0 && "$runs_as_root" -eq 0 ]]; then
|
|
probe_as=(s6-setuidgid frigate)
|
|
fi
|
|
ffmpeg_path=$(python3 -I /usr/local/ffmpeg/get_ffmpeg_path.py frigate)
|
|
LIBAVFORMAT_VERSION_MAJOR=$("${probe_as[@]}" "$ffmpeg_path" -version | grep -Po "libavformat\W+\K\d+")
|
|
export LIBAVFORMAT_VERSION_MAJOR
|
|
}
|
|
|
|
echo "[INFO] Preparing Frigate..."
|
|
set_libva_version
|
|
|
|
# HOME=/root survives s6-setuidgid, so any run that is not root gets
|
|
# HOME=/config explicitly. The runtime user owns /config, so these paths go
|
|
# only to the service process, never to root. Detector runtimes installed at
|
|
# first start (pip install --user) live under $HOME/.local.
|
|
run_as=()
|
|
runtime_home="${HOME}"
|
|
if [[ "$runs_as_root" -eq 0 ]]; then
|
|
runtime_home=/config
|
|
if [[ "$(id -u)" -eq 0 ]]; then
|
|
run_as=(s6-setuidgid frigate)
|
|
fi
|
|
fi
|
|
run_as+=(env
|
|
"HOME=${runtime_home}"
|
|
"LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}${runtime_home}/.local/lib"
|
|
"PATH=${PATH}:${runtime_home}/.local/bin")
|
|
|
|
# opt out of openvino telemetry; the marker lands under the service's HOME
|
|
if [ -e /usr/local/bin/opt_in_out ]; then
|
|
"${run_as[@]}" /usr/local/bin/opt_in_out --opt_out > /dev/null 2>&1 || true
|
|
fi
|
|
|
|
echo "[INFO] Starting Frigate..."
|
|
|
|
cd /opt/frigate || echo "[ERROR] Failed to change working directory to /opt/frigate"
|
|
|
|
# Replace the bash process with the Frigate process, redirecting stderr to stdout
|
|
exec 2>&1
|
|
exec "${run_as[@]}" python3 -u -m frigate
|