Skip to content

Commit

Permalink
exporter: force enabling inline attestations for image export
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Chadwell <me@jedevc.com>
  • Loading branch information
jedevc committed Jan 6, 2023
1 parent 4a778a2 commit e55f8b6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
3 changes: 2 additions & 1 deletion exporter/containerimage/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
RefCfg: cacheconfig.RefConfig{
Compression: compression.New(compression.Default),
},
BuildInfo: true,
BuildInfo: true,
ForceInlineAttestations: true,
},
store: true,
}
Expand Down
2 changes: 2 additions & 0 deletions exporter/containerimage/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type ImageCommitOpts struct {
BuildInfoAttrs bool
Annotations AnnotationsGroup
Epoch *time.Time

ForceInlineAttestations bool // force inline attestations to be attached
}

func (c *ImageCommitOpts) Load(opt map[string]string) (map[string]string, error) {
Expand Down
31 changes: 15 additions & 16 deletions exporter/containerimage/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,24 @@ func (ic *ImageWriter) Commit(ctx context.Context, inp *exporter.Source, session
return nil, err
}

requiredAttestations := false
for _, p := range ps.Platforms {
if atts, ok := inp.Attestations[p.ID]; ok {
atts = attestation.Filter(atts, nil, map[string][]byte{
result.AttestationInlineOnlyKey: []byte(strconv.FormatBool(true)),
})
if len(atts) > 0 {
requiredAttestations = true
break
if !isMap {
// enable index if we need to include attestations
for _, p := range ps.Platforms {
if atts, ok := inp.Attestations[p.ID]; ok {
if !opts.ForceInlineAttestations {
// if we don't need force inline attestations (for oci
// exporter), filter them out
atts = attestation.Filter(atts, nil, map[string][]byte{
result.AttestationInlineOnlyKey: []byte(strconv.FormatBool(true)),
})
}
if len(atts) > 0 {
isMap = true
break
}
}
}
}
if requiredAttestations {
isMap = true
}

if opts.Epoch == nil {
if tm, ok, err := epoch.ParseSource(inp); err != nil {
return nil, err
Expand All @@ -108,9 +110,6 @@ func (ic *ImageWriter) Commit(ctx context.Context, inp *exporter.Source, session
if len(ps.Platforms) > 1 {
return nil, errors.Errorf("cannot export multiple platforms without multi-platform enabled")
}
if requiredAttestations {
return nil, errors.Errorf("cannot export attestations without multi-platform enabled")
}

var ref cache.ImmutableRef
var p exptypes.Platform
Expand Down

0 comments on commit e55f8b6

Please sign in to comment.