-
Notifications
You must be signed in to change notification settings - Fork 9.2k
MAPREDUCE-7523. MapReduce Task-Level Security Enforcement #8100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
K0K0V0K
wants to merge
4
commits into
apache:trunk
Choose a base branch
from
K0K0V0K:MAPREDUCE-7523
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+498
−0
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...java/org/apache/hadoop/mapreduce/v2/app/security/authorize/TaskLevelSecurityEnforcer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.hadoop.mapreduce.v2.app.security.authorize; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import org.apache.hadoop.mapred.JobConf; | ||
| import org.apache.hadoop.mapreduce.MRConfig; | ||
| import org.apache.hadoop.mapreduce.MRJobConfig; | ||
|
|
||
| /** | ||
| * Enforces task-level security rules for MapReduce jobs. | ||
| * | ||
| * <p>This security enforcement mechanism validates whether the user who submitted | ||
| * a job is allowed to execute the mapper/reducer/task classes defined in the job | ||
| * configuration. The check is performed inside the Application Master before | ||
| * task containers are launched.</p> | ||
| * <p>If the user is not on the allowed list and any job property within the configured | ||
| * security property domain references a denied class/prefix, a | ||
| * {@link TaskLevelSecurityException} is thrown and the job is rejected.</p> | ||
| * <p>This prevents unauthorized or unsafe custom code from running inside | ||
| * cluster containers.</p> | ||
| */ | ||
| public final class TaskLevelSecurityEnforcer { | ||
| private static final Logger LOG = LoggerFactory.getLogger(TaskLevelSecurityEnforcer.class); | ||
|
|
||
| /** | ||
| * Default constructor. | ||
| */ | ||
| private TaskLevelSecurityEnforcer() { | ||
| } | ||
|
|
||
| /** | ||
| * Validates a MapReduce job's configuration against the cluster's task-level | ||
| * security policy. | ||
| * | ||
| * <p>The method performs the following steps:</p> | ||
| * <ol> | ||
| * <li>Check whether task-level security is enabled.</li> | ||
| * <li>Allow the job immediately if the user is on the configured allowed-users list.</li> | ||
| * <li>Retrieve the security property domain (list of job configuration keys to inspect).</li> | ||
| * <li>Retrieve the list of denied task class prefixes.</li> | ||
| * <li>For each domain property, check whether its value begins with any denied prefix.</li> | ||
| * <li>If a match is found, reject the job by throwing {@link TaskLevelSecurityException}.</li> | ||
| * </ol> | ||
| * | ||
| * @param conf the job configuration to validate | ||
| * @throws TaskLevelSecurityException if the user is not authorized to use one of the task classes | ||
| */ | ||
| public static void validate(JobConf conf) throws TaskLevelSecurityException { | ||
| if (!conf.getBoolean(MRConfig.SECURITY_ENABLED, MRConfig.DEFAULT_SECURITY_ENABLED)) { | ||
| LOG.debug("The {} is disabled", MRConfig.SECURITY_ENABLED); | ||
| return; | ||
| } | ||
|
|
||
| String currentUser = conf.get(MRJobConfig.USER_NAME); | ||
| List<String> allowedUsers = Arrays.asList(conf.getTrimmedStrings( | ||
| MRConfig.SECURITY_ALLOWED_USERS, | ||
| MRConfig.DEFAULT_SECURITY_ALLOWED_USERS | ||
| )); | ||
| if (allowedUsers.contains(currentUser)) { | ||
| LOG.debug("The {} is allowed to execute every task", currentUser); | ||
| return; | ||
| } | ||
|
|
||
| String[] propertyDomain = conf.getTrimmedStrings( | ||
| MRConfig.SECURITY_PROPERTY_DOMAIN, | ||
| MRConfig.DEFAULT_SECURITY_PROPERTY_DOMAIN | ||
| ); | ||
| String[] deniedTasks = conf.getTrimmedStrings( | ||
| MRConfig.SECURITY_DENIED_TASKS, | ||
| MRConfig.DEFAULT_SECURITY_DENIED_TASKS | ||
| ); | ||
| for (String property : propertyDomain) { | ||
| String propertyValue = conf.get(property, ""); | ||
| for (String deniedTask : deniedTasks) { | ||
| if (propertyValue.startsWith(deniedTask)) { | ||
| throw new TaskLevelSecurityException(currentUser, property, propertyValue, deniedTask); | ||
| } | ||
| } | ||
| } | ||
| LOG.debug("The {} is allowed to execute the submitted job", currentUser); | ||
| } | ||
| } | ||
43 changes: 43 additions & 0 deletions
43
...ava/org/apache/hadoop/mapreduce/v2/app/security/authorize/TaskLevelSecurityException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.hadoop.mapreduce.v2.app.security.authorize; | ||
|
|
||
| import org.apache.hadoop.security.AccessControlException; | ||
|
|
||
| /** | ||
| * Exception thrown when a MapReduce job violates the Task-Level Security policy. | ||
| */ | ||
| public class TaskLevelSecurityException extends AccessControlException { | ||
|
|
||
| /** | ||
| * Constructs a new TaskLevelSecurityException describing the specific policy violation. | ||
| * | ||
| * @param user the submitting user | ||
| * @param property the MapReduce configuration key that was checked | ||
| * @param propertyValue the value provided for that configuration property | ||
| * @param deniedTask the blacklist entry that the value matched | ||
| */ | ||
| public TaskLevelSecurityException( | ||
| String user, String property, String propertyValue, String deniedTask | ||
| ) { | ||
| super(String.format( | ||
| "The %s is not allowed to use %s = %s config, cause it match with %s denied task", | ||
| user, property, propertyValue, deniedTask | ||
| )); | ||
| } | ||
| } |
140 changes: 140 additions & 0 deletions
140
.../org/apache/hadoop/mapreduce/v2/app/security/authorize/TestTaskLevelSecurityEnforcer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.hadoop.mapreduce.v2.app.security.authorize; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import org.apache.hadoop.mapred.JobConf; | ||
| import org.apache.hadoop.mapreduce.MRConfig; | ||
| import org.apache.hadoop.mapreduce.MRJobConfig; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| public class TestTaskLevelSecurityEnforcer { | ||
K0K0V0K marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extends 'AbstractHadoopTestBase` |
||
|
|
||
| @Test | ||
| public void testServiceDisabled() { | ||
| JobConf conf = new JobConf(); | ||
| assertPass(conf); | ||
| } | ||
|
|
||
| @Test | ||
| public void testServiceEnabled() { | ||
| JobConf conf = new JobConf(); | ||
| conf.setBoolean(MRConfig.SECURITY_ENABLED, true); | ||
| assertPass(conf); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDeniedPackage() { | ||
| JobConf conf = new JobConf(); | ||
| conf.setBoolean(MRConfig.SECURITY_ENABLED, true); | ||
| conf.setStrings(MRConfig.SECURITY_DENIED_TASKS, "org.apache.hadoop.streaming"); | ||
| conf.set(MRJobConfig.MAP_CLASS_ATTR, "org.apache.hadoop.streaming.PipeMapper"); | ||
| assertDenied(conf); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDeniedClass() { | ||
| JobConf conf = new JobConf(); | ||
| conf.setBoolean(MRConfig.SECURITY_ENABLED, true); | ||
| conf.setStrings(MRConfig.SECURITY_DENIED_TASKS, | ||
| "org.apache.hadoop.streaming", | ||
| "org.apache.hadoop.examples.QuasiMonteCarlo$QmcReducer"); | ||
| conf.set(MRJobConfig.REDUCE_CLASS_ATTR, | ||
| "org.apache.hadoop.examples.QuasiMonteCarlo$QmcReducer"); | ||
| assertDenied(conf); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIgnoreReducer() { | ||
| JobConf conf = new JobConf(); | ||
| conf.setBoolean(MRConfig.SECURITY_ENABLED, true); | ||
| conf.setStrings(MRConfig.SECURITY_PROPERTY_DOMAIN, | ||
| MRJobConfig.MAP_CLASS_ATTR, | ||
| MRJobConfig.COMBINE_CLASS_ATTR); | ||
| conf.setStrings(MRConfig.SECURITY_DENIED_TASKS, | ||
| "org.apache.hadoop.streaming", | ||
| "org.apache.hadoop.examples.QuasiMonteCarlo$QmcReducer"); | ||
| conf.set(MRJobConfig.REDUCE_CLASS_ATTR, | ||
| "org.apache.hadoop.examples.QuasiMonteCarlo$QmcReducer"); | ||
| assertPass(conf); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDeniedUser() { | ||
| JobConf conf = new JobConf(); | ||
| conf.setBoolean(MRConfig.SECURITY_ENABLED, true); | ||
| conf.setStrings(MRConfig.SECURITY_DENIED_TASKS, "org.apache.hadoop.streaming"); | ||
| conf.setStrings(MRConfig.SECURITY_ALLOWED_USERS, "alice"); | ||
| conf.set(MRJobConfig.MAP_CLASS_ATTR, "org.apache.hadoop.streaming.PipeMapper"); | ||
| conf.set(MRJobConfig.USER_NAME, "bob"); | ||
| assertDenied(conf); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAllowedUser() { | ||
| JobConf conf = new JobConf(); | ||
| conf.setBoolean(MRConfig.SECURITY_ENABLED, true); | ||
| conf.setStrings(MRConfig.SECURITY_DENIED_TASKS, "org.apache.hadoop.streaming"); | ||
| conf.setStrings(MRConfig.SECURITY_ALLOWED_USERS, "alice", "bob"); | ||
| conf.set(MRJobConfig.MAP_CLASS_ATTR, "org.apache.hadoop.streaming.PipeMapper"); | ||
| conf.set(MRJobConfig.USER_NAME, "bob"); | ||
| assertPass(conf); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTurnOff() { | ||
| JobConf conf = new JobConf(); | ||
| conf.setBoolean(MRConfig.SECURITY_ENABLED, false); | ||
| conf.setStrings(MRConfig.SECURITY_DENIED_TASKS, "org.apache.hadoop.streaming"); | ||
| conf.setStrings(MRConfig.SECURITY_ALLOWED_USERS, "alice"); | ||
| conf.set(MRJobConfig.MAP_CLASS_ATTR, "org.apache.hadoop.streaming.PipeMapper"); | ||
| conf.set(MRJobConfig.USER_NAME, "bob"); | ||
| assertPass(conf); | ||
| } | ||
|
|
||
| @Test | ||
| public void testJobConfigCanNotOverwriteMapreduceConfig() { | ||
| JobConf mapreduceConf = new JobConf(); | ||
| mapreduceConf.setBoolean(MRConfig.SECURITY_ENABLED, true); | ||
| mapreduceConf.setStrings(MRConfig.SECURITY_DENIED_TASKS, "org.apache.hadoop.streaming"); | ||
| mapreduceConf.setStrings(MRConfig.SECURITY_ALLOWED_USERS, "alice"); | ||
|
|
||
| JobConf jobConf = new JobConf(); | ||
| jobConf.setStrings(MRConfig.SECURITY_ALLOWED_USERS, "bob"); | ||
| jobConf.set(MRJobConfig.MAP_CLASS_ATTR, "org.apache.hadoop.streaming.PipeMapper"); | ||
| jobConf.set(MRJobConfig.USER_NAME, "bob"); | ||
|
|
||
| mapreduceConf.addResource(jobConf); | ||
| assertDenied(mapreduceConf); | ||
| } | ||
|
|
||
| private void assertPass(JobConf conf) { | ||
| assertDoesNotThrow( | ||
| () -> TaskLevelSecurityEnforcer.validate(conf), | ||
| "Config denied but validation pass was expected"); | ||
| } | ||
|
|
||
| private void assertDenied(JobConf conf) { | ||
| assertThrows(TaskLevelSecurityException.class, | ||
| () -> TaskLevelSecurityEnforcer.validate(conf), | ||
| "Config validation pass but denied was expected"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking at JobSubmitter, this is set to UGI.currentUser.shortName. Is that enough? Shouldn't it be on fullName?
if so, JobSubmitter should add that as a property too