diff --git a/container_linux_test.go b/container_linux_test.go index 3140ff3be..8fa8133a2 100644 --- a/container_linux_test.go +++ b/container_linux_test.go @@ -1321,3 +1321,38 @@ func TestContainerNoImage(t *testing.T) { t.Fatalf("expected error to be %s but received %s", errdefs.ErrNotFound, err) } } + +func TestUIDNoGID(t *testing.T) { + t.Parallel() + + ctx, cancel := testContext() + defer cancel() + id := t.Name() + + client, err := newClient(t, address) + if err != nil { + t.Fatal(err) + } + defer client.Close() + image, err := client.GetImage(ctx, testImage) + if err != nil { + t.Fatal(err) + } + + container, err := client.NewContainer(ctx, id, WithNewSnapshot(id, image), WithNewSpec(oci.WithUserID(1000))) + if err != nil { + t.Fatal(err) + } + defer container.Delete(ctx) + + spec, err := container.Spec(ctx) + if err != nil { + t.Fatal(err) + } + if uid := spec.Process.User.UID; uid != 1000 { + t.Fatalf("expected uid 1000 but received %d", uid) + } + if gid := spec.Process.User.GID; gid != 0 { + t.Fatalf("expected gid 0 but received %d", gid) + } +} diff --git a/oci/spec_opts_unix.go b/oci/spec_opts_unix.go index 9b01afa44..e42f61da1 100644 --- a/oci/spec_opts_unix.go +++ b/oci/spec_opts_unix.go @@ -371,7 +371,7 @@ func WithUserID(uid uint32) SpecOpts { }) if err != nil { if os.IsNotExist(err) || err == errNoUsersFound { - s.Process.User.UID, s.Process.User.GID = uid, uid + s.Process.User.UID, s.Process.User.GID = uid, 0 return nil } return err @@ -397,7 +397,7 @@ func WithUserID(uid uint32) SpecOpts { }) if err != nil { if os.IsNotExist(err) || err == errNoUsersFound { - s.Process.User.UID, s.Process.User.GID = uid, uid + s.Process.User.UID, s.Process.User.GID = uid, 0 return nil } return err