- app runs as uid 1000; a one-shot data-permissions service chowns ./data to it and closes it to others (works on an older root-owned install with no host sudo); files are created 0600 (umask 077) - python:3.12-slim and caddy:2-alpine pinned by digest; dependencies installed from requirements.lock with --require-hashes - the Fernet key is XPRV_ENCRYPTION_KEY_FILE (./secrets/xprv_encryption.key, a compose secret), out of every environment variable and of a ./data backup - setup.md no longer presents a second way to run the server (B-72) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
30 lines
1.5 KiB
Markdown
30 lines
1.5 KiB
Markdown
# ADR-11 — Il server rifiuta di partire con segreti inadeguati
|
|
|
|
- **Stato:** Accettata
|
|
- **Area:** Configurazione e ambiente
|
|
- **Fonte di verità per:** la scelta di progetto descritta qui sotto; i requisiti (`PREFISSO-NN`) che la attuano stanno nei documenti di dominio, indicati nelle *Conseguenze*.
|
|
|
|
## Decisione
|
|
|
|
**Il server rifiuta di partire con segreti inadeguati**:
|
|
`JWT_SECRET` sotto i 32 caratteri o `XPRV_ENCRYPTION_KEY` vuota fermano
|
|
l'avvio. Un `ADMIN_TOKEN` vuoto invece non è fatale: il pannello resta
|
|
chiuso a tutti. Il controllo è nel lifespan, non in un validatore di
|
|
`Settings`.
|
|
- *Motivazione:* evitare un container che sembra sano e si rompe al primo
|
|
utente reale; tenerlo fuori da `Settings` permette a import e test di
|
|
funzionare senza `.env`.
|
|
- *Alternative scartate:* validatore Pydantic su `Settings` (avrebbe fatto
|
|
fallire la raccolta dei test su un clone pulito, B-15).
|
|
- *Conseguenze:* lo stesso principio («rifiutare di servire piuttosto che
|
|
rompersi al primo uso») si estende alla master key decifrata e confrontata
|
|
con gli indirizzi già salvati (B-89) e al quorum minimo di server (B-84);
|
|
l'ordine dei controlli all'avvio è in
|
|
[architettura.md](../architettura.md#nel-lifespan).
|
|
|
|
*Codice:* `app/config.py:validate_runtime_secrets` · `app/main.py:lifespan` · `app/api/routes/admin.py:require_admin` ·
|
|
*Test:* `tests/unit/test_config.py`
|
|
La chiave Fernet arriva da un file (`XPRV_ENCRYPTION_KEY_FILE`,
|
|
[sicurezza.md](../sicurezza.md#sec-53) SEC-53) e il rifiuto riguarda un file
|
|
mancante o vuoto.
|