fix(camera): restrict reports to assigned agent
Heimdall Gitea / Detect CI scope (pull_request) Successful in 8s
Heimdall Gitea / Build and tests (pull_request) Successful in 18m9s
Heimdall Gitea / Build and scan server image (pull_request) Successful in 6m56s
Heimdall Gitea / Build and scan agent image (pull_request) Successful in 16m23s
Heimdall Gitea / Build and scan NVIDIA Agent image (pull_request) Successful in 23m2s
Heimdall Gitea / Publish versioned installer release (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Successful in 2s

This commit is contained in:
arnaud.dartois committed 2026-11-12 01:00:37 +01:00
1 parent 35ff573341
commit 883eeac99f
3 files changed
+8 -3

No files matched your search

+2 -2
View File
@@ -10,7 +10,7 @@ Read `AGENTS.md`, the Toggle caméra #59/#199 Gitea issue, `skills/heimdall-dotn
## Implementation path
- `POST /api/cameras/{id}/toggle-status` requires the normal camera-write permission and persists `Camera.Status` in Central. Enabling a Disabled camera sets it to Offline (enabled, connectivity not yet confirmed); only an Agent status report can set it Online. Toggling any enabled status sets it to Disabled.
- Agent status reports require the API key to resolve to the same Agent ID in the route. Authenticate and authorize that identity with `ResourceAccess`; never trust the route ID alone. Keep the existing same-site camera check in `ReportCameraStatusCommandHandler`.
- Agent status reports require the API key to resolve to the same Agent ID in the route and the camera to be assigned to that Agent. Authenticate and authorize both resources with `ResourceAccess`; never trust the route ID alone. Keep the existing same-site camera check in `ReportCameraStatusCommandHandler`.
- `AppDbContext.SaveChangesAsync` publishes a payload-free config invalidation after camera/assignment/profile changes. Agent refetches its authorized full camera snapshot over its ConfigHub/API path and acknowledges the digest.
- `GetEffectiveAgentConfigQuery` emits `camera.<id>.enabled` from the persisted status. `CameraConfigStore` atomically replaces the snapshot and raises `Changed`.
- `SnapshotPipelineService` reconciles enabled assignments with `CameraStreamService`; disabling/removing an assignment kills FFmpeg, awaits its read loop cleanup and releases its stream permit. Enabling starts the stream. Keep central status authoritative; an Agent status report must not re-enable a disabled camera.
@@ -58,6 +58,6 @@ The sixth run kept the FFmpeg process deadline separate from the config ACK dead
## Camera status contract acceptance
For status semantics (issue #291), run `CamerasControllerTests.ToggleStatus_WithAuth_TogglesCamera` against PostgreSQL and the `ToggleCameraStatusCommandTests` suite. The relational test must assert Disabled → Offline and the online counter remains zero before connectivity, register and heartbeat a synthetic same-site Agent, assign the synthetic camera, accept that Agent's Online report, reject a request that uses its API key with a different route Agent ID, and then confirm admin toggle → Disabled.
For status semantics (issue #291), run `CamerasControllerTests.ToggleStatus_WithAuth_TogglesCamera` against PostgreSQL and the `ToggleCameraStatusCommandTests` suite. The relational test must assert Disabled → Offline and the online counter remains zero before connectivity, register and heartbeat a synthetic same-site Agent, reject its report before camera assignment, assign the synthetic camera, accept that Agent's Online report, reject a request that uses its API key with a different route Agent ID, and then confirm admin toggle → Disabled.
A source-built disposable Central + PostgreSQL Compose run on 2026-11-11 used project `heimdall-291-acceptance-1794427561-8428`, synthetic bootstrap/site/Agent/camera data, loopback ports 18543/15439, and image `heimdall:heimdall-291-acceptance-1794427561-8428-central`. It observed health HTTP 200, activation Offline, online count 0, then Agent-confirmed Online and online count 1. Cleanup verified zero project containers, volumes and networks, the exact image tag absent, and temporary files removed. This is software acceptance only; it does not satisfy `validation:field` hardware/deployment evidence.
@@ -158,7 +158,8 @@ public class AgentsController : ControllerBase
{
var requester = await _resourceAccess.ResolveAsync(User, ct);
if (requester is null || requester.Kind != RequesterKind.Agent ||
!await _resourceAccess.AgentAsync(requester, id, ct))
!await _resourceAccess.AgentAsync(requester, id, ct) ||
!await _resourceAccess.CameraAsync(requester, cameraId, ct))
return Forbid();
if (!Enum.TryParse<CameraStatus>(request.Status, true, out var status))
@@ -96,6 +96,10 @@ public class CamerasControllerTests : PostgresTestBase
$"api/agents/{agentId}/heartbeat", new { publicIp = "127.0.0.1" });
heartbeatResponse.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
var unassignedReport = await agentClient.PutAsJsonAsync(
$"api/agents/{agentId}/cameras/{cameraId}/status", new { status = "Online" });
unassignedReport.StatusCode.ShouldBe(System.Net.HttpStatusCode.Forbidden);
var assignmentResponse = await client.PostAsJsonAsync("api/assignments", new
{
cameraId,