feat: system and security - start-up, accounts, sign-in, licences, log, jobs, companies (M2)
CI / Build and test (SQLite) (pull_request) Successful in 55s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / YAML check (pull_request) Successful in 5s
CI / Docker image (pull_request) Failing after 2m4s
CI / Build and test (SQLite) (pull_request) Successful in 55s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / YAML check (pull_request) Successful in 5s
CI / Docker image (pull_request) Failing after 2m4s
The instance now starts on its own from KHAEMHAT_* variables: it migrates the system and company databases, creates the super user and the first company, and only then reports ready. Users sign in with password and TOTP through revocable database sessions, and licences decide which modules and how many companies are available. - Configuration: every wrong variable reported at once (exit code 2), _FILE variants - Accounts, password policy and lockout, TOTP with recovery codes, session states with token rotation, security audit with a hash chain - Sign-in pages (mockups 001-003), authorization attributes, security headers and a CSP without inline scripts, login rate limit - Signed licences, activation codes, test mode, licence tool - DataProtection keys in the system database, encrypted with the instance key - Memory or Redis cache (in-house RESP client) that falls back to memory - Database log by section with trace id; cron scheduler with locks and system jobs; record history (audit_log) - Company creation, states, company context and X-Company, 503 in maintenance - In-memory SQLite databases stay alive for the process (tests, demo) - Tests for all of the above, ADR 0019, wiki, SECURITY, CHANGELOG, STATUS, DATA-MODEL Refs #15 #16 #17 #18 #19 #20 #21 #22 #23 #24 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4582837b70
commit
032c602b49
107 files changed
+12202
-116
No files matched your search
+21
-13
@@ -136,8 +136,8 @@ programmata passa da un controllo esplicito.
|
||||
|
||||
| Aspetto | Regola |
|
||||
|---|---|
|
||||
| Autenticazione | cookie ASP.NET Core con `CookieSessionAuthenticationHandler`; nessun ASP.NET Identity/EF |
|
||||
| Attributi del cookie | `HttpOnly; Secure; SameSite=Lax` |
|
||||
| Autenticazione | schema `KhaemhatSession` scritto in casa (`SessionAuthenticationHandler`, ADR 0019); nessun ASP.NET Identity/EF |
|
||||
| Attributi del cookie | `khaemhat_session`, `HttpOnly; SameSite=Lax`; `Secure` quando la richiesta è HTTPS o `KHAEMHAT_PUBLIC_URL` è `https` |
|
||||
| Identificatore | 256 bit casuali da `SecureTokenGenerator` (`RandomNumberGenerator`) |
|
||||
| Stato | riga di sessione in `sys_sessions` (account di istanza) o `user_sessions` (utenti aziendali): dispositivo, IP, creazione, ultimo uso, revoca |
|
||||
| Scadenza | scorrevole, con timeout di inattività da impostazioni (mockup 086: 480 minuti) |
|
||||
@@ -148,9 +148,12 @@ programmata passa da un controllo esplicito.
|
||||
| Antiforgery | sui form statici (login, cambio password, recupero) |
|
||||
| Cookie ammessi | sessione e tema prima del login (SPEC §1.5); nessun cookie di profilazione |
|
||||
|
||||
Proposta: nella riga di sessione salvare l'**hash SHA-256** dell'identificatore, non il valore, così una lettura del
|
||||
database non consente di impersonare le sessioni attive. Rigenerare l'identificatore dopo il login e dopo il
|
||||
passaggio TOTP (prevenzione della session fixation).
|
||||
**Implementato in M2.** La riga di sessione contiene solo l'**hash SHA-256** dell'identificatore: una lettura del
|
||||
database non consente di impersonare le sessioni attive. L'identificatore viene **rigenerato a ogni passaggio di
|
||||
stato** (password verificata, TOTP verificato, password cambiata), contro la session fixation. Una sessione che non è
|
||||
ancora *attiva* (manca il TOTP o il cambio password) apre solo le pagine del suo passo. Il circuito Blazor ricontrolla
|
||||
la sessione ogni minuto e si chiude se è stata revocata; mettere un'azienda in manutenzione o disattivarla revoca le
|
||||
sessioni dei suoi utenti.
|
||||
|
||||
---
|
||||
|
||||
@@ -253,8 +256,8 @@ passaggio TOTP (prevenzione della session fixation).
|
||||
interfaccia `ISecretProtector` in `Khaemhat.Core`.
|
||||
- La chiave e i segreti in chiaro **non vanno mai** in log, messaggi d'errore, diagnostica, risposte API o file su
|
||||
disco (SPEC §1.5: nessun `appsettings.<Env>.json` con segreti, nessun file temporaneo).
|
||||
- Le varianti `_FILE` delle variabili (Docker secrets) sono previste per `KHAEMHAT_SYSTEM_DB` e le credenziali del
|
||||
super utente; proposta: estenderle a `KHAEMHAT_SECRET_KEY` e alle altre variabili sensibili.
|
||||
- Le varianti `_FILE` (Docker secrets) valgono per tutte le variabili sensibili, `KHAEMHAT_SECRET_KEY` compresa
|
||||
(ADR 0014); impostare sia la variabile sia la sua `_FILE` è un errore di avvio.
|
||||
|
||||
### 7.2 Rotazione (`SecretRotationService`, `SecretRotation`)
|
||||
|
||||
@@ -275,8 +278,9 @@ della vecchia chiave come chiave di sola decifratura identificata dalla versione
|
||||
- Le chiavi DataProtection di ASP.NET Core (cookie, antiforgery) sono nel **database di sistema**
|
||||
(`sys_data_protection_keys`) tramite `DataProtectionDbXmlRepository`: nessun file su disco, cookie validi dopo un
|
||||
riavvio o un nuovo container.
|
||||
- Proposta: cifrare l'XML delle chiavi a riposo con un `IXmlEncryptor` basato su `SecretProtector`, così la sola
|
||||
lettura del database di sistema non consente di falsificare cookie.
|
||||
- **Implementato in M2** (`DataProtectionKeyStore`, `SecretKeyXmlEncryptor`): l'XML delle chiavi è cifrato a riposo
|
||||
con `SecretProtector` (scopo `dataprotection:keys`), così la sola lettura del database di sistema non consente di
|
||||
falsificare cookie o token antiforgery. Il database di sistema è migrato prima che DataProtection legga le chiavi.
|
||||
|
||||
---
|
||||
|
||||
@@ -286,14 +290,18 @@ della vecchia chiave come chiave di sola decifratura identificata dalla versione
|
||||
|
||||
| Header | Valore |
|
||||
|---|---|
|
||||
| `Content-Security-Policy` | `default-src 'self'`; script solo `'self'` + **nonce** per gli script di Blazor; `connect-src 'self'` (WebSocket del circuito sullo stesso host); `frame-ancestors 'none'`; `object-src 'none'`; `base-uri 'self'` (dettaglio proposto) |
|
||||
| `Content-Security-Policy` | `default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'; frame-ancestors 'none'; form-action 'self'; base-uri 'self'; object-src 'none'` |
|
||||
| `X-Frame-Options` | `DENY` |
|
||||
| `Referrer-Policy` | proposta: `strict-origin-when-cross-origin` (o `no-referrer`) |
|
||||
| `X-Content-Type-Options` | proposta: `nosniff` |
|
||||
| `Referrer-Policy` | `same-origin` |
|
||||
| `X-Content-Type-Options` | `nosniff` |
|
||||
| `Permissions-Policy` | `camera=(), microphone=(), geolocation=(), payment=()` |
|
||||
| `Cross-Origin-Opener-Policy` | `same-origin` |
|
||||
| `Strict-Transport-Security` | impostato dal **reverse proxy**, che termina TLS |
|
||||
|
||||
- Nessuna risorsa da CDN, nessun font scaricato, nessuno script di terze parti (SPEC §1.2): la CSP può restare
|
||||
rigorosa. JavaScript solo in `wwwroot/js`, senza `eval` né gestori inline.
|
||||
rigorosa. In M2 non serve nemmeno il nonce: nessuna pagina ha script inline (la `<ImportMap />` di Blazor, che
|
||||
ne scriverebbe uno, non è usata). `style-src 'unsafe-inline'` resta perché Blazor applica stili agli elementi
|
||||
durante la riconnessione. JavaScript solo in `wwwroot/js`, senza `eval` né gestori inline.
|
||||
- L'impostazione *CSP rigorosa (nonce)* (mockup 086) esiste per la diagnosi; disattivarla è un evento di audit.
|
||||
- Blazor esegue l'escaping dell'output: vietato `MarkupString` su contenuti provenienti da utenti o da file
|
||||
(eccezione: l'anteprima XML formattata, che va resa come testo).
|
||||
|
||||
Reference in new issue
Block a user