Skip to content

Commit

Permalink
Backfill artifactType and SubjectDigest when validating manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Feb 21, 2025
1 parent d4b9d30 commit ff03920
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 11 deletions.
58 changes: 47 additions & 11 deletions internal/keppel/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ import (
// ParsedManifest is an interface that can interrogate manifests about the blobs
// and submanifests referenced therein.
type ParsedManifest interface {
// BlobReferences returns all blobs referenced by this manifest.
BlobReferences() []manifest.LayerInfo
// FindImageConfigBlob returns the descriptor of the blob containing this
// manifest's image configuration, or nil if the manifest does not have an image
// configuration.
FindImageConfigBlob() *types.BlobInfo
// FindImageLayerBlobs returns the descriptors of the blobs containing this
// manifest's image layers, or an empty list if the manifest does not have layers.
FindImageLayerBlobs() []manifest.LayerInfo
// BlobReferences returns all blobs referenced by this manifest.
BlobReferences() []manifest.LayerInfo
// GetArtifactType returns the artifactType of OCI images
GetArtifactType() string
// GetSubject returns the subject of OCI images
GetSubject() *imagespecs.Descriptor
// ManifestReferences returns all manifests referenced by this manifest.
ManifestReferences(pf models.PlatformFilter) []imagespecs.Descriptor
// AcceptableAlternates returns the subset of ManifestReferences() that is
Expand Down Expand Up @@ -95,6 +99,10 @@ type v2ManifestListAdapter struct {
m *manifest.Schema2List
}

func (a v2ManifestListAdapter) BlobReferences() []manifest.LayerInfo {
return nil
}

func (a v2ManifestListAdapter) FindImageConfigBlob() *types.BlobInfo {
return nil
}
Expand All @@ -103,7 +111,11 @@ func (a v2ManifestListAdapter) FindImageLayerBlobs() []manifest.LayerInfo {
return nil
}

func (a v2ManifestListAdapter) BlobReferences() []manifest.LayerInfo {
func (a v2ManifestListAdapter) GetArtifactType() string {
return ""
}

func (a v2ManifestListAdapter) GetSubject() *imagespecs.Descriptor {
return nil
}

Expand Down Expand Up @@ -154,6 +166,11 @@ type v2ManifestAdapter struct {
m *manifest.Schema2
}

func (a v2ManifestAdapter) BlobReferences() []manifest.LayerInfo {
references := []manifest.LayerInfo{{BlobInfo: a.m.ConfigInfo()}}
return append(references, a.m.LayerInfos()...)
}

func (a v2ManifestAdapter) FindImageConfigBlob() *types.BlobInfo {
config := a.m.ConfigInfo()
return &config
Expand All @@ -163,9 +180,12 @@ func (a v2ManifestAdapter) FindImageLayerBlobs() []manifest.LayerInfo {
return a.m.LayerInfos()
}

func (a v2ManifestAdapter) BlobReferences() []manifest.LayerInfo {
references := []manifest.LayerInfo{{BlobInfo: a.m.ConfigInfo()}}
return append(references, a.m.LayerInfos()...)
func (a v2ManifestAdapter) GetArtifactType() string {
return ""
}

func (a v2ManifestAdapter) GetSubject() *imagespecs.Descriptor {
return nil
}

func (a v2ManifestAdapter) ManifestReferences(pf models.PlatformFilter) []imagespecs.Descriptor {
Expand All @@ -181,6 +201,10 @@ type ociIndexAdapter struct {
m *manifest.OCI1Index
}

func (a ociIndexAdapter) BlobReferences() []manifest.LayerInfo {
return nil
}

func (a ociIndexAdapter) FindImageConfigBlob() *types.BlobInfo {
return nil
}
Expand All @@ -189,8 +213,12 @@ func (a ociIndexAdapter) FindImageLayerBlobs() []manifest.LayerInfo {
return nil
}

func (a ociIndexAdapter) BlobReferences() []manifest.LayerInfo {
return nil
func (a ociIndexAdapter) GetArtifactType() string {
return a.m.ArtifactType
}

func (a ociIndexAdapter) GetSubject() *imagespecs.Descriptor {
return a.m.Subject
}

func (a ociIndexAdapter) ManifestReferences(pf models.PlatformFilter) []imagespecs.Descriptor {
Expand All @@ -212,6 +240,11 @@ type ociManifestAdapter struct {
m *manifest.OCI1
}

func (a ociManifestAdapter) BlobReferences() []manifest.LayerInfo {
references := []manifest.LayerInfo{{BlobInfo: a.m.ConfigInfo()}}
return append(references, a.m.LayerInfos()...)
}

func (a ociManifestAdapter) FindImageConfigBlob() *types.BlobInfo {
// Standard OCI images have this specific MediaType for their config blob, and
// this is the format that we can inspect.
Expand All @@ -229,9 +262,12 @@ func (a ociManifestAdapter) FindImageLayerBlobs() []manifest.LayerInfo {
return a.m.LayerInfos()
}

func (a ociManifestAdapter) BlobReferences() []manifest.LayerInfo {
references := []manifest.LayerInfo{{BlobInfo: a.m.ConfigInfo()}}
return append(references, a.m.LayerInfos()...)
func (a ociManifestAdapter) GetArtifactType() string {
return a.m.ArtifactType
}

func (a ociManifestAdapter) GetSubject() *imagespecs.Descriptor {
return a.m.Subject
}

func (a ociManifestAdapter) ManifestReferences(pf models.PlatformFilter) []imagespecs.Descriptor {
Expand Down
6 changes: 6 additions & 0 deletions internal/processor/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ func (p *Processor) validateAndStoreManifestCommon(ctx context.Context, account
manifest.MinLayerCreatedAt = keppel.MinMaybeTime(refsInfo.MinCreationTime, configInfo.MinCreationTime)
manifest.MaxLayerCreatedAt = keppel.MaxMaybeTime(refsInfo.MaxCreationTime, configInfo.MaxCreationTime)

// backfill information incase the manifest was uploaded before we supported them
manifest.ArtifactType = manifestParsed.GetArtifactType()
if subject := manifestParsed.GetSubject(); subject != nil {
manifest.SubjectDigest = subject.Digest
}

// create or update database entries
err = upsertManifest(tx, *manifest, manifestBytes.Bytes(), p.timeNow())
if err != nil {
Expand Down

0 comments on commit ff03920

Please sign in to comment.