2 Commits
Author SHA1 Message Date
arnaud.dartois dc8a313deb [Camera] Keep activated cameras offline until agent confirmation (#325)
Heimdall Gitea / Detect CI scope (push) Successful in 7s
Heimdall Gitea / Build and tests (push) Successful in 21m18s
Heimdall Gitea / Build and scan server image (push) Successful in 8m5s
Heimdall Gitea / Build and scan agent image (push) Successful in 11m29s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 33m56s
Heimdall Gitea / Publish versioned installer release (push) Successful in 4m13s
Heimdall Gitea / CI policy (push) Successful in 2s
Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-12 02:06:10 +01:00
arnaud.dartois 9fd9c75f94 [Security] Update container bases to .NET 10.0.15
Heimdall Gitea / Build and tests (push) Successful in 19m55s
Heimdall Gitea / Detect CI scope (push) Successful in 1m1s
Heimdall Gitea / Build and scan server image (push) Successful in 9m7s
Heimdall Gitea / Build and scan agent image (push) Successful in 12m27s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 19m7s
Heimdall Gitea / Publish versioned installer release (push) Successful in 5m47s
Heimdall Gitea / CI policy (push) Successful in 6s
Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-12 00:57:51 +01:00
14 changed files with 97 additions and 25 deletions

No files matched your search

+5 -5
View File
@@ -75,7 +75,7 @@ jobs:
needs: [changes]
runs-on: [ubuntu-latest, build-agent]
container:
image: mcr.microsoft.com/dotnet/sdk:10.0-noble@sha256:de4fe90a98845d75910b9769662465c84de1a934665c431279d1382b2bddc02b
image: mcr.microsoft.com/dotnet/sdk:10.0-noble@sha256:fe0fd4e93bd2fbb47c883b7a6369e5c8d3db8bf01cdc5981f6ee35fbdf3ff4fb
services:
postgres:
image: postgres:17-alpine@sha256:b0f9560a2de083e2cc7382e75f808c7381a32852a7ec49117deedb300e552b24
@@ -163,7 +163,7 @@ jobs:
needs: [changes, verify]
runs-on: [ubuntu-latest, build-agent]
container:
image: mcr.microsoft.com/dotnet/sdk:10.0-noble@sha256:de4fe90a98845d75910b9769662465c84de1a934665c431279d1382b2bddc02b
image: mcr.microsoft.com/dotnet/sdk:10.0-noble@sha256:fe0fd4e93bd2fbb47c883b7a6369e5c8d3db8bf01cdc5981f6ee35fbdf3ff4fb
steps:
- name: Prepare action runtime before checkout
run: |
@@ -208,7 +208,7 @@ jobs:
needs: [changes, verify]
runs-on: [ubuntu-latest, build-agent]
container:
image: mcr.microsoft.com/dotnet/sdk:10.0-noble@sha256:de4fe90a98845d75910b9769662465c84de1a934665c431279d1382b2bddc02b
image: mcr.microsoft.com/dotnet/sdk:10.0-noble@sha256:fe0fd4e93bd2fbb47c883b7a6369e5c8d3db8bf01cdc5981f6ee35fbdf3ff4fb
steps:
- name: Prepare action runtime before checkout
run: |
@@ -253,7 +253,7 @@ jobs:
needs: [changes, verify]
runs-on: [ubuntu-latest, build-agent]
container:
image: mcr.microsoft.com/dotnet/sdk:10.0-noble@sha256:de4fe90a98845d75910b9769662465c84de1a934665c431279d1382b2bddc02b
image: mcr.microsoft.com/dotnet/sdk:10.0-noble@sha256:fe0fd4e93bd2fbb47c883b7a6369e5c8d3db8bf01cdc5981f6ee35fbdf3ff4fb
steps:
- name: Prepare action runtime before checkout
run: |
@@ -298,7 +298,7 @@ jobs:
needs: [changes, verify, server_image, agent_image, agent_gpu_image]
runs-on: [ubuntu-latest, build-agent]
container:
image: mcr.microsoft.com/dotnet/sdk:10.0-noble@sha256:de4fe90a98845d75910b9769662465c84de1a934665c431279d1382b2bddc02b
image: mcr.microsoft.com/dotnet/sdk:10.0-noble@sha256:fe0fd4e93bd2fbb47c883b7a6369e5c8d3db8bf01cdc5981f6ee35fbdf3ff4fb
permissions:
contents: write
pull-requests: read
+2 -2
View File
@@ -1,5 +1,5 @@
# Server/PWA: restore the complete project graph from locked dependencies.
FROM mcr.microsoft.com/dotnet/sdk:10.0-noble@sha256:de4fe90a98845d75910b9769662465c84de1a934665c431279d1382b2bddc02b AS build
FROM mcr.microsoft.com/dotnet/sdk:10.0-noble@sha256:fe0fd4e93bd2fbb47c883b7a6369e5c8d3db8bf01cdc5981f6ee35fbdf3ff4fb AS build
WORKDIR /src
ARG VERSION=0.0.0-local
COPY global.json Directory.Build.props Directory.Build.targets ./
@@ -8,7 +8,7 @@ COPY install/ ./install/
RUN dotnet restore src/Heimdall.Web/Heimdall.Web.csproj --locked-mode
RUN dotnet publish src/Heimdall.Web/Heimdall.Web.csproj -c Release --no-restore -o /out -p:Version=$VERSION -p:ContinuousIntegrationBuild=true
FROM mcr.microsoft.com/dotnet/aspnet:10.0-noble@sha256:de0ee358cdd672f7017a003bed21e9ac9ed48a27c922a59b18175b6e82fa7fee
FROM mcr.microsoft.com/dotnet/aspnet:10.0-noble@sha256:bfd912c83295ce66d4b706ebb8541b9f14259b0e76fbb88b2751f58ce2399d2e
WORKDIR /app
RUN apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends --only-upgrade apt libapt-pkg6.0t64 \
+2 -2
View File
@@ -1,6 +1,6 @@
# CPU agent: use glibc for ONNX native dependencies. GPU variants need a
# separately validated .NET/native-library runtime and are not published here.
FROM mcr.microsoft.com/dotnet/sdk:10.0-noble@sha256:de4fe90a98845d75910b9769662465c84de1a934665c431279d1382b2bddc02b AS build
FROM mcr.microsoft.com/dotnet/sdk:10.0-noble@sha256:fe0fd4e93bd2fbb47c883b7a6369e5c8d3db8bf01cdc5981f6ee35fbdf3ff4fb AS build
WORKDIR /src
ARG VERSION=0.0.0-local
ARG TARGET_RUNTIME=cpu
@@ -10,7 +10,7 @@ COPY src/ ./src/
RUN dotnet restore src/Heimdall.Agent/Heimdall.Agent.csproj --locked-mode
RUN dotnet publish src/Heimdall.Agent/Heimdall.Agent.csproj -c Release --no-restore -o /out -p:Version=$VERSION -p:ContinuousIntegrationBuild=true
FROM mcr.microsoft.com/dotnet/aspnet:10.0-noble@sha256:de0ee358cdd672f7017a003bed21e9ac9ed48a27c922a59b18175b6e82fa7fee
FROM mcr.microsoft.com/dotnet/aspnet:10.0-noble@sha256:bfd912c83295ce66d4b706ebb8541b9f14259b0e76fbb88b2751f58ce2399d2e
WORKDIR /app
ARG DOCKER_CLI_VERSION=29.9.3
ARG DOCKER_CLI_SHA256=3fb5d1f13014c18cc54945bc177c58a9056a482dada031e17d12cf2e6922c973
+2 -2
View File
@@ -1,6 +1,6 @@
# Optional NVIDIA Agent image. ONNX Runtime 1.22 GPU uses CUDA 12.8 and cuDNN 9.
# NVIDIA amd64 runtime image digest is pinned; it includes CUDA 12.8.1/cuDNN 9.8.0.87.
FROM mcr.microsoft.com/dotnet/sdk:10.0-noble@sha256:de4fe90a98845d75910b9769662465c84de1a934665c431279d1382b2bddc02b AS build
FROM mcr.microsoft.com/dotnet/sdk:10.0-noble@sha256:fe0fd4e93bd2fbb47c883b7a6369e5c8d3db8bf01cdc5981f6ee35fbdf3ff4fb AS build
WORKDIR /src
ARG VERSION=0.0.0-local
COPY global.json Directory.Build.props Directory.Build.targets ./
@@ -9,7 +9,7 @@ RUN dotnet restore src/Heimdall.Agent/Heimdall.Agent.csproj -p:HeimdallOnnxRunti
RUN dotnet publish src/Heimdall.Agent/Heimdall.Agent.csproj -c Release --no-restore -o /out \
-p:HeimdallOnnxRuntime=GPU -p:Version=$VERSION -p:ContinuousIntegrationBuild=true
FROM mcr.microsoft.com/dotnet/aspnet:10.0-noble@sha256:de0ee358cdd672f7017a003bed21e9ac9ed48a27c922a59b18175b6e82fa7fee AS dotnet-runtime
FROM mcr.microsoft.com/dotnet/aspnet:10.0-noble@sha256:bfd912c83295ce66d4b706ebb8541b9f14259b0e76fbb88b2751f58ce2399d2e AS dotnet-runtime
FROM nvidia/cuda:12.8.1-cudnn-runtime-ubuntu24.04@sha256:9175fa92f96de35a8cfb9493f0dfcf9435c7a597e9d95ad41d2cae382a95e3f9 AS runtime
WORKDIR /app
+11 -1
View File
@@ -9,14 +9,18 @@ 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.
- `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 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.
- Camera counts and lists consider only Online cameras connected. An enabled Offline/Error camera remains enabled in the Agent configuration but is not counted as Online. UI toggle messages treat every status except Disabled as enabled.
- Agent identity and API key are protected in `AgentState` under the configured state directory. Mount a project-scoped volume there so a restart reuses the same Agent identity and the Central configuration is refetched from persistent camera state.
## Local verification
The Central status contract is covered by `ToggleCameraStatusCommandTests` and the `CamerasControllerTests.ToggleStatus_WithAuth_TogglesCamera` relational API test: activation persists Offline, the authorized same-site Agent status endpoint can confirm Online, and a subsequent administrative toggle persists Disabled. Run these focused tests alongside the Agent lifecycle suites when changing this contract.
Run the focused Agent lifecycle suites:
```bash
@@ -51,3 +55,9 @@ The fifth disposable Compose attempt used `/proc/*/comm == ffmpeg`, avoiding sel
## Sixth source-built run
The sixth run kept the FFmpeg process deadline separate from the config ACK deadline and verified exact initial digest equality between the Central config version and Agent `LastAppliedCameraConfigVersion`. It failed the OFF process bound: Central and Agent effective config both showed Disabled, but `/proc/*/comm` reached zero only after the two-second assertion timed out. No restart-OFF/persisted identity acceptance ran. Treat OFF <2 seconds and OFF restart persistence as unverified; investigate the measured delay before changing the acceptance threshold.
## 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, 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.
+2
View File
@@ -11,4 +11,6 @@ Heimdall server, CPU Agent, and NVIDIA Agent images use Ubuntu 24.04 runtime lay
For acceptance, build Central, CPU Agent, and NVIDIA Agent from the changed checkout under unique Compose image tags with synthetic credentials, loopback ports, project-scoped volumes/network, and an EXIT cleanup trap. Verify Central health and the native Agent installer and supervisor URLs; build the NVIDIA image without claiming GPU runtime validation. Scan all three built images with the same pinned Trivy version, vulnerability DB repositories, and HIGH/CRITICAL exit policy used by `scripts/ci/security.sh`. A passing acceptance requires zero HIGH/CRITICAL findings, successful teardown, no project containers/volumes/networks, and removal plus absence checks for every exact local tag. Retain upstream base and scanner images.
When Trivy reports fixed .NET runtime advisories, update the pinned SDK and ASP.NET runtime manifest-list digests together across all three Dockerfiles and every SDK container in `.gitea/workflows/build.yml`. CI must use the SDK matching the updated lockfile, or locked restore fails against stale SDK reference assets. Confirm the new tags and digests against Microsoft's .NET release notes and `docker buildx imagetools inspect`; keep the SDK major/minor aligned with `global.json`. For the November 2026 ASP.NET Core 10.0.15 security update, the `10.0-noble` tags must resolve to images containing runtime 10.0.15, which fixes CVE-2026-114146, CVE-2026-114147, and CVE-2026-114149. Do not suppress these findings or change the CI severity threshold.
The CI image scan is a merge gate. Do not publish or merge around a failed scan; inspect the report and correct the affected package, then rerun the complete workflow. Keep Gitea issue evidence split between disposable local acceptance and the actual CI publication run.
@@ -23,7 +23,7 @@ public class ToggleCameraStatusCommandHandler : IRequestHandler<ToggleCameraStat
var oldStatus = camera.Status;
var newStatus = camera.Status == CameraStatus.Disabled
? CameraStatus.Online
? CameraStatus.Offline
: CameraStatus.Disabled;
camera.SetStatus(newStatus);
@@ -633,7 +633,7 @@ else
if (result.Succeeded && result.Data is not null)
{
_camera.Status = result.Data.Status;
Snackbar.Add(result.Data.Status == "Online" ? Text["CameraDetail_Enabled"] : Text["CameraDetail_Disabled"], Severity.Success);
Snackbar.Add(result.Data.Status != "Disabled" ? Text["CameraDetail_Enabled"] : Text["CameraDetail_Disabled"], Severity.Success);
}
else _editError = result.ErrorMessage ?? Text["CameraDetail_StatusError"];
}
@@ -638,7 +638,7 @@
{
camera.Status = result.Data.Status;
Snackbar.Add(
result.Data.Status == "Online" ? string.Format(Language.Culture, Text["CamerasPage_CameraEnabled"], camera.Name) : string.Format(Language.Culture, Text["CamerasPage_CameraDisabled"], camera.Name),
result.Data.Status != "Disabled" ? string.Format(Language.Culture, Text["CamerasPage_CameraEnabled"], camera.Name) : string.Format(Language.Culture, Text["CamerasPage_CameraDisabled"], camera.Name),
Severity.Success);
}
else
@@ -10,6 +10,7 @@ using Heimdall.Application.AgentLogs.Queries.GetAgentLogs;
using Heimdall.Application.Inventory.Queries.GetAgentMetricHistory;
using Heimdall.Application.Cameras.Commands.ReportCameraStatus;
using Heimdall.Application.DTOs;
using Heimdall.Api.Security;
using Heimdall.Domain.Enums;
using Heimdall.Infrastructure.Security;
using MediatR;
@@ -24,6 +25,8 @@ namespace Heimdall.Api.Controllers;
[EnableRateLimiting("Api")]
public class AgentsController : ControllerBase
{
private readonly ResourceAccess _resourceAccess;
/// <summary>Query parameters for agent log retrieval.</summary>
public record AgentLogsQuery(
[FromQuery] int Page = 1,
@@ -35,7 +38,11 @@ public class AgentsController : ControllerBase
private readonly IMediator _mediator;
public AgentsController(IMediator mediator) => _mediator = mediator;
public AgentsController(IMediator mediator, ResourceAccess resourceAccess)
{
_mediator = mediator;
_resourceAccess = resourceAccess;
}
/// <summary>Register an agent using a site registration token.</summary>
[AllowAnonymous]
@@ -149,6 +156,12 @@ public class AgentsController : ControllerBase
public async Task<IActionResult> ReportCameraStatus(
Guid id, Guid cameraId, [FromBody] ReportCameraStatusRequest request, CancellationToken ct)
{
var requester = await _resourceAccess.ResolveAsync(User, ct);
if (requester is null || requester.Kind != RequesterKind.Agent ||
!await _resourceAccess.AgentAsync(requester, id, ct) ||
!await _resourceAccess.CameraAsync(requester, cameraId, ct))
return Forbid();
if (!Enum.TryParse<CameraStatus>(request.Status, true, out var status))
return BadRequest(new { error = $"Invalid status: {request.Status}" });
@@ -171,7 +171,7 @@ public class CamerasController : ControllerBase
: StatusCode(result.StatusCode ?? 400, new { error = result.Error });
}
/// <summary>Toggle a camera between Online and Disabled.</summary>
/// <summary>Toggle a camera between enabled (initially Offline) and Disabled.</summary>
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraWrite)]
[HttpPost("{id:guid}/toggle-status")]
[ProducesResponseType(typeof(CameraResponse), StatusCodes.Status200OK)]
+3 -3
View File
@@ -44,9 +44,9 @@
},
"Microsoft.AspNetCore.App.Internal.Assets": {
"type": "Direct",
"requested": "[10.0.14, )",
"resolved": "10.0.14",
"contentHash": "T1IOYbID1msKjQEh684HebnN+Xnq/pocMXDukOMZtzzPTf9c4/30+/JndM/1txrqwuSYqWvLiAQWzu4U93cshw=="
"requested": "[10.0.15, )",
"resolved": "10.0.15",
"contentHash": "cineG7aU2cpo+CC5rDORY4bFRya0mlaULDpzQ+ncfG0tMyZlWATyVAo2P29i0hH40EElK5O204pjT4XEYALb6g=="
},
"Microsoft.AspNetCore.OpenApi": {
"type": "Direct",
@@ -20,7 +20,7 @@ public class ToggleCameraStatusCommandTests
}
[Fact]
public async Task Toggle_disabled_camera_should_set_online()
public async Task Toggle_disabled_camera_should_set_offline_until_agent_confirms_connectivity()
{
var context = Substitute.For<IApplicationDbContext>();
context.Cameras.Returns(MockDbSetHelper.CreateFor<Camera>([_disabledCamera]));
@@ -30,7 +30,7 @@ public class ToggleCameraStatusCommandTests
result.IsSuccess.ShouldBeTrue();
result.Data.ShouldNotBeNull();
result.Data.Status.ShouldBe(CameraStatus.Online);
result.Data.Status.ShouldBe(CameraStatus.Offline);
}
[Fact]
@@ -76,6 +76,6 @@ public class ToggleCameraStatusCommandTests
context.AuditLogs.Received(1).Add(Arg.Is<AuditLog>(log => log != null
&& log.UserId == actorId && log.Action == "Camera.StatusChanged"
&& log.OldValue!.Contains("\"status\":\"Disabled\"")
&& log.NewValue!.Contains("\"status\":\"Online\"")));
&& log.NewValue!.Contains("\"status\":\"Offline\"")));
}
}
@@ -67,11 +67,58 @@ public class CamerasControllerTests : PostgresTestBase
var cameraId = cameraContent.GetProperty("id").GetGuid();
cameraContent.GetProperty("status").GetString().ShouldBe("Disabled");
// Toggle → Online
// Activation is enabled but has no connectivity evidence yet.
var toggleResponse = await client.PostAsync($"api/cameras/{cameraId}/toggle-status", null);
toggleResponse.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
var toggled = await toggleResponse.Content.ReadFromJsonAsync<JsonElement>();
toggled.GetProperty("status").GetString().ShouldBe("Online");
toggled.GetProperty("status").GetString().ShouldBe("Offline");
var cameraResponse = await client.GetAsync($"api/cameras/{cameraId}");
var camera = await cameraResponse.Content.ReadFromJsonAsync<JsonElement>();
camera.GetProperty("status").GetString().ShouldBe("Offline");
var tokenResponse = await client.PostAsync($"api/sites/{siteId}/tokens", null);
var siteToken = (await tokenResponse.Content.ReadFromJsonAsync<JsonElement>())
.GetProperty("token").GetString()!;
var registerResponse = await client.PostAsJsonAsync("api/agents/register", new
{
token = siteToken,
hostname = "camera-connectivity-agent",
version = "1.0.0-test"
});
var registration = await registerResponse.Content.ReadFromJsonAsync<JsonElement>();
var agentId = registration.GetProperty("agentId").GetGuid();
var apiKey = registration.GetProperty("apiKey").GetString()!;
var agentClient = Factory.CreateClient();
agentClient.DefaultRequestHeaders.Add("X-API-Key", apiKey);
var heartbeatResponse = await agentClient.PostAsJsonAsync(
$"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,
agentId,
reason = "integration test"
});
assignmentResponse.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
var reportResponse = await agentClient.PutAsJsonAsync(
$"api/agents/{agentId}/cameras/{cameraId}/status", new { status = "Online" });
reportResponse.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
var wrongAgentReport = await agentClient.PutAsJsonAsync(
$"api/agents/{Guid.NewGuid()}/cameras/{cameraId}/status", new { status = "Offline" });
wrongAgentReport.StatusCode.ShouldBe(System.Net.HttpStatusCode.Forbidden);
cameraResponse = await client.GetAsync($"api/cameras/{cameraId}");
camera = await cameraResponse.Content.ReadFromJsonAsync<JsonElement>();
camera.GetProperty("status").GetString().ShouldBe("Online");
// Toggle back → Disabled
var toggleBack = await client.PostAsync($"api/cameras/{cameraId}/toggle-status", null);