diff --git a/skills/central-auto-updates/SKILL.md b/skills/central-auto-updates/SKILL.md index f2bb55c..af4be1d 100644 --- a/skills/central-auto-updates/SKILL.md +++ b/skills/central-auto-updates/SKILL.md @@ -49,7 +49,7 @@ For an explicitly authorized host validation, inspect existing services and data ## Acceptance -Run `bash -n install/install-server.sh`, validate PowerShell syntax when `pwsh` is available, and run `docker compose config --quiet` for both the installer output and `docker/docker-compose.prod.yml`. Exercise a first install and a second run against an isolated temporary directory: confirm secrets and nondefault `.env` values are byte-for-byte unchanged, the old Compose is backed up, missing new variables are added once, and no volume removal command appears. For the Site Install UI, assert generated CPU/GPU Compose and `docker run` references use the corresponding `:latest` Agent image, Compose sets `pull_policy: always`, Docker Run commands set `--pull always`, all paths mount `/var/run/docker.sock`, and the non-root Agent receives the socket group (`DOCKER_GID` in Compose; detected socket GID for Linux `docker run`). Keep signed digest validation for updates dispatched by Central. Then follow `skills/compose-disposable-recipe/SKILL.md` with a unique project, generated credentials, isolated ports/volumes, and an EXIT cleanup trap installed before build/start. Never connect the recipe to a deployed Docker daemon or production data. +Run `bash -n install/install-server.sh`, validate PowerShell syntax when `pwsh` is available, and run `docker compose config --quiet` for both the installer output and `docker/docker-compose.prod.yml`. Exercise a first install and a second run against an isolated temporary directory: confirm secrets and nondefault `.env` values are byte-for-byte unchanged, the old Compose is backed up, missing new variables are added once, and no volume removal command appears. For the Site Install UI, assert generated CPU/GPU Compose and `docker run` references use the corresponding `:latest` Agent image, Compose sets `pull_policy: always`, Docker Run commands set `--pull always`, all paths mount `/var/run/docker.sock`, and the non-root Agent receives the socket group (`DOCKER_GID` in Compose; detected socket GID for Linux `docker run`). Keep signed digest validation for updates dispatched by Central. A signed Agent manifest always requires the CPU image repository and digest; GPU image metadata is optional for CPU-only releases, and must be present as a valid repository/digest pair when either field is supplied. Unit tests cover CPU-only and CPU+GPU signed manifests plus a malformed half-pair. Source-built Compose acceptance probes Central's latest-release API against the configured public Forgejo source and verifies the returned signature and required CPU digest; record whether the current release also carries GPU metadata. Then follow `skills/compose-disposable-recipe/SKILL.md` with a unique project, generated credentials, isolated ports/volumes, and an EXIT cleanup trap installed before build/start. Never connect the recipe to a deployed Docker daemon or production data. When a runtime Dockerfile changes for OS security updates, source-build and health-check the corresponding Central/Agent image, then scan its saved image archive with the pinned Trivy version and the same `HIGH,CRITICAL` severities used by CI. Record the finding IDs and fixed package versions; do not hide a nonzero scan behind application acceptance. diff --git a/src/Heimdall.Agent/packages.gpu.lock.json b/src/Heimdall.Agent/packages.gpu.lock.json index 3462760..75dd3be 100644 --- a/src/Heimdall.Agent/packages.gpu.lock.json +++ b/src/Heimdall.Agent/packages.gpu.lock.json @@ -91,8 +91,8 @@ }, "AutoMapper": { "type": "Transitive", - "resolved": "16.1.1", - "contentHash": "VNEky8JA15ci+oIDRGHITOGOpV4dILsf8pnn24QhDl2urtqgJ2IXiS/V2EtGU17P/+f6OeFQPJETaZXV9QOIZg==", + "resolved": "16.3.0", + "contentHash": "wFTqA37e1I4AOEhTTYlxrqDE8BQ4OB3dqhlv2KwYmHv+a4tn7R1JW2n2bzXb8eTBhWVBSl7iTZ0VxEt0a57D4w==", "dependencies": { "Microsoft.IdentityModel.JsonWebTokens": "8.14.0" } @@ -326,7 +326,7 @@ "heimdall.application": { "type": "Project", "dependencies": { - "AutoMapper": "[16.1.1, )", + "AutoMapper": "[16.3.0, )", "FluentValidation": "[11.11.0, )", "FluentValidation.DependencyInjectionExtensions": "[11.11.0, )", "Heimdall.Domain": "[1.0.0, )", diff --git a/src/Heimdall.Web/Services/AgentReleaseManifestVerifier.cs b/src/Heimdall.Web/Services/AgentReleaseManifestVerifier.cs index 1b62caf..82ed243 100644 --- a/src/Heimdall.Web/Services/AgentReleaseManifestVerifier.cs +++ b/src/Heimdall.Web/Services/AgentReleaseManifestVerifier.cs @@ -32,8 +32,10 @@ public static class AgentReleaseManifestVerifier parsed.Assets.Any(asset => string.IsNullOrWhiteSpace(asset.Key) || asset.Value is null || !IsSha256(asset.Value)) || !IsValidContainerImageRepository(parsed.ContainerImage) || !IsValidContainerImageDigest(parsed.ContainerImageDigest) || - !IsValidContainerImageRepository(parsed.ContainerImageGpu) || - !IsValidContainerImageDigest(parsed.ContainerImageGpuDigest)) + ((parsed.ContainerImageGpu is null) != (parsed.ContainerImageGpuDigest is null)) || + (parsed.ContainerImageGpu is not null && + (!IsValidContainerImageRepository(parsed.ContainerImageGpu) || + !IsValidContainerImageDigest(parsed.ContainerImageGpuDigest)))) return false; manifest = parsed; diff --git a/tests/Heimdall.Web.Tests/Services/AgentReleaseManifestVerifierTests.cs b/tests/Heimdall.Web.Tests/Services/AgentReleaseManifestVerifierTests.cs index fbb16f5..47b0bdd 100644 --- a/tests/Heimdall.Web.Tests/Services/AgentReleaseManifestVerifierTests.cs +++ b/tests/Heimdall.Web.Tests/Services/AgentReleaseManifestVerifierTests.cs @@ -23,6 +23,33 @@ public sealed class AgentReleaseManifestVerifierTests Assert.True(manifest.Assets.ContainsKey("portable")); } + [Fact] + public void TryVerify_AcceptsCpuOnlySignedManifest() + { + using var key = ECDsa.Create(ECCurve.NamedCurves.nistP256); + var bytes = ManifestBytes(includeGpuImage: false); + var signature = key.SignData(bytes, HashAlgorithmName.SHA256, DSASignatureFormat.Rfc3279DerSequence); + + var valid = AgentReleaseManifestVerifier.TryVerify( + key.ExportSubjectPublicKeyInfoPem(), bytes, signature, "1.0.7", out var manifest); + + Assert.True(valid); + Assert.NotNull(manifest); + Assert.Null(manifest.ContainerImageGpu); + Assert.Null(manifest.ContainerImageGpuDigest); + } + + [Fact] + public void TryVerify_RejectsIncompleteGpuImageMetadata() + { + using var key = ECDsa.Create(ECCurve.NamedCurves.nistP256); + var bytes = ManifestBytes(invalidGpuPair: true); + var signature = key.SignData(bytes, HashAlgorithmName.SHA256, DSASignatureFormat.Rfc3279DerSequence); + + Assert.False(AgentReleaseManifestVerifier.TryVerify(key.ExportSubjectPublicKeyInfoPem(), bytes, signature, + "1.0.7", out _)); + } + [Fact] public void TryVerify_RejectsModifiedManifest() { @@ -51,13 +78,23 @@ public sealed class AgentReleaseManifestVerifierTests "1.0.7", out _)); } - private static byte[] ManifestBytes(bool invalidArchiveHash = false) => JsonSerializer.SerializeToUtf8Bytes(new + private static byte[] ManifestBytes(bool invalidArchiveHash = false, bool includeGpuImage = true, + bool invalidGpuPair = false) { - version = "1.0.7", - assets = new { portable = invalidArchiveHash ? "not-a-sha256" : new string('c', 64) }, - containerImage = "eltruncho/heimdall-agent", - containerImageDigest = "sha256:" + new string('a', 64), - containerImageGpu = "eltruncho/heimdall-agent-gpu", - containerImageGpuDigest = "sha256:" + new string('b', 64), - }); + var manifest = new Dictionary + { + ["version"] = "1.0.7", + ["assets"] = new Dictionary + { + ["portable"] = invalidArchiveHash ? "not-a-sha256" : new string('c', 64) + }, + ["containerImage"] = "eltruncho/heimdall-agent", + ["containerImageDigest"] = "sha256:" + new string('a', 64), + }; + if (includeGpuImage || invalidGpuPair) + manifest["containerImageGpu"] = "eltruncho/heimdall-agent-gpu"; + if (includeGpuImage && !invalidGpuPair) + manifest["containerImageGpuDigest"] = "sha256:" + new string('b', 64); + return JsonSerializer.SerializeToUtf8Bytes(manifest); + } }