Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use different tokens instead of forcing WD and all HMS to use the same delegatetoken in the kerberos environment #313

Merged
merged 9 commits into from
May 29, 2024
57 changes: 30 additions & 27 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public abstract class AbstractMetaStore {
private long latency = 0;
private transient @JsonIgnore HashBiMap<String, String> databaseNameBiMapping = HashBiMap.create();
private boolean impersonationEnabled;
private Map<String, String> configurationProperties = new HashMap<>();

public AbstractMetaStore(String name, String remoteMetaStoreUris, AccessControlType accessControlType) {
this.name = name;
this.remoteMetaStoreUris = remoteMetaStoreUris;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void nullDatabasePrefix() {

@Test
public void toJson() throws Exception {
String expected = "{\"accessControlType\":\"READ_ONLY\",\"connectionType\":\"DIRECT\",\"databaseNameMapping\":{},\"databasePrefix\":\"name_\",\"federationType\":\"FEDERATED\",\"hiveMetastoreFilterHook\":null,\"impersonationEnabled\":false,\"latency\":0,\"mappedDatabases\":null,\"mappedTables\":null,\"metastoreTunnel\":null,\"name\":\"name\",\"remoteMetaStoreUris\":\"uri\",\"status\":\"UNKNOWN\",\"writableDatabaseWhiteList\":[]}";
String expected = "{\"accessControlType\":\"READ_ONLY\",\"configurationProperties\":{},\"connectionType\":\"DIRECT\",\"databaseNameMapping\":{},\"databasePrefix\":\"name_\",\"federationType\":\"FEDERATED\",\"hiveMetastoreFilterHook\":null,\"impersonationEnabled\":false,\"latency\":0,\"mappedDatabases\":null,\"mappedTables\":null,\"metastoreTunnel\":null,\"name\":\"name\",\"remoteMetaStoreUris\":\"uri\",\"status\":\"UNKNOWN\",\"writableDatabaseWhiteList\":[]}";
ObjectMapper mapper = new ObjectMapper();
// Sorting to get deterministic test behaviour
mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void nonEmptyDatabasePrefix() {

@Test
public void toJson() throws Exception {
String expected = "{\"accessControlType\":\"READ_ONLY\",\"connectionType\":\"DIRECT\",\"databaseNameMapping\":{},\"databasePrefix\":\"\",\"federationType\":\"PRIMARY\",\"hiveMetastoreFilterHook\":null,\"impersonationEnabled\":false,\"latency\":0,\"mappedDatabases\":null,\"mappedTables\":null,\"metastoreTunnel\":null,\"name\":\"name\",\"remoteMetaStoreUris\":\"uri\",\"status\":\"UNKNOWN\",\"writableDatabaseWhiteList\":[]}";
String expected = "{\"accessControlType\":\"READ_ONLY\",\"configurationProperties\":{},\"connectionType\":\"DIRECT\",\"databaseNameMapping\":{},\"databasePrefix\":\"\",\"federationType\":\"PRIMARY\",\"hiveMetastoreFilterHook\":null,\"impersonationEnabled\":false,\"latency\":0,\"mappedDatabases\":null,\"mappedTables\":null,\"metastoreTunnel\":null,\"name\":\"name\",\"remoteMetaStoreUris\":\"uri\",\"status\":\"UNKNOWN\",\"writableDatabaseWhiteList\":[]}";
ObjectMapper mapper = new ObjectMapper();
// Sorting to get deterministic test behaviour
mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@
public abstract class AbstractThriftMetastoreClientManager implements Closeable {


static final AtomicInteger CONN_COUNT = new AtomicInteger(0);
final HiveConf conf;
final HiveCompatibleThriftHiveMetastoreIfaceFactory hiveCompatibleThriftHiveMetastoreIfaceFactory;
final URI[] metastoreUris;
ThriftHiveMetastore.Iface client = null;
TTransport transport = null;
boolean isConnected = false;
protected static final AtomicInteger CONN_COUNT = new AtomicInteger(0);
jmnunezizu marked this conversation as resolved.
Show resolved Hide resolved
protected final HiveConf conf;
protected final HiveCompatibleThriftHiveMetastoreIfaceFactory hiveCompatibleThriftHiveMetastoreIfaceFactory;
protected final URI[] metastoreUris;
protected ThriftHiveMetastore.Iface client = null;
protected TTransport transport = null;
protected boolean isConnected = false;
// for thrift connects
int retries = 5;
long retryDelaySeconds = 0;
protected int retries = 5;
protected long retryDelaySeconds = 0;

final int connectionTimeout;
final String msUri;
protected final int connectionTimeout;
protected final String msUri;

AbstractThriftMetastoreClientManager(
HiveConf conf,
Expand Down Expand Up @@ -116,18 +116,6 @@ public void setHiveConfValue(String key, String value) {
conf.set(key, value);
}

public String generateNewTokenSignature(String defaultTokenSignature) {
String tokenSignature = conf.get(ConfVars.METASTORE_TOKEN_SIGNATURE.varname,
defaultTokenSignature);
conf.set(ConfVars.METASTORE_TOKEN_SIGNATURE.varname,
tokenSignature);
return tokenSignature;
}

public Boolean isSaslEnabled() {
return conf.getBoolVar(ConfVars.METASTORE_USE_THRIFT_SASL);
}

@Override
public void close() {
if (!isConnected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

import javax.security.sasl.SaslException;

import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
import org.apache.hadoop.hive.metastore.api.MetaException;
Expand Down Expand Up @@ -91,7 +89,7 @@ void open(HiveUgiArgs ugiArgs) {
}
}

void createMetastoreClientAndOpen(String delegationToken, HiveUgiArgs ugiArgs) {
private void createMetastoreClientAndOpen(String delegationToken, HiveUgiArgs ugiArgs) {
TException te = null;
boolean useSsl = conf.getBoolVar(ConfVars.HIVE_METASTORE_USE_SSL);
boolean useCompactProtocol = conf.getBoolVar(ConfVars.METASTORE_USE_THRIFT_COMPACT_PROTOCOL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ThriftMetastoreClientManager extends AbstractThriftMetastoreClientManager
HiveConf conf,
HiveCompatibleThriftHiveMetastoreIfaceFactory hiveCompatibleThriftHiveMetastoreIfaceFactory,
int connectionTimeout) {
super(conf,hiveCompatibleThriftHiveMetastoreIfaceFactory,connectionTimeout);
super(conf, hiveCompatibleThriftHiveMetastoreIfaceFactory, connectionTimeout);
}

void open(HiveUgiArgs ugiArgs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
import org.apache.hadoop.hive.metastore.api.WMValidateResourcePlanRequest;
import org.apache.hadoop.hive.metastore.api.WMValidateResourcePlanResponse;
import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
import org.apache.hadoop.hive.metastore.security.HadoopThriftAuthBridge;
import org.apache.hadoop.hive.metastore.txn.TxnStore;
import org.apache.hadoop.hive.metastore.txn.TxnUtils;
import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils;
Expand Down Expand Up @@ -1375,12 +1376,20 @@ public String get_delegation_token(String token_owner, String renewer_kerberos_p
try {
return saslServerWrapper.getDelegationTokenManager()
.getDelegationToken(token_owner, renewer_kerberos_principal_name,
saslServerWrapper.getIPAddress());
getIPAddressFromSaslServer());
} catch (IOException | InterruptedException e) {
throw new MetaException(e.getMessage());
}
}

private String getIPAddressFromSaslServer() {
HadoopThriftAuthBridge.Server saslServer = saslServerWrapper.getSaslServer();
if (saslServer != null && saslServer.getRemoteAddress() != null) {
return saslServer.getRemoteAddress().getHostAddress();
}
return null;
}

@Override
@Loggable(value = Loggable.DEBUG, skipResult = true, name = INVOCATION_LOG_NAME)
public long renew_delegation_token(String token_str_form) throws MetaException, TException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,4 @@ public Server getSaslServer() {
return saslServer;
}


String getIPAddress() {
if (saslServer != null && saslServer.getRemoteAddress() != null) {
return saslServer.getRemoteAddress().getHostAddress();
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ public void saveFederationWriteFederations() throws Exception {
storage.insert(newFederatedInstance);
storage.saveFederation();
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
assertThat(lines.size(), is(26));
assertThat(lines.size(), is(27));
int i = 0;
while (i < 26) {
while (i < lines.size()) {
assertThat(lines.get(i++), is("primary-meta-store:"));
assertThat(lines.get(i++), is(" access-control-type: READ_ONLY"));
assertThat(lines.get(i++), is(" database-prefix: ''"));
Expand All @@ -228,7 +228,8 @@ public void saveFederationWriteFederations() throws Exception {
assertThat(lines.get(i++), is(" remote-meta-store-uris: thrift://localhost:19083"));
assertThat(lines.get(i++), is("federated-meta-stores:"));
assertThat(lines.get(i++), is("- access-control-type: READ_ONLY"));
assertThat(lines.get(i++), is(" database-name-mapping: {}"));
assertThat(lines.get(i++), is(" configuration-properties:"));
assertThat(lines.get(i++), is(" hive.metastore.kerberos.principal: hive/_HOST@REALM"));
assertThat(lines.get(i++), is(" database-prefix: hcom_2_"));
assertThat(lines.get(i++), is(" hive-metastore-filter-hook: filter.hook.class"));
assertThat(lines.get(i++), is(" impersonation-enabled: false"));
Expand Down Expand Up @@ -304,11 +305,13 @@ public void savePrimaryWriteFederations() throws Exception {
storage.insert(newFederatedInstance("hcom_2", "thrift://localhost:29083"));
storage.saveFederation();
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
assertThat(lines.size(), is(25));
assertThat(lines.size(), is(26));
int i = 0;
while (i < 25) {
while (i < lines.size()) {
assertThat(lines.get(i++), is("primary-meta-store:"));
assertThat(lines.get(i++), is(" access-control-type: READ_ONLY"));
assertThat(lines.get(i++), is(" configuration-properties:"));
assertThat(lines.get(i++), is(" hive.metastore.kerberos.principal: hive/_HOST@REALM"));
assertThat(lines.get(i++), is(" database-prefix: ''"));
assertThat(lines.get(i++), is(" impersonation-enabled: false"));
assertThat(lines.get(i++), is(" latency: 0"));
Expand All @@ -326,7 +329,6 @@ public void savePrimaryWriteFederations() throws Exception {
assertThat(lines.get(i++), is(" remote-meta-store-uris: thrift://localhost:19083"));
assertThat(lines.get(i++), is("federated-meta-stores:"));
assertThat(lines.get(i++), is("- access-control-type: READ_ONLY"));
assertThat(lines.get(i++), is(" database-name-mapping: {}"));
assertThat(lines.get(i++), is(" database-prefix: hcom_2_"));
assertThat(lines.get(i++), is(" impersonation-enabled: false"));
assertThat(lines.get(i++), is(" latency: 0"));
Expand Down
Loading