Skip to content

Commit 96725a5

Browse files
authored
Merge pull request containerd#1620 from mlaventure/runc-io-id
Allow setting the uid & gid of the io pipes
2 parents 1ea8ac4 + c807ba8 commit 96725a5

File tree

11 files changed

+216
-126
lines changed

11 files changed

+216
-126
lines changed

container_linux_test.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,3 +979,93 @@ func TestContainerKillInitPidHost(t *testing.T) {
979979
t.Error(err)
980980
}
981981
}
982+
983+
func TestUserNamespaces(t *testing.T) {
984+
t.Parallel()
985+
t.Run("WritableRootFS", func(t *testing.T) { testUserNamespaces(t, false) })
986+
// see #1373 and runc#1572
987+
t.Run("ReadonlyRootFS", func(t *testing.T) { testUserNamespaces(t, true) })
988+
}
989+
990+
func testUserNamespaces(t *testing.T, readonlyRootFS bool) {
991+
client, err := newClient(t, address)
992+
if err != nil {
993+
t.Fatal(err)
994+
}
995+
defer client.Close()
996+
997+
var (
998+
image Image
999+
ctx, cancel = testContext()
1000+
id = strings.Replace(t.Name(), "/", "-", -1)
1001+
)
1002+
defer cancel()
1003+
1004+
image, err = client.GetImage(ctx, testImage)
1005+
if err != nil {
1006+
t.Error(err)
1007+
return
1008+
}
1009+
1010+
opts := []NewContainerOpts{WithNewSpec(withImageConfig(image),
1011+
withExitStatus(7),
1012+
WithUserNamespace(0, 1000, 10000),
1013+
)}
1014+
if readonlyRootFS {
1015+
opts = append(opts, withRemappedSnapshotView(id, image, 1000, 1000))
1016+
} else {
1017+
opts = append(opts, withRemappedSnapshot(id, image, 1000, 1000))
1018+
}
1019+
1020+
container, err := client.NewContainer(ctx, id, opts...)
1021+
if err != nil {
1022+
t.Error(err)
1023+
return
1024+
}
1025+
defer container.Delete(ctx, WithSnapshotCleanup)
1026+
1027+
task, err := container.NewTask(ctx, Stdio, func(_ context.Context, client *Client, r *TaskInfo) error {
1028+
r.Options = &runcopts.CreateOptions{
1029+
IoUid: 1000,
1030+
IoGid: 1000,
1031+
}
1032+
return nil
1033+
})
1034+
if err != nil {
1035+
t.Error(err)
1036+
return
1037+
}
1038+
defer task.Delete(ctx)
1039+
1040+
statusC, err := task.Wait(ctx)
1041+
if err != nil {
1042+
t.Error(err)
1043+
return
1044+
}
1045+
1046+
if pid := task.Pid(); pid <= 0 {
1047+
t.Errorf("invalid task pid %d", pid)
1048+
}
1049+
if err := task.Start(ctx); err != nil {
1050+
t.Error(err)
1051+
task.Delete(ctx)
1052+
return
1053+
}
1054+
status := <-statusC
1055+
code, _, err := status.Result()
1056+
if err != nil {
1057+
t.Error(err)
1058+
return
1059+
}
1060+
if code != 7 {
1061+
t.Errorf("expected status 7 from wait but received %d", code)
1062+
}
1063+
deleteStatus, err := task.Delete(ctx)
1064+
if err != nil {
1065+
t.Error(err)
1066+
return
1067+
}
1068+
if ec := deleteStatus.ExitCode(); ec != 7 {
1069+
t.Errorf("expected status 7 from delete but received %d", ec)
1070+
}
1071+
}

container_test.go

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -706,92 +706,6 @@ func TestContainerExecNoBinaryExists(t *testing.T) {
706706
<-finishedC
707707
}
708708

709-
func TestUserNamespaces(t *testing.T) {
710-
t.Parallel()
711-
t.Run("WritableRootFS", func(t *testing.T) { testUserNamespaces(t, false) })
712-
// see #1373 and runc#1572
713-
t.Run("ReadonlyRootFS", func(t *testing.T) { testUserNamespaces(t, true) })
714-
}
715-
716-
func testUserNamespaces(t *testing.T, readonlyRootFS bool) {
717-
client, err := newClient(t, address)
718-
if err != nil {
719-
t.Fatal(err)
720-
}
721-
defer client.Close()
722-
723-
var (
724-
image Image
725-
ctx, cancel = testContext()
726-
id = strings.Replace(t.Name(), "/", "-", -1)
727-
)
728-
defer cancel()
729-
730-
if runtime.GOOS != "windows" {
731-
image, err = client.GetImage(ctx, testImage)
732-
if err != nil {
733-
t.Error(err)
734-
return
735-
}
736-
}
737-
738-
opts := []NewContainerOpts{WithNewSpec(withImageConfig(image),
739-
withExitStatus(7),
740-
withUserNamespace(0, 1000, 10000),
741-
)}
742-
if readonlyRootFS {
743-
opts = append(opts, withRemappedSnapshotView(id, image, 1000, 1000))
744-
} else {
745-
opts = append(opts, withRemappedSnapshot(id, image, 1000, 1000))
746-
}
747-
748-
container, err := client.NewContainer(ctx, id, opts...)
749-
if err != nil {
750-
t.Error(err)
751-
return
752-
}
753-
defer container.Delete(ctx, WithSnapshotCleanup)
754-
755-
task, err := container.NewTask(ctx, empty())
756-
if err != nil {
757-
t.Error(err)
758-
return
759-
}
760-
defer task.Delete(ctx)
761-
762-
statusC, err := task.Wait(ctx)
763-
if err != nil {
764-
t.Error(err)
765-
return
766-
}
767-
768-
if pid := task.Pid(); pid <= 0 {
769-
t.Errorf("invalid task pid %d", pid)
770-
}
771-
if err := task.Start(ctx); err != nil {
772-
t.Error(err)
773-
task.Delete(ctx)
774-
return
775-
}
776-
status := <-statusC
777-
code, _, err := status.Result()
778-
if err != nil {
779-
t.Error(err)
780-
return
781-
}
782-
if code != 7 {
783-
t.Errorf("expected status 7 from wait but received %d", code)
784-
}
785-
deleteStatus, err := task.Delete(ctx)
786-
if err != nil {
787-
t.Error(err)
788-
return
789-
}
790-
if ec := deleteStatus.ExitCode(); ec != 7 {
791-
t.Errorf("expected status 7 from delete but received %d", ec)
792-
}
793-
}
794-
795709
func TestWaitStoppedTask(t *testing.T) {
796710
t.Parallel()
797711

helpers_unix_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func withExecArgs(s *specs.Process, args ...string) {
4040
}
4141

4242
var (
43-
withUserNamespace = WithUserNamespace
4443
withRemappedSnapshot = WithRemappedSnapshot
4544
withRemappedSnapshotView = WithRemappedSnapshotView
4645
withNewSnapshot = WithNewSnapshot

helpers_windows_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ func withNewSnapshot(id string, i Image) NewContainerOpts {
5353
}
5454
}
5555

56-
func withUserNamespace(u, g, s uint32) SpecOpts {
57-
return withNoop
58-
}
59-
6056
func withRemappedSnapshot(id string, i Image, u, g uint32) NewContainerOpts {
6157
return func(ctx context.Context, client *Client, c *containers.Container) error {
6258
return nil

linux/runcopts/next.pb.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,20 @@ file {
9898
type: TYPE_STRING
9999
json_name: "shimCgroup"
100100
}
101+
field {
102+
name: "io_uid"
103+
number: 10
104+
label: LABEL_OPTIONAL
105+
type: TYPE_UINT32
106+
json_name: "ioUid"
107+
}
108+
field {
109+
name: "io_gid"
110+
number: 11
111+
label: LABEL_OPTIONAL
112+
type: TYPE_UINT32
113+
json_name: "ioGid"
114+
}
101115
}
102116
message_type {
103117
name: "CheckpointOptions"

linux/runcopts/runc.pb.go

Lines changed: 90 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

linux/runcopts/runc.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ message CreateOptions {
2323
string cgroups_mode = 7;
2424
bool no_new_keyring = 8;
2525
string shim_cgroup = 9;
26+
uint32 io_uid = 10;
27+
uint32 io_gid = 11;
2628
}
2729

2830
message CheckpointOptions {

0 commit comments

Comments
 (0)