Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Adds user namespace support to libcontainer #304

Merged
merged 1 commit into from
Jan 19, 2015

Conversation

mrunalp
Copy link
Contributor

@mrunalp mrunalp commented Dec 17, 2014

The build will fail as this depends on golang 1.4
I am sending the PR, hoping to get people to test it and give feedback.
There are still log statements for debugging that I will clean up (but keeping them now to make it easier to catch issues).

@crosbymichael @vmarmol @rjnagal PTAL and try it out :)

@dqminh
Copy link
Contributor

dqminh commented Dec 18, 2014

yay, i tried with a custom Dockerfile that has go 1.4 and it seems to work.

# inside sh nsinit shell
drwxr-xr-x    2 root     root        4.0K Dec 18 09:42 .
drwxrwxr-x    5 65534    65534       4.0K Dec 18 09:42 ..
-rw-r--r--    1 root     root           6 Dec 18 09:42 test

# 26792 is the pid of sh process spawned by make sh
❯ cat /proc/26792/gid_map                                                                                
         0       1000          1
         1          1        999
      1001       1001       9000
❯ cat /proc/26792/uid_map                                                                                
         0       1000          1
         1          1        999
      1001       1001       9000

@mrunalp
Copy link
Contributor Author

mrunalp commented Dec 18, 2014

@dqminh Thanks for testing it out! :)

@@ -58,14 +58,17 @@ func InitializeMountNamespace(rootfs, console string, sysReadonly bool, mountCon
return fmt.Errorf("create device nodes %s", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

mknod isn't allowed in a non-root userns

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The setup process is run in the root userns. The init is started (cloning into userns) and then waits for setup to run and set things up. Setup joins all the namespaces of init except userns. Thanks for taking a look. Feedback and suggestions appreciated.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mrunalp Sorry, I don't get the idea with a setup process. Which actions can't be done from userns? Could you elaborate? Maybe you can add a comment before the SetupContainer() function.
LoadContainerEnvironment(), apparmor.ApplyProfile(), label.SetProcessLabel() affect only a current process. Now we call them for the setup process and don't call for the init process. Where are these parameters applied to the init process?
Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right about SetProcessLabel and ApplyProfile. I have to move them to init. I was aware but missed moving them back. I will post an updated patch with more comments. Thanks.

Sent from my iPhone

On Jan 13, 2015, at 12:29 AM, Andrew Vagin notifications@github.com wrote:

In mount/init.go:

@@ -58,14 +58,17 @@ func InitializeMountNamespace(rootfs, console string, sysReadonly bool, mountCon
return fmt.Errorf("create device nodes %s", err)
@mrunalp Sorry, I don't get the idea with a setup process. Which actions can't be done from userns? Could you elaborate? Maybe you can add a comment before the SetupContainer() function.
LoadContainerEnvironment(), apparmor.ApplyProfile(), label.SetProcessLabel() affect only a current process. Now we call them for the setup process and don't call for the init process. Where are these parameters applied to the init process?
Thanks.


Reply to this email directly or view it on GitHub.

@mrunalp
Copy link
Contributor Author

mrunalp commented Jan 2, 2015

@avagin Yes, we need to add support for userns to nsenter. I was thinking of doing that in follow on patches after this one gets in.

@mrunalp mrunalp force-pushed the feature/user_namespaces branch 2 times, most recently from 95746d1 to ce7d276 Compare January 5, 2015 21:50
@crosbymichael
Copy link
Contributor

This is looking good, just installed Go 1.4 for testing

@crosbymichael
Copy link
Contributor

Maybe we can get this merged this week.

ping @LK4D4 @vmarmol

@mrunalp
Copy link
Contributor Author

mrunalp commented Jan 13, 2015

Cool, I will rebase it and address comments.

@mrunalp
Copy link
Contributor Author

mrunalp commented Jan 16, 2015

Ping anyone? :)

@LK4D4
Copy link
Contributor

LK4D4 commented Jan 16, 2015

@mrunalp Hah, sorry, will review now.

@@ -21,7 +21,7 @@ func Setup(rootfs, consolePath, mountLabel string) error {
return err
}

if err := os.Chown(consolePath, 0, 0); err != nil {
if err := os.Chown(consolePath, hostRootUid, hostRootUid); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this always true, that hostRootUid == hostRootGid?

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 could make that assumption since it doesn't make sense to have separate uid/gid mappings. (Even though we have exposed that).

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 think we can pass down hostRootGid as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@mrunalp
Copy link
Contributor Author

mrunalp commented Jan 19, 2015

@LK4D4 Any more comments? :)

return err
}
if consolePath != "" {
if err := console.OpenAndDup("/dev/console"); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be consolePath instead of hard coded /dev/console?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The mount setup is done before we reach here to setup /dev/console and the original consolePath isn't available anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ic

// to perform these operations.
func SetupContainer(container *libcontainer.Config, args []string) error {
consolePath := ""
dataPath := args[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this just be parameters of the function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, fixing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Signed-off-by: Mrunal Patel <mrunalp@gmail.com> (github: mrunalp)

Adds sample configuration to test user namespaces.
Signed-off-by: Mrunal Patel <mrunalp@gmail.com> (github: mrunalp)

Rebases to master.
Signed-off-by: Mrunal Patel <mrunalp@gmail.com> (github: mrunalp)

Fixes integration tests.
Signed-off-by: Mrunal Patel <mrunalp@gmail.com> (github: mrunalp)

Move selinux labeling, apparmor profile and restrict kernel files back to init.

Signed-off-by: Mrunal Patel <mrunalp@gmail.com> (github: mrunalp)

Separate the code paths for userns and default cases.

Signed-off-by: Mrunal Patel <mrunalp@gmail.com> (github: mrunalp)

tty not required for setup

Signed-off-by: Mrunal Patel <mrunalp@gmail.com> (github: mrunalp)

Cleanup and address review comments.

Signed-off-by: Mrunal Patel <mrunalp@gmail.com> (github: mrunalp)

Remove debug logs and other cleanup.

Signed-off-by: Mrunal Patel <mrunalp@gmail.com> (github: mrunalp)

Use function paramaters for SetupContainer.

Signed-off-by: Mrunal Patel <mrunalp@gmail.com> (github: mrunalp)
@crosbymichael
Copy link
Contributor

LGTM

@LK4D4
Copy link
Contributor

LK4D4 commented Jan 19, 2015

LGTM

LK4D4 added a commit that referenced this pull request Jan 19, 2015
Adds user namespace support to libcontainer
@LK4D4 LK4D4 merged commit b89cd0c into docker-archive:master Jan 19, 2015
@brauner
Copy link

brauner commented Jan 20, 2015

Really looking forward to this. Out of impatience when can we expect to make use of uid and gid mappings with docker run?

@mrunalp
Copy link
Contributor Author

mrunalp commented Jan 20, 2015

@brauner Don't know when that will land, but work has started on basic docker integration. Keep an eye on the PRs :)

@brauner
Copy link

brauner commented Jan 20, 2015

@mrunalp excellent! :)

@slafs
Copy link

slafs commented Jan 23, 2015

This is great! Can you please link a relevant PR from Docker to this one?

@LK4D4
Copy link
Contributor

LK4D4 commented Jan 23, 2015

@slafs We will link when we create it :)

@TomasTomecek
Copy link

@slafs moby/moby#12648

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants