Merge pull request #280 from crosbymichael/stdio-perms

Fix STDIO permissions when container user not root
This commit is contained in:
Michael Crosby
2015-09-21 11:23:29 -07:00
2 changed files with 31 additions and 1 deletions
+11 -1
View File
@@ -187,7 +187,17 @@ func setupUser(config *initConfig) error {
return err
}
}
// change the permissions on the STDIO of the current process so that when the user
// is changed for the container, it's STDIO of the process matches the user.
for _, fd := range []uintptr{
os.Stdin.Fd(),
os.Stderr.Fd(),
os.Stdout.Fd(),
} {
if err := syscall.Fchown(int(fd), execUser.Uid, execUser.Gid); err != nil {
return err
}
}
suppGroups := append(execUser.Sgids, addGroups...)
if err := syscall.Setgroups(suppGroups); err != nil {
return err
+20
View File
@@ -994,3 +994,23 @@ func TestHook(t *testing.T) {
t.Fatalf("expected file to not exist, got %s", fi.Name())
}
}
func TestSTDIOPermissions(t *testing.T) {
if testing.Short() {
return
}
rootfs, err := newRootfs()
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(rootfs)
buffers, exitCode, err := runContainer(config, "", "sh", "-c", "echo hi > /dev/stderr")
ok(t, err)
if exitCode != 0 {
t.Fatalf("exit code not 0. code %d stderr %q", exitCode, buffers.Stderr)
}
if actual := strings.Trim(buffers.Stderr.String(), "\n"); actual != "hi" {
t.Fatalf("stderr should equal be equal %q %q", actual, "hi")
}
}