Skip to content

Commit e3f6207

Browse files
committed
YARN-961. Changed ContainerManager to enforce Token auth irrespective of security. Contributed by Omkar Vinit Joshi.
svn merge --ignore-ancestry -c 1508216 ../../trunk/ git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2.1-beta@1508218 13f79535-47bb-0310-9956-ffa450edef68
1 parent a7e066b commit e3f6207

File tree

5 files changed

+67
-32
lines changed

5 files changed

+67
-32
lines changed

hadoop-yarn-project/CHANGES.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,12 @@ Release 2.1.0-beta - 2013-07-02
738738
YARN-245. Fixed NodeManager to handle duplicate responses from
739739
ResourceManager. (Mayank Bansal via vinodkv)
740740

741+
YARN-932. TestResourceLocalizationService.testLocalizationInit can fail on
742+
JDK7. (Karthik Kambatla via Sandy Ryza)
743+
744+
YARN-961. Changed ContainerManager to enforce Token auth irrespective of
745+
security. (Omkar Vinit Joshi via vinodkv)
746+
741747
BREAKDOWN OF HADOOP-8562/YARN-191 SUBTASKS AND RELATED JIRAS
742748

743749
YARN-158. Yarn creating package-info.java must not depend on sh.
@@ -803,9 +809,6 @@ Release 2.1.0-beta - 2013-07-02
803809
YARN-909. Disable TestLinuxContainerExecutorWithMocks on Windows. (Chuan Liu
804810
via cnauroth)
805811

806-
YARN-932. TestResourceLocalizationService.testLocalizationInit can fail on
807-
JDK7. (Karthik Kambatla via Sandy Ryza)
808-
809812
Release 2.0.5-alpha - 06/06/2013
810813

811814
INCOMPATIBLE CHANGES

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/ContainerManagerImpl.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.apache.hadoop.ipc.Server;
4141
import org.apache.hadoop.net.NetUtils;
4242
import org.apache.hadoop.security.Credentials;
43+
import org.apache.hadoop.security.SaslRpcServer;
4344
import org.apache.hadoop.security.UserGroupInformation;
4445
import org.apache.hadoop.security.authorize.PolicyProvider;
4546
import org.apache.hadoop.security.token.SecretManager.InvalidToken;
@@ -230,6 +231,13 @@ protected void serviceStart() throws Exception {
230231
// Enqueue user dirs in deletion context
231232

232233
Configuration conf = getConfig();
234+
Configuration serverConf = new Configuration(conf);
235+
236+
// always enforce it to be token-based.
237+
serverConf.set(
238+
CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
239+
SaslRpcServer.AuthMethod.TOKEN.toString());
240+
233241
YarnRPC rpc = YarnRPC.create(conf);
234242

235243
InetSocketAddress initialAddress = conf.getSocketAddr(
@@ -238,8 +246,8 @@ protected void serviceStart() throws Exception {
238246
YarnConfiguration.DEFAULT_NM_PORT);
239247

240248
server =
241-
rpc.getServer(ContainerManagementProtocol.class, this, initialAddress, conf,
242-
this.context.getNMTokenSecretManager(),
249+
rpc.getServer(ContainerManagementProtocol.class, this, initialAddress,
250+
serverConf, this.context.getNMTokenSecretManager(),
243251
conf.getInt(YarnConfiguration.NM_CONTAINER_MGR_THREAD_COUNT,
244252
YarnConfiguration.DEFAULT_NM_CONTAINER_MGR_THREAD_COUNT));
245253

@@ -249,7 +257,7 @@ protected void serviceStart() throws Exception {
249257
false)) {
250258
refreshServiceAcls(conf, new NMPolicyProvider());
251259
}
252-
260+
253261
LOG.info("Blocking new container-requests as container manager rpc" +
254262
" server is still starting.");
255263
this.setBlockNewContainerRequests(true);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ApplicationMasterService.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.hadoop.conf.Configuration;
3434
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
3535
import org.apache.hadoop.ipc.Server;
36+
import org.apache.hadoop.security.SaslRpcServer;
3637
import org.apache.hadoop.security.UserGroupInformation;
3738
import org.apache.hadoop.security.authorize.PolicyProvider;
3839
import org.apache.hadoop.security.token.TokenIdentifier;
@@ -119,12 +120,11 @@ protected void serviceStart() throws Exception {
119120
YarnConfiguration.DEFAULT_RM_SCHEDULER_PORT);
120121

121122
Configuration serverConf = conf;
122-
if (!UserGroupInformation.isSecurityEnabled()) {
123-
// If the auth is not-simple, enforce it to be token-based.
124-
serverConf = new Configuration(conf);
125-
serverConf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
126-
UserGroupInformation.AuthenticationMethod.TOKEN.toString());
127-
}
123+
// If the auth is not-simple, enforce it to be token-based.
124+
serverConf = new Configuration(conf);
125+
serverConf.set(
126+
CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
127+
SaslRpcServer.AuthMethod.TOKEN.toString());
128128
this.server =
129129
rpc.getServer(ApplicationMasterProtocol.class, this, masterServiceAddress,
130130
serverConf, this.rmContext.getAMRMTokenSecretManager(),

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAMAuthorization.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,14 @@ public ApplicationMasterProtocol run() {
253253
} catch (Exception e) {
254254
// Because there are no tokens, the request should be rejected as the
255255
// server side will assume we are trying simple auth.
256-
String availableAuthMethods;
256+
String expectedMessage = "";
257257
if (UserGroupInformation.isSecurityEnabled()) {
258-
availableAuthMethods = "[TOKEN, KERBEROS]";
258+
expectedMessage = "Client cannot authenticate via:[TOKEN]";
259259
} else {
260-
availableAuthMethods = "[TOKEN]";
260+
expectedMessage =
261+
"SIMPLE authentication is not enabled. Available:[TOKEN]";
261262
}
262-
Assert.assertTrue(e.getCause().getMessage().contains(
263-
"SIMPLE authentication is not enabled. "
264-
+ "Available:" + availableAuthMethods));
263+
Assert.assertTrue(e.getCause().getMessage().contains(expectedMessage));
265264
}
266265

267266
// TODO: Add validation of invalid authorization when there's more data in

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/TestContainerManagerSecurity.java

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.net.InetSocketAddress;
2525
import java.security.PrivilegedAction;
2626
import java.util.ArrayList;
27+
import java.util.Arrays;
28+
import java.util.Collection;
2729
import java.util.List;
2830

2931
import junit.framework.Assert;
@@ -63,36 +65,45 @@
6365
import org.apache.hadoop.yarn.util.ConverterUtils;
6466
import org.apache.hadoop.yarn.util.Records;
6567
import org.junit.Test;
68+
import org.junit.runner.RunWith;
69+
import org.junit.runners.Parameterized;
70+
import org.junit.runners.Parameterized.Parameters;
6671

72+
@RunWith(Parameterized.class)
6773
public class TestContainerManagerSecurity {
6874

6975
static Log LOG = LogFactory.getLog(TestContainerManagerSecurity.class);
7076
static final RecordFactory recordFactory = RecordFactoryProvider
7177
.getRecordFactory(null);
7278
private static MiniYARNCluster yarnCluster;
7379

74-
static final Configuration conf = new Configuration();
80+
private Configuration conf;
7581

76-
@Test (timeout = 1000000)
77-
public void testContainerManagerWithSecurityEnabled() throws Exception {
78-
conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
82+
@Parameters
83+
public static Collection<Object[]> configs() {
84+
Configuration configurationWithoutSecurity = new Configuration();
85+
configurationWithoutSecurity.set(
86+
CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "simple");
87+
88+
Configuration configurationWithSecurity = new Configuration();
89+
configurationWithSecurity.set(
90+
CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
7991
"kerberos");
80-
testContainerManager();
92+
return Arrays.asList(new Object[][] { { configurationWithoutSecurity },
93+
{ configurationWithSecurity } });
8194
}
8295

83-
@Test (timeout=1000000)
84-
public void testContainerManagerWithSecurityDisabled() throws Exception {
85-
conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
86-
"simple");
87-
testContainerManager();
96+
public TestContainerManagerSecurity(Configuration conf) {
97+
conf.setLong(YarnConfiguration.RM_AM_EXPIRY_INTERVAL_MS, 100000L);
98+
UserGroupInformation.setConfiguration(conf);
99+
this.conf = conf;
88100
}
89101

90-
private void testContainerManager() throws Exception {
102+
@Test (timeout = 1000000)
103+
public void testContainerManager() throws Exception {
91104
try {
92105
yarnCluster = new MiniYARNCluster(TestContainerManagerSecurity.class
93106
.getName(), 1, 1, 1);
94-
conf.setLong(YarnConfiguration.RM_AM_EXPIRY_INTERVAL_MS, 100000L);
95-
UserGroupInformation.setConfiguration(conf);
96107
yarnCluster.init(conf);
97108
yarnCluster.start();
98109

@@ -184,6 +195,18 @@ private void testNMTokens(Configuration conf) throws Exception {
184195
} while (tempManager.getCurrentKey().getKeyId() == nmTokenSecretManagerRM
185196
.getCurrentKey().getKeyId());
186197

198+
// Testing that NM rejects the requests when we don't send any token.
199+
if (UserGroupInformation.isSecurityEnabled()) {
200+
sb = new StringBuilder("Client cannot authenticate via:[TOKEN]");
201+
} else {
202+
sb =
203+
new StringBuilder(
204+
"SIMPLE authentication is not enabled. Available:[TOKEN]");
205+
}
206+
String errorMsg = testStartContainer(rpc, validAppAttemptId, validNode,
207+
validContainerToken, null, true);
208+
Assert.assertTrue(errorMsg.contains(sb.toString()));
209+
187210
org.apache.hadoop.yarn.api.records.Token invalidNMToken =
188211
tempManager.createNMToken(validAppAttemptId, validNode, user);
189212
sb = new StringBuilder("Given NMToken for application : ");
@@ -402,7 +425,9 @@ protected ContainerManagementProtocol getContainerManagementProtocolProxy(
402425
UserGroupInformation ugi = UserGroupInformation.createRemoteUser(user);
403426
final InetSocketAddress addr =
404427
NetUtils.createSocketAddr(nodeId.getHost(), nodeId.getPort());
405-
ugi.addToken(ConverterUtils.convertFromYarn(nmToken, addr));
428+
if (nmToken != null) {
429+
ugi.addToken(ConverterUtils.convertFromYarn(nmToken, addr));
430+
}
406431

407432
proxy = ugi
408433
.doAs(new PrivilegedAction<ContainerManagementProtocol>() {

0 commit comments

Comments
 (0)