Unverified Commit 355bfd02 authored by Forus's avatar Forus Committed by GitHub

[Feature-1337]新增Yarn-Session模式,Kerberos环境票据认证 (#1339)

parent 16b18f10
......@@ -30,6 +30,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>${target.java.version}</maven.compiler.source>
<maven.compiler.target>${target.java.version}</maven.compiler.target>
<hadoop.version>3.1.0</hadoop.version>
</properties>
<dependencies>
......@@ -57,6 +58,22 @@
<artifactId>dlink-metadata-mysql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>${hadoop.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<profiles>
......
......@@ -43,7 +43,10 @@ import org.apache.flink.table.api.TableConfig;
import org.apache.flink.table.api.TableResult;
import org.apache.flink.table.catalog.CatalogManager;
import org.apache.flink.util.JarUtils;
import org.apache.hadoop.security.UserGroupInformation;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
......@@ -58,12 +61,15 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.extern.slf4j.Slf4j;
/**
* Executor
*
* @author wenmo
* @since 2021/11/17
**/
@Slf4j
public abstract class Executor {
private static final Logger logger = LoggerFactory.getLogger(Executor.class);
......@@ -239,12 +245,68 @@ public abstract class Executor {
return flinkInterceptorResult.getTableResult();
}
if (!flinkInterceptorResult.isNoExecute()) {
this.loginFromKeytabIfNeed();
return stEnvironment.executeSql(statement);
} else {
return CustomTableResultImpl.TABLE_RESULT_OK;
}
}
private void reset() {
try {
if (UserGroupInformation.isLoginKeytabBased()) {
Method reset = UserGroupInformation.class.getDeclaredMethod("reset");
reset.invoke(UserGroupInformation.class);
log.info("Reset kerberos authentication...");
}
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private void loginFromKeytabIfNeed() {
this.reset();
setConfig.forEach((k, v) -> log.debug("setConfig key: [{}], value: [{}]", k, v));
String krb5ConfPath = (String) setConfig.getOrDefault("java.security.krb5.conf", "");
String keytabPath = (String) setConfig.getOrDefault("security.kerberos.login.keytab", "");
String principal = (String) setConfig.getOrDefault("security.kerberos.login.principal", "");
if (krb5ConfPath.isEmpty() && keytabPath.isEmpty() && principal.isEmpty()) {
log.info("Simple authentication mode");
return;
}
log.info("Kerberos authentication mode");
if (krb5ConfPath.isEmpty()) {
log.error("Parameter [java.security.krb5.conf] is null or empty.");
return;
}
if (keytabPath.isEmpty()) {
log.error("Parameter [security.kerberos.login.keytab] is null or empty.");
return;
}
if (principal.isEmpty()) {
log.error("Parameter [security.kerberos.login.principal] is null or empty.");
return;
}
System.setProperty("java.security.krb5.conf", krb5ConfPath);
org.apache.hadoop.conf.Configuration config = new org.apache.hadoop.conf.Configuration();
config.set("hadoop.security.authentication", "Kerberos");
config.setBoolean("hadoop.security.authorization", true);
UserGroupInformation.setConfiguration(config);
try {
UserGroupInformation.loginUserFromKeytab(principal, keytabPath);
log.error("Kerberos [{}] authentication success.", UserGroupInformation.getLoginUser().getUserName());
} catch (IOException e) {
log.error("Kerberos authentication failed.");
e.printStackTrace();
}
}
/**
* init udf
*
......@@ -254,7 +316,7 @@ public abstract class Executor {
JarUtils.getJarFiles(udfFilePath).forEach(Executor::loadJar);
}
public void initPyUDF(String executable,String... udfPyFilePath) {
public void initPyUDF(String executable, String... udfPyFilePath) {
if (udfPyFilePath == null || udfPyFilePath.length == 0) {
return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment