@@ -134,6 +134,64 @@ func testExecInRlimit(t *testing.T, userns bool) {
134134 }
135135}
136136
137+ func TestExecInAdditionalGroups (t * testing.T ) {
138+ if testing .Short () {
139+ return
140+ }
141+
142+ rootfs , err := newRootfs ()
143+ ok (t , err )
144+ defer remove (rootfs )
145+
146+ config := newTemplateConfig (rootfs )
147+ container , err := newContainer (config )
148+ ok (t , err )
149+ defer container .Destroy ()
150+
151+ // Execute a first process in the container
152+ stdinR , stdinW , err := os .Pipe ()
153+ ok (t , err )
154+ process := & libcontainer.Process {
155+ Cwd : "/" ,
156+ Args : []string {"cat" },
157+ Env : standardEnvironment ,
158+ Stdin : stdinR ,
159+ }
160+ err = container .Run (process )
161+ stdinR .Close ()
162+ defer stdinW .Close ()
163+ ok (t , err )
164+
165+ var stdout bytes.Buffer
166+ pconfig := libcontainer.Process {
167+ Cwd : "/" ,
168+ Args : []string {"sh" , "-c" , "id" , "-Gn" },
169+ Env : standardEnvironment ,
170+ Stdin : nil ,
171+ Stdout : & stdout ,
172+ AdditionalGroups : []string {"plugdev" , "audio" },
173+ }
174+ err = container .Run (& pconfig )
175+ ok (t , err )
176+
177+ // Wait for process
178+ waitProcess (& pconfig , t )
179+
180+ stdinW .Close ()
181+ waitProcess (process , t )
182+
183+ outputGroups := string (stdout .Bytes ())
184+
185+ // Check that the groups output has the groups that we specified
186+ if ! strings .Contains (outputGroups , "audio" ) {
187+ t .Fatalf ("Listed groups do not contain the audio group as expected: %v" , outputGroups )
188+ }
189+
190+ if ! strings .Contains (outputGroups , "plugdev" ) {
191+ t .Fatalf ("Listed groups do not contain the plugdev group as expected: %v" , outputGroups )
192+ }
193+ }
194+
137195func TestExecInError (t * testing.T ) {
138196 if testing .Short () {
139197 return
0 commit comments