Skip to content
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

Add support for --pid=container:<id> #22481

Merged
merged 1 commit into from May 19, 2016
Merged

Conversation

mrunalp
Copy link
Contributor

@mrunalp mrunalp commented May 3, 2016

This is for #22479

I will take out the engine-api code once docker/engine-api#218 is merged.

Signed-off-by: Mrunal Patel mrunalp@gmail.com

@mrunalp mrunalp force-pushed the pid_container branch 3 times, most recently from ab8b67f to a51da5f Compare May 3, 2016 22:24
@hqhq
Copy link
Contributor

hqhq commented May 5, 2016

For reference, it'll Closes: #10163

@mrunalp mrunalp changed the title WIP: Add support for --pid=container:<id> Add support for --pid=container:<id> May 5, 2016
@mrunalp
Copy link
Contributor Author

mrunalp commented May 5, 2016

This is ready to test/review.

@tiborvass
Copy link
Contributor

Maintainers (from today's review session) agree with the design, so moving to code review.

@mrunalp
Copy link
Contributor Author

mrunalp commented May 5, 2016

@tiborvass Thanks for the update! We need to get docker/engine-api#218 reviewed/merged as well.

@thaJeztah
Copy link
Member

@mrunalp its merged 😄 👍

@mrunalp
Copy link
Contributor Author

mrunalp commented May 6, 2016

@thaJeztah yeah, now waiting for the vendor PR #22538 :)

@thaJeztah
Copy link
Member

@mrunalp done as well \o/

@mrunalp
Copy link
Contributor Author

mrunalp commented May 6, 2016

@thaJeztah Thanks! I have rebased this PR to pick up the engine-api update.

@LK4D4
Copy link
Contributor

LK4D4 commented May 9, 2016

LGTM

@icecrime
Copy link
Contributor

Ping @mlaventure!

return nil, err
}

return label.DupSecOpt(c.ProcessLabel), nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have both ipcMode.IsContainer() and pidMode.IsContainer() are true and they both point to different containers with different labels we will never apply the second container labels.

I'm no selinux expert, but shouldn't those be merged somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't join two namespaces of two different containers unless transitively they have the same label.
Cc: @rhatdan

Sent from my iPhone

On May 11, 2016, at 8:32 PM, Kenfe-Mickaël Laventure notifications@github.com wrote:

In daemon/create.go:

@@ -150,6 +150,14 @@ func (daemon *Daemon) generateSecurityOpt(ipcMode containertypes.IpcMode, pidMod

    return label.DupSecOpt(c.ProcessLabel), nil
}
  • if pidContainer := pidMode.Container(); pidContainer != "" {
  •   c, err := daemon.GetContainer(pidContainer)
    
  •   if err != nil {
    
  •       return nil, err
    
  •   }
    
  •   return label.DupSecOpt(c.ProcessLabel), nil
    
    If we have both ipcMode.IsContainer() and pidMode.IsContainer() are true and they both point to different containers with different labels we will never apply the second container labels.

I'm no selinux expert, but shouldn't those be merged somehow?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order for two containers to share the same PID or same IPC Namespace, they have to run with the same SELinux label. Otherwise SELinux will break when a process in container1 tries to look at the processes in container2, or a process in container 1 tries to use an IPC created in container2. This is why when the second container is created it switches to the first containers labels. By merging the containers namespaces, you are saying that they share the same security structure, from an SELinux point of view.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is ipc=<container-A>, pid=<container-B> a valid configuration, or should that produce an error?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's valid if they have the same selinux configuration it seems. Which
should check for this or prohibit it entirely to avoid runtime error later
on I'd say.

On Thu, May 12, 2016, 5:19 AM Sebastiaan van Stijn notifications@github.com
wrote:

In daemon/create.go
#22481 (comment):

@@ -150,6 +150,14 @@ func (daemon *Daemon) generateSecurityOpt(ipcMode containertypes.IpcMode, pidMod

    return label.DupSecOpt(c.ProcessLabel), nil
}
  • if pidContainer := pidMode.Container(); pidContainer != "" {
  •   c, err := daemon.GetContainer(pidContainer)
    
  •   if err != nil {
    
  •       return nil, err
    
  •   }
    
  •   return label.DupSecOpt(c.ProcessLabel), nil
    

is ipc=, pid= a valid configuration, or should
that produce an error?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/docker/docker/pull/22481/files/0c5d257326331f2bcaf03a4b3147d3225acf09c7#r63009686

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be bad to keep it simple for now, and require them to be the same container? (as in "no is temporary, yes is forever")?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could release note it. Not sure if their would be other problems. Combining containers together without combining their security attributes could lead to some weird errors. Right now we keep seccomp, apparmor and capabiltiies separate, but you could figure out ways where weird bugs or priv escalations can happen. Basically one process with limited privs in one container causing a process in a different container through IPC or shared pid to do something more privileged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prohibiting joining ipc and pid from 2 different containers works for me as long as it's well documented.

We can extend it later to allow this case if both containers are using the same selinux configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have pushed an update that compares the pid and ipc labels for the use case and allows them only if they are same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also works for this example as the labels are the same transitively.

start container A
container B joins --ipc:container:A
container C joins --ipc:container:B --pid:container:A

@mrunalp mrunalp force-pushed the pid_container branch 3 times, most recently from 2f3566c to 4772a40 Compare May 13, 2016 18:48

if pidLabel != nil && ipcLabel != nil {
for i := 0; i < len(pidLabel); i++ {
if pidLabel[i] != ipcLabel[i] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the labels are identical but not in the same order?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify your question? If the labels are the same, then all the strings in the label array will match up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we can't have a scenario where

ipcLabel[0] = "label1" ; ipcLabel[1] = "label2"
pidLabel[0] = "label2" ; pidLabel[1] = "label1"

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mlaventure No, that can't happen.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, LGTM then! (IANAM)

On Fri, May 13, 2016, 8:33 PM Mrunal Patel notifications@github.com wrote:

In daemon/create.go
#22481 (comment):

  •   return label.DupSecOpt(c.ProcessLabel), nil
    
  •   pidLabel = label.DupSecOpt(c.ProcessLabel)
    
  •   if ipcContainer == "" {
    
  •       return pidLabel, err
    
  •   }
    
  • }
  • if pidLabel != nil && ipcLabel != nil {
  •   for i := 0; i < len(pidLabel); i++ {
    
  •       if pidLabel[i] != ipcLabel[i] {
    

@mlaventure https://github.com/mlaventure No, that can't happen.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/docker/docker/pull/22481/files/4772a40138e8f88e77f04049c1c2dc4865508dc7#r63270556

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me.

@mrunalp
Copy link
Contributor Author

mrunalp commented May 16, 2016

@thaJeztah ping. who else needs to review this? :) Also looks like janky failure is a test environment issue that should go away on restart.

@thaJeztah
Copy link
Member

ping @LK4D4 @crosbymichael PTAL for the latest changes, let's get this merged 👍

@thaJeztah thaJeztah added this to the 1.12.0 milestone May 17, 2016
@thaJeztah
Copy link
Member

thaJeztah commented May 17, 2016

actually; this needs changes to the documentation, so please move it to "docs review" if it LGTY

@mrunalp The documentation needs to be updated to show this is now possible; preferably
with an example (explaining why someone would use this as an option?). I think it needs a note as well, explaining that, although --pid and --net can use different containers, their labels should match, if SELinux is used (don't know if we can come up with an example for having different containers for that?)

Man pages;

Also, the completion scripts need to be updated; let me know if you want to try
updating those yourself, or if @albers and @sdurrheimer need to assist. I think
the same approach can be taken as for the --net option (although I couldn't
find completion for container-names in the zsh script);

@Random-Liu
Copy link

/sub @Random-Liu

@crosbymichael
Copy link
Contributor

LGTM

@thaJeztah
Copy link
Member

moving to docs review with a LGTM from @mlaventure and @LK4D4

@mrunalp
Copy link
Contributor Author

mrunalp commented May 19, 2016

This is all green!

@vdemeester
Copy link
Member

LGTM 🐸

@vdemeester vdemeester merged commit ebeb5a0 into moby:master May 19, 2016
stepanstipl added a commit to stepanstipl/docker-py that referenced this pull request Aug 31, 2016
Docker added support for sharing PID namespaces with other containers
since version 1.12 (see moby/moby#22481).

Signed-off-by: Stepan Stipl <stepan@stipl.net>
stepanstipl added a commit to stepanstipl/docker-py that referenced this pull request Sep 1, 2016
Docker added support for sharing PID namespaces with other containers
since version 1.12 (see moby/moby#22481).

Signed-off-by: Stepan Stipl <stepan@stipl.net>
stepanstipl added a commit to stepanstipl/docker-py that referenced this pull request Sep 1, 2016
Docker added support for sharing PID namespaces with other containers
since version 1.12 (see moby/moby#22481).

Signed-off-by: Stepan Stipl <stepan@stipl.net>
WeiZhang555 pushed a commit to WeiZhang555/moby that referenced this pull request Nov 25, 2016
Backported from: moby#22481

Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
WeiZhang555 pushed a commit to WeiZhang555/moby that referenced this pull request Nov 25, 2016
Add support for --pid=container:<id>

Backported from: moby#22481

Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>


See merge request docker/docker!147
bfirsh pushed a commit to docker/docker-py that referenced this pull request Nov 28, 2016
Docker added support for sharing PID namespaces with other containers
since version 1.12 (see moby/moby#22481).

Signed-off-by: Stepan Stipl <stepan@stipl.net>
shin- pushed a commit to docker/docker-py that referenced this pull request Nov 28, 2016
Docker added support for sharing PID namespaces with other containers
since version 1.12 (see moby/moby#22481).

Signed-off-by: Stepan Stipl <stepan@stipl.net>
shin- pushed a commit to docker/docker-py that referenced this pull request Dec 8, 2016
Docker added support for sharing PID namespaces with other containers
since version 1.12 (see moby/moby#22481).

Signed-off-by: Stepan Stipl <stepan@stipl.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet