| 79 | |
| 80 | |
| 81 | TEST_P(LinuxDevicesIsolatorTest, |
| 82 | ROOT_UNPRIVILEGED_USER_PopulateWhitelistedDevices) |
| 83 | { |
| 84 | // Verify that all the necessary devices are present on the host. |
| 85 | // All reasonable Linux configuration should have these devices. |
| 86 | ASSERT_TRUE(os::exists("/dev/kmsg")); |
| 87 | ASSERT_TRUE(os::exists("/dev/loop-control")); |
| 88 | ASSERT_TRUE(os::exists("/dev/net/tun")); |
| 89 | |
| 90 | slave::Flags flags = CreateSlaveFlags(); |
| 91 | |
| 92 | flags.isolation = "linux/devices,filesystem/linux,docker/runtime"; |
| 93 | flags.docker_registry = path::join(sandbox.get(), "registry"); |
| 94 | flags.docker_store_dir = path::join(sandbox.get(), "store"); |
| 95 | flags.image_providers = "docker"; |
| 96 | |
| 97 | flags.allowed_devices = |
| 98 | flags::parse<DeviceWhitelist>(param.allowedDevices).get(); |
| 99 | |
| 100 | AWAIT_READY(DockerArchive::create(flags.docker_registry, "test_image")); |
| 101 | |
| 102 | Fetcher fetcher(flags); |
| 103 | |
| 104 | Try<MesosContainerizer*> create = |
| 105 | MesosContainerizer::create(flags, true, &fetcher); |
| 106 | |
| 107 | ASSERT_SOME(create); |
| 108 | |
| 109 | Owned<Containerizer> containerizer(create.get()); |
| 110 | |
| 111 | ContainerID containerId; |
| 112 | containerId.set_value(id::UUID::random().toString()); |
| 113 | |
| 114 | ExecutorInfo executor = createExecutorInfo( |
| 115 | "test_executor", |
| 116 | strings::join(";", "ls -l /dev", param.containerCheck)); |
| 117 | |
| 118 | executor.mutable_container()->CopyFrom(createContainerInfo("test_image")); |
| 119 | |
| 120 | string directory = path::join(flags.work_dir, "sandbox"); |
| 121 | ASSERT_SOME(os::mkdir(directory)); |
| 122 | |
| 123 | // Launch the container check command as the non-root user. All the |
| 124 | // check commands are testing for device file access, but root will |
| 125 | // always have access. |
| 126 | Future<Containerizer::LaunchResult> launch = containerizer->launch( |
| 127 | containerId, |
| 128 | createContainerConfig( |
| 129 | None(), executor, directory, os::getenv("SUDO_USER").get()), |
| 130 | map<string, string>(), |
| 131 | None()); |
| 132 | |
| 133 | AWAIT_ASSERT_EQ(Containerizer::LaunchResult::SUCCESS, launch); |
| 134 | |
| 135 | Future<Option<ContainerTermination>> wait = containerizer->wait(containerId); |
| 136 | |
| 137 | AWAIT_READY(wait); |
| 138 | ASSERT_SOME(wait.get()); |
nothing calls this directly
no test coverage detected