From 2dbff1dbcab39ec5c6fc5e2d9381429677bab915 Mon Sep 17 00:00:00 2001 From: Ye Sijun Date: Fri, 5 Aug 2022 18:09:08 +0800 Subject: [PATCH] oci: skip checking gid for WithAppendAdditionalGroups Signed-off-by: Ye Sijun --- oci/spec_opts.go | 14 +++++++++----- oci/spec_opts_linux_test.go | 5 +++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/oci/spec_opts.go b/oci/spec_opts.go index 355fd45b5..cf239cef7 100644 --- a/oci/spec_opts.go +++ b/oci/spec_opts.go @@ -879,15 +879,19 @@ func WithAppendAdditionalGroups(groups ...string) SpecOpts { groupMap := make(map[string]user.Group) for _, group := range ugroups { groupMap[group.Name] = group - groupMap[strconv.Itoa(group.Gid)] = group } var gids []uint32 for _, group := range groups { - g, ok := groupMap[group] - if !ok { - return fmt.Errorf("unable to find group %s", group) + gid, err := strconv.ParseUint(group, 10, 32) + if err == nil { + gids = append(gids, uint32(gid)) + } else { + g, ok := groupMap[group] + if !ok { + return fmt.Errorf("unable to find group %s", group) + } + gids = append(gids, uint32(g.Gid)) } - gids = append(gids, uint32(g.Gid)) } s.Process.User.AdditionalGids = append(s.Process.User.AdditionalGids, gids...) return nil diff --git a/oci/spec_opts_linux_test.go b/oci/spec_opts_linux_test.go index 08cbd71ef..d41e0efca 100644 --- a/oci/spec_opts_linux_test.go +++ b/oci/spec_opts_linux_test.go @@ -476,6 +476,11 @@ daemon:x:2:root,bin,daemon groups: []string{"bin", "daemon"}, expected: []uint32{0, 1, 2}, }, + { + name: "append group id", + groups: []string{"999"}, + expected: []uint32{999}, + }, { name: "unknown group", groups: []string{"unknown"},