@@ -119,6 +119,59 @@ function setup() {
119
119
#
120
120
}
121
121
122
+ @test " runc exec (cgroup v2 without chown-cgroup annotation) does not chown cgroup" {
123
+ requires root cgroups_v2 systemd
124
+
125
+ set_cgroups_path
126
+ set_cgroup_mount_writable
127
+
128
+ # configure a user namespace
129
+ update_config ' .linux.namespaces += [{"type": "user"}]'
130
+ update_config ' .linux.uidMappings += [{"hostID": 100000, "containerID": 0, "size": 65536}]'
131
+ update_config ' .linux.gidMappings += [{"hostID": 100000, "containerID": 0, "size": 65536}]'
132
+
133
+ # chown test temp dir to allow host user to read it
134
+ chown 100000 $ROOT
135
+
136
+ # chown rootfs to allow host user to mkdir mount points
137
+ chown 100000 $ROOT /bundle/rootfs
138
+
139
+ runc run -d --console-socket " $CONSOLE_SOCKET " test_cgroup_chown
140
+ [ " $status " -eq 0 ]
141
+
142
+ runc exec test_cgroup_chown sh -c " ls -ld /sys/fs/cgroup | awk '{print \$ 3}'"
143
+ [ " $status " -eq 0 ]
144
+ [ " $output " = " nobody" ] # /sys/fs/cgroup owned by unmapped user
145
+ }
146
+
147
+ @test " runc exec (cgroup v2 with chown-cgroup annotation) does chown cgroup" {
148
+ requires root cgroups_v2 systemd
149
+
150
+ set_cgroups_path
151
+ set_cgroup_mount_writable
152
+
153
+ # configure a user namespace
154
+ update_config ' .linux.namespaces += [{"type": "user"}]'
155
+ update_config ' .linux.uidMappings += [{"hostID": 100000, "containerID": 0, "size": 65536}]'
156
+ update_config ' .linux.gidMappings += [{"hostID": 100000, "containerID": 0, "size": 65536}]'
157
+
158
+ # set chown-cgroup annotation
159
+ update_config ' .annotations += {"org.opencontainers.runc.chown-cgroup": "true"}'
160
+
161
+ # chown test temp dir to allow host user to read it
162
+ chown 100000 $ROOT
163
+
164
+ # chown rootfs to allow host user to mkdir mount points
165
+ chown 100000 $ROOT /bundle/rootfs
166
+
167
+ runc run -d --console-socket " $CONSOLE_SOCKET " test_cgroup_chown
168
+ [ " $status " -eq 0 ]
169
+
170
+ runc exec test_cgroup_chown sh -c " ls -ld /sys/fs/cgroup | awk '{print \$ 3}'"
171
+ [ " $status " -eq 0 ]
172
+ [ " $output " = " root" ] # /sys/fs/cgroup owned by root (of user namespace)
173
+ }
174
+
122
175
@test " runc run (cgroup v1 + unified resources should fail)" {
123
176
requires root cgroups_v1
124
177
0 commit comments