Sicherheits-Härtung und Bugfixes

This commit is contained in:
Patrick Asmus
2026-10-11 17:39:03 +02:00
parent c3f68ace96
commit 65b0b5ac0f
25 changed files with 2577 additions and 686 deletions
+77
View File
@@ -0,0 +1,77 @@
#!/bin/sh
# stream-recorder - Container-Entrypoint
#
# Läuft der Container als root, werden UID/GID des Users "app" an PUID/PGID
# angepasst, die Datenverzeichnisse übernommen und der Prozess anschließend
# ohne Root-Rechte gestartet. Läuft der Container bereits als Nicht-root
# (z.B. "user:" in docker-compose), wird der Befehl direkt ausgeführt.
set -eu
PUID="${PUID:-1000}"
PGID="${PGID:-1000}"
DATA_DIR="${DATA_DIR:-/app/data}"
RECORDING_ROOTS="${RECORDING_ROOTS:-/app/data/recordings:/recordings}"
log() {
echo "[entrypoint] $*"
}
# Nur Dateien/Verzeichnisse umschreiben, die noch nicht PUID:PGID gehören.
fix_owner() {
if [ -d "$1" ]; then
find "$1" \( ! -user "$PUID" -o ! -group "$PGID" \) \
-exec chown "$PUID:$PGID" {} + 2>/dev/null \
|| log "WARNUNG: Besitzrechte in $1 konnten nicht vollständig angepasst werden"
fi
}
if [ "$(id -u)" != "0" ]; then
exec "$@"
fi
case "$PUID" in
''|*[!0-9]*) log "FEHLER: PUID muss numerisch sein (aktuell: $PUID)"; exit 1 ;;
esac
case "$PGID" in
''|*[!0-9]*) log "FEHLER: PGID muss numerisch sein (aktuell: $PGID)"; exit 1 ;;
esac
if [ "$PUID" = "0" ]; then
log "WARNUNG: PUID=0 - Anwendung läuft als root"
exec "$@"
fi
# UID/GID des app-Users anpassen (-o erlaubt bereits vergebene IDs)
if [ "$(id -g app)" != "$PGID" ]; then
log "Setze GID von app auf $PGID"
groupmod -o -g "$PGID" app
fi
if [ "$(id -u app)" != "$PUID" ]; then
log "Setze UID von app auf $PUID"
usermod -o -u "$PUID" app
fi
mkdir -p "$DATA_DIR"
fix_owner "$DATA_DIR"
OLD_IFS="$IFS"
IFS=':'
for root in $RECORDING_ROOTS; do
IFS="$OLD_IFS"
if [ -n "$root" ]; then
fix_owner "$root"
fi
done
IFS="$OLD_IFS"
if [ -f "$DATA_DIR/config.yml" ]; then
chmod 600 "$DATA_DIR/config.yml" || log "WARNUNG: chmod 600 auf config.yml fehlgeschlagen"
fi
if ! command -v setpriv >/dev/null 2>&1; then
log "FEHLER: setpriv nicht gefunden (Paket util-linux) - Rechteabgabe nicht möglich"
exit 1
fi
export HOME=/tmp
exec setpriv --reuid="$PUID" --regid="$PGID" --init-groups "$@"