veza/docs/ENV_VARIABLES.md
2026-03-05 19:35:57 +01:00

152 lines
7.3 KiB
Markdown

# Variables d'environnement Veza
> Référence complète des variables d'environnement utilisées par la plateforme Veza.
> v0.9.1 : Migration JWT RS256 (JWT_PRIVATE_KEY_PATH, JWT_PUBLIC_KEY_PATH).
>
> Voir aussi : [.env.example](../.env.example), [veza-backend-api/.env.template](../veza-backend-api/.env.template), [veza-stream-server/.env.example](../veza-stream-server/.env.example).
---
## Backend API (veza-backend-api)
### Authentification JWT (v0.9.1 RS256)
| Variable | Description | Type | Requis | Valeur par défaut | Exemple |
|----------|--------------|------|--------|------------------|---------|
| `JWT_PRIVATE_KEY_PATH` | Chemin vers la clé privée RSA (signature) | string | Oui (prod) | — | `/secrets/jwt-private.pem` |
| `JWT_PUBLIC_KEY_PATH` | Chemin vers la clé publique RSA (vérification) | string | Oui (prod) | — | `/secrets/jwt-public.pem` |
| `JWT_SECRET` | Secret HS256 (déprécié, fallback dev uniquement) | string | Si pas RS256 | — | min 32 chars |
| `JWT_ISSUER` | Issuer claim (access/refresh tokens) | string | Non | `veza-api` | `veza-api` |
| `JWT_AUDIENCE` | Audience claim | string | Non | `veza-platform` | `veza-platform` |
| `JWT_ACCESS_TOKEN_DURATION` | Durée access token | duration | Non | `15m` | `5m`, `1h` |
| `JWT_REFRESH_TOKEN_DURATION` | Durée refresh token | duration | Non | `30d` | `7d`, `14d` |
**Génération des clés RS256 :**
```bash
scripts/generate-jwt-keys.sh
# ou manuellement :
openssl genrsa -out jwt-private.pem 2048
openssl rsa -in jwt-private.pem -pubout -out jwt-public.pem
```
### Base de données
| Variable | Description | Type | Requis | Valeur par défaut | Exemple |
|----------|--------------|------|--------|------------------|---------|
| `DATABASE_URL` | URL connexion PostgreSQL | string | Oui | — | `postgres://veza:password@localhost:5432/veza?sslmode=disable` |
| `DATABASE_READ_URL` | URL réplica lecture (optionnel) | string | Non | — | `postgres://veza:password@replica:5432/veza` |
### Redis
| Variable | Description | Type | Requis | Valeur par défaut | Exemple |
|----------|--------------|------|--------|------------------|---------|
| `REDIS_URL` | URL connexion Redis | string | Oui | — | `redis://localhost:6379` |
| `REDIS_ENABLE` | Activer Redis | bool | Non | `true` | `true`, `false` |
### CORS & Domaine
| Variable | Description | Type | Requis | Valeur par défaut | Exemple |
|----------|--------------|------|--------|------------------|---------|
| `APP_DOMAIN` | Domaine applicatif | string | Non | `veza.fr` | `veza.fr`, `app.veza.com` |
| `CORS_ALLOWED_ORIGINS` | Origines CORS autorisées | string | Oui | — | `http://veza.fr:5173` |
| `FRONTEND_URL` | URL frontend (OAuth, reset) | string | Non | `http://localhost:5173` | `https://app.veza.com` |
### Autres services
| Variable | Description | Type | Requis | Valeur par défaut | Exemple |
|----------|--------------|------|--------|------------------|---------|
| `STREAM_SERVER_URL` | URL stream server | string | Non | `http://veza.fr:8082` | `http://stream:8082` |
| `STREAM_SERVER_INTERNAL_API_KEY` | Clé API interne transcode | string | Non | — | secret partagé |
| `CHAT_SERVER_URL` | URL chat (legacy) | string | Non | `http://veza.fr:8081` | — |
| `RABBITMQ_URL` | URL RabbitMQ | string | Non | — | `amqp://veza:password@localhost:5672/` |
### Rate limiting (v0.9.2 TASK-SEC-003)
| Variable | Description | Type | Requis | Valeur par défaut | Exemple |
|----------|--------------|------|--------|------------------|---------|
| `RATE_LIMIT_IP_PER_HOUR` | Requêtes/heure par IP (non-auth) | int | Non | 100 (prod), 500 (dev) | `100` |
| `RATE_LIMIT_USER_PER_HOUR` | Requêtes/heure par utilisateur auth | int | Non | 1000 (prod), 2000 (dev) | `1000` |
### Endpoint /metrics (v0.9.2 TASK-SEC-006)
| Variable | Description | Type | Requis | Valeur par défaut | Exemple |
|----------|--------------|------|--------|------------------|---------|
| `METRICS_BEARER_TOKEN` | Token Bearer pour accès Prometheus | string | Non | — | secret partagé |
| `METRICS_ALLOWED_IPS` | IPs autorisées (exact ou CIDR, CSV) | string | Non | — | `10.0.0.0/8,127.0.0.1` |
| `METRICS_PUBLIC_IN_DEV` | Si `true` et non-prod, accès sans auth | bool | Non | `false` | `true` |
**Note :** Si ni `METRICS_BEARER_TOKEN` ni `METRICS_ALLOWED_IPS` n'est défini, l'accès à `/metrics` est refusé (403) en production.
### Taille des payloads (v0.9.2 TASK-SEC-005)
| Variable | Description | Type | Requis | Valeur par défaut | Exemple |
|----------|--------------|------|--------|------------------|---------|
| `MAX_JSON_BODY_SIZE` | Taille max body JSON (bytes) | int | Non | `1048576` (1MB) | `2097152` (2MB) |
**Upload audio :** 500MB par défaut (`UploadConfig.MaxAudioSize` dans `services.DefaultUploadConfig`).
### Security headers (TASK-SEC-004)
Headers HTTP de sécurité appliqués globalement via `middleware.SecurityHeaders()` (router.go) :
| Header | Valeur | Rôle |
|--------|--------|------|
| Strict-Transport-Security | max-age=31536000; includeSubDomains; preload | HSTS (prod) |
| X-Content-Type-Options | nosniff | Anti MIME sniffing |
| X-Frame-Options | DENY (SAMEORIGIN pour Swagger) | Anti clickjacking |
| X-XSS-Protection | 1; mode=block | XSS legacy |
| Referrer-Policy | strict-origin-when-cross-origin | Referrer |
| Permissions-Policy | geolocation=(), microphone=(), … | Restriction features |
| Content-Security-Policy | default-src 'none'; … | CSP |
| X-Permitted-Cross-Domain-Policies | none | Flash/PDF |
| Cross-Origin-Embedder-Policy | require-corp | COEP |
| Cross-Origin-Opener-Policy | same-origin | COOP |
| Cross-Origin-Resource-Policy | same-origin | CORP |
---
## Stream Server (veza-stream-server)
### JWT (v0.9.1 RS256)
| Variable | Description | Type | Requis | Valeur par défaut | Exemple |
|----------|--------------|------|--------|------------------|---------|
| `JWT_PUBLIC_KEY_PATH` | Chemin clé publique RSA (vérification) | string | Oui (prod) | — | `/secrets/jwt-public.pem` |
| `JWT_SECRET` | Secret HS256 (phase transition uniquement) | string | Si pas RS256 | — | min 32 chars |
| `JWT_EXPIRATION` | TTL tokens (secondes) | int | Non | `3600` | `300`, `3600` |
**Remarque :** Le stream server valide les tokens émis par le backend. Il utilise la clé publique partagée (JWT_PUBLIC_KEY_PATH) pour RS256.
---
## Variables communes (veza-common)
Services Rust utilisant veza-common (config_rust JwtConfig) :
| Variable | Description | Type | Requis | Valeur par défaut | Exemple |
|----------|--------------|------|--------|------------------|---------|
| `JWT_SECRET` | Secret JWT | string | Oui | — | min 32 chars (VEZA-SEC-001) |
| `JWT_ISSUER` | Issuer | string | Non | `veza-api` | `veza-api` |
| `JWT_AUDIENCE` | Audience | string | Non | `veza-platform` | `veza-platform` |
---
## Validation (TASK-QA-009)
Valider les variables avant démarrage :
```bash
./scripts/validate-env.sh development # ou production, test
```
Intégré dans `make doctor`.
---
## Checklist de démarrage
1. Copier `.env.example` vers `.env` (racine) et `veza-backend-api/.env.template` vers `veza-backend-api/.env`
2. Pour RS256 : exécuter `scripts/generate-jwt-keys.sh` et configurer `JWT_PRIVATE_KEY_PATH`, `JWT_PUBLIC_KEY_PATH`
3. Configurer `DATABASE_URL`, `REDIS_URL`, `CORS_ALLOWED_ORIGINS`
4. Valider : `./scripts/validate-env.sh development`
5. En production : ne jamais commiter `.env` ni les fichiers `.pem`