Skip to content

Commit

Permalink
storage: generate different imageID with partial layers
Browse files Browse the repository at this point in the history
when an image using partial layers is pulled, generate a different
imageID that combines the digest of the TOC for the partial layers
since the partial pull didn't validate the diffID.

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Jun 6, 2023
1 parent 82b559c commit 8fc6be2
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions storage/storage_dest.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ func (s *storageImageDestination) computeID(m manifest.Manifest) string {
// fill in the DiffIDs. It's expected (but not enforced by us) that the number of
// diffIDs corresponds to the number of non-EmptyLayer entries in the history.
var diffIDs []digest.Digest
var tocDigests []digest.Digest
switch m := m.(type) {
case *manifest.Schema1:
// Build a list of the diffIDs we've generated for the non-throwaway FS layers,
Expand All @@ -442,16 +443,39 @@ func (s *storageImageDestination) computeID(m manifest.Manifest) string {
}
diffIDs = append([]digest.Digest{diffID}, diffIDs...)
}
case *manifest.Schema2, *manifest.OCI1:
// We know the ID calculation for these formats doesn't actually use the diffIDs,
// so we don't need to populate the diffID list.
case *manifest.Schema2:
// We know the ID calculation doesn't actually use the diffIDs, so we don't need to populate
// the diffID list.
case *manifest.OCI1:
for _, layer := range m.Layers {
toc, err := chunked.GetTOCDigest(layer.Annotations)
if err != nil {
logrus.Infof("error looking up annotation for layer %q: %v", layer.Digest, err)
continue
}
if toc != nil {
tocDigests = append(tocDigests, *toc)
}
}
default:
return ""
}
id, err := m.ImageID(diffIDs)
if err != nil {
return ""
}

// If the image is using any partial layer, let's generate a new image ID by combining the
// original image ID with the TOC digest of the partial layers.
if len(tocDigests) > 0 {
for _, d := range tocDigests {
id = id + "+" + string(d)
}
newID := digest.Canonical.Digester()
_, err = newID.Hash().Write([]byte(id))
id = newID.Digest().Hex()
}

return id
}

Expand Down

0 comments on commit 8fc6be2

Please sign in to comment.