Meilenstein 5: Deployment mit systemd und Caddy
- deploy/it-connect.service: eigener Benutzer, nur 127.0.0.1, Proxy-Header nur von Caddy, StateDirectory /var/lib/it-connect, systemd-Härtung - deploy/it-connect-backup.service/.timer: tägliches Backup nach /var/backups/it-connect - deploy/Caddyfile: HTTPS (interne CA oder Firmenzertifikat), Sicherheits-Header, Log - SETUP.md Teil 7: Installation, Konfiguration, Zertifikate, Backup, Update, Fehlerbehebung Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4a153de78d
commit
ad0fa6ff8a
5 files changed
+282
-5
No files matched your search
@@ -0,0 +1,39 @@
|
||||
# Caddy als HTTPS-Reverse-Proxy vor it-connect
|
||||
# Installation: siehe SETUP.md, Teil 7
|
||||
# sudo cp deploy/Caddyfile /etc/caddy/Caddyfile
|
||||
# Hostnamen unten anpassen, dann: sudo systemctl reload caddy
|
||||
#
|
||||
# Hostname: der interne Name, unter dem die App im Browser aufgerufen wird
|
||||
# (muss per DNS oder hosts-Datei auf den Server zeigen).
|
||||
|
||||
it-connect.example.local {
|
||||
# --- Zertifikat (eine Variante wählen) ---
|
||||
|
||||
# Variante A (Heimnetz): Caddys eigene interne CA.
|
||||
# Das Stammzertifikat muss auf den Windows-Rechnern als vertrauenswürdig importiert werden.
|
||||
tls internal
|
||||
|
||||
# Variante B (Firma): Zertifikat der internen Firmen-CA.
|
||||
# Dateien nach /etc/caddy/certs/ legen (lesbar für den Benutzer caddy) und
|
||||
# "tls internal" oben auskommentieren.
|
||||
# tls /etc/caddy/certs/it-connect.crt /etc/caddy/certs/it-connect.key
|
||||
|
||||
encode gzip
|
||||
|
||||
header {
|
||||
Strict-Transport-Security "max-age=31536000"
|
||||
X-Content-Type-Options "nosniff"
|
||||
X-Frame-Options "DENY"
|
||||
Referrer-Policy "no-referrer"
|
||||
-Server
|
||||
}
|
||||
|
||||
reverse_proxy 127.0.0.1:8000
|
||||
|
||||
log {
|
||||
output file /var/log/caddy/it-connect.log {
|
||||
roll_size 10MiB
|
||||
roll_keep 10
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
# Einmalige Sicherung der it-connect-Datenbank, gestartet von it-connect-backup.timer
|
||||
[Unit]
|
||||
Description=it-connect Datenbank-Backup
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
User=itconnect
|
||||
Group=itconnect
|
||||
EnvironmentFile=/opt/it-connect/.env
|
||||
ExecStart=/opt/it-connect/scripts/backup.sh /var/backups/it-connect
|
||||
UMask=0077
|
||||
|
||||
NoNewPrivileges=true
|
||||
ProtectSystem=strict
|
||||
ProtectHome=true
|
||||
PrivateTmp=true
|
||||
# Schreibrecht nötig: SQLite im WAL-Modus braucht die -shm-Datei auch zum Lesen
|
||||
ReadWritePaths=/var/lib/it-connect
|
||||
ReadWritePaths=/var/backups/it-connect
|
||||
@@ -0,0 +1,11 @@
|
||||
# Tägliche Sicherung um 02:30 (verpasste Läufe werden nach dem Start nachgeholt)
|
||||
[Unit]
|
||||
Description=Tägliches Backup von it-connect
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* 02:30:00
|
||||
Persistent=true
|
||||
RandomizedDelaySec=10m
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
@@ -0,0 +1,51 @@
|
||||
# systemd-Unit für it-connect
|
||||
# Installation: siehe SETUP.md, Teil 7
|
||||
# sudo cp deploy/it-connect.service /etc/systemd/system/
|
||||
# sudo systemctl daemon-reload && sudo systemctl enable --now it-connect
|
||||
|
||||
[Unit]
|
||||
Description=it-connect (FastAPI)
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=itconnect
|
||||
Group=itconnect
|
||||
WorkingDirectory=/opt/it-connect/backend
|
||||
EnvironmentFile=/opt/it-connect/.env
|
||||
# Nur lokal lauschen: von außen ist die App ausschließlich über Caddy (HTTPS) erreichbar.
|
||||
# uvicorn übernimmt die Client-IP aus X-Forwarded-For nur von 127.0.0.1 (Caddy).
|
||||
ExecStart=/opt/it-connect/.venv/bin/uvicorn app.main:app \
|
||||
--host 127.0.0.1 --port 8000 \
|
||||
--proxy-headers --forwarded-allow-ips 127.0.0.1 \
|
||||
--no-server-header
|
||||
Restart=on-failure
|
||||
RestartSec=3
|
||||
|
||||
# Datenbankverzeichnis /var/lib/it-connect (wird von systemd angelegt, gehört itconnect)
|
||||
StateDirectory=it-connect
|
||||
StateDirectoryMode=0750
|
||||
UMask=0077
|
||||
|
||||
# Härtung
|
||||
NoNewPrivileges=true
|
||||
ProtectSystem=strict
|
||||
ProtectHome=true
|
||||
PrivateTmp=true
|
||||
PrivateDevices=true
|
||||
ProtectKernelTunables=true
|
||||
ProtectKernelModules=true
|
||||
ProtectKernelLogs=true
|
||||
ProtectControlGroups=true
|
||||
ProtectClock=true
|
||||
ProtectHostname=true
|
||||
RestrictNamespaces=true
|
||||
RestrictRealtime=true
|
||||
RestrictSUIDSGID=true
|
||||
LockPersonality=true
|
||||
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
|
||||
CapabilityBoundingSet=
|
||||
SystemCallArchitectures=native
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in new issue
Block a user