mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-25 14:57:07 +03:00
TLS renewal and healthcheck fixes (#25081)
* hand renewed tls keys to the runtime user and time out the go2rtc healthcheck - Renewed certbot keys were owned by root with mode 0600, so the non-root nginx couldn't read them and every certsync reload failed until the cert expired. certsync now chowns a mounted key to the runtime user before each reload, under the same conditions as the nginx startup handover - The go2rtc healthcheck curl had no total timeout, so a go2rtc that accepted connections but never answered blocked the check forever. It now gives up after 15 s - The TLS and non-root docs now tell read-only mount users to set the key's group and group read, which certbot keeps on renewal * stop chowning mounted tls keys and check they're readable instead The root chown of a mounted key followed symlinks, so a runtime user that could write the cert folder could have any root file handed to it, and the chown never covered keys renewed after startup. Frigate no longer changes ownership of mounted certs. nginx startup logs an error naming the gid when the runtime user can't read the key, and the TLS docs have users grant group read once on the host, which certbot keeps on renewal. This also drops the certsync handover added earlier on this branch. * skip the tls key check when tls is disabled and tighten its wording * check fullchain.pem and folder access in the tls startup check
This commit is contained in:
@@ -12,7 +12,7 @@ echo "[INFO] Starting go2rtc healthcheck service..."
|
||||
|
||||
while sleep 30s; do
|
||||
# Check if the service is running
|
||||
if ! curl --connect-timeout 10 --fail --silent --show-error --output /dev/null http://127.0.0.1:1984/api/streams 2>&1; then
|
||||
if ! curl --connect-timeout 10 --max-time 15 --fail --silent --show-error --output /dev/null http://127.0.0.1:1984/api/streams 2>&1; then
|
||||
echo "[ERROR] The go2rtc service is not responding to ping, restarting..."
|
||||
# We can also use -r instead of -t to send kill signal rather than term
|
||||
s6-svc -t /var/run/service/go2rtc 2>&1
|
||||
|
||||
@@ -152,13 +152,24 @@ if [[ "$(id -u)" -eq 0 && "$runs_as_root" -eq 0 ]]; then
|
||||
# nginx reopens /dev/stdout by path for its logs, and s6 made the pipe
|
||||
# root-owned 0600; without this the non-root master exits EACCES
|
||||
chown frigate /dev/stdout
|
||||
# Only mounted certs need handing over; the self-signed pair is already
|
||||
# owned by the runtime user that generated it. Never chown the /config copy:
|
||||
# chown follows symlinks, so it would retarget onto any root file the
|
||||
# runtime user pointed it at. Tolerant because mounted certs may be :ro.
|
||||
if [ "$cert_path" = "$letsencrypt_path" ] && [ -f "$cert_path/privkey.pem" ]; then
|
||||
chown frigate:frigate "$cert_path/privkey.pem" "$cert_path/fullchain.pem" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Mounted certs are never chowned: chown follows symlinks, and the runtime user
|
||||
# may control the mounted folder. The key's group and group read survive certbot
|
||||
# renewals, so the host grants access once.
|
||||
if [[ "$cert_path" == "$letsencrypt_path" && "$runs_as_root" -eq 0 ]] &&
|
||||
[[ "$(echo "$nginx_settings" | jq -r .tls.enabled)" == "true" ]]; then
|
||||
as_runtime=()
|
||||
if [[ "$(id -u)" -eq 0 ]]; then
|
||||
as_runtime=(s6-setuidgid frigate)
|
||||
fi
|
||||
|
||||
for file in privkey.pem fullchain.pem; do
|
||||
if ! "${as_runtime[@]}" test -r "$cert_path/$file"; then
|
||||
runtime_gid=$("${as_runtime[@]}" id -g)
|
||||
echo "[ERROR] The mounted ${file} is not readable by the runtime user; on the host, give it group ${runtime_gid} with read access and let that group enter the folders above it" >&2
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Replace the bash process with the NGINX process, redirecting stderr to stdout
|
||||
|
||||
@@ -389,7 +389,7 @@ Rockchip NPU and GPU usage come from `/sys/kernel/debug`, which the kernel makes
|
||||
|
||||
go2rtc's ffmpeg processes no longer appear in Intel GPU stats. Frigate reads per-process GPU usage from `/proc/<pid>/fdinfo`, which the kernel won't let one user read for another user's processes, so anything go2rtc spawns is invisible to it. Overall GPU utilization is unaffected.
|
||||
|
||||
If you mount your own TLS certificate at `/etc/letsencrypt/live/frigate`, the private key has to be readable by the runtime user, which runs nginx. Frigate hands the key to that user at startup if the mount is writable; on a read-only mount, make the key readable by uid 1000 (or your `PUID`) yourself.
|
||||
If you mount your own TLS certificate at `/etc/letsencrypt/live/frigate`, the key and the certificate have to be readable by the runtime user, which runs nginx, and that user has to be able to enter the folders above them. Frigate doesn't change ownership of mounted certificates, so give the key to the runtime user's group (gid 1000, your `PGID`, or the group in Docker's `user:`) with group read on the host. certbot keeps the key's group and group read on renewal, so this is a one-time step.
|
||||
|
||||
If you're debugging nginx, run the config check as the runtime user with stdout discarded:
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ frigate:
|
||||
|
||||
Within the folder, the private key is expected to be named `privkey.pem` and the certificate is expected to be named `fullchain.pem`. Mounted certificates take precedence over the self signed pair in `/config/tls`.
|
||||
|
||||
`privkey.pem` must be readable by the runtime user that runs NGINX. Frigate hands it over at startup when the mount is writable; on a `:ro` mount, make it readable by uid 1000 (or your `PUID`) yourself. See [Running as a non-root user](/configuration/non_root).
|
||||
`privkey.pem` and `fullchain.pem` must be readable by the runtime user that runs NGINX, and that user must be able to enter the folders above them. Frigate doesn't change ownership of mounted certificates, so give the key to the runtime user's group (gid 1000, your `PGID`, or the group in Docker's `user:`) with group read on the host, for example `chgrp 1000 privkey.pem && chmod g+r privkey.pem`. certbot keeps the key's group and group read on renewal, so this is a one-time step. See [Running as a non-root user](/configuration/non_root).
|
||||
|
||||
Note that certbot uses symlinks, and those can't be followed by the container unless it has access to the targets as well, so if using certbot you'll also have to mount the `archive` folder for your domain, e.g.:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user