Repository navigation
Description
We discussed this and think it would be best to not use something like --opts to be able to add and remove individual capabilities and namespaces for containers. We would rather use a dedicated flag and make sure that these features work across libcontainer and lxc. So our proposal is to add these two flags and provide a warning when elevating privileges for a container so that a user is aware of that they are doing.
Caps
- In addition to the default caps that are keep for a container add the
NET_ADMINcap to a container.
docker run --cap +NET_ADMIN crosbymichael/redis- Remove the MKNOD capability from the default cap set that is kept
docker run --cap -MKNOD crosbymichael/redis- Drop MKNOD and add NET_ADMIN and SYS_ADMIN
docker run --cap -MKNOD --cap +NET_ADMIN --cap +SYS_ADMIN crosbymichael/redisAny additional caps that are retained for a container should produce an error on stderr when running the container to let the user know they have elevated the privileges for a container.
Namespaces
There are a few reasons why you want to modify the namespaces applied to a container. If you are running a monitoring application in a container you may want to not drop into your own PID namespace so that you can see all your parents PID.
- Do not create a PID namespace
docker run --namespace +PID -ti crosbymichael/htopChanging the default namespace profile should result in a warning to the user.
Privileged
Using the privileged flag should result in a warning on stderr just like the two new flags above.
Development
We can discuss some of the details in this issue but if you would like to work on any of the changes please let me know.
I think all three of these changes, caps, namespaces, and privileged warning can be done separately. Ideally the privileged warning code can be merged in first so we have the warning pipeline to work with on the other prs. Caps should be easy to implement. Namespaces will be a little more challenging because it may consist of some runtime/libcontainer changes to support the different configuration.
Suggestions?
Activity
crosbymichael commentedon Jun 26, 2014
ping @philips @unclejack @rhatdan
mrunalp commentedon Jun 26, 2014
@crosbymichael +1 to adding this feature. I can help with changes to libcontainer to make this happen.
vishh commentedon Jun 26, 2014
+1
On Wed, Jun 25, 2014 at 5:12 PM, Mrunal Patel [email protected]
wrote:
[-]Implement --caps and --namespaces flags for better control[/-][+]Implement --cap and --namespace flags for better control[/+]rhatdan commentedon Jun 26, 2014
Does this mean we are going away from the --opts patch altogether, and I should work on the --selinuxopts?
rhatdan commentedon Jun 26, 2014
I actually like the feature but the CLI is a little ugly.
--namespace -PID
PID looks like an Option but it is really not, and does this eliminate the use of -P as an option.
systemd-nspawn does this using --capabiltiy and --drop-capabilty
man systemd-nspawn
...
--capability=
List one or more additional capabilities to grant the container. Takes a comma-separated list of capability names, see capabilities(7) for more information. Note that the following capabilities will be granted in any way: CAP_CHOWN, CAP_DAC_OVERRIDE, CAP_DAC_READ_SEARCH, CAP_FOWNER, CAP_FSETID, CAP_IPC_OWNER, CAP_KILL, CAP_LEASE, CAP_LINUX_IMMUTABLE, CAP_NET_BIND_SERVICE, CAP_NET_BROADCAST, CAP_NET_RAW, CAP_SETGID, CAP_SETFCAP, CAP_SETPCAP, CAP_SETUID, CAP_SYS_ADMIN, CAP_SYS_CHROOT, CAP_SYS_NICE,CAP_SYS_PTRACE, CAP_SYS_TTY_CONFIG, CAP_SYS_RESOURCE, CAP_SYS_BOOT, CAP_AUDIT_WRITE, CAP_AUDIT_CONTROL. Also CAP_NET_ADMIN is retained if --private-network is specified.
If the special value "all" is passed, all capabilities are retained.
cpuguy83 commentedon Jun 26, 2014
I agree with @rhatdan, but more concisely just --drop-cap, --add-cap
Also, for namespaces it would be really nice to have the same functionality that we currently have with net for all namespaces... so host/new/container:<id/name>
jeremyeder commentedon Jun 26, 2014
Any thoughts about adding this support to Dockerfiles, such that these things can be baked into an image? Dockerfile could also allow/deny override of the baked-in config via docker run ...
danbeaulieu commentedon Jun 26, 2014
I like --add-cap, other options are --keep-cap or --allow-cap.
namespace is sort of overloaded, what about something like --pid-namespace=true|false?
I think as separate issues it'd be great to list capabilities via docker inspect, or possibly a new API method.
crosbymichael commentedon Jun 26, 2014
@rhatdan yes, I would just work on a
--selinuxflag for what you need. We are not ready for --opts right nowcrosbymichael commentedon Jun 26, 2014
@jeremyeder No, we are not ready to add anything to the image until we have some type of control that says do not run any untrusted image with elevated permissions on my docker host. For now we will keep these as runtime only options
crosbymichael commentedon Jun 26, 2014
ping @vieux @shykes what do you think about these alternate flag suggestions?
19 remaining items
ewindisch commentedon Jul 16, 2014
One thing we discussed part of #2452 was support for FreeBSD and how this feature looks when we consider supporting other operating systems. Do we simply assume that all arguments to --cap are OS-dependent, or do we attempt a mapping to our own verbs to the OS-specific ones? I'm inclined to say it should be OS-dependent.
rhatdan commentedon Jul 17, 2014
It should be OS Specific. We should not be inventing a new language.
How close is the --namespace patch?
phemmer commentedon Jan 5, 2015
Has there been any progress on this? I am highly interested in the ability to drop specific namespaces.
ewindisch commentedon Jan 5, 2015
--cap-add and --cap-drop was included with Docker 1.2. No --namespace flag has been added.
We should probably close this issue, possibly creating one for more granular namespace configuration.
LK4D4 commentedon Jan 5, 2015
@phemmer We have support for dropping and specifying paths for namespaces in libcontainer. This can be added with dozen lines of code in docker. But having way to override namespaces in docker is sort of UX decision, so this is probably depending on @shykes.
phemmer commentedon Jan 5, 2015
Perhaps my use case would help here. What I'm trying to do is mount something within a volume in one container, and then share the volume (containing the mount) with another container. Because of the mount namespace, when the volume is shared with another container, it appears empty. If I could disable the mount namespace, I could work around this.
rhatdan commentedon Jan 5, 2015
Currently you can disable network,UTC and IPC namespace.
--net=host, --ipc=host
I have submitted a patch to disable the PID namespace --pid=host
Usernamespace is not enabled yet. That leaves mount, but kind of the definition of docker is using the MNT Namespace for handing of the image content. Not sure how you disable that and still have docker. libcontainer allows you to disable/enable all combinations.
phemmer commentedon Jan 5, 2015
Well I imagine images would break left and right if the root (
/) of the container isn't the root of the image, but we can fall back to a simplechrootto solve that issue.SvenDowideit commentedon Jan 6, 2015
imo it would be cool to have it tho - perhaps its a way for a container to union on top of another host dir / container, and in the process, we make even lighter weight containers. :)
rhatdan commentedon Jan 6, 2015
Even if you shared / or /usr you would probably still want to have applications write to locations that are different per container /var and /tmp for example.
But if you want just to have namespaces, why not just use the unshare command.
crosbymichael commentedon Jan 14, 2015
This is complete with
--pid