feat: journal d'audit complet + auto-update agent natif & Docker (#92 #96 #97) #174

Merged
nonobis merged 5 commits from feat/heimdall-92-96-97 into main 2026-08-27 18:56:57 +02:00
Owner

Résumé

PR combinée pour les tickets #92, #96 et #97 — journal d'audit complet et auto-update des agents.


🎫 #92 — Journal d'audit : couverture complète + UI enrichie

Back-end :

  • Audit logging ajouté dans 7 handlers précédemment non instrumentés :
    • Site.Created, Site.Updated (avec OldValue/NewValue JSON), Site.Deleted
    • Camera.Created, Camera.Updated (avec OldValue/NewValue JSON), Camera.Deleted, Camera.StatusChanged
  • Query enrichie : filtres par texte libre, utilisateur, plage de dates + résolution des noms de ressource
  • DTO AuditLogResponse enrichi avec ResourceName

UI :

  • Colonne « Détails » avec diff lisible (ancien barré rouge → nouveau vert)
  • Filtres : recherche texte, dates (From/To)
  • Affichage du nom de ressource (Site/Camera) plutôt que l'ID tronqué
  • Export CSV
  • Actions supplémentaires dans le filtre dropdown

🎫 #96 — Auto-update agent : mode natif Linux/Windows

Central :

  • UpdatesController : GET /api/updates/latest (cache 1h stale-while-revalidate, fetch Forgejo releases API)
  • POST /api/agents/{id}/update : déclenchement manuel
  • AutoUpdateEnabled ajouté à l'entité Site + migration EF Core

Agent :

  • AgentUpdateService : BackgroundService qui vérifie la version toutes les 12h
    • Téléchargement binaire, vérification SHA256, remplacement atomique (temp + rename)
    • Skip si pipeline de capture actif ou auto-update désactivé
    • Restart systemd/Windows Service automatique

Install scripts :

  • install/install-agent.sh (Linux, systemd, détection arch)
  • install/install-agent.ps1 (Windows, Windows Service)

UI :

  • Section « Mise à jour » dans AgentDetail.razor (version courante vs disponible)
  • Switch AutoUpdateEnabled dans l'édition de site (SitesPage.razor)

🎫 #97 — Auto-update agent : mode Docker

Agent :

  • DockerUpdateService : BackgroundService (seulement en mode Docker, via ContainerInfoProvider)
    • Pull image, inspect container, stop/stop grace, recreate avec même config
    • Health check /health/live avec rollback automatique
    • Toutes les opérations via CLI Docker (System.Diagnostics.Process)

Docker Compose :

  • Prod : image: eltruncho/heimdall-agent:${AGENT_IMAGE_TAG:-latest}

Fichiers clés

Fichier Ticket
src/Heimdall.Web/Controllers/UpdatesController.cs #96 #97
src/Heimdall.Agent/Services/AgentUpdateService.cs #96
src/Heimdall.Agent/Services/DockerUpdateService.cs #97
src/Heimdall.Domain/Entities/Site.cs #96
src/Heimdall.Application/Audit/Queries/GetAuditLogs/GetAuditLogsQuery.cs #92
src/Heimdall.Web/Components/Pages/AuditLogsPage.razor #92
src/Heimdall.Web/Components/Pages/AgentDetail.razor #96 #97
install/install-agent.sh #96
install/install-agent.ps1 #96

CI

  • ✅ dotnet build — 0 erreurs, 0 warnings
  • ✅ dotnet format whitespace --verify-no-changes — OK

Fixes #92
Fixes #96
Fixes #97

## Résumé PR combinée pour les tickets **#92**, **#96** et **#97** — journal d'audit complet et auto-update des agents. --- ### 🎫 #92 — Journal d'audit : couverture complète + UI enrichie **Back-end :** - Audit logging ajouté dans **7 handlers** précédemment non instrumentés : - `Site.Created`, `Site.Updated` (avec OldValue/NewValue JSON), `Site.Deleted` - `Camera.Created`, `Camera.Updated` (avec OldValue/NewValue JSON), `Camera.Deleted`, `Camera.StatusChanged` - Query enrichie : filtres par texte libre, utilisateur, plage de dates + résolution des noms de ressource - DTO `AuditLogResponse` enrichi avec `ResourceName` **UI :** - Colonne « Détails » avec diff lisible (ancien barré rouge → nouveau vert) - Filtres : recherche texte, dates (From/To) - Affichage du nom de ressource (Site/Camera) plutôt que l'ID tronqué - Export CSV - Actions supplémentaires dans le filtre dropdown --- ### 🎫 #96 — Auto-update agent : mode natif Linux/Windows **Central :** - `UpdatesController` : `GET /api/updates/latest` (cache 1h stale-while-revalidate, fetch Forgejo releases API) - `POST /api/agents/{id}/update` : déclenchement manuel - `AutoUpdateEnabled` ajouté à l'entité `Site` + migration EF Core **Agent :** - `AgentUpdateService` : BackgroundService qui vérifie la version toutes les 12h - Téléchargement binaire, vérification SHA256, remplacement atomique (temp + rename) - Skip si pipeline de capture actif ou auto-update désactivé - Restart systemd/Windows Service automatique **Install scripts :** - `install/install-agent.sh` (Linux, systemd, détection arch) - `install/install-agent.ps1` (Windows, Windows Service) **UI :** - Section « Mise à jour » dans AgentDetail.razor (version courante vs disponible) - Switch AutoUpdateEnabled dans l'édition de site (SitesPage.razor) --- ### 🎫 #97 — Auto-update agent : mode Docker **Agent :** - `DockerUpdateService` : BackgroundService (seulement en mode Docker, via `ContainerInfoProvider`) - Pull image, inspect container, stop/stop grace, recreate avec même config - Health check `/health/live` avec rollback automatique - Toutes les opérations via CLI Docker (`System.Diagnostics.Process`) **Docker Compose :** - Prod : `image: eltruncho/heimdall-agent:${AGENT_IMAGE_TAG:-latest}` --- ## Fichiers clés | Fichier | Ticket | |---------|--------| | `src/Heimdall.Web/Controllers/UpdatesController.cs` | #96 #97 | | `src/Heimdall.Agent/Services/AgentUpdateService.cs` | #96 | | `src/Heimdall.Agent/Services/DockerUpdateService.cs` | #97 | | `src/Heimdall.Domain/Entities/Site.cs` | #96 | | `src/Heimdall.Application/Audit/Queries/GetAuditLogs/GetAuditLogsQuery.cs` | #92 | | `src/Heimdall.Web/Components/Pages/AuditLogsPage.razor` | #92 | | `src/Heimdall.Web/Components/Pages/AgentDetail.razor` | #96 #97 | | `install/install-agent.sh` | #96 | | `install/install-agent.ps1` | #96 | ## CI - ✅ `dotnet build` — 0 erreurs, 0 warnings - ✅ `dotnet format whitespace --verify-no-changes` — OK --- Fixes #92 Fixes #96 Fixes #97
- Add audit logging to all Site/Camera commands (Create, Update, Delete, ToggleStatus)
- Capture old/new values for Update operations with JSON diffs
- Enhance GetAuditLogsQuery with Search, UserId, FromDate, ToDate filters
- Batch-resolve resource names (Site/Camera) for display
- Add ResourceName to AuditLogResponse DTO
- AuditLogsPage: search field, date range pickers, details diff column (strikethrough red old -> green new)
- Add all action types to MudSelect filter dropdown
- CSV export via JS interop (downloadFile helper)
- Update API client with new filter parameters

Fixes #92
- Add AutoUpdateEnabled property to Site entity with EF migration support
- Create UpdatesController: GET /api/updates/latest (stale-while-revalidate cache)
- Create UpdatesController: POST /api/agents/{id}/update trigger endpoint
- Create AgentUpdateService: BackgroundService for native binary auto-update
  - Periodic checks, version comparison, SHA256 verification, atomic replacement
  - Platform detection (linux-x64, linux-arm64, win-x64, osx-x64, etc.)
  - Skips when capture pipeline is active or auto-update is disabled
- Add UpdateCheckIntervalHours to AgentOptions (default: 12h)
- ConfigReceiverService handles autoUpdateEnabled setting from Central
- AgentDetail.razor: Mise à jour SectionCard with version comparison + update button
- SitesPage.razor: MudSwitch for AutoUpdateEnabled in site edit dialog
- install/install-agent.sh: Linux installer (systemd service, SHA256 verification)
- Update all DTOs, commands, handlers for AutoUpdateEnabled propagation

Fixes #96
- DockerUpdateService: BackgroundService for container auto-update
  - Periodic checks (12h) against Central /api/updates/latest endpoint
  - Falls back to /api/version for pre-#96 deployments
  - Pulls new image, inspects current container config
  - Stops old container, starts new with identical config
  - Health verification via /health/live (60s timeout)
  - Automatic rollback on health check failure
- Program.cs: Register DockerUpdateService in DI
- docker-compose.prod.yml: Versioned image tag via AGENT_IMAGE_TAG env var

Fixes #97
# Conflicts:
#	src/Heimdall.Application/Sites/Commands/UpdateSite/UpdateSiteHandler.cs
fix: resolve merge conflicts + build fixes for combined 92/96/97
Some checks failed
CI / Docker + Trivy (pull_request) Has been skipped
CI / Détection changements (pull_request) Successful in 4s
CI / OWASP Dependency-Check (pull_request) Has been skipped
Auto-Fix / Auto-Fix (pull_request) Failing after 1m7s
CI / Docker PR (pull_request) Failing after 5m43s
CI / Build + Format (pull_request) Failing after 6m0s
CI / SonarQube (pull_request) Has been skipped
CI / Tests unitaires (pull_request) Has been skipped
CI / Tests Web (bUnit) (pull_request) Has been skipped
CI / Tests DB (Integration) (pull_request) Has been skipped
CI / Tests DB (Infrastructure) (pull_request) Has been skipped
CI / Résumé tests (PR) (pull_request) Successful in 3s
CI / ci (pull_request) Failing after 1s
83a0436494
- Fix CA1805: remove redundant AutoUpdateEnabled = false
- Fix CA1860: use Count > 0 instead of Any() in audit query
- Fix CS1739: correct UpdateSiteCommand parameter names
- Fix CS0414: remove unused _updateLoading/_updateTriggering fields
- Fix CS1061: add NtfyTopic to UpdateSiteRequest DTO
- Fix CS7036: add AutoUpdateEnabled param to SiteItem in tests

🤖 Résumé des tests

Tests unitaires

Pas de résultats (job skippé)


Tests Web (bUnit)

Pas de résultats


Tests DB (Infrastructure)

Pas de résultats

Généré automatiquement par la CI.

## 🤖 Résumé des tests ## Tests unitaires _Pas de résultats (job skippé)_ --- ## Tests Web (bUnit) _Pas de résultats_ --- ## Tests DB (Infrastructure) _Pas de résultats_ _Généré automatiquement par la CI._
nonobis deleted branch feat/heimdall-92-96-97 2026-08-27 18:56:58 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
nonobis/Heimdall!174
No description provided.