From 369c85bab99bbebe31fe059134a40ef711700b93 Mon Sep 17 00:00:00 2001 From: Zack Brady Date: Wed, 1 Oct 2025 11:56:36 -0400 Subject: [PATCH] allow loading of docker tarballs (#452) Signed-off-by: Adam Martin Co-authored-by: Adam Martin --- cmd/hauler/cli/store/load.go | 39 ++++++++++++++++++++++++++++++++++++ pkg/consts/consts.go | 2 ++ 2 files changed, 41 insertions(+) diff --git a/cmd/hauler/cli/store/load.go b/cmd/hauler/cli/store/load.go index 029c1a3..1c26b4a 100644 --- a/cmd/hauler/cli/store/load.go +++ b/cmd/hauler/cli/store/load.go @@ -2,6 +2,7 @@ package store import ( "context" + "encoding/json" "io" "net/url" "os" @@ -15,6 +16,8 @@ import ( "hauler.dev/go/hauler/pkg/getter" "hauler.dev/go/hauler/pkg/log" "hauler.dev/go/hauler/pkg/store" + + ocispec "github.com/opencontainers/image-spec/specs-go/v1" ) // extracts the contents of an archived oci layout to an existing oci layout @@ -85,6 +88,42 @@ func unarchiveLayoutTo(ctx context.Context, haulPath string, dest string, tempDi return err } + // ensure the incoming index.json has the correct annotations. + data, err := os.ReadFile(tempDir + "/index.json") + if err != nil { + return (err) + } + + var idx ocispec.Index + if err := json.Unmarshal(data, &idx); err != nil { + return (err) + } + + for i := range idx.Manifests { + if idx.Manifests[i].Annotations == nil { + idx.Manifests[i].Annotations = make(map[string]string) + } + if _, exists := idx.Manifests[i].Annotations[consts.KindAnnotationName]; !exists { + idx.Manifests[i].Annotations[consts.KindAnnotationName] = consts.KindAnnotationImage + } + if ref, ok := idx.Manifests[i].Annotations[consts.ContainerdImageNameKey]; ok { + if slash := strings.Index(ref, "/"); slash != -1 { + ref = ref[slash+1:] + } + if idx.Manifests[i].Annotations[consts.ImageRefKey] != ref { + idx.Manifests[i].Annotations[consts.ImageRefKey] = ref + } + } + } + + out, err := json.MarshalIndent(idx, "", " ") + if err != nil { + return err + } + if err := os.WriteFile(tempDir+"/index.json", out, 0644); err != nil { + return err + } + s, err := store.NewLayout(tempDir) if err != nil { return err diff --git a/pkg/consts/consts.go b/pkg/consts/consts.go index 2ef6ab0..aef4821 100644 --- a/pkg/consts/consts.go +++ b/pkg/consts/consts.go @@ -42,6 +42,7 @@ const ( HaulerVendorPrefix = "vnd.hauler" // annotation keys + ContainerdImageNameKey = "io.containerd.image.name" KindAnnotationName = "kind" KindAnnotationImage = "dev.cosignproject.cosign/image" KindAnnotationIndex = "dev.cosignproject.cosign/imageIndex" @@ -49,6 +50,7 @@ const ( ImageAnnotationPlatform = "hauler.dev/platform" ImageAnnotationRegistry = "hauler.dev/registry" ImageAnnotationTlog = "hauler.dev/use-tlog-verify" + ImageRefKey = "org.opencontainers.image.ref.name" // cosign keyless validation options ImageAnnotationCertIdentity = "hauler.dev/certificate-identity"