-
Notifications
You must be signed in to change notification settings - Fork 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
run: flag to include the docker socket #5858
base: master
Are you sure you want to change the base?
Conversation
Adds a flag, `--include-docker-socket` that can be used to start a container with the correctly configured parameters to ensure that accessing the docker socket will work with out the fiddly flags. There are a few problems with this approach: 1. We need a reliably way to clean up the configuration file. This currently is put into a tmp file then bind mounted. There is probably a better way to do this such as copying in the file. 2. We need a way to resolve the correct socket outside the container. If a different socket is used or a address and port, this will attempt to bind mount a nonexistent socket. Either way, this is good start and resolves a long standing issue. Signed-off-by: Stephen Day <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5858 +/- ##
==========================================
- Coverage 59.30% 58.75% -0.56%
==========================================
Files 353 350 -3
Lines 29694 29763 +69
==========================================
- Hits 17609 17486 -123
- Misses 11104 11293 +189
- Partials 981 984 +3 |
Alright, I just validated an approach to the credential leak issue using copy into the container. Let's validate the cli ux and then we can add that implementation if we want to go forward with the change. |
We've now removed the bind mount dependency to inject the config, meaning that we won't leak the credentials on the client host. An approach with a tmp mount was attempted but the tmpfs isn't available until the container is started. Signed-off-by: Stephen Day <[email protected]>
Signed-off-by: Stephen Day <[email protected]>
This is a tricky one; bind-mounting the docker socket by setting these options from the CLI will break in many scenarios. The current approach in this PR uses the default location ( For a daemon running locally (same machine), the CLI could have slightly more information, and look at the docker host configuration in the docker context inspect | jq .[].Endpoints.docker.Host
"unix:///var/run/docker.sock" In general, these could be somewhat tricky even with the good location, as there's a potential race condition where the container is started before the API server (and thus socket) is up, in which case using the I recall some older proposals to have an option on the daemon side to grant a container access to the API; for those, the daemon would handle setting up a socket and mounting it into the container. Those were a really long time ago, and IIRC the initial implementation was to do so automatically for any container with
I think something along those lines (i.e., having an option to forward the socket, and have the daemon set this up) could solve most of the issues mentioned earlier; the daemon would be able to set up the socket for the container, regardless how it was configured, which could even mean a dedicated socket for the container (which could potentially be expanded to more granular / limited access to the socket, instead of access to all endpoints). Slightly related (forwarding a socket from the client to the daemon to allow ssh-agent-like constructs for forwarding into the container); this could possibly be tying in to the "forward authentication" part; |
For the credentials; potentially we could use some env-var, although env-vars may not be ideal as they will leak both into the container's config ( Possibly we can make the CLI aware of an env-var along those lines; IIRC, BuildKit requests auth from the CLI when building, so not 100% sure if that would work in that combination, and likely all CLI plugins would have to be updated to be aware of this approach. |
Tangential, but regarding:
Ultimately, this should be unnecessary and we should make the necessary changes to stop the "credentials in |
@laurazard Yes but unfortunately, there is no way to call the credential helps from inside the container. We could have an ssh-agent like call api for it but that would require an interactive client to that to work correctly. @thaJeztah It sounds like I should at least use a mount rather that volume notation to avoid the accidental file creation. |
Right, that's definitely true. I think there's two separate issues that folks frequently run into that we should keep in mind:
It'd be awesome if whatever solution we came up with could account for/solve both cases (and splitting out creds – even if just to another file – from |
@laurazard Looking at compose, they actually use the same technique that I've employed here: https://github.com/docker/compose/blob/145bb8466dffd18d7828ca0bc0725b1059506098/pkg/compose/secrets.go#L31. The secrets are copied over to Here's my proposal:
I know this isn't ideal but this has been a long-lived pain point. The abstraction of the I hope this is reasonable and can allow us to move forward. |
We now use mounts to perform the bind mount of the socket, avoiding some of the confusing behavior of the bind syntax implemented in `--volume`. As part of this, we now resolve the socket location from the cli configuration and throw an error if the docker endpoint address is incompatible with the `--use-docker-socket` flag. Signed-off-by: Stephen Day <[email protected]>
Adds a flag,
--edit-docker-socket
that can be used to start a container with the correctly configured parameters to ensure that accessing the docker socket will work with out the fiddly flags.There are a few problems with this approach:
Either way, this is good start and resolves a long standing issue.
To try it out, you can do the following:
This PR is somewhat incomplete and needs the following: