-
Notifications
You must be signed in to change notification settings - Fork 876
Add --source-policy-file flag for BuildKit-compatible source policies #6647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --source-policy-file flag for BuildKit-compatible source policies #6647
Conversation
4dcc534 to
445591e
Compare
This comment was marked as resolved.
This comment was marked as resolved.
d0d291b to
65256a1
Compare
This comment was marked as resolved.
This comment was marked as resolved.
65256a1 to
15f208c
Compare
Implements support for the BuildKit source policy feature, bringing feature parity with `buildctl build --source-policy-file`. The JSON schema is compatible with BuildKit's source policy format. Features: - New `--source-policy-file` flag for `buildah build` - ALLOW, DENY, and CONVERT actions for controlling source references - EXACT and WILDCARD match types for flexible policy rules - Automatic image reference normalization to docker-image:// format This allows organizations to: - Pin base image tags to specific digests at build time - Deny specific sources from being used to enforce security policies - Transform source references without modifying Containerfiles Changes: - pkg/sourcepolicy/: New package for policy parsing, validation, matching - define/build.go: Added SourcePolicyFile field to BuildOptions - pkg/cli/common.go: Added --source-policy-file flag definition - imagebuildah/executor.go: Policy loading in newExecutor() - imagebuildah/stage_executor.go: Policy evaluation in prepare() - docs/buildah-build.1.md: Man page documentation with examples - tests/source-policy.bats: Integration tests - pkg/sourcepolicy/policy_test.go: Unit tests Signed-off-by: Konstantin Vyatkin <tino@vtkn.io> Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
15f208c to
2c225f3
Compare
|
Couple small nits, otherwise LGTM. @nalind? |
nalind
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I rather like this. I'd be tempted to handle wildcard matching using filepath.Match(), but it looks like the implementation we're trying to be compatible with isn't as flexible as that. A couple of notes on the normalization of docker image names and the default matching method, but otherwise it looks pretty good to me.
Change the default match type from EXACT to WILDCARD based on BuildKit's protobuf/json tagging which indicates wildcard should be the default behavior. Addresses: containers#6647 (comment) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Konstantin Vyatkin <tino@vtkn.io>
Add note explaining that CONVERT rules are processed after --build-context substitutions but before containers-registries.conf substitutions. Also update matchType default documentation to reflect WILDCARD being the default. Addresses: containers#6647 (comment) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Konstantin Vyatkin <tino@vtkn.io>
|
Ephemeral COPR build failed. @containers/packit-build please check. |
Replace custom image reference normalization with the proper go.podman.io/image/v5/docker/reference.ParseNormalizedNamed() function. Updated test cases to use valid SHA256 digests. Addresses: containers#6647 (comment) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Konstantin Vyatkin <tino@vtkn.io>
Co-authored-by: Tom Sweeney <tsweeney@redhat.com> Signed-off-by: Konstantin Vyatkin <tino@vtkn.io>
nalind
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, restarted a test run that failed due to a known flake.
|
LGTM |
Summary
--source-policy-fileflag tobuildah buildthat enables users to control and transform source references during builds without modifying DockerfilesBackground
This implements support for the BuildKit source policy feature as documented in BuildKit's build reproducibility guide. Docker Buildx supports this via the
EXPERIMENTAL_BUILDKIT_SOURCE_POLICYenvironment variable. The JSON schema is compatible with BuildKit's source policy format.Motivation
This feature allows organizations to:
Changes
Example Usage
Pin alpine:latest to a specific digest:
{ "rules": [ { "action": "CONVERT", "selector": { "identifier": "docker-image://docker.io/library/alpine:latest" }, "updates": { "identifier": "docker-image://docker.io/library/alpine@sha256:abc123" } } ] }buildah build --source-policy-file policy.json -t myimage .Test plan
🤖 Generated with Claude Code