|
@@ -694,7 +694,7 @@ public class TestDockerContainerRuntime {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testLaunchPrivilegedContainersInvalidEnvVar()
|
|
|
+ public void testLaunchPidNamespaceContainersInvalidEnvVar()
|
|
|
throws ContainerExecutionException, PrivilegedOperationException,
|
|
|
IOException{
|
|
|
DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
@@ -702,7 +702,7 @@ public class TestDockerContainerRuntime {
|
|
|
runtime.initialize(conf, null);
|
|
|
|
|
|
env.put(DockerLinuxContainerRuntime
|
|
|
- .ENV_DOCKER_CONTAINER_RUN_PRIVILEGED_CONTAINER, "invalid-value");
|
|
|
+ .ENV_DOCKER_CONTAINER_PID_NAMESPACE, "invalid-value");
|
|
|
runtime.launchContainer(builder.build());
|
|
|
|
|
|
PrivilegedOperation op = capturePrivilegedOperationAndVerifyArgs();
|
|
@@ -717,6 +717,107 @@ public class TestDockerContainerRuntime {
|
|
|
|
|
|
String command = dockerCommands.get(0);
|
|
|
|
|
|
+ //ensure --pid isn't in the invocation
|
|
|
+ Assert.assertTrue("Unexpected --pid in docker run args : " + command,
|
|
|
+ !command.contains("--pid"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testLaunchPidNamespaceContainersWithDisabledSetting()
|
|
|
+ throws ContainerExecutionException {
|
|
|
+ DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
+ runtime.initialize(conf, null);
|
|
|
+
|
|
|
+ env.put(DockerLinuxContainerRuntime
|
|
|
+ .ENV_DOCKER_CONTAINER_PID_NAMESPACE, "host");
|
|
|
+
|
|
|
+ try {
|
|
|
+ runtime.launchContainer(builder.build());
|
|
|
+ Assert.fail("Expected a pid host disabled container failure.");
|
|
|
+ } catch (ContainerExecutionException e) {
|
|
|
+ LOG.info("Caught expected exception : " + e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testLaunchPidNamespaceContainersEnabled()
|
|
|
+ throws ContainerExecutionException, PrivilegedOperationException,
|
|
|
+ IOException{
|
|
|
+ //Enable host pid namespace containers.
|
|
|
+ conf.setBoolean(YarnConfiguration.NM_DOCKER_ALLOW_HOST_PID_NAMESPACE,
|
|
|
+ true);
|
|
|
+
|
|
|
+ DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
+ runtime.initialize(conf, null);
|
|
|
+
|
|
|
+ env.put(DockerLinuxContainerRuntime
|
|
|
+ .ENV_DOCKER_CONTAINER_PID_NAMESPACE, "host");
|
|
|
+
|
|
|
+ runtime.launchContainer(builder.build());
|
|
|
+ PrivilegedOperation op = capturePrivilegedOperationAndVerifyArgs();
|
|
|
+ List<String> args = op.getArguments();
|
|
|
+ String dockerCommandFile = args.get(11);
|
|
|
+
|
|
|
+ List<String> dockerCommands = Files.readAllLines(
|
|
|
+ Paths.get(dockerCommandFile), Charset.forName("UTF-8"));
|
|
|
+
|
|
|
+ int expected = 14;
|
|
|
+ int counter = 0;
|
|
|
+ Assert.assertEquals(expected, dockerCommands.size());
|
|
|
+ Assert.assertEquals("[docker-command-execution]",
|
|
|
+ dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" cap-add=SYS_CHROOT,NET_BIND_SERVICE",
|
|
|
+ dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" cap-drop=ALL", dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" detach=true", dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" docker-command=run", dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" hostname=ctr-id", dockerCommands.get(counter++));
|
|
|
+ Assert
|
|
|
+ .assertEquals(" image=busybox:latest", dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(
|
|
|
+ " launch-command=bash,/test_container_work_dir/launch_container.sh",
|
|
|
+ dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" name=container_id", dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" net=host", dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" pid=host", dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(
|
|
|
+ " rw-mounts=/test_container_local_dir:/test_container_local_dir,"
|
|
|
+ + "/test_filecache_dir:/test_filecache_dir,"
|
|
|
+ + "/test_container_work_dir:/test_container_work_dir,"
|
|
|
+ + "/test_container_log_dir:/test_container_log_dir,"
|
|
|
+ + "/test_user_local_dir:/test_user_local_dir",
|
|
|
+ dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" user=run_as_user", dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" workdir=/test_container_work_dir",
|
|
|
+ dockerCommands.get(counter++));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testLaunchPrivilegedContainersInvalidEnvVar()
|
|
|
+ throws ContainerExecutionException, PrivilegedOperationException,
|
|
|
+ IOException{
|
|
|
+ DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
+ runtime.initialize(conf, null);
|
|
|
+
|
|
|
+ env.put(DockerLinuxContainerRuntime
|
|
|
+ .ENV_DOCKER_CONTAINER_RUN_PRIVILEGED_CONTAINER, "invalid-value");
|
|
|
+ runtime.launchContainer(builder.build());
|
|
|
+
|
|
|
+ PrivilegedOperation op = capturePrivilegedOperationAndVerifyArgs();
|
|
|
+ List<String> args = op.getArguments();
|
|
|
+ String dockerCommandFile = args.get(11);
|
|
|
+
|
|
|
+ List<String> dockerCommands = Files.readAllLines(
|
|
|
+ Paths.get(dockerCommandFile), Charset.forName("UTF-8"));
|
|
|
+
|
|
|
+ int expected = 13;
|
|
|
+ Assert.assertEquals(expected, dockerCommands.size());
|
|
|
+
|
|
|
+ String command = dockerCommands.get(0);
|
|
|
+
|
|
|
//ensure --privileged isn't in the invocation
|
|
|
Assert.assertTrue("Unexpected --privileged in docker run args : " + command,
|
|
|
!command.contains("--privileged"));
|