Alarik is a drop-in S3-compatible replacement requiring no application code changes. All S3 APIs (upload, download, list, delete, multipart) are fully supported.
210 lines
6.1 KiB
Markdown
210 lines
6.1 KiB
Markdown
# Heimdall — Plateforme de Surveillance Vidéo
|
|
|
|
Heimdall est une plateforme de surveillance vidéo multi-sites avec détection IA. Architecture **.NET 10 Clean Architecture** avec **Blazor Server** + **PostgreSQL**.
|
|
|
|
## Architecture
|
|
|
|
```
|
|
Heimdall.Central (Api + Web + Workers) Heimdall.Agent
|
|
┌──────────────────────────────┐ ┌──────────────┐
|
|
│ 🌐 Blazor UI (MudBlazor) │ │ 📹 FFmpeg │
|
|
│ 🔌 REST API │ ←──HTTPS──→ │ 🧠 IA locale│
|
|
│ ⏰ Hangfire Workers │ │ 💓 Heartbeat│
|
|
│ 🗄️ PostgreSQL │ └──────────────┘
|
|
└──────────────────────────────┘
|
|
```
|
|
|
|
### Projets
|
|
| Projet | Rôle |
|
|
|--------|------|
|
|
| `Heimdall.Domain` | Entités, énums, value objects |
|
|
| `Heimdall.Application` | Interfaces services, DTOs, validation |
|
|
| `Heimdall.Infrastructure` | EF Core, Identity, JWT, API Key, Hangfire |
|
|
| `Heimdall.Api` | REST API (controllers, middleware) |
|
|
| `Heimdall.Web` | Blazor Server UI (MudBlazor) |
|
|
| `Heimdall.Workers` | Hangfire background jobs (heartbeat monitor) |
|
|
| `Heimdall.Agent` | Agent d'enregistrement et heartbeat |
|
|
|
|
## Démarrage rapide
|
|
|
|
### 1. Docker (production — Docker Hub)
|
|
|
|
Les images pré-buildées sont disponibles sur [Docker Hub](https://hub.docker.com/repository/docker/eltruncho/heimdall) :
|
|
|
|
| Image | Description |
|
|
|-------|-------------|
|
|
| `eltruncho/heimdall-central:latest` | API + Web UI + Workers |
|
|
| `eltruncho/heimdall-agent:latest` | Agent d'enregistrement |
|
|
|
|
```bash
|
|
# Copier la configuration
|
|
cp .env.example .env
|
|
# Éditer les secrets (JWT__Key, mots de passe)
|
|
nano .env
|
|
|
|
# Lancer (pull images depuis Docker Hub)
|
|
docker compose -f docker/docker-compose.prod.yml up -d
|
|
```
|
|
|
|
Accès :
|
|
- **UI** : http://localhost:5000
|
|
- **API** : http://localhost:5000/api
|
|
- **Documentation API** : http://localhost:5000/scalar (dev)
|
|
- **Alarik Console** : http://localhost:9001
|
|
|
|
### 2. Build local (développement)
|
|
|
|
```bash
|
|
cp .env.example .env
|
|
# Éditer les secrets
|
|
nano .env
|
|
|
|
# Build & lancer depuis les sources
|
|
docker compose -f docker/docker-compose.yml up -d
|
|
```
|
|
|
|
### 3. Développement
|
|
|
|
Prérequis : .NET 10 SDK, PostgreSQL 17
|
|
|
|
```bash
|
|
# Lancer PostgreSQL
|
|
docker run -d --name pg -e POSTGRES_DB=heimdall -e POSTGRES_USER=heimdall \
|
|
-e POSTGRES_PASSWORD=heimdall -p 5432:5432 postgres:17-alpine
|
|
|
|
# Lancer l'API
|
|
make dev-api
|
|
|
|
# Lancer le worker (dans un autre terminal)
|
|
make dev-worker
|
|
|
|
# Lancer le web UI (dans un autre terminal)
|
|
make dev-web
|
|
```
|
|
|
|
### Commandes Make
|
|
|
|
```bash
|
|
make build # Build .NET
|
|
make test # Run tests
|
|
make docker-up # docker compose up
|
|
make docker-down # docker compose down
|
|
make dev-api # API en dev
|
|
make dev-web # Web UI en dev
|
|
```
|
|
|
|
## Authentification
|
|
|
|
| Méthode | Usage | Endpoints |
|
|
|---------|-------|-----------|
|
|
| **JWT** | Humains (Admin/Supervisor/Viewer) | `POST /api/auth/login` |
|
|
| **API Key** | Agents | `Authorization: Bearer <key>` |
|
|
| **2FA TOTP** | Sécurité renforcée | `POST /api/auth/2fa/verify` |
|
|
|
|
Comptes par défaut (dev) :
|
|
- `admin@heimdall.test` / `Admin123!Pass` — Admin
|
|
|
|
## API — Endpoints principaux
|
|
|
|
| Méthode | Endpoint | Auth | Description |
|
|
|---------|----------|------|-------------|
|
|
| POST | `/api/auth/register` | - | Créer un compte |
|
|
| POST | `/api/auth/login` | - | Connexion |
|
|
| GET | `/api/sites` | JWT | Lister les sites |
|
|
| POST | `/api/sites` | JWT | Créer un site |
|
|
| POST | `/api/sites/{id}/tokens` | JWT | Générer token agent |
|
|
| POST | `/api/agents/register` | - | Enregistrer un agent |
|
|
| POST | `/api/agents/{id}/heartbeat` | API Key | Heartbeat agent |
|
|
| GET | `/api/users` | JWT | Lister utilisateurs |
|
|
| POST | `/api/users` | JWT | Créer utilisateur |
|
|
| PUT | `/api/users/{id}/roles` | JWT | Modifier rôles |
|
|
| POST | `/api/users/{id}/lock` | JWT | Verrouiller compte |
|
|
| POST | `/api/users/{id}/reset-password` | JWT | Reset mot de passe |
|
|
| GET | `/api/cameras/by-site/{siteId}` | JWT | Caméras d'un site |
|
|
| POST | `/api/cameras` | JWT | Ajouter une caméra |
|
|
| GET | `/api/stats` | JWT | Statistiques globales |
|
|
| GET | `/api/audit-logs` | JWT | Journal d'audit |
|
|
|
|
## Sécurité
|
|
|
|
- **JWT** 15min access + refresh token
|
|
- **API Key** HMACSHA256 + comparaison constant-time
|
|
- **Rate limiting** : 10 req/min auth, 200 req/min API
|
|
- **CORS** configurable
|
|
- **Journal d'audit** : toutes les actions critiques sont loguées
|
|
- **ASP.NET Identity** : lockout après 5 tentatives
|
|
|
|
## Tests
|
|
|
|
```bash
|
|
# Tout exécuter
|
|
dotnet test
|
|
|
|
# Résultat attendu
|
|
34 tests — 0 failed, 0 skipped
|
|
```
|
|
|
|
| Suite | Tests | Ce qui est testé |
|
|
|-------|-------|------------------|
|
|
| Domain | 13 | Entités (Site, Agent, Camera) |
|
|
| Integration | 16 | API (Auth, Sites, Users, Cameras, Agents) |
|
|
| Placeholder | 5 | Projets vides |
|
|
|
|
## Déploiement Docker
|
|
|
|
### Depuis Docker Hub (recommandé)
|
|
|
|
```yaml
|
|
# docker-compose.prod.yml minimal
|
|
services:
|
|
postgresql:
|
|
image: postgres:17-alpine
|
|
environment:
|
|
POSTGRES_DB: heimdall
|
|
POSTGRES_USER: heimdall
|
|
POSTGRES_PASSWORD: <mot-de-passe>
|
|
volumes:
|
|
- pgdata:/var/lib/postgresql/data
|
|
|
|
heimdall-central:
|
|
image: eltruncho/heimdall-central:latest
|
|
environment:
|
|
DATABASE_URL: "Host=postgresql;Port=5432;Database=heimdall;Username=heimdall;Password=<mot-de-passe>"
|
|
JWT__Key: "<votre-clé-32-caractères-min>"
|
|
ports:
|
|
- "5000:8080"
|
|
depends_on:
|
|
postgresql:
|
|
condition: service_healthy
|
|
```
|
|
|
|
### Build local
|
|
|
|
```yaml
|
|
# docker-compose.yml minimal
|
|
services:
|
|
heimdall-central:
|
|
build:
|
|
context: .
|
|
dockerfile: docker/Dockerfile.central
|
|
environment:
|
|
DATABASE_URL: "Host=postgresql;Port=5432;Database=heimdall;Username=heimdall;Password=heimdall"
|
|
JWT__Key: "<votre-clé-32-caractères-min>"
|
|
ports:
|
|
- "5000:8080"
|
|
```
|
|
|
|
## Stack technique
|
|
|
|
| Technologie | Version |
|
|
|-------------|---------|
|
|
| .NET | 10.0 |
|
|
| EF Core | 10.0.8 |
|
|
| Npgsql | 10.0.3 |
|
|
| PostgreSQL | 17 |
|
|
| Blazor Server | 10.0 |
|
|
| MudBlazor | 9.1.0 |
|
|
| Hangfire | 1.8.17 |
|
|
| xUnit | - |
|
|
| Shouldly | - |
|