Deployment-Setup (PostgreSQL+nginx-Installer) + Sprint-0-Fixes aus Subagenten-Reviews
CI / backend-tests (push) Failing after 1s

Installer (deploy/):
- install_server.sh: PostgreSQL+nginx auf Debian 13, idempotente Rolle/DB-Anlage,
  pgcrypto-Extension, Speicher-Tuning für 4GB-VPS, Zugangsdaten in chmod-600-Datei
  statt stdout (postgres-expert/owasp-Review)
- nginx-Template mit Security-Headern + Rate-Limit auf /auth/login
- systemd-Unit-Template mit Sandboxing (NoNewPrivileges/ProtectSystem/PrivateTmp)

Backend-Fixes (fastapi-expert-Review):
- get_db: einheitliche commit/rollback-Konvention statt Endpunkt-Copy-Paste
- Test-Fixtures auf SQLAlchemy-2.0-Savepoint-Pattern umgestellt (join_transaction_mode),
  da get_db jetzt selbst committet
- Lifespan-Handler: Startup-Guard gegen JWT-Secret-Platzhalter, engine.dispose() beim Shutdown
- JWT-Payload ohne ungenutztes roles-Claim (Rollen kommen immer frisch aus der DB)

Zusätzlich: Subagenten-Definitionen (~/.claude/agents/) auf lauffähiges Modell fixiert.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L85hmKbvX7Cqkq47KnQhFt
This commit is contained in:
2026-09-03 23:00:46 +02:00
co-authored by Claude Sonnet 5
parent 48b6d6a5be
commit 446e4f912d
10 changed files with 487 additions and 8 deletions
+264
View File
@@ -843,3 +843,267 @@ Keine Änderungen ermittelbar.
- ergebnisse/sprintplan.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - ergebnisse/sprintplan.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
--- ---
## 2026-09-03 22:37 22:39 (1m)
**Beschreibung:** Claude Code Session
**Projekt:** asb-material
### Commits
Keine Commits in dieser Session.
### Geänderte Dateien
- .gitea/workflows/ci.yml | 52 ++++++++++++
- DEVLOG.md | 13 +++
- backend/.gitignore | 9 +++
- backend/README.md | 35 +++++++++
- backend/alembic.ini | 38 +++++++++
- backend/alembic/env.py | 51 ++++++++++++
- backend/alembic/script.py.mako | 26 ++++++
- backend/alembic/versions/0001_initial_schema.py | 291 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- backend/alembic/versions/0002_seed_hauptserver.py | 25 ++++++
- backend/app/__init__.py | 0
- backend/app/api/__init__.py | 0
- backend/app/api/deps.py | 52 ++++++++++++
- backend/app/api/v1/__init__.py | 0
- backend/app/api/v1/api.py | 7 ++
- backend/app/api/v1/endpoints/__init__.py | 0
- backend/app/api/v1/endpoints/auth.py | 55 +++++++++++++
- backend/app/api/v1/endpoints/health.py | 19 +++++
- backend/app/core/__init__.py | 0
- backend/app/core/app_settings.py | 18 +++++
- backend/app/core/security.py | 33 ++++++++
- backend/app/db/__init__.py | 0
- backend/app/db/base.py | 5 ++
- backend/app/db/session.py | 13 +++
- backend/app/main.py | 6 ++
- backend/app/models/__init__.py | 3 +
- backend/app/models/auth.py | 60 ++++++++++++++
- backend/example.env | 9 +++
- backend/pyproject.toml | 31 ++++++++
- backend/pytest.ini | 4 +
- backend/tests/__init__.py | 0
- backend/tests/conftest.py | 70 +++++++++++++++++
- backend/tests/test_auth.py | 45 +++++++++++
- backend/tests/test_health.py | 8 ++
- backend/tests/test_roles.py | 28 +++++++
---
## 2026-09-03 22:37 22:39 (1m)
**Beschreibung:** Claude Code Session
**Projekt:** asb-material
### Commits
Keine Commits in dieser Session.
### Geänderte Dateien
- .gitea/workflows/ci.yml | 52 ++++++++++++
- DEVLOG.md | 13 +++
- backend/.gitignore | 9 +++
- backend/README.md | 35 +++++++++
- backend/alembic.ini | 38 +++++++++
- backend/alembic/env.py | 51 ++++++++++++
- backend/alembic/script.py.mako | 26 ++++++
- backend/alembic/versions/0001_initial_schema.py | 291 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- backend/alembic/versions/0002_seed_hauptserver.py | 25 ++++++
- backend/app/__init__.py | 0
- backend/app/api/__init__.py | 0
- backend/app/api/deps.py | 52 ++++++++++++
- backend/app/api/v1/__init__.py | 0
- backend/app/api/v1/api.py | 7 ++
- backend/app/api/v1/endpoints/__init__.py | 0
- backend/app/api/v1/endpoints/auth.py | 55 +++++++++++++
- backend/app/api/v1/endpoints/health.py | 19 +++++
- backend/app/core/__init__.py | 0
- backend/app/core/app_settings.py | 18 +++++
- backend/app/core/security.py | 33 ++++++++
- backend/app/db/__init__.py | 0
- backend/app/db/base.py | 5 ++
- backend/app/db/session.py | 13 +++
- backend/app/main.py | 6 ++
- backend/app/models/__init__.py | 3 +
- backend/app/models/auth.py | 60 ++++++++++++++
- backend/example.env | 9 +++
- backend/pyproject.toml | 31 ++++++++
- backend/pytest.ini | 4 +
- backend/tests/__init__.py | 0
- backend/tests/conftest.py | 70 +++++++++++++++++
- backend/tests/test_auth.py | 45 +++++++++++
- backend/tests/test_health.py | 8 ++
- backend/tests/test_roles.py | 28 +++++++
---
## 2026-09-03 22:37 22:39 (1m)
**Beschreibung:** Claude Code Session
**Projekt:** asb-material
### Commits
Keine Commits in dieser Session.
### Geänderte Dateien
- .gitea/workflows/ci.yml | 52 ++++++++++++
- DEVLOG.md | 13 +++
- backend/.gitignore | 9 +++
- backend/README.md | 35 +++++++++
- backend/alembic.ini | 38 +++++++++
- backend/alembic/env.py | 51 ++++++++++++
- backend/alembic/script.py.mako | 26 ++++++
- backend/alembic/versions/0001_initial_schema.py | 291 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- backend/alembic/versions/0002_seed_hauptserver.py | 25 ++++++
- backend/app/__init__.py | 0
- backend/app/api/__init__.py | 0
- backend/app/api/deps.py | 52 ++++++++++++
- backend/app/api/v1/__init__.py | 0
- backend/app/api/v1/api.py | 7 ++
- backend/app/api/v1/endpoints/__init__.py | 0
- backend/app/api/v1/endpoints/auth.py | 55 +++++++++++++
- backend/app/api/v1/endpoints/health.py | 19 +++++
- backend/app/core/__init__.py | 0
- backend/app/core/app_settings.py | 18 +++++
- backend/app/core/security.py | 33 ++++++++
- backend/app/db/__init__.py | 0
- backend/app/db/base.py | 5 ++
- backend/app/db/session.py | 13 +++
- backend/app/main.py | 6 ++
- backend/app/models/__init__.py | 3 +
- backend/app/models/auth.py | 60 ++++++++++++++
- backend/example.env | 9 +++
- backend/pyproject.toml | 31 ++++++++
- backend/pytest.ini | 4 +
- backend/tests/__init__.py | 0
- backend/tests/conftest.py | 70 +++++++++++++++++
- backend/tests/test_auth.py | 45 +++++++++++
- backend/tests/test_health.py | 8 ++
- backend/tests/test_roles.py | 28 +++++++
---
## 2026-09-03 22:37 22:39 (1m)
**Beschreibung:** Claude Code Session
**Projekt:** asb-material
### Commits
Keine Commits in dieser Session.
### Geänderte Dateien
- .gitea/workflows/ci.yml | 52 ++++++++++++
- DEVLOG.md | 13 +++
- backend/.gitignore | 9 +++
- backend/README.md | 35 +++++++++
- backend/alembic.ini | 38 +++++++++
- backend/alembic/env.py | 51 ++++++++++++
- backend/alembic/script.py.mako | 26 ++++++
- backend/alembic/versions/0001_initial_schema.py | 291 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- backend/alembic/versions/0002_seed_hauptserver.py | 25 ++++++
- backend/app/__init__.py | 0
- backend/app/api/__init__.py | 0
- backend/app/api/deps.py | 52 ++++++++++++
- backend/app/api/v1/__init__.py | 0
- backend/app/api/v1/api.py | 7 ++
- backend/app/api/v1/endpoints/__init__.py | 0
- backend/app/api/v1/endpoints/auth.py | 55 +++++++++++++
- backend/app/api/v1/endpoints/health.py | 19 +++++
- backend/app/core/__init__.py | 0
- backend/app/core/app_settings.py | 18 +++++
- backend/app/core/security.py | 33 ++++++++
- backend/app/db/__init__.py | 0
- backend/app/db/base.py | 5 ++
- backend/app/db/session.py | 13 +++
- backend/app/main.py | 6 ++
- backend/app/models/__init__.py | 3 +
- backend/app/models/auth.py | 60 ++++++++++++++
- backend/example.env | 9 +++
- backend/pyproject.toml | 31 ++++++++
- backend/pytest.ini | 4 +
- backend/tests/__init__.py | 0
- backend/tests/conftest.py | 70 +++++++++++++++++
- backend/tests/test_auth.py | 45 +++++++++++
- backend/tests/test_health.py | 8 ++
- backend/tests/test_roles.py | 28 +++++++
---
## 2026-09-03 22:53 22:54 (0m)
**Beschreibung:** Claude Code Session
**Projekt:** asb-material
### Commits
Keine Commits in dieser Session.
### Geänderte Dateien
- .gitea/workflows/ci.yml | 52 ++++++++++++
- DEVLOG.md | 13 +++
- backend/.gitignore | 9 +++
- backend/README.md | 35 +++++++++
- backend/alembic.ini | 38 +++++++++
- backend/alembic/env.py | 51 ++++++++++++
- backend/alembic/script.py.mako | 26 ++++++
- backend/alembic/versions/0001_initial_schema.py | 291 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- backend/alembic/versions/0002_seed_hauptserver.py | 25 ++++++
- backend/app/__init__.py | 0
- backend/app/api/__init__.py | 0
- backend/app/api/deps.py | 52 ++++++++++++
- backend/app/api/v1/__init__.py | 0
- backend/app/api/v1/api.py | 7 ++
- backend/app/api/v1/endpoints/__init__.py | 0
- backend/app/api/v1/endpoints/auth.py | 55 +++++++++++++
- backend/app/api/v1/endpoints/health.py | 19 +++++
- backend/app/core/__init__.py | 0
- backend/app/core/app_settings.py | 18 +++++
- backend/app/core/security.py | 33 ++++++++
- backend/app/db/__init__.py | 0
- backend/app/db/base.py | 5 ++
- backend/app/db/session.py | 13 +++
- backend/app/main.py | 6 ++
- backend/app/models/__init__.py | 3 +
- backend/app/models/auth.py | 60 ++++++++++++++
- backend/example.env | 9 +++
- backend/pyproject.toml | 31 ++++++++
- backend/pytest.ini | 4 +
- backend/tests/__init__.py | 0
- backend/tests/conftest.py | 70 +++++++++++++++++
- backend/tests/test_auth.py | 45 +++++++++++
- backend/tests/test_health.py | 8 ++
- backend/tests/test_roles.py | 28 +++++++
---
## 2026-09-03 22:54 22:55 (0m)
**Beschreibung:** Claude Code Session
**Projekt:** asb-material
### Commits
Keine Commits in dieser Session.
### Geänderte Dateien
- .gitea/workflows/ci.yml | 52 ++++++++++++
- DEVLOG.md | 13 +++
- backend/.gitignore | 9 +++
- backend/README.md | 35 +++++++++
- backend/alembic.ini | 38 +++++++++
- backend/alembic/env.py | 51 ++++++++++++
- backend/alembic/script.py.mako | 26 ++++++
- backend/alembic/versions/0001_initial_schema.py | 291 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- backend/alembic/versions/0002_seed_hauptserver.py | 25 ++++++
- backend/app/__init__.py | 0
- backend/app/api/__init__.py | 0
- backend/app/api/deps.py | 52 ++++++++++++
- backend/app/api/v1/__init__.py | 0
- backend/app/api/v1/api.py | 7 ++
- backend/app/api/v1/endpoints/__init__.py | 0
- backend/app/api/v1/endpoints/auth.py | 55 +++++++++++++
- backend/app/api/v1/endpoints/health.py | 19 +++++
- backend/app/core/__init__.py | 0
- backend/app/core/app_settings.py | 18 +++++
- backend/app/core/security.py | 33 ++++++++
- backend/app/db/__init__.py | 0
- backend/app/db/base.py | 5 ++
- backend/app/db/session.py | 13 +++
- backend/app/main.py | 6 ++
- backend/app/models/__init__.py | 3 +
- backend/app/models/auth.py | 60 ++++++++++++++
- backend/example.env | 9 +++
- backend/pyproject.toml | 31 ++++++++
- backend/pytest.ini | 4 +
- backend/tests/__init__.py | 0
- backend/tests/conftest.py | 70 +++++++++++++++++
- backend/tests/test_auth.py | 45 +++++++++++
- backend/tests/test_health.py | 8 ++
- backend/tests/test_roles.py | 28 +++++++
---
+1 -1
View File
@@ -41,7 +41,7 @@ async def login(
detail="Login oder Passwort falsch", detail="Login oder Passwort falsch",
headers={"WWW-Authenticate": "Bearer"}, headers={"WWW-Authenticate": "Bearer"},
) )
token = create_access_token(subject=benutzer.login, roles=benutzer.rollen_namen) token = create_access_token(subject=benutzer.login)
return TokenResponse(access_token=token) return TokenResponse(access_token=token)
+4 -2
View File
@@ -16,9 +16,11 @@ def verify_password(plain_password: str, password_hash: str) -> bool:
return _pwd_context.verify(plain_password, password_hash) return _pwd_context.verify(plain_password, password_hash)
def create_access_token(*, subject: str, roles: list[str]) -> str: def create_access_token(*, subject: str) -> str:
# Bewusst KEINE Rollen im Token: get_current_user liest Rollen bei jedem Request
# frisch aus der DB (Rollenänderung wirkt sofort, kein Token-Refresh nötig).
expire = datetime.now(timezone.utc) + timedelta(minutes=settings.access_token_expire_minutes) expire = datetime.now(timezone.utc) + timedelta(minutes=settings.access_token_expire_minutes)
payload = {"sub": subject, "roles": roles, "exp": expire} payload = {"sub": subject, "exp": expire}
return jwt.encode(payload, settings.jwt_secret_key, algorithm=settings.jwt_algorithm) return jwt.encode(payload, settings.jwt_secret_key, algorithm=settings.jwt_algorithm)
+11
View File
@@ -9,5 +9,16 @@ SessionLocal = async_sessionmaker(engine, expire_on_commit=False)
async def get_db() -> AsyncGenerator[AsyncSession, None]: async def get_db() -> AsyncGenerator[AsyncSession, None]:
"""Konvention für alle Endpunkte: Erfolg -> commit, Exception -> rollback.
Endpunkte selbst rufen kein `db.commit()`/`db.rollback()` auf, sondern verlassen
sich auf diese Dependency (Review-Fund: Konvention muss zentral, nicht pro
Endpunkt copy-paste sein).
"""
async with SessionLocal() as session: async with SessionLocal() as session:
try:
yield session yield session
await session.commit()
except Exception:
await session.rollback()
raise
+19 -1
View File
@@ -1,6 +1,24 @@
from contextlib import asynccontextmanager
from fastapi import FastAPI from fastapi import FastAPI
from app.api.v1.api import api_router from app.api.v1.api import api_router
from app.core.app_settings import settings
from app.db.session import engine
app = FastAPI(title="MABEA", version="0.1.0") _PLACEHOLDER_JWT_SECRET = "change-me-to-a-long-random-value"
@asynccontextmanager
async def lifespan(app: FastAPI):
if not settings.jwt_secret_key or settings.jwt_secret_key == _PLACEHOLDER_JWT_SECRET:
raise RuntimeError(
"JWT_SECRET_KEY ist leer oder noch der Platzhalter aus example.env "
"in .env auf dem Zielsystem einen echten zufälligen Wert setzen."
)
yield
await engine.dispose()
app = FastAPI(title="MABEA", version="0.1.0", lifespan=lifespan)
app.include_router(api_router, prefix="/api/v1") app.include_router(api_router, prefix="/api/v1")
+15 -3
View File
@@ -18,14 +18,26 @@ TestSessionLocal = async_sessionmaker(engine, expire_on_commit=False)
@pytest_asyncio.fixture @pytest_asyncio.fixture
async def db_session(): async def db_session():
"""Jeder Test läuft in einer äußeren Transaktion, die am Ende zurückgerollt wird.
Die Session ist per `join_transaction_mode="create_savepoint"` an die äußere
Connection gebunden: ein `commit()` innerhalb des Tests (z. B. durch `get_db`,
das jetzt selbst committet) schließt nur eine SAVEPOINT ab, nicht die äußere
Transaktion das äußere `connection.rollback()` verwirft am Ende trotzdem alles.
(SQLAlchemy 2.0 "Joining a Session into an External Transaction" Review-Fund
fastapi-expert: ohne dieses Pattern hätte ein commit() in Endpunkten die
Testisolation gebrochen.)
"""
async with engine.connect() as connection: async with engine.connect() as connection:
transaction = await connection.begin() await connection.begin()
session = AsyncSession(bind=connection, expire_on_commit=False) session = AsyncSession(
bind=connection, expire_on_commit=False, join_transaction_mode="create_savepoint"
)
try: try:
yield session yield session
finally: finally:
await session.close() await session.close()
await transaction.rollback() await connection.rollback()
@pytest_asyncio.fixture @pytest_asyncio.fixture
+27
View File
@@ -0,0 +1,27 @@
# Deployment MABEA
Zielserver: siehe Projekt-Memory (Debian 13, kein Docker-Zwang, Prompt 19).
## Server-Grundausstattung (einmalig)
```bash
scp -i ~/.ssh/id_claude -r deploy root@<server>:/root/mabea-deploy
ssh -i ~/.ssh/id_claude root@<server>
cd /root/mabea-deploy
chmod +x install_server.sh
DB_PASSWORD='<sicheres-passwort>' APP_DOMAIN=<domain-oder-ip> ./install_server.sh
```
Installiert PostgreSQL + nginx, legt DB-Rolle/Datenbank an, richtet nginx als Reverse-Proxy vor `127.0.0.1:8000` ein. Ausgegebene `DATABASE_URL` sichern.
## Backend deployen (später, nach Sprint-Fortschritt)
1. `backend/` auf den Server kopieren (z. B. nach `/opt/mabea/backend`), `.venv` dort anlegen, `pip install -e ".[dev]"` bzw. ohne `dev`-Extra für Produktion.
2. `.env` aus `backend/example.env` ableiten, `DATABASE_URL` aus Schritt oben eintragen.
3. `alembic upgrade head` ausführen.
4. `mabea-backend.service.template` nach `/etc/systemd/system/mabea-backend.service` kopieren (Pfade/User anpassen), `systemctl daemon-reload && systemctl enable --now mabea-backend`.
## Dateien
- `install_server.sh` Server-Grundausstattung (PostgreSQL, nginx), idempotent
- `nginx_mabea.conf.template` Reverse-Proxy-Vorlage, von `install_server.sh` verwendet
- `mabea-backend.service.template` systemd-Unit-Vorlage für das Backend (noch nicht aktiviert, Pfade anpassen)
+89
View File
@@ -0,0 +1,89 @@
#!/usr/bin/env bash
# MABEA Server-Setup (Debian 13). Installiert PostgreSQL + nginx, legt DB/Rolle an,
# richtet nginx als Reverse-Proxy vor dem späteren FastAPI/Uvicorn-Backend ein.
# Idempotent: mehrfacher Aufruf überschreibt keine bestehende DB-Rolle/DB.
#
# Ausführung auf dem Zielserver als root:
# DB_PASSWORD=... APP_DOMAIN=mabea.example.org ./install_server.sh
# Ohne DB_PASSWORD wird ein zufälliges Passwort erzeugt und am Ende ausgegeben
# (sofort sichern, z. B. in backend/.env auf dem Server nicht committen).
set -euo pipefail
DB_NAME="${DB_NAME:-mabea}"
DB_USER="${DB_USER:-mabea}"
DB_PASSWORD="${DB_PASSWORD:-$(openssl rand -base64 24)}"
JWT_SECRET_KEY="${JWT_SECRET_KEY:-$(openssl rand -base64 48)}"
APP_DOMAIN="${APP_DOMAIN:-_}" # "_" = nginx catch-all, solange keine Domain feststeht
echo "== apt update/install =="
export DEBIAN_FRONTEND=noninteractive
apt-get update -qq
apt-get install -y -qq postgresql nginx python3-venv python3-pip git openssl
echo "== PostgreSQL: Rolle + Datenbank =="
if ! sudo -u postgres psql -tAc "SELECT 1 FROM pg_roles WHERE rolname='${DB_USER}'" | grep -q 1; then
sudo -u postgres psql -c "CREATE ROLE ${DB_USER} WITH LOGIN PASSWORD '${DB_PASSWORD}';"
echo "Rolle ${DB_USER} angelegt."
else
echo "Rolle ${DB_USER} existiert bereits, überspringe."
fi
if ! sudo -u postgres psql -tAc "SELECT 1 FROM pg_database WHERE datname='${DB_NAME}'" | grep -q 1; then
sudo -u postgres psql -c "CREATE DATABASE ${DB_NAME} OWNER ${DB_USER};"
echo "Datenbank ${DB_NAME} angelegt."
else
echo "Datenbank ${DB_NAME} existiert bereits, überspringe."
fi
# gen_random_uuid() ist seit PG13 built-in, aber pgcrypto schadet nicht und macht es
# explizit/robust gegen ältere Backports (Review-Fund postgres-expert).
sudo -u postgres psql -d "${DB_NAME}" -c "CREATE EXTENSION IF NOT EXISTS pgcrypto;"
echo "== PostgreSQL: Speicher-Tuning für kleinen VPS (4GB RAM) =="
PG_CONF_DIR=$(sudo -u postgres psql -tAc "SHOW config_file;" | xargs dirname)
mkdir -p "${PG_CONF_DIR}/conf.d"
cat > "${PG_CONF_DIR}/conf.d/mabea-tuning.conf" <<'PGCONF'
# MABEA: konservatives Tuning für ~4GB RAM VPS, nicht enterprise-scale.
shared_buffers = 1GB
effective_cache_size = 3GB
maintenance_work_mem = 256MB
work_mem = 8MB
max_connections = 50
PGCONF
grep -q "conf.d/\*.conf" "${PG_CONF_DIR}/postgresql.conf" || \
echo "include_dir = 'conf.d'" >> "${PG_CONF_DIR}/postgresql.conf"
echo "== nginx Reverse-Proxy Config (inkl. Security-Header) =="
sed -e "s/__APP_DOMAIN__/${APP_DOMAIN}/g" \
"$(dirname "$0")/nginx_mabea.conf.template" > /etc/nginx/sites-available/mabea.conf
ln -sf /etc/nginx/sites-available/mabea.conf /etc/nginx/sites-enabled/mabea.conf
rm -f /etc/nginx/sites-enabled/default
nginx -t
echo "== Dienste aktivieren =="
systemctl enable --now postgresql
systemctl restart postgresql # Tuning-Konfiguration laden
systemctl enable --now nginx
systemctl reload nginx
echo "== Zugangsdaten sichern =="
CRED_FILE="/root/mabea_db_credentials.env"
umask 077
cat > "${CRED_FILE}" <<EOF
DB_NAME=${DB_NAME}
DB_USER=${DB_USER}
DB_PASSWORD=${DB_PASSWORD}
DATABASE_URL=postgresql+asyncpg://${DB_USER}:${DB_PASSWORD}@localhost:5432/${DB_NAME}
JWT_SECRET_KEY=${JWT_SECRET_KEY}
EOF
chmod 600 "${CRED_FILE}"
echo
echo "=== Fertig ==="
echo "Zugangsdaten liegen (chmod 600) in ${CRED_FILE} NICHT auf stdout ausgegeben (Review-Fund: keine Secrets im Terminal-Scrollback)."
echo "DATABASE_URL von dort in backend/.env auf dem Server übernehmen (siehe backend/example.env)."
echo "Backend selbst ist noch nicht deployt siehe deploy/mabea-backend.service.template für den späteren systemd-Dienst."
echo
echo "Hinweis: nginx läuft aktuell nur über Port 80 (kein TLS). Für echten Betrieb vor Domain-Vergabe"
echo "TLS nachziehen (Let's Encrypt bei Domain, sonst selbstsigniertes Zertifikat fürs LAN)."
+23
View File
@@ -0,0 +1,23 @@
[Unit]
Description=MABEA Backend (FastAPI/Uvicorn)
After=network.target postgresql.service
Requires=postgresql.service
[Service]
Type=simple
User=mabea
WorkingDirectory=/opt/mabea/backend
EnvironmentFile=/opt/mabea/backend/.env
ExecStart=/opt/mabea/backend/.venv/bin/uvicorn app.main:app --host 127.0.0.1 --port 8000
Restart=on-failure
RestartSec=5
# Sandboxing (Review-Fund owasp-top10-expert): begrenzt Blast-Radius bei App-RCE.
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true
ReadWritePaths=/opt/mabea/backend
[Install]
WantedBy=multi-user.target
+33
View File
@@ -0,0 +1,33 @@
# limit_req_zone gehört in den http-Kontext (hier: via sites-enabled-Include-Kette
# bereits innerhalb von http{}, aber außerhalb des server{}-Blocks nötig).
# Grober Schutz gegen Brute-Force auf Login, ergänzt (nicht ersetzt) die
# Rate-Begrenzung/Lockout auf Anwendungsebene, die noch aussteht (Review-Fund).
limit_req_zone $binary_remote_addr zone=mabea_login:10m rate=5r/m;
server {
listen 80;
server_name __APP_DOMAIN__;
# Basis-Hardening-Header (Review-Fund owasp-top10-expert). Sobald TLS aktiv ist,
# zusätzlich Strict-Transport-Security ergänzen.
add_header X-Content-Type-Options nosniff always;
add_header X-Frame-Options DENY always;
add_header Referrer-Policy strict-origin-when-cross-origin always;
location /api/v1/auth/login {
limit_req zone=mabea_login burst=5 nodelay;
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}