From e15b86edb935075e46e9a2d07db2ae11677de79e Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Wed, 1 Jul 2015 09:57:26 -0700 Subject: [PATCH] Add user struct based on spec implementation. Signed-off-by: Michael Crosby --- README.md | 6 +++++- main_unsupported.go | 4 ++++ spec.go | 6 ++---- spec_linux.go | 10 ++++++---- utils.go | 2 +- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9ec62397..14da3766 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,11 @@ user named `daemon` defined within that file-system. }, "process": { "terminal": true, - "user": "daemon", + "user": { + "uid": 0, + "gid": 0, + "additionalGids": null + }, "args": [ "sh" ], diff --git a/main_unsupported.go b/main_unsupported.go index 7cb1e9ab..be33a658 100644 --- a/main_unsupported.go +++ b/main_unsupported.go @@ -7,6 +7,10 @@ import ( "github.com/codegangsta/cli" ) +type User struct { + NOTSUPPORTED string +} + func getDefaultID() string { return "" } diff --git a/spec.go b/spec.go index 42f80c89..47cf3467 100644 --- a/spec.go +++ b/spec.go @@ -9,8 +9,6 @@ import ( "github.com/codegangsta/cli" ) -const cpuQuotaMultiplyer = 100000 - type Mount struct { Type string `json:"type"` Source string `json:"source"` @@ -20,7 +18,7 @@ type Mount struct { type Process struct { Terminal bool `json:"terminal"` - User string `json:"user"` + User User `json:"user"` Args []string `json:"args"` Env []string `json:"env"` Cwd string `json:"cwd"` @@ -61,7 +59,7 @@ var specCommand = cli.Command{ }, Process: Process{ Terminal: true, - User: "daemon", + User: User{}, Args: []string{ "sh", }, diff --git a/spec_linux.go b/spec_linux.go index 6725e9c4..d49dbdca 100644 --- a/spec_linux.go +++ b/spec_linux.go @@ -30,6 +30,12 @@ type Linux struct { Devices []string `json:"devices"` } +type User struct { + Uid int32 `json:"uid"` + Gid int32 `json:"gid"` + AdditionalGids []int32 `json:"additionalGids"` +} + type Namespace struct { Type string `json:"type"` Path string `json:"path"` @@ -273,10 +279,6 @@ func setReadonly(config *configs.Config) { } } -func getCPUQuota(cpus float64) int64 { - return int64(cpus * cpuQuotaMultiplyer) -} - func setupUserNamespace(spec *Spec, config *configs.Config) error { if len(spec.Linux.UserMapping) == 0 { return nil diff --git a/utils.go b/utils.go index 7153c4d4..8d9f5a67 100644 --- a/utils.go +++ b/utils.go @@ -166,7 +166,7 @@ func newProcess(p Process) *libcontainer.Process { return &libcontainer.Process{ Args: p.Args, Env: p.Env, - User: p.User, + User: fmt.Sprintf("%d:%d", p.User.Uid, p.User.Gid), Cwd: p.Cwd, Stdin: os.Stdin, Stdout: os.Stdout,