Use Int64SliceFlag instead of StringFlag to get additional gids.

Signed-off-by: Sumit Sanghrajka <sumit.sanghrajka@gmail.com>
This commit is contained in:
Sumit Sanghrajka
2017-02-06 19:29:40 -08:00
committed by Michael Crosby
parent 7a386c2b60
commit f55f79d6ba
3 changed files with 7 additions and 13 deletions

14
exec.go
View File

@@ -50,9 +50,9 @@ following will output a list of processes running in the container:
Name: "user, u", Name: "user, u",
Usage: "UID (format: <uid>[:<gid>])", Usage: "UID (format: <uid>[:<gid>])",
}, },
cli.StringFlag{ cli.Int64SliceFlag{
Name: "additional-gids, g", Name: "additional-gids, g",
Usage: "additional gids separated by comma", Usage: "additional gids",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "process, p", Name: "process, p",
@@ -212,14 +212,8 @@ func getProcess(context *cli.Context, bundle string) (*specs.Process, error) {
} }
p.User.UID = uint32(uid) p.User.UID = uint32(uid)
} }
if context.String("additional-gids") != "" { for _, gid := range context.Int64Slice("additional-gids") {
for _, i := range strings.Split(context.String("additional-gids"), ",") { p.User.AdditionalGids = append(p.User.AdditionalGids, uint32(gid))
gid, err := strconv.Atoi(i)
if err != nil {
return nil, fmt.Errorf("parsing %s as int for gid failed: %v", i, err)
}
p.User.AdditionalGids = append(p.User.AdditionalGids, uint32(gid))
}
} }
return p, nil return p, nil
} }

View File

@@ -19,7 +19,7 @@ following will output a list of processes running in the container:
--env value, -e value set environment variables --env value, -e value set environment variables
--tty, -t allocate a pseudo-TTY --tty, -t allocate a pseudo-TTY
--user value, -u value UID (format: <uid>[:<gid>]) --user value, -u value UID (format: <uid>[:<gid>])
--additional-gids value, -g value additional gids separated by comma --additional-gids value, -g value additional gids
--process value, -p value path to the process.json --process value, -p value path to the process.json
--detach, -d detach from the container's process --detach, -d detach from the container's process
--pid-file value specify the file to write the process id to --pid-file value specify the file to write the process id to

View File

@@ -120,8 +120,8 @@ function teardown() {
wait_for_container 15 1 test_busybox wait_for_container 15 1 test_busybox
runc exec --user 1000:1000 --additional-gids 100 test_busybox id runc exec --user 1000:1000 --additional-gids 100 --additional-gids 99 test_busybox id
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${output} == "uid=1000 gid=1000 groups=100(users)" ]] [[ ${output} == "uid=1000 gid=1000 groups=99(nogroup),100(users)" ]]
} }