fix: pin Docker Agent installs to signed image digests
Heimdall Gitea / Detect CI scope (pull_request) Successful in 6s
Heimdall Gitea / Build and tests (pull_request) Failing after 23m23s
Heimdall Gitea / Build and scan server image (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Build and scan NVIDIA Agent image (pull_request) Skipped
Heimdall Gitea / Publish versioned installer release (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Failing after 2s

This commit is contained in:
arnaud.dartois committed 2026-11-13 17:56:25 +01:00
1 parent 923f9e7a55
commit e6cc3edb67
3 files changed
+45 -23

No files matched your search

+2
View File
@@ -54,3 +54,5 @@ Run `bash -n install/install-server.sh`, validate PowerShell syntax when `pwsh`
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.
If acceptance builds a local Central/helper image, record its project-unique tag before build and remove/verify that exact tag in the same cleanup trap, including on failure. Do not remove registry/base images or use `--rmi all` or broad image pruning; Watchtower's deployment `--cleanup` behavior is separate from disposable-test cleanup.
- The Site Install UI must retain the CPU/GPU image digest returned by Central and generate immutable `repository@sha256:digest` references for both Compose and Docker Run. Never reduce a verified release image to a mutable `:latest` tag. Test with distinct CPU/GPU digests and reject malformed/missing digest values by disabling Docker install generation.
@@ -248,12 +248,8 @@ else if (_method == "windows-service")
!string.IsNullOrWhiteSpace(release?.SignedManifest) &&
!string.IsNullOrWhiteSpace(release?.ManifestSignature) &&
release?.Assets.Count > 0;
if (!string.IsNullOrWhiteSpace(release?.ContainerImage) &&
!string.IsNullOrWhiteSpace(release.ContainerImageDigest))
_agentImageReference = LatestImageReference(release.ContainerImage);
if (!string.IsNullOrWhiteSpace(release?.ContainerImageGpu) &&
!string.IsNullOrWhiteSpace(release.ContainerImageGpuDigest))
_agentGpuImageReference = LatestImageReference(release.ContainerImageGpu);
_agentImageReference = ImmutableImageReference(release?.ContainerImage, release?.ContainerImageDigest);
_agentGpuImageReference = ImmutableImageReference(release?.ContainerImageGpu, release?.ContainerImageGpuDigest);
_updatePublicKeyPem = release?.UpdatePublicKeyPem;
}
catch
@@ -266,12 +262,14 @@ else if (_method == "windows-service")
}
}
private static string LatestImageReference(string image)
private static string? ImmutableImageReference(string? image, string? digest)
{
var lastSlash = image.LastIndexOf('/');
var lastColon = image.LastIndexOf(':');
var repository = lastColon > lastSlash ? image[..lastColon] : image;
return $"{repository}:latest";
if (string.IsNullOrWhiteSpace(image) || image.Contains('@', StringComparison.Ordinal) ||
string.IsNullOrWhiteSpace(digest) || !System.Text.RegularExpressions.Regex.IsMatch(
digest, "^sha256:[0-9a-fA-F]{64}$", System.Text.RegularExpressions.RegexOptions.CultureInvariant))
return null;
return $"{image}@{digest.ToLowerInvariant()}";
}
private string ComposeYaml
@@ -82,7 +82,7 @@ public class SiteDetailTests : PageTestBase
cut.Markup.ShouldContain("Agent__SiteToken");
cut.Markup.ShouldContain("Régénérer");
var compose = cut.Find("pre code").TextContent;
compose.ShouldContain("image: registry.example/heimdall-agent:latest");
compose.ShouldContain("image: registry.example/heimdall-agent@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
compose.ShouldContain("pull_policy: always");
compose.ShouldContain("network_mode: host");
compose.ShouldContain("Agent__CentralUrl: \"http://localhost\"");
@@ -95,7 +95,7 @@ public class SiteDetailTests : PageTestBase
var agent = GetAgentService(ParseCompose(compose));
agent.Children.ShouldNotContainKey(new YamlScalarNode("deploy"));
((YamlScalarNode)agent.Children[new YamlScalarNode("image")]).Value
.ShouldBe("registry.example/heimdall-agent:latest");
.ShouldBe("registry.example/heimdall-agent@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
((YamlScalarNode)agent.Children[new YamlScalarNode("pull_policy")]).Value.ShouldBe("always");
var volumes = (YamlSequenceNode)agent.Children[new YamlScalarNode("volumes")];
volumes.Children.Select(node => ((YamlScalarNode)node).Value)
@@ -112,12 +112,12 @@ public class SiteDetailTests : PageTestBase
{
var commands = cut.FindAll("pre code").Select(code => code.TextContent).ToArray();
commands.Length.ShouldBe(6);
commands[0].ShouldContain("docker pull registry.example/heimdall-agent:latest");
commands[0].ShouldContain("docker pull registry.example/heimdall-agent@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
commands[1].ShouldContain("--pull always");
commands[1].ShouldContain("registry.example/heimdall-agent:latest");
commands[3].ShouldContain("docker pull 'registry.example/heimdall-agent:latest'");
commands[1].ShouldContain("registry.example/heimdall-agent@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
commands[3].ShouldContain("docker pull 'registry.example/heimdall-agent@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'");
commands[4].ShouldContain("'--pull','always'");
commands[4].ShouldContain("'registry.example/heimdall-agent:latest'");
commands[4].ShouldContain("'registry.example/heimdall-agent@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'");
});
}
@@ -183,7 +183,7 @@ public class SiteDetailTests : PageTestBase
cut.WaitForAssertion(() =>
{
var compose = cut.Find("pre code").TextContent;
compose.ShouldContain("image: registry.example/heimdall-agent-gpu:latest");
compose.ShouldContain("image: registry.example/heimdall-agent-gpu@sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
compose.ShouldContain("pull_policy: always");
compose.ShouldContain("Agent__InferenceExecutionProvider: CUDA");
compose.ShouldContain("driver: nvidia");
@@ -191,7 +191,7 @@ public class SiteDetailTests : PageTestBase
compose.ShouldContain("\n deploy:\n resources:\n reservations:");
var agent = GetAgentService(ParseCompose(compose));
((YamlScalarNode)agent.Children[new YamlScalarNode("image")]).Value.ShouldBe(
"registry.example/heimdall-agent-gpu:latest");
"registry.example/heimdall-agent-gpu@sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
((YamlScalarNode)agent.Children[new YamlScalarNode("pull_policy")]).Value.ShouldBe("always");
var deploy = (YamlMappingNode)agent.Children[new YamlScalarNode("deploy")];
var resources = (YamlMappingNode)deploy.Children[new YamlScalarNode("resources")];
@@ -208,11 +208,33 @@ public class SiteDetailTests : PageTestBase
run.ShouldContain("--gpus all");
run.ShouldContain("Agent__InferenceExecutionProvider=CUDA");
run.ShouldContain("--pull always");
run.ShouldContain("registry.example/heimdall-agent-gpu:latest");
run.ShouldContain("registry.example/heimdall-agent-gpu@sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
run.ShouldContain("--group-add \"$(stat -c '%g' /var/run/docker.sock)\"");
run.ShouldContain("-v /var/run/docker.sock:/var/run/docker.sock");
commands[4].ShouldContain("'--pull','always'");
commands[4].ShouldContain("'registry.example/heimdall-agent-gpu:latest'");
commands[4].ShouldContain("'registry.example/heimdall-agent-gpu@sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'");
});
}
[Fact]
public void SiteDetail_RefuseDockerComposeQuandDigestImageInvalide()
{
Handler.OnGet("api/updates/latest", AgentRelease("sha256:not-a-digest"));
Handler.OnGet("api/sites/", new SiteItem(
SiteId, "Site Principal", null, "UTC", null, true, false, DateTime.UtcNow.AddDays(-10)));
Handler.On(HttpMethod.Post, "api/sites/", new TokenResult("tok-invalid-digest", DateTime.UtcNow.AddHours(24)));
LoginAs();
var cut = RenderPage<SiteDetail>(p => p.Add(x => x.Id, SiteId));
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Générer un token"));
cut.FindAll("button").Single(b => b.TextContent.Contains("Générer un token")).Click();
cut.WaitForAssertion(() => cut.Markup.ShouldContain("tok-invalid-digest"));
cut.FindAll("button").Single(b => b.TextContent.Contains("Docker", StringComparison.OrdinalIgnoreCase)).Click();
cut.WaitForAssertion(() =>
{
cut.Markup.ShouldContain("Le manifeste d’image de l’agent fourni par Central est indisponible");
cut.FindAll(".installer-copy-box").ShouldBeEmpty();
});
}
@@ -273,11 +295,11 @@ public class SiteDetailTests : PageTestBase
LastUsedAt = lastUsed,
};
private static LatestReleaseInfo AgentRelease() => new()
private static LatestReleaseInfo AgentRelease(string? imageDigest = null) => new()
{
Version = "1.0.0",
ContainerImage = "registry.example/heimdall-agent",
ContainerImageDigest = "sha256:" + new string('a', 64),
ContainerImageDigest = imageDigest ?? "sha256:" + new string('a', 64),
UpdatePublicKeyPem = "test-public-key",
SignedManifest = "eyJ2ZXJzaW9uIjoiMS4wLjAifQ==",
ManifestSignature = "c2lnbmF0dXJl",