Skip to content

Implement --cap and --namespace flags for better control #6687

Closed

Description

@crosbymichael

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

http://linux.die.net/man/7/capabilities

  1. In addition to the default caps that are keep for a container add the NET_ADMIN cap to a container.
docker run --cap +NET_ADMIN crosbymichael/redis
  1. Remove the MKNOD capability from the default cap set that is kept
docker run --cap -MKNOD crosbymichael/redis
  1. Drop MKNOD and add NET_ADMIN and SYS_ADMIN
docker run --cap -MKNOD --cap +NET_ADMIN --cap +SYS_ADMIN crosbymichael/redis

Any 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.

  1. Do not create a PID namespace
docker run --namespace +PID -ti crosbymichael/htop

Changing 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

  1. crosbymichael commented on Jun 26, 2014

    @crosbymichael
    ContributorAuthor
  2. mrunalp commented on Jun 26, 2014

    @mrunalp
    Contributor

    @crosbymichael +1 to adding this feature. I can help with changes to libcontainer to make this happen.

  3. vishh commented on Jun 26, 2014

    @vishh
    Contributor

    +1

    On Wed, Jun 25, 2014 at 5:12 PM, Mrunal Patel [email protected]
    wrote:

    @crosbymichael https://github.com/crosbymichael +1 to adding this
    feature. I can help with changes to libcontainer to make this happen.

    —
    Reply to this email directly or view it on GitHub
    #6687 (comment).

  4. changed the title [-]Implement --caps and --namespaces flags for better control[/-] [+]Implement --cap and --namespace flags for better control[/+] on Jun 26, 2014
  5. added this to the milestone on Jun 26, 2014
  6. rhatdan commented on Jun 26, 2014

    @rhatdan
    Contributor

    Does this mean we are going away from the --opts patch altogether, and I should work on the --selinuxopts?

  7. rhatdan commented on Jun 26, 2014

    @rhatdan
    Contributor

    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.

       --drop-capability=
           Specify one or more additional capabilities to drop for the container. This allows running the container with fewer capabilities than the default (see above).
    
  8. cpuguy83 commented on Jun 26, 2014

    @cpuguy83
    Member

    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>

  9. jeremyeder commented on Jun 26, 2014

    @jeremyeder

    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 ...

  10. danbeaulieu commented on Jun 26, 2014

    @danbeaulieu

    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.

  11. crosbymichael commented on Jun 26, 2014

    @crosbymichael
    ContributorAuthor

    @rhatdan yes, I would just work on a --selinux flag for what you need. We are not ready for --opts right now

  12. crosbymichael commented on Jun 26, 2014

    @crosbymichael
    ContributorAuthor

    @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

  13. crosbymichael commented on Jun 26, 2014

    @crosbymichael
    ContributorAuthor

    ping @vieux @shykes what do you think about these alternate flag suggestions?

  14. 19 remaining items

  15. modified the milestones: , 1.1.1 on Jul 12, 2014
  16. ewindisch commented on Jul 16, 2014

    @ewindisch
    Contributor

    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.

  17. rhatdan commented on Jul 17, 2014

    @rhatdan
    Contributor

    It should be OS Specific. We should not be inventing a new language.

    How close is the --namespace patch?

  18. removed this from the milestone on Aug 15, 2014
  19. phemmer commented on Jan 5, 2015

    @phemmer
    Contributor

    Has there been any progress on this? I am highly interested in the ability to drop specific namespaces.

  20. ewindisch commented on Jan 5, 2015

    @ewindisch
    Contributor

    --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.

  21. LK4D4 commented on Jan 5, 2015

    @LK4D4
    Contributor

    @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.

  22. phemmer commented on Jan 5, 2015

    @phemmer
    Contributor

    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.

  23. rhatdan commented on Jan 5, 2015

    @rhatdan
    Contributor

    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.

  24. phemmer commented on Jan 5, 2015

    @phemmer
    Contributor

    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 simple chroot to solve that issue.

  25. SvenDowideit commented on Jan 6, 2015

    @SvenDowideit
    Contributor

    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. :)

  26. rhatdan commented on Jan 6, 2015

    @rhatdan
    Contributor

    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.

  27. crosbymichael commented on Jan 14, 2015

    @crosbymichael
    ContributorAuthor

    This is complete with --pid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions