SECRET_KEY: verständliche Fehlermeldung mit Befehl zum Erzeugen eines gültigen Schlüssels

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
RubenRWU
2026-10-15 15:54:36 +02:00
parent b6165bc0b2
commit e663b007d4
2 changed files with 10 additions and 2 deletions

View File

@@ -4,7 +4,14 @@ from cryptography.fernet import Fernet
from app.settings import SECRET_KEY
_f = Fernet(SECRET_KEY.encode())
try:
_f = Fernet(SECRET_KEY.encode())
except ValueError as exc:
raise RuntimeError(
"SECRET_KEY ist kein gültiger Fernet-Schlüssel (erwartet: 32 Zufallsbytes in URL-sicherem Base64, 44 Zeichen, endet meist mit „=“). "
"Erzeugen mit: python3 -c \"import base64,os; print(base64.urlsafe_b64encode(os.urandom(32)).decode())\" "
"– und in Coolify als SECRET_KEY setzen (außerhalb von Coolify sichern; ohne ihn sind die Secrets in der Datenbank nicht entschlüsselbar)."
) from exc
def encrypt(v: str) -> str: