feat: User-Verwaltung mit Login, Sessions und Owner-Filter

Backend:
- User-Modell (sqlmodel) mit bcrypt-Passwort-Hash und is_admin-Flag
- Job.owner_id (FK auf user.id), per Migration nachgerüstet (SQLite ALTER)
- Starlette SessionMiddleware mit signiertem Cookie (SESSION_SECRET)
- /api/auth: login / logout / me / needs-setup / setup (Initial-Admin)
- /api/admin: User-CRUD + Passwort-Reset (Admin-only); letzter Admin /
  eigener Account vor Löschung geschützt
- /api/jobs: Owner-Filter (Admin sieht alle inkl. owner_username),
  404 statt 403 bei fremden Jobs (kein Existenz-Leak)

Frontend:
- Auth-Overlay mit Login bzw. Erst-Setup-Modus (auto-Detection)
- Header zeigt User + Logout, Admin-Badge bei Admin-Konten
- Admin-Karte: User anlegen, Passwort zurücksetzen, Löschen (mit Confirm)
- 401 → Login-Overlay (auch bei XHR-Upload)

Deploy:
- install.sh generiert SESSION_SECRET einmalig per python-secrets
- .env wird auf chmod 600 gesetzt
- Erstaufruf zeigt automatisch das Setup-Formular; bestehende Jobs werden
  dem ersten Admin zugeordnet
This commit is contained in:
root
2026-05-14 02:38:52 +00:00
parent d4b0d21ed1
commit a1167df4f1
16 changed files with 760 additions and 47 deletions
+17 -2
View File
@@ -39,6 +39,18 @@ if [ ! -f "$APP_DIR/lxc-frontend/.env" ]; then
cp "$APP_DIR/lxc-frontend/.env.example" "$APP_DIR/lxc-frontend/.env"
chown "$APP_USER:$APP_USER" "$APP_DIR/lxc-frontend/.env"
fi
chmod 600 "$APP_DIR/lxc-frontend/.env"
# SESSION_SECRET einmalig generieren, falls noch Platzhalter drinsteht
if grep -q "^SESSION_SECRET=CHANGE-ME-SET-IN-ENV" "$APP_DIR/lxc-frontend/.env"; then
SECRET="$(python3 -c 'import secrets; print(secrets.token_urlsafe(48))')"
sed -i "s|^SESSION_SECRET=CHANGE-ME-SET-IN-ENV|SESSION_SECRET=${SECRET}|" "$APP_DIR/lxc-frontend/.env"
echo " SESSION_SECRET wurde generiert."
elif ! grep -q "^SESSION_SECRET=" "$APP_DIR/lxc-frontend/.env"; then
SECRET="$(python3 -c 'import secrets; print(secrets.token_urlsafe(48))')"
echo "SESSION_SECRET=${SECRET}" >> "$APP_DIR/lxc-frontend/.env"
echo " SESSION_SECRET nachgetragen."
fi
mkdir -p /var/lib/voice-agent/uploads /var/lib/voice-agent/results
chown -R "$APP_USER:$APP_USER" /var/lib/voice-agent
@@ -60,5 +72,8 @@ echo
echo "Fertig. Health-Check:"
echo " curl -s http://localhost/health"
echo
echo "Nach erstem Start unbedingt MAC_API_URL in $APP_DIR/lxc-frontend/.env setzen und Service neu starten:"
echo " sudo systemctl restart voice-agent"
echo "Beim ersten Aufruf im Browser: Initialer Admin wird angelegt — bestehende Jobs"
echo "werden diesem Account automatisch zugeordnet."
echo
echo "Falls noch nicht geschehen: MAC_API_URL in $APP_DIR/lxc-frontend/.env setzen"
echo "und Service neu starten: sudo systemctl restart voice-agent"