Commit Graph
141 Commits
Author SHA1 Message Date
Arnaud Dartois 153be535d4 fix(multiple): auth, workers, EF Core, MudTheme fixes
- Auth: AssignmentsController auth bug, ReleaseCamera result, logout endpoint
- Security: open redirect fix
- Workers: AgentState thread-safety, CameraStreamService async, HttpClientFactory
- EF Core: AddCameraDiscoveryFields migration, DI interceptors, retry helper
- UI: MudTheme palette config, aria-labels on icon buttons
2026-07-19 19:58:45 +00:00
Arnaud Dartois 4b83e35df0 fix(infra): persist Data Protection keys for Docker resilience
- Add PersistKeysToFileSystem with SetApplicationName so camera
  credential decryption survives container restarts
- Move connection string resolution inside else block to fix
  integration tests (was evaluating connection string eagerly
  before Testing environment check)
- Remove hardcoded connection string fallback, throw instead
- Add Microsoft.AspNetCore.DataProtection.Extensions dependency
2026-07-19 19:34:58 +00:00
Arnaud Dartois 32025eae67 fix(infra): persist Data Protection keys to filesystem for Docker
- Add PersistKeysToFileSystem to /var/lib/heimdall/dp-keys so camera
  credential decryption survives container restarts
- Remove hardcoded connection string fallback, throw instead
- Add Microsoft.AspNetCore.DataProtection.Extensions dependency
2026-07-19 19:33:10 +00:00
Arnaud Dartois 3f75a20860 fix(infra): copy web wwwroot to /app/wwwroot in Dockerfile
Static files are served from /app/wwwroot but the web publish
output is at /app/web/. Copying wwwroot to the expected location
so StaticFileMiddleware can find CSS, JS, and other static assets.
2026-07-19 19:14:47 +00:00
Arnaud Dartois 41d9ae2bc0 fix(infra): add working_dir /app/web to heimdall-web service
Content root was /app/ but published files are at /app/web/,
causing StaticFileMiddleware to look for wwwroot at /app/wwwroot/
which doesn't exist. Add working_dir to set correct content root.
2026-07-19 19:13:10 +00:00
Arnaud Dartois d2288617f7 fix(web): replace MapStaticAssets with UseStaticFiles 2026-07-19 18:37:52 +00:00
Arnaud Dartois a6f37b8e9d fix(auth): add permission claims to ApiKeyAuthenticationHandler
API keys used by camera agents were missing 'permission' claims,
causing all endpoints with ApiKey + Policy to return 403 Forbidden
(e.g. POST /api/events, POST /api/events/{id}/snapshot).

Add CameraWrite, CameraRead, CameraLive, SiteRead, EventRead
permissions — matching agent operational needs (Supervisor minus
Person permissions).
2026-07-19 16:46:32 +00:00
Arnaud Dartois a50a567f8c feat(auth): improve authentication security rules
- First registered user is auto-assigned Admin role (empty DB)
- Add auth.public-registration.enabled setting to disable public
  registration (only admins can create users via POST /api/users)
- Add DELETE /api/users/{id} endpoint (Admin only) with guards:
  - Cannot delete own account
  - Cannot delete the last administrator
- Guard AssignRolesAsync to prevent removing Admin from last admin
- Add AuthSettings constants class for well-known setting keys
2026-07-19 16:39:35 +00:00
Arnaud Dartois 554fd7ffc3 chore(docker): fix compose files and update README documentation
- Fix docker-compose.prod.yml: agent image ref
  (heimdall-central→heimdall-agent) and env var naming
  (HEIMDALL_* → Agent__*)
- Add missing SENTRY_DSN env vars to central, workers,
  web, and agent services
- Add agent_state volume for agent identity persistence
- Update README with accurate test counts (34→225),
  env var reference table, troubleshooting guide,
  and proper docker documentation
- Update docker-compose.yml header and add
  Agent__StateDirectory/Agent__RegistrationMaxRetries
2026-07-19 16:07:32 +00:00
Arnaud Dartois 363b43f779 fix: prevent orphaned TaskCompletionSource in frame queue
Changed BoundedChannelFullMode from DropOldest to DropWrite.
With DropOldest, the oldest queued job is silently removed when the
channel is full, but its TaskCompletionSource is never completed —
causing the caller to hang indefinitely.

DropWrite rejects new writes when full, returning TryWrite=false,
which triggers the existing graceful fallback (tcs.TrySetResult(null)).
2026-07-19 15:54:46 +00:00
Arnaud Dartois d9f5224e21 fix: resolve review findings — SignalR JWT, enum serialization, TCS leak, thread safety 2026-07-19 15:54:13 +00:00
Arnaud Dartois 926d866749 fix(security): validate returnUrl against open redirect
The returnUrl query parameter is now validated as a local/relative URL
(starts with '/' and does not contain '://') before being used as a
redirect target after login.
2026-07-19 15:54:07 +00:00
Arnaud Dartois 54496cd947 refactor: extract duplicate JS interop signIn to AuthHelper
Both Login and Register pages had identical JsRuntime.InvokeVoidAsync calls
with the same anonymous object shape. Extracted to a shared AuthHelper
static class with SignInAsync(IJSRuntime, object) and CreateSignInPayload(UserInfo).

- New file: Services/AuthHelper.cs
- Login.razor and Register.razor now call AuthHelper.SignInAsync
- Pre-existing fix: Person.cs IAuditableEntity setters made public
2026-07-19 15:53:38 +00:00
Arnaud Dartois b955a98760 refactor(css): use CSS custom properties for auth page theme
Define --auth-* variables on .auth-page for all colors, shadows, and
backgrounds. Dark mode now only overrides variables on .auth-page —
zero selector duplication, single source of truth for theme values.
2026-07-19 15:51:07 +00:00
Arnaud Dartois 0030173c38 refactor: rename mud-button-submit to auth-submit-btn
Avoid potential CSS conflicts with future MudBlazor versions using a
project-specific class name for auth page submit buttons.
2026-07-19 15:50:32 +00:00
Arnaud Dartois b62e48bef7 chore: add justification comment for NU1510 suppression
NU1510 fires because System.Threading.Channels is a transitive dependency
of Microsoft.AspNetCore.SignalR.Client but is already part of the
.NET 10 framework. Safe to suppress.
2026-07-19 15:50:10 +00:00
Arnaud Dartois 70176124cb refactor(css): merge duplicate dark mode media blocks into one
- Single @media (prefers-color-scheme: dark) block containing both
  auth-specific rules and general (body, blazor-error-ui) rules
- Removes duplicate @media query, simplifies maintenance
2026-07-19 15:49:46 +00:00
Arnaud Dartois f0083de97d fix(a11y): add prefers-reduced-motion support for auth page
- Disable auth-card entrance animation when user prefers reduced motion
- Disable auth-footer link color transition
- Respects WCAG accessibility guidelines for vestibular disorders
2026-07-19 15:49:13 +00:00
Arnaud Dartois 898a9be6fa fix: remove method="post" from Blazor interactive forms 2026-07-19 15:49:00 +00:00
Arnaud Dartois 28d6b9ea81 fix(a11y): improve color contrast on auth page text
- Light mode: .auth-header p and .auth-footer p #64748b → #475569 (~6.5:1 contrast)
- Dark mode: .auth-header p and .auth-footer p #94a3b8 → #cbd5e1
Both pass WCAG AA and now approach AAA (7:1) for small text readability.
2026-07-19 15:48:26 +00:00
Arnaud Dartois 493747bb70 feat(ui): add global search bar in header with smart routing 2026-07-19 15:35:44 +00:00
Arnaud Dartois d5776496e7 fix: suppress NU1510 for transitive System.Threading.Channels 2026-07-19 15:32:47 +00:00
Arnaud Dartois 255c3f6260 fix: resolve CA1822 and CA1859 in FrameAnalyzerService 2026-07-19 15:30:51 +00:00
Arnaud Dartois 488996a760 fix: add missing System.Threading.Channels import in FrameAnalyzerService 2026-07-19 15:30:08 +00:00
Arnaud Dartois 129a6148f5 feat(persons): add person manager with known face registry and CRUD API 2026-07-19 15:28:38 +00:00
Arnaud Dartois c5728fa810 feat(events): add SignalR real-time event broadcasting to web UI 2026-07-19 15:24:52 +00:00
Arnaud Dartois 0d2f0574c9 feat(ui): add snapshot gallery with lightbox and search filter 2026-07-19 15:19:33 +00:00
Arnaud Dartois 76b261378c fix: resolve review findings — thread safety, N+1, DTO layering, sentry, S3 retry 2026-07-19 13:43:48 +00:00
Arnaud Dartois 2d65f273c6 feat(ui): enrich dashboard with event data, camera status, and agent workload 2026-07-19 13:30:03 +00:00
Arnaud Dartois add9ebf462 feat(ui): add events page and event timeline on camera detail 2026-07-19 13:21:25 +00:00
Arnaud Dartois 8ac8baf20a feat(storage): add S3 snapshot service and comprehensive tests for phases 2-3
Adds S3-compatible snapshot storage (Alarik) with AWS Signature V4,
upload, thumbnail, and delete operations. Backfills Phase 2 & 3 with
27 new tests covering camera assignment strategies, event CRUD with
filtering, snapshot attachment, and API contract validation.

- SnapshotService with S3 REST API via HttpClient + SigV4 signing
- 10 unit tests for CameraAssignmentService (assign, release, failover, history)
- 9 unit tests for CameraEventService (create, query, filter, delete, snapshot)
- 8 integration tests for AssignmentsController + EventsController
- SnapshotService registration with 5-min timeout HTTP client
2026-07-19 13:14:05 +00:00
Arnaud Dartois 358443ff1a feat(events): implement camera event pipeline with AI detection storage
Adds the foundation for AI-powered detection events storage, query,
and snapshot management. Agents can POST detection events (motion,
person, vehicle, face, etc.) with confidence scores and metadata;
users can query, filter, and view event history.

- CameraEvent entity with EF Core configuration + migration
- ICameraEventService / CameraEventService with paged query + filters
- EventsController: 5 REST endpoints (create, get, query, attach snapshot, delete)
- Agent-side CameraStreamService: FFmpeg-based RTSP frame capture (foundation)
- Supports both ApiKey (agent) and JWT (user) authentication
2026-07-19 12:55:05 +00:00
Arnaud Dartois 159da2ca26 feat(assign): implement camera-to-agent assignment with failover and strategy support
Multi-agent sites need automatic camera distribution, failover when
an agent goes offline, and rebalancing when new agents join.

Adds CameraAssignment entity with audit trail, 4 assignment strategies
(RoundRobin, GpuPriority, LeastCameras, Failover), a Hangfire failover
job that checks for stale heartbeats every 60s, a discovery coordinator
for leader election, 6 REST endpoints, EF migration, and DI registration.
2026-07-19 12:20:07 +00:00
Arnaud Dartois 2152fca3c6 feat(discovery): implement camera detection and dedup pipeline
Manual camera configuration does not scale beyond a few devices.
Automated discovery is needed to support deployments with 50+
cameras across heterogeneous protocols (ONVIF, mDNS, HTTP, ARP).

Phase 1 introduces 5 network probe services, a stream tester, an
orchestrating discovery service with IP+MAC deduplication, 11 REST
endpoints, a pre-verification endpoint, 57 tests, and DI registration.
2026-07-19 12:00:16 +00:00
Arnaud Dartois 31f2056d48 feat(agents): add global agents page, reusable components, KPIs, admin-only security 2026-07-19 07:25:27 +00:00
Arnaud Dartois 9113191547 feat(ui): modernize all pages — auto-refresh, skeleton loading, tooltips, filters 2026-07-19 07:12:40 +00:00
Arnaud Dartois 2ff355e567 feat(auth): add default groups, claims-based authorization and update spec 2026-07-19 07:04:25 +00:00
Arnaud Dartois 57b51f403c feat(web): add profile, roles, groups and claims pages 2026-07-19 06:49:17 +00:00
Arnaud Dartois e73c4b357b chore: update opencode submodule to 4bc9d1d — fix broken agent launch (frontmatter + double definitions) 2026-07-19 06:35:01 +00:00
Arnaud Dartois 3056452b9e fix(web): repair design on users page, settings page and audit logs 2026-07-19 06:34:32 +00:00
Arnaud Dartois ca693a2ed0 fix(web): repair home page design — invalid CSS, dead code, missing form wrappers 2026-07-19 06:28:13 +00:00
Arnaud Dartois 7e66bb4fbb feat(discovery): add camera detection pipeline inspired by Strix
Add complete camera discovery and stream testing specification,
Domain entities, enums, DTOs, Application interfaces, and EF Core
configurations for automated ONVIF/mDNS/HTTP/ARP camera detection.

- 4 new enums: CameraDiscoveryMethod, DetectedCameraType,
  StreamProtocol, CameraCapability (flags)
- Camera entity extended with 15+ discovery/test fields
- New entities: CameraDiscoveryResult, DiscoveredStreamUrl
- DTOs: ProbeRequest/Response, StreamTestRequest/Session, etc.
- Interface: ICameraDiscoveryService (8 methods)
- EF Core configurations for all new tables + columns
- Full spec doc: docs/specifications/detection-camera.md (16 sections)
- 145 tests pass, 0 warnings

Inspiré de Strix (github.com/eduard256/Strix) — moteur de
découverte de flux IP supportant 3600+ marques, 100K+ patterns.
2026-07-18 21:15:05 +00:00
Arnaud Dartois 8c6b2610a0 fix(web): register HeimdallAuthStateProvider concrete type in DI
The service was registered only as AuthenticationStateProvider (base class),
but Login.razor, Register.razor, and MainLayout.razor inject the concrete
@inject HeimdallAuthStateProvider. Blazor's DI could not resolve it,
causing InvalidOperationException on page render.

Fix: register the concrete type first, then make the base class
registration resolve to the same instance via GetRequiredService.
2026-07-18 21:08:08 +00:00
Arnaud Dartois 39f08e39ed fix(web): add cookie authentication to fix IAuthenticationService missing error 2026-07-18 20:59:38 +00:00
Arnaud Dartois f5c4bcd5f0 feat(deploy): add heimdall-web Blazor UI service to Docker Compose
The Dockerfile.central already compiled Heimdall.Web but it was never
deployed as a service. Add heimdall-web service using the same image
with entrypoint overridden to dotnet web/Heimdall.Web.dll.

- Expose port 5001 for the Blazor Server UI
- API_BASE_URL points to heimdall-central:8080 for server-side HTTP calls
- Healthcheck on root / returns 200 once the Blazor circuit is ready
2026-07-18 20:44:38 +00:00
Arnaud Dartois fdfd506977 fix: resolve GlitchTip anomalies — DB retry, query filters, Sentry DSN, Workers tracking
- 🔴 Fix startup crash when DB is temporarily unavailable: add 5x retry
  with exponential backoff to Database.MigrateAsync() in API and Workers
- 🔴 Fix EF Core 'required navigation with query filter' warnings:
  add matching soft-delete query filters to AgentSetting, CameraCredentials,
  CameraDetectionProfile, UserSite
- 🔴 Add Sentry error tracking to Workers (Hangfire background jobs)
- 🟡 Make Sentry/GlitchTip DSN configurable via SENTRY_DSN env var
  (applies to API, Web, Agent, Workers)
- 🟡 Suppress EF Core RedundantIndexRemoved informational messages

Closes GlitchTip #538
2026-07-18 20:31:37 +00:00
Arnaud Dartois ee66cf5971 chore: update opencode submodule to 09da68e — fully automatic auto-learning/auto-healing pipeline 2026-07-18 20:15:41 +00:00
Arnaud Dartois abf8162824 fix(db): fix index filter casing in all migration snapshots
Fix the filtered index column name casing in ALL .Designer.cs files
and AppDbContextModelSnapshot.cs:
  - "status" → "Status" (Agent.LastHeartbeat index)
  - "is_deleted" → "IsDeleted" (Site.IsDeleted index)

These must match the actual column names (PascalCase) since
PostgreSQL quoted identifiers are case-sensitive.

Also fix the InitialCreate migration .cs file directly.
All 10 references across 5 snapshot files corrected.
2026-07-18 20:11:19 +00:00
Arnaud Dartois 3978f64f93 fix(workers): use IDbContextFactory for HeartbeatMonitorJob thread safety
Pattern #4 from cross-project learning analysis: HeartbeatMonitorJob
injected AppDbContext directly (not thread-safe). Changed to
IDbContextFactory<AppDbContext> + registered factory in DI.

Other patterns verified already in place:
- CancellationToken on all async methods ✅ (100% controller adoption)
- N+1 per-entity loops ✅ (all services use bulk-loading)
- AsNoTracking ✅ (explicit on read-only queries)
- Global QueryTrackingBehavior.NoTracking deferred: safe for
  new projects but requires write-path audit on existing codebase
2026-07-18 20:05:22 +00:00
Arnaud Dartois 0f22a60fbc fix(db): correct Site index filter column casing ("is_deleted" → "IsDeleted")
The filtered index IX_sites_IsDeleted uses a WHERE clause
referencing "is_deleted" (lowercase underscore) but the column
is "IsDeleted" (PascalCase). PostgreSQL quoted identifiers are
case-sensitive, causing Npgsql.PostgresException on migration.

Fixes remaining HEIMDALL issues on GlitchTip.
2026-07-18 20:01:31 +00:00