首页 > 解决方案 > 如何实现自定义委托令牌

问题描述

我有以下情况:

我看了看DelegationTokenAuthenticationFilter,但我无法弄清楚我应该如何使用它。我将它添加到我的服务中,我发现它DelegationTokenAuthenticationHandler#managementOperation可以处理我op=GETDELEGATIONTOKEN在查询部分中的请求。如果我curl --negotiate -u : http://host:port/callback?op= GETDELEGATIONTOKEN从命令行执行类似操作,我会得到一个委托令牌,这很好。

但这不是我想要的,对吧?我想做的是:client_user调用我的服务,通过 spnego 进行身份验证,服务创建自定义委托令牌client_user,将该委托令牌传递给 Yarn 容器(我设置了HADOOP_TOKEN_FILE_LOCATIONenv 变量),然后从 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 环境。

标签: hadooptokenhadoop-yarnkerberos-delegation

解决方案


推荐阅读