-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
dockerfile: support Dockerfile.pin for pinning sources #2816
Conversation
type Source = binfotypes.Source | ||
|
||
// Pin provides pinning information to ensure determinism of sources. | ||
type Pin struct { |
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.
@tonistiigi
Should this have a version
field or mediaType
field for extensibility?
#2794 (comment)
This may be a confusing comparison. This feels more like a lock file, which lists the one and only digest of the dependency as you depend on it at the time you build. We may want to call this |
“Dockerfile.pin” might be better? |
Changed the filename to |
This looks really good. Other than that, it would be nice to have a way to support this from the LLB level, but this doesn't seem possible today since resolution happens in the frontend. |
I'm a big fan of the kind of functionality of pinning sources, think it would be a real help to enabling more reproducible builds 🎉 I think that there's some overlap between the pinning of docker-image sources, and the named contexts that are supported in bake - I'm not quite sure what the desired interaction might be between these, especially if they conflict? I'm also not sure about introducing a new file (and file format) - there's already quite a mix of formats involved in standard image build pipelines. It feels like something like this might be better to see if we could handle almost entirely client side, since different build setups might want to have different ways of handling these kind of dependencies. Could we possibly achieve the same level of functionality by writing the pin information to a # build the image
$ docker buildx bake -f docker-bake.hcl myimagetarget -pin pin.json
# build the image again, but with pins
$ docker buildx bake -f docker-bake.hcl -f pin.json myimagetarget Today bake doesn't support doing file checksums, so we'd need to add support for that, but don't think any other changes would be required in bake itself. |
@jedevc Doing this client side means that the client needs to know how to parse/rewrite the Dockerfile ahead of time. |
Rebased.
This feature has to be available for non-buildx clients too , so this feature has to be implemented in the frontend part. |
When Dockerfile.pin exists in the context, the dockerfile.v0 frontend does: - Pinning the digest of `docker-image` sources (`FROM ...`) - Pinning the digest of `http` sources (`ADD https://...`) - Recording the consumed Dockerfile.pin entries to the exporter response `pin.consumed` The content of Dockerfile.pin is a subset of BuildInfo: ```json { "sources": [ { "type": "docker-image", "ref": "docker.io/library/alpine:latest", "pin": "sha256:4edbd2beb5f78b1014028f4fbb99f3237d9561100b6881aabbf5acce2c4f9454" }, { "type": "http", "ref": "https://raw.githubusercontent.com/moby/buildkit/v0.10.1/README.md", "pin": "sha256:6e4b94fc270e708e1068be28bd3551dc6917a4fc5a61293d51bb36e6b75c4b53" } ] } ``` In the future, Dockerfile should also support `ADD git://...` and pinning its commit hash. (PR 2799) Closes issue 2794 "Dockerfile.pin" was originally proposed as "Dockerfile.sum" in Issue 2794. Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
(Ideally pinning should be implemented in the LLB rather than in the frontend but it is hard as the Dockerfile frontend calls ImageMetaResolver ahead of generating the LLB) |
That isn't really a problem. You would not put the pins inside of LLB anyway. When client sends the build requests it sends the pins/checksums (might be better to think of it more as a policy) that are associated with the job. Now when this job does LLB builds (or when it calls the config resolver that also goes through the LLB bride) all these calls go through the policy validation first (or if needed then the LLB is modified on the load phase). It is very similar to the current entitlements model where the client passes the allowed entitlements, and then anything the build does needs to be compliant with these rules. |
To avoid potential TOCTOU attacks, (unlike entitlements) we should rewrite LLB ops to append source digests to their identifiers rather than just validating the LLB ops, but I'm not sure how we can mutate the LLB ops inside the LLB solver. Are we allowed to add something like "MutatedIdentifier" string to Or can we just go through with the current frontend-oriented design? |
@tonistiigi ↑WDYT? 🙏 |
Alternative PR (pure-LLB): |
Closes #2794
When
Dockerfile.pin
(initially proposed asDockerfile.sum
in #2794) exists in the context, thedockerfile.v0
builder does:docker-image
sources (FROM ...
)http
sources (ADD https://...
)Dockerfile.pin
entries to the exporter responsepin.consumed
The content of
Dockerfile.pin
is a subset ofBuildInfo
:In the future, Dockerfile should also support
ADD <gitref>.
and pinning its commit hash.ADD <git ref>
#2799Usage
When a
docker-image
pin is wrong:When an
http
pin is wrong:Changes from
pin-poc.20220411-0
in #2794Dockerfile.sum
toDockerfile.pin