morningman closed pull request #373: fix bug: add _IP/_HOST in principal of
kerberos
URL: https://github.com/apache/incubator-doris/pull/373
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/fs_brokers/apache_hdfs_broker/src/main/java/org/apache/doris/broker/hdfs/FileSystemManager.java
b/fs_brokers/apache_hdfs_broker/src/main/java/org/apache/doris/broker/hdfs/FileSystemManager.java
index d01a1f73..fc11a47f 100644
---
a/fs_brokers/apache_hdfs_broker/src/main/java/org/apache/doris/broker/hdfs/FileSystemManager.java
+++
b/fs_brokers/apache_hdfs_broker/src/main/java/org/apache/doris/broker/hdfs/FileSystemManager.java
@@ -17,40 +17,31 @@
package org.apache.doris.broker.hdfs;
+import com.google.common.base.Strings;
import org.apache.doris.thrift.TBrokerFD;
import org.apache.doris.thrift.TBrokerFileStatus;
import org.apache.doris.thrift.TBrokerOperationStatusCode;
-
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.FSDataInputStream;
-import org.apache.hadoop.fs.FSDataOutputStream;
-import org.apache.hadoop.fs.FileStatus;
-import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
+import org.apache.hadoop.fs.*;
import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.util.StringUtils;
import org.apache.log4j.Logger;
-import com.google.common.base.Strings;
import java.io.File;
import java.io.FileOutputStream;
-import java.io.FileWriter;
import java.io.IOException;
+import java.net.InetAddress;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.UnknownHostException;
import java.nio.ByteBuffer;
+import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import java.util.Base64;
-import java.util.Random;
+import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
-import java.security.MessageDigest;
public class FileSystemManager {
@@ -91,6 +82,25 @@ public FileSystemManager() {
writeBufferSize = BrokerConfig.hdfs_write_buffer_size_kb << 10;
handleManagementPool.schedule(new FileSystemExpirationChecker(), 0,
TimeUnit.SECONDS);
}
+
+ private static String preparePrincipal(String originalPrincipal) throws
UnknownHostException {
+ String finalPrincipal = originalPrincipal;
+ String[] components = originalPrincipal.split("[/@]");
+ if (components != null && components.length == 3) {
+ if (components[1].equals("_HOST")) {
+ // Convert hostname(fqdn) to lower case according to
SecurityUtil.getServerPrincipal
+ finalPrincipal = components[0] + "/" +
+
StringUtils.toLowerCase(InetAddress.getLocalHost().getCanonicalHostName())
+ + "@" + components[2];
+ } else if (components[1].equals("_IP")) {
+ finalPrincipal = components[0] + "/" +
+
InetAddress.getByName(InetAddress.getLocalHost().getCanonicalHostName()).getHostAddress()
+ + "@" + components[2];
+ }
+ }
+
+ return finalPrincipal;
+ }
/**
* visible for test
@@ -196,7 +206,7 @@ public BrokerFileSystem getFileSystem(String path,
Map<String, String> propertie
conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
AUTHENTICATION_KERBEROS);
- String principal = properties.get(KERBEROS_PRINCIPAL);
+ String principal =
preparePrincipal(properties.get(KERBEROS_PRINCIPAL));
String keytab = "";
if (properties.containsKey(KERBEROS_KEYTAB)) {
keytab = properties.get(KERBEROS_KEYTAB);
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]