hadoop - 如何实现自定义委托令牌
问题描述
我有以下情况:
- 我有一个 HTTP 服务,其中我有一个使用 keytab 和一个 kerberos 主体的登录用户 -为了示例起见,让我们命名这个用户
service_user
- 然后我有一个调用该服务并通过 kerberos (spnego) 进行身份验证的客户端 -让我们命名调用该服务的用户
client_user
- 从我的服务中,我想启动一个 Yarn Java 应用程序(运行良好),最后从 Yarn 容器中我需要调用需要身份验证的服务的回调端点
- 在 Yarn 容器中,我不在一个 kerberized 环境中,我只有委托令牌
- 所以理想情况下,我的服务也应该接受 spnego 和委托令牌身份验证
我看了看DelegationTokenAuthenticationFilter
,但我无法弄清楚我应该如何使用它。我将它添加到我的服务中,我发现它DelegationTokenAuthenticationHandler#managementOperation
可以处理我op=GETDELEGATIONTOKEN
在查询部分中的请求。如果我curl --negotiate -u : http://host:port/callback?op= GETDELEGATIONTOKEN
从命令行执行类似操作,我会得到一个委托令牌,这很好。
但这不是我想要的,对吧?我想做的是:client_user
调用我的服务,通过 spnego 进行身份验证,服务创建自定义委托令牌client_user
,将该委托令牌传递给 Yarn 容器(我设置了HADOOP_TOKEN_FILE_LOCATION
env 变量),然后从 Yarn 容器回调使用我创建的委托令牌到我的服务。
我还尝试以自己的方式创建委托令牌:
DelegationTokenManager tokenManager = new DelegationTokenManager(conf, new Text("..."));
tokenManager.init();
Token<? extends AbstractDelegationTokenIdentifier> token = tokenManager.createToken(ugi, renewer);
Credentials credentials = ...
credentials.addToken(new Text("..."), token);
然后这在我做的纱线容器中可用:
import static org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticator.DELEGATION_TOKEN_HEADER;
UserGroupInformation currentUser = UserGroupInformation.getCurrentUser();
Credentials credentials = currentUser.getCredentials();
Token<? extends TokenIdentifier> delegationToken = credentials.getToken(new Text("..."));
HttpURLConnection connection = ...
connection.setRequestProperty(DELEGATION_TOKEN_HEADER, delegationToken.encodeToUrlString());
我看到DelegationTokenAuthenticationFilter
拿起我的令牌,但它说它是无效的。关于它没有被签名的东西。
我什至走在正确的道路上吗?我是否应该忘记DelegationTokenAuthenticationFilter
并简单地扩展AuthenticationFilter
我可以在 HTTP 请求中接受自定义委托令牌标头的位置?或者我应该使用DelegationTokenAuthenticationFilter
并尝试以DelegationTokenManager#verifyToken
某种方式覆盖?
我看到在我可以使用的 Yarn 容器中创建一个 HttpURLConnection DelegationTokenAuthenticatedURL.openConnection
,但这需要一个 kerberized 环境。
解决方案
推荐阅读
- php - 上传脚本无法上传到某个不在附近的位置,我该如何解决?
- python - 在扩展中使用 PyModule_AddIntConstant()
- android - window.setStatusBarColor 不起作用?
- java - 使用 MapView 嵌套片段
- vue.js - Vue.js 中的动态路由,在 html 中显示 `this.$route.params.id`
- shopify - 显示给定系列中最畅销的产品列表,但忽略特定产品?
- python - 在熊猫数据框中将多列转换为字符串
- javascript - 如何在 Firebase 中的 ios 应用程序和 Web 应用程序之间发送聊天推送通知
- javascript - 无法从 Ionic 3 中的 Google Map Listener 函数中访问全局函数
- c++ - 如何获取 ZeroMQ 时间戳?