Skip to content

Commit 2080b0e

Browse files
committed
history: build arg to opt-in for provenance slsa v1
Signed-off-by: CrazyMax <[email protected]>
1 parent a3b8850 commit 2080b0e

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

frontend/dockerfile/docs/reference.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,15 +2608,16 @@ RUN echo "I'm building for $TARGETPLATFORM"
26082608

26092609
### BuildKit built-in build args
26102610

2611-
| Arg | Type | Description |
2612-
| ------------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
2613-
| `BUILDKIT_CACHE_MOUNT_NS` | String | Set optional cache ID namespace. |
2614-
| `BUILDKIT_CONTEXT_KEEP_GIT_DIR` | Bool | Trigger Git context to keep the `.git` directory. |
2615-
| `BUILDKIT_INLINE_CACHE`[^2] | Bool | Inline cache metadata to image config or not. |
2616-
| `BUILDKIT_MULTI_PLATFORM` | Bool | Opt into deterministic output regardless of multi-platform output or not. |
2617-
| `BUILDKIT_SANDBOX_HOSTNAME` | String | Set the hostname (default `buildkitsandbox`) |
2618-
| `BUILDKIT_SYNTAX` | String | Set frontend image |
2619-
| `SOURCE_DATE_EPOCH` | Int | Set the Unix timestamp for created image and layers. More info from [reproducible builds](https://reproducible-builds.org/docs/source-date-epoch/). Supported since Dockerfile 1.5, BuildKit 0.11 |
2611+
| Arg | Type | Description |
2612+
|----------------------------------|--------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
2613+
| `BUILDKIT_CACHE_MOUNT_NS` | String | Set optional cache ID namespace. |
2614+
| `BUILDKIT_CONTEXT_KEEP_GIT_DIR` | Bool | Trigger Git context to keep the `.git` directory. |
2615+
| `BUILDKIT_HISTORY_PROVENANCE_V1` | Bool | Enable [SLSA Provenance v1](https://slsa.dev/spec/v1.1/provenance) for build history record. |
2616+
| `BUILDKIT_INLINE_CACHE`[^2] | Bool | Inline cache metadata to image config or not. |
2617+
| `BUILDKIT_MULTI_PLATFORM` | Bool | Opt into deterministic output regardless of multi-platform output or not. |
2618+
| `BUILDKIT_SANDBOX_HOSTNAME` | String | Set the hostname (default `buildkitsandbox`) |
2619+
| `BUILDKIT_SYNTAX` | String | Set frontend image |
2620+
| `SOURCE_DATE_EPOCH` | Int | Set the Unix timestamp for created image and layers. More info from [reproducible builds](https://reproducible-builds.org/docs/source-date-epoch/). Supported since Dockerfile 1.5, BuildKit 0.11 |
26202621

26212622
#### Example: keep `.git` dir
26222623

solver/llbsolver/solver.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"maps"
88
"os"
9+
"strconv"
910
"strings"
1011
"sync"
1112
"time"
@@ -229,12 +230,18 @@ func (s *Solver) recordBuildHistory(ctx context.Context, id string, req frontend
229230
}
230231
}
231232

233+
slsaVersion := provenancetypes.ProvenanceSLSA02
234+
if v, ok := req.FrontendOpt["build-arg:BUILDKIT_HISTORY_PROVENANCE_V1"]; ok {
235+
if b, err := strconv.ParseBool(v); err == nil && b {
236+
slsaVersion = provenancetypes.ProvenanceSLSA1
237+
}
238+
}
239+
232240
makeProvenance := func(name string, res solver.ResultProxy, cap *provenance.Capture) (*controlapi.Descriptor, func(), error) {
233241
span, ctx := tracing.StartSpan(ctx, fmt.Sprintf("create %s history provenance", name))
234242
defer span.End()
235243

236-
// TODO: use provenance slsa v1 for build history?
237-
pc, err := NewProvenanceCreator(ctx2, provenancetypes.ProvenanceSLSA02, cap, res, attrs, j, usage)
244+
pc, err := NewProvenanceCreator(ctx2, slsaVersion, cap, res, attrs, j, usage)
238245
if err != nil {
239246
return nil, nil, err
240247
}

0 commit comments

Comments
 (0)