From 51a6aed72ed04cc9f4972b70144c5066c9b8815d Mon Sep 17 00:00:00 2001 From: Haoning Sun Date: Fri, 4 Jun 2021 14:15:25 +0800 Subject: [PATCH] HBASE-25930 Thrift does not support requests in Kerberos environment (#3326) Co-authored-by: sunhaoning Signed-off-by: Istvan Toth Signed-off-by: Balazs Meszaros --- .../hadoop/hbase/thrift/ThriftServer.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java index a33cc4a063a..298ed6b8519 100644 --- a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java +++ b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java @@ -78,6 +78,7 @@ import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; +import java.security.PrivilegedAction; import java.util.List; import java.util.Map; import java.util.concurrent.BlockingQueue; @@ -97,6 +98,7 @@ import org.apache.hadoop.hbase.HBaseInterfaceAudience; import org.apache.hadoop.hbase.filter.ParseFilter; import org.apache.hadoop.hbase.http.HttpServerUtil; import org.apache.hadoop.hbase.http.InfoServer; +import org.apache.hadoop.hbase.log.HBaseMarkers; import org.apache.hadoop.hbase.security.SaslUtil; import org.apache.hadoop.hbase.security.SecurityUtil; import org.apache.hadoop.hbase.security.UserProvider; @@ -845,15 +847,30 @@ public class ThriftServer extends Configured implements Tool { public int run(String[] strings) throws Exception { processOptions(strings); setupParamters(); - startInfoServer(); if (httpEnabled) { setupHTTPServer(); - httpServer.start(); - httpServer.join(); } else { setupServer(); - tserver.serve(); } + serviceUGI.doAs(new PrivilegedAction() { + @Override + public Object run() { + try { + startInfoServer(); + if (httpEnabled) { + httpServer.start(); + httpServer.join(); + } else { + tserver.serve(); + } + } catch (Exception e) { + LOG.error(HBaseMarkers.FATAL, "Cannot run ThriftServer", e); + + System.exit(-1); + } + return null; + } + }); return 0; }