Kerberos:Spark UGI凭据未传递到Hive

问题描述 投票:1回答:1

[我使用的是Spark-2.4,我有一个启用Kerberos的群集,正在尝试通过spark-sql Shell运行查询。

简化的设置基本上看起来像这样:spark-sql shell在Yarn集群中的一台主机上运行->运行一台主机的外部hive-metastore-> S3存储表数据。

在启用调试日志记录的情况下启动spark-sql shell时,这是我在日志中看到的内容:

> bin/spark-sql --proxy-user proxy_user

...
DEBUG HiveDelegationTokenProvider: Getting Hive delegation token for proxy_user against hive/[email protected] at thrift://hive-metastore:9083
DEBUG UserGroupInformation: PrivilegedAction as:spark/[email protected] (auth:KERBEROS) from:org.apache.spark.deploy.security.HiveDelegationTokenProvider.doAsRealUser(HiveDelegationTokenProvider.scala:130)

这意味着Spark发出了从Hive元存储中获取委托令牌的调用,然后将其添加到UGI的凭据列表中。 Spark中的This is the piece of code会执行此操作。我还在metastore日志中验证了正在进行get_delegation_token()调用。

现在,当我运行一个简单的查询,例如create table test_table (id int) location "s3://some/prefix";时,我会遇到AWS凭证错误。我修改了配置单元metastore代码,并在初始化Hadoop中的文件系统(org/apache/hadoop/hive/metastore/Warehouse.java)之前添加了此代码:

 public static FileSystem getFs(Path f, Configuration conf) throws MetaException {
...
    try {
      // get the current user 
      UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
      LOG.info("UGI information: " + ugi);
      Collection<Token<? extends TokenIdentifier>> tokens = ugi.getCredentials().getAllTokens();
      // print all the tokens it has 
      for(Token token : tokens) {
        LOG.info(token);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
...
}

在metastore日志中,这确实会打印正确的UGI信息:

UGI information: proxy_user (auth:PROXY) via hive/[email protected] (auth:KERBEROS)

但UGI中没有令牌。看起来Spark code为它添加了别名hive.server2.delegation.token,但我在UGI中看不到它。这使我怀疑,以某种方式隔离了UGI范围,而不在spark-sql和hive元存储之间共享UGI范围。我该如何解决这个问题?

apache-spark hadoop kerberos hive-metastore kerberos-delegation
1个回答
0
投票

Spark是not拾取您的Kerberos身份-它要求每个FS发出一些“委托令牌”,使调用者可以与该服务和该服务单独交互进行交互。这受到更多限制,因此更加安全。

这里的问题是,spark从可以发布它们的每个文件系统中收集委托令牌,并且由于您的S3连接器未发布任何令牌,因此没有任何问题。

现在,可以将Apache Hadoop 3.3.0的S3A连接器设置为在委派令牌中发布您的AWS凭证,或者,为了获得额外的安全性,请向AWS索取会话凭证,然后仅将其发送出去。但是(a)您需要具有这些依赖关系的Spark构建,并且(b)Hive需要使用这些凭据与S3进行通信。

© www.soinside.com 2019 - 2024. All rights reserved.