policy: verify BuildKit builder images
Extend the built-in policy to validate signed moby/buildkit release and floating tags before docker-container builders are created. Pull the image first, inspect it through Docker, and bind verification to the descriptor digest. Resolve signature attestations through the BuildKit API embedded in the Docker daemon. If pulling fails, use a local image while applying the same verification when the containerd image store exposes an immutable descriptor. Keep the classic image-store behavior unchanged because no descriptor is available. Allow unmanaged repositories and digest-only references unchanged. Add the allow-untrusted-image driver option as an explicit verification bypass. Document the behavior and add policy, digest-pinning, and local fallback coverage. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/buildx/driver"
|
||||
"github.com/docker/buildx/driver/bkimage"
|
||||
"github.com/moby/buildkit/identity"
|
||||
"github.com/moby/buildkit/util/testutil/integration"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -25,6 +26,7 @@ var createTests = []func(t *testing.T, sb integration.Sandbox){
|
||||
testCreateRestartAlways,
|
||||
testCreateRemoteContainer,
|
||||
testCreateWithProvenanceGHA,
|
||||
testCreateCustomImageWithDefaultPolicy,
|
||||
}
|
||||
|
||||
func testCreateMemoryLimit(t *testing.T, sb integration.Sandbox) {
|
||||
@@ -111,6 +113,43 @@ func testCreateRemoteContainer(t *testing.T, sb integration.Sandbox) {
|
||||
require.Fail(t, "remote builder is not running")
|
||||
}
|
||||
|
||||
func testCreateCustomImageWithDefaultPolicy(t *testing.T, sb integration.Sandbox) {
|
||||
if !isDockerContainerWorker(sb) {
|
||||
t.Skip("only testing with docker-container worker")
|
||||
}
|
||||
|
||||
customImage := "localhost:1/buildx-test/custom-buildkit:" + identity.NewID()
|
||||
var builderName string
|
||||
|
||||
cmd := dockerCmd(sb, withArgs("image", "tag", bkimage.DefaultImage, customImage))
|
||||
dt, err := cmd.CombinedOutput()
|
||||
require.NoError(t, err, string(dt))
|
||||
|
||||
t.Cleanup(func() {
|
||||
if builderName != "" {
|
||||
out, err := rmCmd(sb, withArgs(builderName))
|
||||
require.NoError(t, err, out)
|
||||
}
|
||||
cmd := dockerCmd(sb, withArgs("image", "rm", customImage))
|
||||
out, err := cmd.CombinedOutput()
|
||||
require.NoError(t, err, string(out))
|
||||
})
|
||||
|
||||
// images outside the managed moby/buildkit repository pass through the
|
||||
// default policy, so bootstrapping a builder from a custom local image
|
||||
// needs no opt-out or registry access.
|
||||
out, err := createCmd(sb,
|
||||
withArgs("--driver", "docker-container", "--driver-opt", "image="+customImage),
|
||||
withEnv("BUILDX_DEFAULT_POLICY=1"),
|
||||
)
|
||||
require.NoError(t, err, out)
|
||||
builderName = strings.TrimSpace(out)
|
||||
|
||||
out, err = inspectCmd(sb, withArgs(builderName, "--bootstrap"), withEnv("BUILDX_DEFAULT_POLICY=1"))
|
||||
require.NoError(t, err, out)
|
||||
require.Contains(t, out, "using local image "+customImage)
|
||||
}
|
||||
|
||||
func testCreateWithProvenanceGHA(t *testing.T, sb integration.Sandbox) {
|
||||
if !isDockerContainerWorker(sb) {
|
||||
t.Skip("only testing with docker-container worker")
|
||||
|
||||
Reference in New Issue
Block a user