Skip to content

Commit f335be0

Browse files
authored
Merge pull request moby#3466 from jedevc/export-force-inline-attestation-image
exporter: force enabling inline attestations for image export
2 parents 4a778a2 + 3eaf157 commit f335be0

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
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: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ import (
1212
)
1313

1414
const (
15-
keyImageName = "name"
16-
keyLayerCompression = "compression"
17-
keyCompressionLevel = "compression-level"
18-
keyForceCompression = "force-compression"
19-
keyOCITypes = "oci-mediatypes"
20-
keyBuildInfo = "buildinfo"
21-
keyBuildInfoAttrs = "buildinfo-attrs"
15+
keyImageName = "name"
16+
keyLayerCompression = "compression"
17+
keyCompressionLevel = "compression-level"
18+
keyForceCompression = "force-compression"
19+
keyOCITypes = "oci-mediatypes"
20+
keyBuildInfo = "buildinfo"
21+
keyBuildInfoAttrs = "buildinfo-attrs"
22+
keyForceInlineAttestations = "attestation-inline"
2223

2324
// preferNondistLayersKey is an exporter option which can be used to mark a layer as non-distributable if the layer reference was
2425
// already found to use a non-distributable media type.
@@ -34,6 +35,8 @@ type ImageCommitOpts struct {
3435
BuildInfoAttrs bool
3536
Annotations AnnotationsGroup
3637
Epoch *time.Time
38+
39+
ForceInlineAttestations bool // force inline attestations to be attached
3740
}
3841

3942
func (c *ImageCommitOpts) Load(opt map[string]string) (map[string]string, error) {
@@ -73,6 +76,8 @@ func (c *ImageCommitOpts) Load(opt map[string]string) (map[string]string, error)
7376
err = parseBoolWithDefault(&c.BuildInfo, k, v, true)
7477
case keyBuildInfoAttrs:
7578
err = parseBoolWithDefault(&c.BuildInfoAttrs, k, v, false)
79+
case keyForceInlineAttestations:
80+
err = parseBool(&c.ForceInlineAttestations, k, v)
7681
case keyPreferNondistLayers:
7782
err = parseBool(&c.RefCfg.PreferNonDistributable, k, v)
7883
default:

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)