|
@@ -1035,6 +1035,115 @@ public class TestDockerContainerRuntime {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testUserMounts()
|
|
|
+ throws ContainerExecutionException, PrivilegedOperationException,
|
|
|
+ IOException{
|
|
|
+ DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
+ runtime.initialize(conf, null);
|
|
|
+
|
|
|
+ env.put(
|
|
|
+ DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_MOUNTS,
|
|
|
+ "/tmp/foo:/tmp/foo:ro,/tmp/bar:/tmp/bar:rw");
|
|
|
+
|
|
|
+ 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"));
|
|
|
+
|
|
|
+ Assert.assertEquals(14, dockerCommands.size());
|
|
|
+ Assert.assertEquals("[docker-command-execution]", dockerCommands.get(0));
|
|
|
+ Assert.assertEquals(" cap-add=SYS_CHROOT,NET_BIND_SERVICE",
|
|
|
+ dockerCommands.get(1));
|
|
|
+ Assert.assertEquals(" cap-drop=ALL", dockerCommands.get(2));
|
|
|
+ Assert.assertEquals(" detach=true", dockerCommands.get(3));
|
|
|
+ Assert.assertEquals(" docker-command=run", dockerCommands.get(4));
|
|
|
+ Assert.assertEquals(" hostname=ctr-id", dockerCommands.get(5));
|
|
|
+ Assert.assertEquals(" image=busybox:latest", dockerCommands.get(6));
|
|
|
+ Assert.assertEquals(
|
|
|
+ " launch-command=bash,/test_container_work_dir/launch_container.sh",
|
|
|
+ dockerCommands.get(7));
|
|
|
+ Assert.assertEquals(" name=container_id", dockerCommands.get(8));
|
|
|
+ Assert.assertEquals(" net=host", dockerCommands.get(9));
|
|
|
+ Assert.assertEquals(" ro-mounts=/tmp/foo:/tmp/foo",
|
|
|
+ dockerCommands.get(10));
|
|
|
+ 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,"
|
|
|
+ + "/tmp/bar:/tmp/bar",
|
|
|
+ dockerCommands.get(11));
|
|
|
+ Assert.assertEquals(" user=run_as_user", dockerCommands.get(12));
|
|
|
+ Assert.assertEquals(" workdir=/test_container_work_dir",
|
|
|
+ dockerCommands.get(13));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testUserMountInvalid()
|
|
|
+ throws ContainerExecutionException, PrivilegedOperationException,
|
|
|
+ IOException{
|
|
|
+ DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
+ runtime.initialize(conf, null);
|
|
|
+
|
|
|
+ env.put(
|
|
|
+ DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_MOUNTS,
|
|
|
+ "source:target");
|
|
|
+
|
|
|
+ try {
|
|
|
+ runtime.launchContainer(builder.build());
|
|
|
+ Assert.fail("Expected a launch container failure due to invalid mount.");
|
|
|
+ } catch (ContainerExecutionException e) {
|
|
|
+ LOG.info("Caught expected exception : " + e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testUserMountModeInvalid()
|
|
|
+ throws ContainerExecutionException, PrivilegedOperationException,
|
|
|
+ IOException{
|
|
|
+ DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
+ runtime.initialize(conf, null);
|
|
|
+
|
|
|
+ env.put(
|
|
|
+ DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_MOUNTS,
|
|
|
+ "source:target:other");
|
|
|
+
|
|
|
+ try {
|
|
|
+ runtime.launchContainer(builder.build());
|
|
|
+ Assert.fail("Expected a launch container failure due to invalid mode.");
|
|
|
+ } catch (ContainerExecutionException e) {
|
|
|
+ LOG.info("Caught expected exception : " + e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testUserMountModeNulInvalid()
|
|
|
+ throws ContainerExecutionException, PrivilegedOperationException,
|
|
|
+ IOException{
|
|
|
+ DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
+ runtime.initialize(conf, null);
|
|
|
+
|
|
|
+ env.put(
|
|
|
+ DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_MOUNTS,
|
|
|
+ "s\0ource:target:ro");
|
|
|
+
|
|
|
+ try {
|
|
|
+ runtime.launchContainer(builder.build());
|
|
|
+ Assert.fail("Expected a launch container failure due to NUL in mount.");
|
|
|
+ } catch (ContainerExecutionException e) {
|
|
|
+ LOG.info("Caught expected exception : " + e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testContainerLivelinessCheck()
|
|
|
throws ContainerExecutionException, PrivilegedOperationException {
|