4

我使用 kerberos 配置了 hadoop,一切正常,我可以浏览 hdfs,提交作业等。但是 http web 身份验证失败。

我在 cdh3u2 中使用 hadoop-0.20.2,它支持 HTTP SPNEGO。

core-site.xml中HTTP认证相关配置如下:

  <!-- HTTP web-consoles Authentication -->
  <property>
    <name>hadoop.http.filter.initializers</name>
    <value>org.apache.hadoop.security.AuthenticationFilterInitializer</value>
  </property>

  <property>
    <name>hadoop.http.authentication.type</name>
    <value>kerberos</value>
  </property>

  <property>
    <name>hadoop.http.authentication.token.validity</name>
    <value>36000</value>
  </property>

  <property>
    <name>hadoop.http.authentication.signature.secret.file</name>
    <value>/home/hadoop/hadoop/conf/http-secret-file</value>
  </property>

  <property>
    <name>hadoop.http.authentication.cookie.domain</name>
    <value></value>
  </property>

  <property>
    <name>hadoop.http.authentication.simple.anonymous.allowed</name>
    <value>false</value>
  </property>

  <property>
    <name>hadoop.http.authentication.kerberos.principal</name>
    <value>HTTP/hz169-91.i.site.com@I.NETEASE.COM</value>
  </property>

  <property>
    <name>hadoop.http.authentication.kerberos.keytab</name>
    <value>/home/hadoop/hadoop/conf/http.keytab</value>
  </property>
</configuration>

在启动过程中,http 认证成功。

2011-11-15 15:43:59,106 INFO org.apache.hadoop.security.authentication.server.KerberosAuthenticationHandler: Initialized, principal [HTTP/hz169-91.i.site.com@I.NETEASE.COM] from keytab [/home/hadoop/hadoop/conf/http.keytab]

查看代码后,我发现 AuthenticationFilter 在 doFilter 期间获取了空令牌,因此,身份验证开始(代码如下),但 httpservletrequest 中的授权为空,因此,每次我重新加载页面时,都会出现一个日志。

2011-11-15 15:47:52,190 WARN org.apache.hadoop.security.authentication.server.KerberosAuthenticationHandler: SPNEGO starting

// org.apache.hadoop.security.authentication.server.KerberosAuthenticationHandler
public AuthenticationToken authenticate(HttpServletRequest request, final HttpServletResponse response)
    throws IOException, AuthenticationException {
    AuthenticationToken token = null;
    String authorization = request.getHeader(KerberosAuthenticator.AUTHORIZATION);
    if (authorization == null || !authorization.startsWith(KerberosAuthenticator.NEGOTIATE)) {
      response.setHeader(KerberosAuthenticator.WWW_AUTHENTICATE, KerberosAuthenticator.NEGOTIATE);
      response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
      if (authorization == null) {
        LOG.warn("SPNEGO starting");
      } else {
        LOG.warn("'" + KerberosAuthenticator.AUTHORIZATION + "' does not start with '" +
            KerberosAuthenticator.NEGOTIATE + "' :  {}", authorization);
      }

是否有任何配置错误,或者只是我的浏览器不支持 SPNEGO。我在 Ubuntu 11.04 中使用 Chrome v16。

有没有人有线索可以帮助我弄清楚?

谢谢。

4

1 回答 1

2

首先:感谢您发布有关如何为 SPNNEGO 配置 Hadoop Web 控制台的完整且有效的示例——我很难找到一个好的示例。

在修改配置文件的路径后,您的示例对我有用(我通过从 /dev/random 获取一些随机字节创建了hadoop.http.authentication.signature.secret.file,我认为这是正确的做法,尽管我找不到任何支持该理论的文档)。

Google Chrome从 6.0.472 及更高版本支持 SPNNEGO 。但是,似乎在 Linux 和 OSX 上,您必须向它传递一个服务器列表,可以按照此处记录的方式启用它。因此,请尝试在启动 Chrome 时将 *--auth-server-whitelist="*example.com,*foobar.com, baz"添加到 cmdline。

另一种调试方法是使用更简单的浏览器。如果你的 curl 支持 GSS-Negotiate,我会推荐 curl。通过运行 curl --version 检查

$ curl --version
curl 7.19.7 (i486-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15
Protocols: tftp ftp telnet dict ldap ldaps http file https ftps 
Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz 

如果GSS-Negotiate在 Features 列表中,您可以使用 curl 尝试访问例如 namenode Web 控制台:

$ curl -v -u foo --negotiate http://your.namenode.tld:50070

当要求输入主机密码时,只需按 Enter。

这应该让您更好地了解客户端和服务器之间发生的事情。

于 2011-11-15T19:56:14.250 回答