-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
Build Secrets #30637
Build Secrets #30637
Conversation
3459530
to
4726fb2
Compare
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.
Design LGTM
if err != nil { | ||
return nil, errors.Wrap(err, "unable to create temp directory for secrets") | ||
} | ||
if err := mount.Mount("tmpfs", tempDir, "tmpfs", "nodev,nosuid,noexec"); err != nil { |
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.
should be readonly perhaps?
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.
added the remount to ro
.
docs/reference/commandline/build.md
Outdated
|
||
This will expose the contents of `github-key` in the container during build | ||
as `/run/secrets/git.key`. | ||
|
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.
It would be better to clarify that a file in secret cannot be executed, so that no one try to put install-some-proprietary-software.sh
to secret
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.
Why would you want to prevent people from installing proprietary software?
In any case, can't you always
RUN cp /run/secrets/foo.sh /tmp/ && chmod +x /tmp/foo.sh && /tmp/foo.sh
regardless.
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.
@ehazlett is this different from secrets on docker service
? On services, I was able to actually provide an executable as secret?
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.
@thaJeztah it was probably using the cache as by default the mode is read-only, no-execute. Here is an example:
docker build --no-cache -t testimage --build-secret src=/usr/local/bin/docker,target=docker,mode=0755 .
Sending build context to Docker daemon 12.49 MB
Step 1/4 : FROM alpine:latest
---> 88e169ea8f46
Step 2/4 : RUN mount | grep /run
---> Running in d158b3ff377c
tmpfs on /run type tmpfs (ro,relatime)
---> 9a3f370992b0
Removing intermediate container d158b3ff377c
Step 3/4 : RUN ls -lah /run/secrets/
---> Running in f99f664b5034
total 12200
drwxr-xr-x 2 root root 60 Feb 7 19:52 .
drwxrwxrwt 3 root root 60 Feb 7 19:52 ..
-rwxr-xr-x 1 root root 11.9M Feb 7 19:52 docker
---> d12b13566935
Removing intermediate container f99f664b5034
Step 4/4 : RUN /run/secrets/docker -v
---> Running in 2c64f083244f
Docker version 1.14.0-dev, build 46c4cda71
---> 8e94d203c623
Removing intermediate container 2c64f083244f
Successfully built 8e94d203c623
In the original issue we decided that an explicit cache bust was preferable instead of busting or trying to maintain a hash of a secret (#28079 (comment))
Wouldn't the syntax
be more in line with other command line options like volumes? |
I was going for more inline with the existing `build-arg` for the builder.
…On Fri, Feb 3, 2017 at 1:46 PM, Nikolaus Demmel ***@***.***> wrote:
Wouldn't the syntax
docker build -t test --no-cache --build-secret source=~/git-key:git-key .
be more in line with other command line options like volumes?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#30637 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAP6IhUhpN6k9_frxjlQuosZPZtV-DXvks5rY3YUgaJpZM4L0Jmr>
.
|
4726fb2
to
46c4cda
Compare
Added an example using a private git key in the description. |
docs/reference/commandline/build.md
Outdated
@@ -373,6 +374,21 @@ the command line. | |||
> repeatable builds on remote Docker hosts. This is also the reason why | |||
> `ADD ../file` will not work. | |||
|
|||
### Build with Secrets |
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.
It might be worthwhile for the daemon to be able to specify default build secrets.
The use case for this would be something like importing rhel subscriptions.
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.
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.
would be nice to have rhel subs while building daemon wide (but we also need them at run time :( and we currently inject those)
We desperately need this ... Any chance we could get a patch version 1.13.1 out quick with this merged? :-) |
@joelpresence Since this is a feature addition, I think this is unlikely to be included in 1.13.1. $ hub checkout https://github.com/docker/docker/pull/30637
$ make deb |
@ehazlett Dude, this is awesome! Folks (myself included) have been wanting this for literally years. I'm a bit curious about how we intend to keep users from accidentally doing something like:
(which if I understand correctly would end up with Since that would "just work" in most cases (but would leak the secret), it's going to be pretty tempting for average user. I'm assuming maybe you're specifying SSH key path in the config file you pass in above to be It might be nice to have some helpers to symlink files from the |
docs/reference/commandline/build.md
Outdated
|
||
```bash | ||
docker build -t app \ | ||
--secret source=/path/to/github-key,target=git.key . |
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.
Inconsistent with --build-secret
here. (Although isn't --build-secret
a bit redundant anyway? ;) )
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.
Ya good catch. I used --build-secret
to match the --build-env
flag
docs/reference/commandline/build.md
Outdated
@@ -373,6 +374,21 @@ the command line. | |||
> repeatable builds on remote Docker hosts. This is also the reason why | |||
> `ADD ../file` will not work. | |||
|
|||
### Build with Secrets | |||
|
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.
I think there should be some comparison between the build secret and the swarm secret, but it can be another PR
@nathanleclaire Ya the ssh keys are tough. I solved it by using a custom ssh config. Like so:
As far as copying, I'm not sure what we can do. If we had a fuse fs we could block that but since it's just tmpfs probably education at this point similar to swarm secrets. |
Yeah, it might just be one of those cases where we have to have big all-caps warnings and clear education about best practices in the docs, and that SSH config is pretty simple which is nice. Maybe it might be feasible to have an additional option which would set a symlink from the tmpfs mount to a target FS location in container, e.g., $ docker build \
--build-secret source=~/.aws/config,target=awsconfig,link=/home/user/.aws/config \
. Then it would be a universal way to share secret files safely instead of having to re-design each time and having different solutions for certs, AWS keys, etc., etc. |
edit: yep. |
Bit late to the party, and haven't had a lot of time diving into this so far. I love the ability to have secrets for build, as it's something that's really missing now. I do have some concerns / thoughts though;
This will add a "pre-condition", but would it make sense to require swarm mode to be active, and actually using the swarm-mode secrets for this? Basically;
Given that |
Yes this is why it works the way it does today. In my original PR for secrets I pushed to support containers so we could do just this but it was decided otherwise for various security reasons. I agree that if we could get secrets for containers we could use Swarm as the store but I'm not sure what the timeline would be for that. I also think that there is a use case for not having them in a Swarm store (i.e. they could collide with a production secret, etc) and rather locally. |
I also love the ability to have secrets for build, as it's something that's really missing now. As long as we don't support "swarm mode" (and thus secret) for containers and build, maybe this shouldn't be called |
@vdemeester We were looking for this In a discussion about injecting HashiCorp Vault secrets in the Docker builds. It started with me talking about the sorta complicated way I take a "wrapped token" from Vault and pass it as I'm mostly noting this as a use case: some users of this secret feature might not be pulling files from an existing file system. but rather from some secrets system. [This points to the need for a secrets backend, but I'm super happy to have this sooner rather than later.] For this Hashi Vault use case, I think what I will do is extract secrets into a host tmpfs then map all those files to the build with multiple |
What is needed to move this forward? Build-time secrets have been in discussion for years, and all discussions seem to (eventually) point here. A month ago reviewers seemed to generally approve. Does it just need a rebase? |
Is there a possibility of a The directive could be correlated as $ docker build --secret=source=acme-ro.key,target=github_key,mode=0400 . # Dockerfile example, dest option symlinks secret to path
#SECRET <name> [options]
SECRET github_key dest=/root/.ssh/id_rsa
RUN git clone git@github.com:acme/private-repo.git
... Also, should the secret source (if a file) be limited to the build context? This potentially guards against non-repeatable builds. Obviously having the source file on disk and unencrypted is not good -- and we'd probably want (pre)create and (post)remove it as part of a build script / orchestration. What would be very cool and solve this is to allow plugins to handle the source, such as reading from hashicorp vault. This does go against repeatability however. Something like; $ docker build --secret=plugin=hashicorp_vault,source=keys/acme-ro.key,target=private_key . In any case, build time secrets will be incredibly useful -- and, at least to me, they're more important than runtime which we can get by using vault or tmpfs bindmounts or swarm. Thanks! |
@eatdrinksleepcode i'll bring this up again in the maintainer meeting. there were a few design questions (i.e. wanting to use swarm instead of these locally). @briceburg Yes in a former branch I had implemented In the meantime, I'll work on rebasing to get this ready in case maintainers can agree :) |
Looking at the implementation I think #32507 is a better solution for this. |
@dnephin agreed, looks good. |
wfm |
@ehazlett Can you provide some clarification behind closing this. Are you suggesting #32507 instead of the |
I'd still be for having the same approach as for swarm services; possibly requiring swarm mode to be enabled if people want to make use of this feature. Feels confusing to use completely different mechanisms for one or the other ( |
@tonistiigi This PR has stagnated and maintainers can't agree on a design. This PR didn't add the |
Is there any version of docker that supports this flag already ? I'm running |
@bilby91 No, this is not merged. |
The new multi-stage build feature (17.06) may solves all ours problems, right ? |
@BenoitNorrin what is the multi-stage feature you are mentioning ? |
This will still bake the secrets into the image |
@pvanderlinden Can you explain why please ? |
@BenoitNorrin For example if you use internal software repositories:
This will add the secrets in multiple way to the end image:
I think a good collection of these problems can be found in this ticket: |
Nope, all this will be discarded together with the first image. The result image only contains layers and |
I probably miss something. Here an example.
docker build -t multi-stages --build-arg LOGIN=foo --build-arg PASSWORD=bar .
No matter what is done in the first stage (builder), this not embed in the final stage. |
@AndreKR You confuse a build container and installations. |
I don't know about pip, but I know about npm and composer and in both cases you install all dependencies in the first stage and you just copy |
That would work indeed, but I hardly call handpicking the files you need from a different container a solution to the build secret problem (and this method of handpicking files was already possible). In many occasions it is much simpler to only ignore the credentials you explicitly pass into a build container. |
See : #13490 (comment) |
This replaces #28079 as I had to re-open.
This enables build time secrets using the
--build-secret
flag.Similar to #27794 this creates a tmpfs during each run of the build and exposes the specified "secrets" into the container. These are not committed to the image.
Here is an example Dockerfile:
Given the following command:
This will expose the key from
~/git-key
as/run/secrets/git-key
. This can be used however needed during build by the correspondingRUN
directives.Here is the example output:
Example using a private git key
Dockerfile