Skip to content

Commit b77fc97

Browse files
slfan1989HarshitGupta11
authored andcommitted
YARN-6539. Create SecureLogin inside Router. (apache#4712)
1 parent 98b082e commit b77fc97

16 files changed

Lines changed: 536 additions & 11 deletions

File tree

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4107,6 +4107,16 @@ public static boolean isAclEnabled(Configuration conf) {
41074107
public static final long DEFAULT_ROUTER_WEBAPP_READ_TIMEOUT =
41084108
TimeUnit.SECONDS.toMillis(30);
41094109

4110+
/** The Kerberos keytab for the yarn router.*/
4111+
public static final String ROUTER_KEYTAB = ROUTER_PREFIX + "keytab.file";
4112+
4113+
/** The Kerberos principal for the yarn router.*/
4114+
public static final String ROUTER_PRINCIPAL = ROUTER_PREFIX + "kerberos.principal";
4115+
4116+
/** The Kerberos principal hostname for the yarn router.*/
4117+
public static final String ROUTER_KERBEROS_PRINCIPAL_HOSTNAME_KEY = ROUTER_PREFIX +
4118+
"kerberos.principal.hostname";
4119+
41104120
////////////////////////////////
41114121
// CSI Volume configs
41124122
////////////////////////////////

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4888,4 +4888,37 @@
48884888
default implementation LocalityAppPlacementAllocator is used.
48894889
</description>
48904890
</property>
4891+
4892+
<property>
4893+
<name>yarn.router.keytab.file</name>
4894+
<value></value>
4895+
<description>
4896+
The keytab file used by router to login as its
4897+
service principal. The principal name is configured with
4898+
dfs.federation.router.kerberos.principal.
4899+
</description>
4900+
</property>
4901+
4902+
<property>
4903+
<name>yarn.router.kerberos.principal</name>
4904+
<value></value>
4905+
<description>
4906+
The Router service principal. This is typically set to
4907+
router/_HOST@REALM.TLD. Each Router will substitute _HOST with its
4908+
own fully qualified hostname at startup. The _HOST placeholder
4909+
allows using the same configuration setting on both Router setup.
4910+
</description>
4911+
</property>
4912+
4913+
<property>
4914+
<name>yarn.router.kerberos.principal.hostname</name>
4915+
<value></value>
4916+
<description>
4917+
Optional.
4918+
The hostname for the Router containing this
4919+
configuration file. Will be different for each machine.
4920+
Defaults to current hostname.
4921+
</description>
4922+
</property>
4923+
48914924
</configuration>

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/SubClusterId.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ public static SubClusterId newInstance(String subClusterId) {
4343
return id;
4444
}
4545

46+
@Private
47+
@Unstable
48+
public static SubClusterId newInstance(Integer subClusterId) {
49+
SubClusterId id = Records.newRecord(SubClusterId.class);
50+
id.setId(String.valueOf(subClusterId));
51+
return id;
52+
}
53+
4654
/**
4755
* Get the string identifier of the <em>subcluster</em> which is unique across
4856
* the federated cluster. The identifier is static, i.e. preserved across

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,4 +609,10 @@ public boolean equals(Object obj) {
609609
protected interface Func<T, TResult> {
610610
TResult invoke(T input) throws Exception;
611611
}
612+
613+
614+
@VisibleForTesting
615+
public FederationStateStore getStateStore() {
616+
return stateStore;
617+
}
612618
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/uam/UnmanagedApplicationManager.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,13 @@ protected <T> T createRMProxy(Class<T> protocol, Configuration config,
382382
protected Token<AMRMTokenIdentifier> initializeUnmanagedAM(
383383
ApplicationId appId) throws IOException, YarnException {
384384
try {
385-
UserGroupInformation appSubmitter =
386-
UserGroupInformation.createRemoteUser(this.submitter);
385+
UserGroupInformation appSubmitter;
386+
if (UserGroupInformation.isSecurityEnabled()) {
387+
appSubmitter = UserGroupInformation.createProxyUser(this.submitter,
388+
UserGroupInformation.getLoginUser());
389+
} else {
390+
appSubmitter = UserGroupInformation.createRemoteUser(this.submitter);
391+
}
387392
this.rmClient = createRMProxy(ApplicationClientProtocol.class, this.conf,
388393
appSubmitter, null);
389394

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/amrmproxy/FederationInterceptor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,13 @@ public void recover(Map<String, byte[]> recoveredDataMap) {
459459
// Get the running containers from home RM, note that we will also get the
460460
// AM container itself from here. We don't need it, but no harm to put the
461461
// map as well.
462-
UserGroupInformation appSubmitter = UserGroupInformation
463-
.createRemoteUser(getApplicationContext().getUser());
462+
UserGroupInformation appSubmitter;
463+
if (UserGroupInformation.isSecurityEnabled()) {
464+
appSubmitter = UserGroupInformation.createProxyUser(getApplicationContext().getUser(),
465+
UserGroupInformation.getLoginUser());
466+
} else {
467+
appSubmitter = UserGroupInformation.createRemoteUser(getApplicationContext().getUser());
468+
}
464469
ApplicationClientProtocol rmClient =
465470
createHomeRMProxy(getApplicationContext(),
466471
ApplicationClientProtocol.class, appSubmitter);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@
116116
<artifactId>guice</artifactId>
117117
</dependency>
118118

119+
<dependency>
120+
<groupId>org.apache.hadoop</groupId>
121+
<artifactId>hadoop-minikdc</artifactId>
122+
<scope>test</scope>
123+
</dependency>
124+
125+
<dependency>
126+
<groupId>org.apache.hadoop</groupId>
127+
<artifactId>hadoop-auth</artifactId>
128+
<scope>test</scope>
129+
<type>test-jar</type>
130+
</dependency>
131+
119132
</dependencies>
120133

121134
<build>

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/Router.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919
package org.apache.hadoop.yarn.server.router;
2020

2121
import java.io.IOException;
22+
import java.net.InetAddress;
23+
import java.net.UnknownHostException;
2224
import java.util.concurrent.atomic.AtomicBoolean;
2325

2426
import org.apache.hadoop.classification.InterfaceAudience.Private;
2527
import org.apache.hadoop.conf.Configuration;
2628
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
2729
import org.apache.hadoop.metrics2.source.JvmMetrics;
30+
import org.apache.hadoop.security.SecurityUtil;
2831
import org.apache.hadoop.service.CompositeService;
2932
import org.apache.hadoop.util.JvmPauseMonitor;
3033
import org.apache.hadoop.util.ShutdownHookManager;
@@ -88,7 +91,8 @@ public Router() {
8891
}
8992

9093
protected void doSecureLogin() throws IOException {
91-
// TODO YARN-6539 Create SecureLogin inside Router
94+
SecurityUtil.login(this.conf, YarnConfiguration.ROUTER_KEYTAB,
95+
YarnConfiguration.ROUTER_PRINCIPAL, getHostName(this.conf));
9296
}
9397

9498
@Override
@@ -195,4 +199,31 @@ public static void main(String[] argv) {
195199
System.exit(-1);
196200
}
197201
}
202+
203+
@VisibleForTesting
204+
public RouterClientRMService getClientRMProxyService() {
205+
return clientRMProxyService;
206+
}
207+
208+
@VisibleForTesting
209+
public RouterRMAdminService getRmAdminProxyService() {
210+
return rmAdminProxyService;
211+
}
212+
213+
/**
214+
* Returns the hostname for this Router. If the hostname is not
215+
* explicitly configured in the given config, then it is determined.
216+
*
217+
* @param config configuration
218+
* @return the hostname (NB: may not be a FQDN)
219+
* @throws UnknownHostException if the hostname cannot be determined
220+
*/
221+
private String getHostName(Configuration config)
222+
throws UnknownHostException {
223+
String name = config.get(YarnConfiguration.ROUTER_KERBEROS_PRINCIPAL_HOSTNAME_KEY);
224+
if (name == null) {
225+
name = InetAddress.getLocalHost().getHostName();
226+
}
227+
return name;
228+
}
198229
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/AbstractClientRequestInterceptor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ private void setupUser(String userName) {
106106
try {
107107
// Do not create a proxy user if user name matches the user name on
108108
// current UGI
109-
if (userName.equalsIgnoreCase(
110-
UserGroupInformation.getCurrentUser().getUserName())) {
109+
if (UserGroupInformation.isSecurityEnabled()) {
110+
user = UserGroupInformation.createProxyUser(userName, UserGroupInformation.getLoginUser());
111+
} else if (userName.equalsIgnoreCase(UserGroupInformation.getCurrentUser().getUserName())) {
111112
user = UserGroupInformation.getCurrentUser();
112113
} else {
113114
user = UserGroupInformation.createProxyUser(userName,

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,4 +1623,14 @@ protected SubClusterId getApplicationHomeSubCluster(
16231623
String.format("Can't Found applicationId = %s in any sub clusters", applicationId);
16241624
throw new YarnException(errorMsg);
16251625
}
1626+
1627+
@VisibleForTesting
1628+
public FederationStateStoreFacade getFederationFacade() {
1629+
return federationFacade;
1630+
}
1631+
1632+
@VisibleForTesting
1633+
public Map<SubClusterId, ApplicationClientProtocol> getClientRMProxies() {
1634+
return clientRMProxies;
1635+
}
16261636
}

0 commit comments

Comments
 (0)