fix(build): honor provenance/sbom false in per-service bake attest
Some checks are pending
ci / validate (lint) (push) Waiting to run
ci / validate (validate-docs) (push) Waiting to run
ci / validate (validate-go-mod) (push) Waiting to run
ci / validate (validate-headers) (push) Waiting to run
ci / validate (validate-mocks) (push) Waiting to run
ci / binary (push) Waiting to run
ci / binary-finalize (push) Blocked by required conditions
ci / bin-image-test (push) Waiting to run
ci / test (push) Waiting to run
ci / e2e (plugin, oldstable, graphdriver) (push) Waiting to run
ci / e2e (standalone, oldstable, graphdriver) (push) Waiting to run
ci / e2e (plugin, stable, containerd) (push) Waiting to run
ci / e2e (plugin, stable, graphdriver) (push) Waiting to run
ci / e2e (standalone, stable, containerd) (push) Waiting to run
ci / e2e (standalone, stable, graphdriver) (push) Waiting to run
ci / coverage (push) Blocked by required conditions
ci / release (push) Blocked by required conditions
docs-upstream / docs-yaml (push) Waiting to run
docs-upstream / validate (push) Blocked by required conditions
merge / bin-image-prepare (push) Waiting to run
merge / bin-image (push) Blocked by required conditions
merge / module-image (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
zizmor / zizmor (push) Waiting to run

When a service set `build.provenance: false` (or `sbom: false`), the
bake attest entry was silently omitted (the field is `omitempty`),
so BuildKit applied its defaults and attached a provenance attestation
anyway. The attestation changes the manifest-list digest on every build,
which caused containers to be needlessly recreated on `up --build`.

Emit `"type=<t>,disabled=true"` instead, which BuildKit's
`Attest.UnmarshalText` parses as `Disabled:true` and forwards to
BuildKit as an explicit disable signal.

Extract `appendAttest` to avoid duplicating the three-branch switch
for both provenance and sbom.

Fixes #14111

Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
This commit is contained in:
Guillaume Lours 2026-08-20 21:09:26 +02:00 • committed by Nicolas De loof
parent a472f714d5
commit 03ad3cc1c2
2 changed files with 62 additions and 17 deletions

View file

@ -599,25 +599,21 @@ func toBakeSecrets(project *types.Project, secrets []types.ServiceSecretConfig)
func toBakeAttest(buildConfig types.BuildConfig) []string {
var attests []string
attests = appendAttest(attests, "provenance", buildConfig.Provenance)
attests = appendAttest(attests, "sbom", buildConfig.SBOM)
return attests
}
// Handle per-service provenance configuration (only from build config, not global options)
if buildConfig.Provenance != "" {
if buildConfig.Provenance == "true" {
attests = append(attests, "type=provenance")
} else if buildConfig.Provenance != "false" {
attests = append(attests, fmt.Sprintf("type=provenance,%s", buildConfig.Provenance))
}
func appendAttest(attests []string, attestType, value string) []string {
switch value {
case "":
case "true":
attests = append(attests, "type="+attestType)
case "false":
attests = append(attests, "type="+attestType+",disabled=true")
default:
attests = append(attests, fmt.Sprintf("type=%s,%s", attestType, value))
}
// Handle per-service SBOM configuration (only from build config, not global options)
if buildConfig.SBOM != "" {
if buildConfig.SBOM == "true" {
attests = append(attests, "type=sbom")
} else if buildConfig.SBOM != "false" {
attests = append(attests, fmt.Sprintf("type=sbom,%s", buildConfig.SBOM))
}
}
return attests
}

View file

@ -51,6 +51,55 @@ func TestBakeTargetNames(t *testing.T) {
})
}
func TestToBakeAttest(t *testing.T) {
tests := []struct {
name string
config types.BuildConfig
expected []string
}{
{
name: "empty — no attest entries",
config: types.BuildConfig{},
expected: nil,
},
{
name: "provenance true",
config: types.BuildConfig{Provenance: "true"},
expected: []string{"type=provenance"},
},
{
name: "provenance false — must disable, not omit",
config: types.BuildConfig{Provenance: "false"},
expected: []string{"type=provenance,disabled=true"},
},
{
name: "provenance mode=max",
config: types.BuildConfig{Provenance: "mode=max"},
expected: []string{"type=provenance,mode=max"},
},
{
name: "sbom true",
config: types.BuildConfig{SBOM: "true"},
expected: []string{"type=sbom"},
},
{
name: "sbom false — must disable, not omit",
config: types.BuildConfig{SBOM: "false"},
expected: []string{"type=sbom,disabled=true"},
},
{
name: "provenance false + sbom false",
config: types.BuildConfig{Provenance: "false", SBOM: "false"},
expected: []string{"type=provenance,disabled=true", "type=sbom,disabled=true"},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
assert.DeepEqual(t, toBakeAttest(tc.config), tc.expected)
})
}
}
// makeConsole must hand the genuine *os.File over when the stream wraps one:
// on Windows, containerd/console rejects anything but the exact
// os.Stdin/Stdout/Stderr values, so a wrapper would disable the TTY progress