Skip to content

Commit 2e81be2

Browse files
author
yanxi0227
committed
[kerberos][在启动yarnclient之前添加认证信息]
1 parent 609bd41 commit 2e81be2

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

launcher/src/main/java/com/dtstack/flink/sql/launcher/perjob/PerJobClusterClientBuilder.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.apache.hadoop.yarn.conf.YarnConfiguration;
3535
import org.slf4j.Logger;
3636
import org.slf4j.LoggerFactory;
37-
import sun.rmi.runtime.Log;
3837

3938
import java.io.File;
4039
import java.io.IOException;
@@ -56,8 +55,6 @@ public class PerJobClusterClientBuilder {
5655

5756
private static final Logger LOG = LoggerFactory.getLogger(PerJobClusterClientBuilder.class);
5857

59-
private static String SECURITY = "hadoop.security.authorization";
60-
6158
private static String KEYTAB = "security.kerberos.login.keytab";
6259

6360
private static String PRINCIPAL = "security.kerberos.login.principal";
@@ -74,15 +71,10 @@ public void init(String yarnConfDir, Properties conf) throws IOException {
7471

7572
yarnConf = YarnConfLoader.getYarnConf(yarnConfDir);
7673

77-
Boolean security = yarnConf.getBoolean(SECURITY, false);
78-
79-
String keytab = (String) conf.get(KEYTAB);
80-
String principal = (String) conf.get(PRINCIPAL);
81-
if (security && !Strings.isNullOrEmpty(keytab)){
82-
UserGroupInformation.setConfiguration(yarnConf);
83-
UserGroupInformation.loginUserFromKeytab(keytab, principal);
84-
LOG.info("login successfully! keytab: " + keytab + "principal: " + principal);
85-
LOG.info("UGI: " + UserGroupInformation.getCurrentUser());
74+
if (openKerberos(conf)){
75+
String keytab = (String) conf.get(KEYTAB);
76+
String principal = (String) conf.get(PRINCIPAL);
77+
login(yarnConf, keytab, principal);
8678
}
8779

8880
yarnClient = YarnClient.createYarnClient();
@@ -168,4 +160,21 @@ private AbstractYarnClusterDescriptor getClusterDescriptor(
168160
yarnClient,
169161
false);
170162
}
163+
164+
private boolean openKerberos(Properties conf){
165+
String keytab = (String) conf.get(KEYTAB);
166+
String principal = (String) conf.get(PRINCIPAL);
167+
if (StringUtils.isNotBlank(keytab) && StringUtils.isNotBlank(principal)){
168+
return true;
169+
} else {
170+
return false;
171+
}
172+
}
173+
174+
private void login(org.apache.hadoop.conf.Configuration conf, String keytab, String principal) throws IOException {
175+
UserGroupInformation.setConfiguration(conf);
176+
UserGroupInformation.loginUserFromKeytab(keytab, principal);
177+
LOG.info("login successfully! keytab: " + keytab + "principal: " + principal);
178+
LOG.info("UGI: " + UserGroupInformation.getCurrentUser());
179+
}
171180
}

0 commit comments

Comments
 (0)