Repository navigation
Description
Describe the bug
I'm attempting to get the digest of a built image, as input to attestation tools (and to ensure tags aren't maliciously overwritten), but the value is wrong or otherwise doesn't match the hash of the built image if it's not published.
More specifically, in order to get a "correct" value, it must either be pushed to a registry or zipped to an archive.
To Reproduce
- Create a simple project, eg via
dotnet new web --output repro - Modify the
.csprojto look like the following:<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <ContainerRepository>somerepo</ContainerRepository> <ContainerImageTags>someversion</ContainerImageTags> <ContainerImageFormat>OCI</ContainerImageFormat> </PropertyGroup> <Target Name="OutputContainerInformation" AfterTargets="PublishContainer"> <WriteLinesToFile File="output.txt" Lines="container-digest=$(GeneratedContainerDigest)" /> </Target> </Project>
- Build the project image via
dotnet publish -t:PublishContainer. This builds the image into your local docker/podman system, and also outputs the generated digest intooutput.txt. - Run
docker inspect somerepo:someversion --format '{{.Id}}'to extract the image hash from the built image. Contrast with the value inoutput.txt, which is different.
On the other hand, if the image is packaged into an archive, the hash matches in both places. Starting from the above:
- Run
dotnet publish -t:PublishContainer -p:ContainerArchiveOutputPath=something.tarto generate the archive - Run
docker load --input something.tar. - Inspect the uploaded docker image again, and compare the hash with the hash from
output.txt. The hashes now match.
Also, when creating an archive it leaves off the container registry (eg, if you supplied -p:ContainerRegistry=someregistry.com, even though it's valid to include that information in the archive (saving an image does so).
Further technical details
details of dotnet --info
.NET SDK: Version: 8.0.415 Commit: 7bd5a8c970 Workload version: 8.0.400-manifests.c414f008 MSBuild version: 17.11.48+02bf66295
Runtime Environment:
OS Name: debian
OS Version: 12
OS Platform: Linux
RID: linux-x64
Base Path: /usr/share/dotnet/sdk/8.0.415/
.NET workloads installed:
Configured to use loose manifests when installing new manifests.
There are no installed workloads to display.
Host:
Version: 8.0.21
Architecture: x64
Commit: 362ab6669d
.NET SDKs installed:
8.0.415 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.21 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.21 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsCurrent Release
Activity