-
Notifications
You must be signed in to change notification settings - Fork 676
policy: verify BuildKit builder images #3961
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,14 @@ | ||
| package bkimage | ||
|
|
||
| const ( | ||
| DefaultImage = "moby/buildkit:buildx-stable-1" // TODO: make this verified | ||
| QemuImage = "tonistiigi/binfmt:latest" // TODO: make this verified | ||
| DefaultImage = "moby/buildkit:buildx-stable-1" | ||
| QemuImage = "tonistiigi/binfmt:latest" // TODO: make this verified | ||
| DefaultRootlessImage = DefaultImage + "-rootless" | ||
|
|
||
| // TrustedRepo is the fully-qualified repository whose tags are verified | ||
| // against the builtin default policy before a builder is created from | ||
| // them. Images from other repositories pass through unverified; the | ||
| // allow-untrusted-image driver-opt is only needed when a TrustedRepo tag | ||
| // that the policy covers does not verify correctly. | ||
| TrustedRepo = "docker.io/moby/buildkit" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just promote
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would that help? |
||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package driver | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/distribution/reference" | ||
| "github.com/docker/buildx/driver/bkimage" | ||
| "github.com/docker/buildx/policy" | ||
| "github.com/docker/buildx/util/progress" | ||
| digest "github.com/opencontainers/go-digest" | ||
| ocispecs "github.com/opencontainers/image-spec/specs-go/v1" | ||
| "github.com/pkg/errors" | ||
| ) | ||
|
|
||
| // VerifyImageRef evaluates ref against the builtin default policy through | ||
| // verify and returns the reference pinned to the digest that verification | ||
| // resolved. The boolean result reports whether the policy applied: it is | ||
| // false, with ref returned unchanged, when there is no verifier, when ref is | ||
| // pinned by digest without a tag, or when ref is outside the managed | ||
| // moby/buildkit repository (unmanaged images pass through the default policy | ||
| // unchanged). A tagged canonical reference is still verified because its tag | ||
| // carries the release identity checked by the policy. | ||
| func VerifyImageRef(ctx context.Context, l progress.SubLogger, ref string, platform *ocispecs.Platform, resolver policy.SourceMetadataResolver, verify ImageVerifier) (string, bool, error) { | ||
| if verify == nil { | ||
| return ref, false, nil | ||
| } | ||
| named, err := reference.ParseNormalizedNamed(ref) | ||
| if err != nil { | ||
| return "", false, errors.Wrapf(err, "failed to parse image reference %s", ref) | ||
| } | ||
| _, isCanonical := named.(reference.Canonical) | ||
| _, isTagged := named.(reference.Tagged) | ||
| if isCanonical && !isTagged { | ||
| return ref, false, nil | ||
| } | ||
| if named.Name() != bkimage.TrustedRepo { | ||
| return ref, false, nil | ||
| } | ||
| named = reference.TagNameOnly(named) | ||
|
|
||
| var dgst digest.Digest | ||
| if err := l.Wrap("verifying image "+named.String(), func() error { | ||
| var err error | ||
| dgst, err = verify(ctx, named.String(), platform, resolver) | ||
| return err | ||
| }); err != nil { | ||
| return "", true, err | ||
| } | ||
| canonical, err := reference.WithDigest(named, dgst) | ||
| if err != nil { | ||
| return "", true, errors.Wrapf(err, "failed to construct canonical reference for %s", ref) | ||
| } | ||
| return canonical.String(), true, nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
This could be a follow-up but looks tricky to verify QEMU image used by the kubernetes driver during deployment at:
buildx/driver/kubernetes/manifest/manifest.go
Lines 196 to 205 in 5c10fb7
We would need to know beforehand the node platform to perform the verification.
cc @AkihiroSuda
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.
The current policy verifier resolves signatures against a selected platform manifest, so Kubernetes cannot safely use the local default platform here. We'd need either a known pod platform or an all-platform verification story before verifying and pinning this init image.