Skip to content

Commit e1c59b2

Browse files
HIVE-29615: Fix Hive Metastore and NameNode connection failure due to SASL no common protection layer between client and server (apache#6492)
1 parent 6d9d9b4 commit e1c59b2

5 files changed

Lines changed: 13 additions & 45 deletions

File tree

standalone-metastore/metastore-client/src/main/java/org/apache/hadoop/hive/metastore/client/ThriftHiveMetaStoreClient.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,6 @@ private TTransport createAuthBinaryTransport(URI store, TTransport underlyingTra
835835
TTransport transport = underlyingTransport;
836836
boolean useFramedTransport =
837837
MetastoreConf.getBoolVar(conf, MetastoreConf.ConfVars.USE_THRIFT_FRAMED_TRANSPORT);
838-
boolean useSSL = MetastoreConf.getBoolVar(conf, MetastoreConf.ConfVars.USE_SSL);
839838
boolean useSasl = MetastoreConf.getBoolVar(conf, MetastoreConf.ConfVars.USE_THRIFT_SASL);
840839
String clientAuthMode = MetastoreConf.getVar(conf, MetastoreConf.ConfVars.METASTORE_CLIENT_AUTH_MODE);
841840
boolean usePasswordAuth = false;
@@ -873,9 +872,9 @@ private TTransport createAuthBinaryTransport(URI store, TTransport underlyingTra
873872
} else if (useSasl) {
874873
// Wrap thrift connection with SASL for secure connection.
875874
try {
876-
HadoopThriftAuthBridge.Client authBridge =
877-
HadoopThriftAuthBridge.getBridge().createClient();
878-
875+
HadoopThriftAuthBridge bridge = HadoopThriftAuthBridge.getBridge();
876+
Map<String, String> saslProperties = bridge.getHadoopSaslProperties(conf);
877+
HadoopThriftAuthBridge.Client authBridge = bridge.createClient();
879878
// check if we should use delegation tokens to authenticate
880879
// the call below gets hold of the tokens if they are set up by hadoop
881880
// this should happen on the map/reduce tasks if the client added the
@@ -889,15 +888,14 @@ private TTransport createAuthBinaryTransport(URI store, TTransport underlyingTra
889888
LOG.debug("HMSC::open(): Found delegation token. Creating DIGEST-based thrift connection.");
890889
// authenticate using delegation tokens via the "DIGEST" mechanism
891890
transport = authBridge.createClientTransport(null, store.getHost(),
892-
"DIGEST", tokenStrForm, underlyingTransport,
893-
MetaStoreUtils.getMetaStoreSaslProperties(conf, useSSL));
891+
"DIGEST", tokenStrForm, underlyingTransport, saslProperties);
894892
} else {
895893
LOG.debug("HMSC::open(): Could not find delegation token. Creating KERBEROS-based thrift connection.");
896894
String principalConfig =
897895
MetastoreConf.getVar(conf, MetastoreConf.ConfVars.KERBEROS_PRINCIPAL);
898896
transport = authBridge.createClientTransport(
899897
principalConfig, store.getHost(), "KERBEROS", null,
900-
underlyingTransport, MetaStoreUtils.getMetaStoreSaslProperties(conf, useSSL));
898+
underlyingTransport, saslProperties);
901899
}
902900
} catch (IOException ioe) {
903901
LOG.error("Failed to create client transport", ioe);

standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/MetaStoreUtils.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import com.google.common.collect.Lists;
5050
import org.apache.commons.lang3.StringUtils;
5151
import org.apache.hadoop.conf.Configuration;
52-
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
5352
import org.apache.hadoop.fs.Path;
5453
import org.apache.hadoop.hive.common.StatsSetupConst;
5554
import org.apache.hadoop.hive.common.TableName;
@@ -71,8 +70,6 @@
7170
import org.apache.hadoop.hive.metastore.api.WMPoolSchedulingPolicy;
7271
import org.apache.hadoop.hive.metastore.api.hive_metastoreConstants;
7372
import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
74-
import org.apache.hadoop.hive.metastore.security.HadoopThriftAuthBridge;
75-
import org.apache.hadoop.security.SaslRpcServer;
7673
import org.slf4j.Logger;
7774
import org.slf4j.LoggerFactory;
7875

@@ -559,30 +556,6 @@ public static int getArchivingLevel(Partition part) throws MetaException {
559556
return part.getValues().size();
560557
}
561558

562-
/**
563-
* Read and return the meta store Sasl configuration. Currently it uses the default
564-
* Hadoop SASL configuration and can be configured using "hadoop.rpc.protection"
565-
* HADOOP-10211, made a backward incompatible change due to which this call doesn't
566-
* work with Hadoop 2.4.0 and later.
567-
* @param conf
568-
* @return The SASL configuration
569-
*/
570-
public static Map<String, String> getMetaStoreSaslProperties(Configuration conf, boolean useSSL) {
571-
// As of now Hive Meta Store uses the same configuration as Hadoop SASL configuration
572-
573-
// If SSL is enabled, override the given value of "hadoop.rpc.protection" and set it to "authentication"
574-
// This disables any encryption provided by SASL, since SSL already provides it
575-
String hadoopRpcProtectionVal = conf.get(CommonConfigurationKeysPublic.HADOOP_RPC_PROTECTION);
576-
String hadoopRpcProtectionAuth = SaslRpcServer.QualityOfProtection.AUTHENTICATION.toString();
577-
578-
if (useSSL && hadoopRpcProtectionVal != null && !hadoopRpcProtectionVal.equals(hadoopRpcProtectionAuth)) {
579-
LOG.warn("Overriding value of " + CommonConfigurationKeysPublic.HADOOP_RPC_PROTECTION + " setting it from "
580-
+ hadoopRpcProtectionVal + " to " + hadoopRpcProtectionAuth + " because SSL is enabled");
581-
conf.set(CommonConfigurationKeysPublic.HADOOP_RPC_PROTECTION, hadoopRpcProtectionAuth);
582-
}
583-
return HadoopThriftAuthBridge.getBridge().getHadoopSaslProperties(conf);
584-
}
585-
586559
/**
587560
* Returns currently known class paths as best effort. For system class loader, this may return
588561
* In such cases we will anyway create new child class loader in {@link #addToClassPath(ClassLoader cloader, String[] newPaths)

standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/AuthFactory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
3030
import org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars;
3131
import org.apache.hadoop.hive.metastore.security.TUGIContainingTransport;
32-
import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils;
3332
import org.apache.hadoop.hive.metastore.security.HadoopThriftAuthBridge;
3433
import org.apache.hadoop.hive.metastore.security.MetastoreDelegationTokenManager;
3534
import org.apache.thrift.transport.layered.TFramedTransport;
@@ -118,7 +117,7 @@ public AuthFactory(HadoopThriftAuthBridge bridge, Configuration conf, Object bas
118117
}
119118
}
120119

121-
TTransportFactory getAuthTransFactory(boolean useSSL, Configuration conf) throws LoginException {
120+
TTransportFactory getAuthTransFactory(HadoopThriftAuthBridge bridge, Configuration conf) throws LoginException {
122121
TTransportFactory transportFactory;
123122
TSaslServerTransport.Factory serverTransportFactory;
124123

@@ -128,7 +127,7 @@ TTransportFactory getAuthTransFactory(boolean useSSL, Configuration conf) throws
128127
throw new LoginException("Framed transport is not supported with SASL enabled.");
129128
}
130129
serverTransportFactory = saslServer.createSaslServerTransportFactory(
131-
MetaStoreUtils.getMetaStoreSaslProperties(conf, useSSL));
130+
bridge.getHadoopSaslProperties(conf));
132131
transportFactory = new ChainedTTransportFactory(
133132
saslServer.wrapTransportFactoryInClientUGI(serverTransportFactory), new TUGIContainingTransport.Factory());
134133
} catch (TTransportException e) {

standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ private static ThriftServer startBinaryMetastore(int port, HadoopThriftAuthBridg
504504
}
505505

506506
TProcessor processor;
507-
TTransportFactory transFactory = authFactory.getAuthTransFactory(useSSL, conf);
507+
TTransportFactory transFactory = authFactory.getAuthTransFactory(bridge, conf);
508508
final TProtocolFactory protocolFactory;
509509
final TProtocolFactory inputProtoFactory;
510510
if (useCompactProtocol) {

standalone-metastore/metastore-tools/tools-common/src/main/java/org/apache/hadoop/hive/metastore/tools/HMSClient.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.apache.hadoop.hive.metastore.api.TxnType;
4747
import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
4848
import org.apache.hadoop.hive.metastore.security.HadoopThriftAuthBridge;
49-
import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils;
5049
import org.apache.hadoop.hive.metastore.utils.SecurityUtils;
5150
import org.apache.hadoop.security.UserGroupInformation;
5251
import org.apache.thrift.TConfiguration;
@@ -467,9 +466,9 @@ private TTransport open(Configuration conf, @NotNull URI uri) throws
467466

468467
if (useSasl) {
469468
// Wrap thrift connection with SASL for secure connection.
470-
HadoopThriftAuthBridge.Client authBridge =
471-
HadoopThriftAuthBridge.getBridge().createClient();
472-
469+
HadoopThriftAuthBridge bridge = HadoopThriftAuthBridge.getBridge();
470+
Map<String, String> saslProperties = bridge.getHadoopSaslProperties(conf);
471+
HadoopThriftAuthBridge.Client authBridge = bridge.createClient();
473472
// check if we should use delegation tokens to authenticate
474473
// the call below gets hold of the tokens if they are set up by hadoop
475474
// this should happen on the map/reduce tasks if the client added the
@@ -483,15 +482,14 @@ private TTransport open(Configuration conf, @NotNull URI uri) throws
483482
LOG.info("HMSC::open(): Found delegation token. Creating DIGEST-based thrift connection.");
484483
// authenticate using delegation tokens via the "DIGEST" mechanism
485484
transport = authBridge.createClientTransport(null, host,
486-
"DIGEST", tokenStrForm, transport,
487-
MetaStoreUtils.getMetaStoreSaslProperties(conf, useSSL));
485+
"DIGEST", tokenStrForm, transport, saslProperties);
488486
} else {
489487
LOG.info("HMSC::open(): Could not find delegation token. Creating KERBEROS-based thrift connection.");
490488
String principalConfig =
491489
MetastoreConf.getVar(conf, MetastoreConf.ConfVars.KERBEROS_PRINCIPAL);
492490
transport = authBridge.createClientTransport(
493491
principalConfig, host, "KERBEROS", null,
494-
transport, MetaStoreUtils.getMetaStoreSaslProperties(conf, useSSL));
492+
transport, saslProperties);
495493
}
496494
} else {
497495
if (useFramedTransport) {

0 commit comments

Comments
 (0)