YARN-8228. Added hostname length check for docker container.

Contributed by Shane Kumpf
This commit is contained in:
Eric Yang 2018-04-30 19:12:53 -04:00
parent 919865a34b
commit a966ec6e23
2 changed files with 19 additions and 0 deletions

View File

@ -199,6 +199,7 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime {
HOSTNAME_PATTERN);
private static final Pattern USER_MOUNT_PATTERN = Pattern.compile(
"(?<=^|,)([^:\\x00]+):([^:\\x00]+):([a-z]+)");
private static final int HOST_NAME_LENGTH = 64;
@InterfaceAudience.Private
public static final String ENV_DOCKER_CONTAINER_IMAGE =
@ -541,6 +542,11 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime {
throw new ContainerExecutionException("Hostname '" + hostname
+ "' doesn't match docker hostname pattern");
}
if (hostname.length() > HOST_NAME_LENGTH) {
throw new ContainerExecutionException(
"Hostname can not be greater than " + HOST_NAME_LENGTH
+ " characters: " + hostname);
}
}
}

View File

@ -1539,6 +1539,19 @@ public class TestDockerContainerRuntime {
}
}
@Test
public void testValidDockerHostnameLength() throws Exception {
String validLength = "example.test.site";
DockerLinuxContainerRuntime.validateHostname(validLength);
}
@Test(expected = ContainerExecutionException.class)
public void testInvalidDockerHostnameLength() throws Exception {
String invalidLength =
"exampleexampleexampleexampleexampleexampleexampleexample.test.site";
DockerLinuxContainerRuntime.validateHostname(invalidLength);
}
@SuppressWarnings("unchecked")
private void checkVolumeCreateCommand()
throws PrivilegedOperationException, IOException {