Skip to content

Commit e55f8b6

Browse files
committed
exporter: force enabling inline attestations for image export
Signed-off-by: Justin Chadwell <[email protected]>
1 parent 4a778a2 commit e55f8b6

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

exporter/containerimage/export.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
7878
RefCfg: cacheconfig.RefConfig{
7979
Compression: compression.New(compression.Default),
8080
},
81-
BuildInfo: true,
81+
BuildInfo: true,
82+
ForceInlineAttestations: true,
8283
},
8384
store: true,
8485
}

exporter/containerimage/opts.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ type ImageCommitOpts struct {
3434
BuildInfoAttrs bool
3535
Annotations AnnotationsGroup
3636
Epoch *time.Time
37+
38+
ForceInlineAttestations bool // force inline attestations to be attached
3739
}
3840

3941
func (c *ImageCommitOpts) Load(opt map[string]string) (map[string]string, error) {

exporter/containerimage/writer.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,24 @@ func (ic *ImageWriter) Commit(ctx context.Context, inp *exporter.Source, session
6969
return nil, err
7070
}
7171

72-
requiredAttestations := false
73-
for _, p := range ps.Platforms {
74-
if atts, ok := inp.Attestations[p.ID]; ok {
75-
atts = attestation.Filter(atts, nil, map[string][]byte{
76-
result.AttestationInlineOnlyKey: []byte(strconv.FormatBool(true)),
77-
})
78-
if len(atts) > 0 {
79-
requiredAttestations = true
80-
break
72+
if !isMap {
73+
// enable index if we need to include attestations
74+
for _, p := range ps.Platforms {
75+
if atts, ok := inp.Attestations[p.ID]; ok {
76+
if !opts.ForceInlineAttestations {
77+
// if we don't need force inline attestations (for oci
78+
// exporter), filter them out
79+
atts = attestation.Filter(atts, nil, map[string][]byte{
80+
result.AttestationInlineOnlyKey: []byte(strconv.FormatBool(true)),
81+
})
82+
}
83+
if len(atts) > 0 {
84+
isMap = true
85+
break
86+
}
8187
}
8288
}
8389
}
84-
if requiredAttestations {
85-
isMap = true
86-
}
87-
8890
if opts.Epoch == nil {
8991
if tm, ok, err := epoch.ParseSource(inp); err != nil {
9092
return nil, err
@@ -108,9 +110,6 @@ func (ic *ImageWriter) Commit(ctx context.Context, inp *exporter.Source, session
108110
if len(ps.Platforms) > 1 {
109111
return nil, errors.Errorf("cannot export multiple platforms without multi-platform enabled")
110112
}
111-
if requiredAttestations {
112-
return nil, errors.Errorf("cannot export attestations without multi-platform enabled")
113-
}
114113

115114
var ref cache.ImmutableRef
116115
var p exptypes.Platform

0 commit comments

Comments
 (0)