diff --git a/docker/main/rootfs/etc/s6-overlay/s6-rc.d/go2rtc-healthcheck/run b/docker/main/rootfs/etc/s6-overlay/s6-rc.d/go2rtc-healthcheck/run index 3a6e423e52..48868269ba 100755 --- a/docker/main/rootfs/etc/s6-overlay/s6-rc.d/go2rtc-healthcheck/run +++ b/docker/main/rootfs/etc/s6-overlay/s6-rc.d/go2rtc-healthcheck/run @@ -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 diff --git a/docker/main/rootfs/etc/s6-overlay/s6-rc.d/nginx/run b/docker/main/rootfs/etc/s6-overlay/s6-rc.d/nginx/run index 1e1a7b334f..a1352799b3 100755 --- a/docker/main/rootfs/etc/s6-overlay/s6-rc.d/nginx/run +++ b/docker/main/rootfs/etc/s6-overlay/s6-rc.d/nginx/run @@ -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 diff --git a/docs/docs/configuration/non_root.md b/docs/docs/configuration/non_root.md index bcc2f2ff4a..0347900616 100644 --- a/docs/docs/configuration/non_root.md +++ b/docs/docs/configuration/non_root.md @@ -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//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: diff --git a/docs/docs/configuration/tls.md b/docs/docs/configuration/tls.md index eb7d4ca053..41286131b1 100644 --- a/docs/docs/configuration/tls.md +++ b/docs/docs/configuration/tls.md @@ -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.: