Class JavaSandboxLinuxContainerRuntime
java.lang.Object
org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.DefaultLinuxContainerRuntime
org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.JavaSandboxLinuxContainerRuntime
- All Implemented Interfaces:
LinuxContainerRuntime,ContainerRuntime
@Private
@Unstable
public class JavaSandboxLinuxContainerRuntime
extends DefaultLinuxContainerRuntime
This class extends the DefaultLinuxContainerRuntime specifically
for containers which run Java commands. It generates a new java security
policy file per container and modifies the java command to enable the
Java Security Manager with the generated policy.
JavaSandboxLinuxContainerRuntime can be modified
using the following settings:
-
"yarn.nodemanager.runtime.linux.sandbox-mode" :
This yarn-site.xml setting has three options:
- disabled - Default behavior.
LinuxContainerRuntimeis disabled - permissive - JVM containers will run with Java Security Manager enabled. Non-JVM containers will run normally
- enforcing - JVM containers will run with Java Security Manager
enabled. Non-JVM containers will be prevented from executing and an
ContainerExecutionExceptionwill be thrown.
- disabled - Default behavior.
-
"yarn.nodemanager.runtime.linux.sandbox-mode.local-dirs.permissions"
:
Determines the file permissions for the application directories. The
permissions come in the form of comma separated values
(e.g. read,write,execute,delete). Defaults to
readfor read-only. - "yarn.nodemanager.runtime.linux.sandbox-mode.policy" : Accepts canonical path to a java policy file on the local filesystem. This file will be loaded as the base policy, any additional container grants will be appended to this base file. If not specified, the default java.policy file provided with hadoop resources will be used.
- "yarn.nodemanager.runtime.linux.sandbox-mode.whitelist-group" : Optional setting to specify a YARN queue which will be exempt from the sand-boxing process.
- "yarn.nodemanager.runtime.linux.sandbox-mode.policy.group."$groupName : Optional setting to map groups to java policy files. The value is a path to the java policy file for $groupName. A user which is a member of multiple groups with different policies will receive the superset of all the permissions across their groups.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration of the modes the JavaSandboxLinuxContainerRuntime can use. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionJavaSandboxLinuxContainerRuntime(PrivilegedOperationExecutor privilegedOperationExecutor) Create an instance using the givenPrivilegedOperationExecutorinstance for performing operations. -
Method Summary
Modifier and TypeMethodDescriptionvoidinitialize(org.apache.hadoop.conf.Configuration conf, Context nmContext) Initialize the runtime.booleanisRuntimeRequested(Map<String, String> env) Determine if JVMSandboxLinuxContainerRuntime should be used.voidLaunch a container.voidPrior to environment from being written locally need to generate policy file which limits container access to a small set of directories.voidRelaunch a container.Methods inherited from class org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.DefaultLinuxContainerRuntime
execContainer, getExposedPorts, getIpAndHost, reapContainer, signalContainerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.LinuxContainerRuntime
getLocalResources, start, stop
-
Field Details
-
POLICY_FILE_DIR
- See Also:
-
-
Constructor Details
-
JavaSandboxLinuxContainerRuntime
Create an instance using the givenPrivilegedOperationExecutorinstance for performing operations.- Parameters:
privilegedOperationExecutor- thePrivilegedOperationExecutorinstance
-
-
Method Details
-
initialize
public void initialize(org.apache.hadoop.conf.Configuration conf, Context nmContext) throws ContainerExecutionException Description copied from interface:LinuxContainerRuntimeInitialize the runtime.- Specified by:
initializein interfaceLinuxContainerRuntime- Overrides:
initializein classDefaultLinuxContainerRuntime- Parameters:
conf- theConfigurationto usenmContext- NMContext- Throws:
ContainerExecutionException- if an error occurs while initializing the runtime
-
prepareContainer
Prior to environment from being written locally need to generate policy file which limits container access to a small set of directories. Additionally the container run command needs to be modified to include flags to enable the java security manager with the generated policy.
The Java Sandbox will be circumvented if the user is a member of the group specified in: "yarn.nodemanager.runtime.linux.sandbox-mode.whitelist-group" and if they do not include the JVM flag-Djava.security.manager.- Specified by:
prepareContainerin interfaceContainerRuntime- Overrides:
prepareContainerin classDefaultLinuxContainerRuntime- Parameters:
ctx- TheContainerRuntimeContextcontaining container setup properties.- Throws:
ContainerExecutionException- Exception thrown if temporary policy file directory can't be created, or if any exceptions occur during policy file parsing and generation.
-
launchContainer
Description copied from interface:ContainerRuntimeLaunch a container.- Specified by:
launchContainerin interfaceContainerRuntime- Overrides:
launchContainerin classDefaultLinuxContainerRuntime- Parameters:
ctx- theContainerRuntimeContext- Throws:
ContainerExecutionException- if an error occurs while launching the container
-
relaunchContainer
Description copied from interface:ContainerRuntimeRelaunch a container.- Specified by:
relaunchContainerin interfaceContainerRuntime- Overrides:
relaunchContainerin classDefaultLinuxContainerRuntime- Parameters:
ctx- theContainerRuntimeContext- Throws:
ContainerExecutionException- if an error occurs while relaunching the container
-
isRuntimeRequested
Determine if JVMSandboxLinuxContainerRuntime should be used. This is decided based on the value of "yarn.nodemanager.runtime.linux.sandbox-mode"- Specified by:
isRuntimeRequestedin interfaceLinuxContainerRuntime- Overrides:
isRuntimeRequestedin classDefaultLinuxContainerRuntime- Parameters:
env- the environment variable settings for the operation- Returns:
- true if Sandbox is requested, false otherwise
-