Apache Kerberos身份validation到Active Directory不会发生。 (与KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN有关吗?)

我的目标是使用Kerberos对Apache进行身份validation,而不用提示用户名和密码。 它目前总是显示“401未经授权”,并且似乎没有尝试Kerberos。 我找不到任何错误日志,只能find一个显然不起作用的kinit命令,并给出错误 – WireShark中显示的错误为:

 Linux sends AS-REQ Windows replies KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN 

线索还是红鲱鱼?

设置/背景细节

 Windows Server 2008 R2 SP1, with Active Directory ("winserver"). CentOS 6.5 ("centos"). 
  1. configuration主机名和DNS,并在Windows DNS服务器中添加A和PTR条目。 名称parsing显示正常。

  2. 使用authconfig-tui创build/etc/krb5.conf/etc/samba/smb.conf并调整它们。

的krb5.conf

 `/etc/krb5.conf` [libdefaults] default_realm = SITE.EXAMPLE.COM dns_lookup_realm = false dns_lookup_kdc = false ticket_lifetime = 24h renew_lifetime = 7d forwardable = true [realms] SITE.EXAMPLE.COM = { kdc = winserver.site.example.com admin_server = winserver.site.example.com } [domain_realm] site.example.com = SITE.EXAMPLE.COM 

和桑巴

 `/etc/samba/smb.conf` includes workgroup = SITE password server = winserver realm = SITE.EXAMPLE.COM security = ads kerberos method = system keytab winbind use default domain = true 

从这里,Kerberos设置步骤:

  1. net ads join createupn=HOST/[email protected] -k -U administrator要求我inputWindows密码,并接受它。 它join域(在AD中创build一个计算机对象)。

  2. net ads testjoin报告“join是OK”。

  3. net ads keytab create -k -U administrator创build/etc/krb5.keytab并用HOST/centos....填充它。

  4. net ads keytab add HTTP -k -t /etc/krb5.keytab -U administratorHTTP/centos.site.example.com条目添加到密钥表中。 klist -ke显示了许多SPN组合,包括HTTP/[email protected]并且似乎与服务器对象上的Windows msDS-KeyVersionNumber属性匹配。

此时,我可以使用PuTTY通过SSH进行连接,并且可以使用SSO自动login,不需要密码提示。 我可以通过SSH进行连接,强制密码提示,使用Windows用户名和密码login。使用Windows帐户login后,我可以kinit ,然后klist查看Kerberos票据。 我可以使用wbinfo -uwbinfo -gnet ads search来查询AD并获得结果。

一切看起来不错。 让我们继续前往Apache:

  1. chgrp apache /etc/krb5.keytab

  2. chmod ugo+r /etc/krb5.keytab

  3. yum install mod_auth_kerb

  4. 编辑/etc/httpd/conf/httpd.conf并添加:

httpd.conf

 LoadModule auth_kerb_module /usr/lib64/httpd/modules/mod_auth_kerb.so AuthName "Kerberos Authentication" AuthType Kerberos Krb5Keytab /etc/krb5.keytab KrbAuthRealms SITE.EXAMPLE.COM KrbMethodNegotiate on KrbMethodK5Passwd off KrbServiceName Any 

在Internet Explorer中,“本地Intranet站点”包括http://*.site.example.com ,并设置为“仅在Intranet区域自动login”。 自动login使用这些设置在办公室的其他(基于IIS)的网站。 在FireFox中,about:config有network.negotiate-auth.trusted-uris; .site.example.com network.negotiate-auth.trusted-uris; .site.example.com

在IE,FireFox或Chrome中,我用FQDN访问站点,得到401 Unauthorized 。 Kerberos似乎并没有被尝试。

我在Linux日志文件/ var / log / httpd / error_log或access_log / var / log / secure或/var/log/audit/audit.log中找不到任何内容,以显示出错的地方。

试图find要testing的东西,我发现创build一个清晰的,相关的似乎错误的唯一的事情是命令:

 $ kinit -k -t /etc/krb5.keytab HTTP/centos.site.example.com kinit: Client not found in Kerberos database while getting initial credentials 

我不知道它到底在做什么,但如果我WireShark它:

 Linux sends AS-REQ to Windows with content cname name-string 2 items KerberosString: HTTP KerberosString: centosserver.site.example.com realm: SITE.EXAMPLE.COM Windows replies KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN error-code eRR-C-PRINCIPAL-UNKNOWN (6) 

在Windows上,如果使用setspn -L centos则显示注册的主体名称包括HTTP / centos.site.example.com。

在我的Windows桌面客户端上,如果我的klist get HTTP/centos.site.example.com那么我得到一个显示为客户端的票证:[email protected],服务器:HTTP / centos.site.example.com。

这感觉有点像http://support.microsoft.com/kb/951191 – 但只适用于Windows Server 2008的原始,前Service Pack 2.这是Windows Server 2008 R2 Service Pack 1.我已经试过指出它到另一个域控制器,但这也是运行相同的Windows服务器版本和响应相同的方式。

在Linux方面:我一直在使用CentOS 6.5(Samba 3.x,Kerberos 5.0),但是我也安装了新的CentOS 7(Samba 4.x和Kerberos 5.1),并且尝试了相同的设置并得到了相同的结果来自kinit的结果。 我没有在CentOS 7上试过Apache。

SSH工作的无密码login。 针对AD的loginvalidation可以与kinit一起使用。 Kerberos身份validation在Apache中不起作用,甚至不会在Apache中尝试,也不会logging任何错误。 我错过了什么,为什么不尝试Kerberos身份validation? 我可以testing什么或做什么来使其logging更多?

我唯一能做的就是失败,就是我在互联网上find的那个命令,但是我不知道它在testing什么。 这是什么,为什么它不工作,显然,我的桌面可以查询AD的相同的服务主体,并得到答案?

[编辑更新]

我遵循natxo asenjo的回答'做不同的事情',现在我有一个可行的设置。 我也接受在AD中为每个服务设置不同的用户名,然后创build单独的keytabs是合理的(例如,如果Apache被攻破并且它可以读取的HTTP / keytab被攻破,HOST / keytab仍然是安全的)。

然而,我没有回答为什么Kerberos主体查找窗口与我原来的方法失败。 这是令人沮丧的,因为像http://requesttracker.wikia.com/wiki/Kerberos_SSO_with_Active_Directory_Integration和http://wiki.gentoo.org/wiki/Kerberos_Windows_Interoperability这样的指南把一些keytab绑定到计算机帐户的几个主体,使用Samba净广告命令,并(大概)从它得到一个工作的设置。

我多次使用了http://www.grolmsnet.de/kerbtut/上的说明,因为他们工作。 为了logging,您不需要将Linux主机joinAD域,可以这样做,但不是必需的。

首先,确保你可以从centos主机到你的AD领域。 您可以像这样使用您的普通用户凭据:

 $ kinit [email protected] 

(顺便说一下,kinit是centos中的krb5-workstation包的一部分)

input你的密码,没有消息是好消息。 运行klist,你应该看到一个Kerberos票据作为你的AD用户名。 如果这一步不成功,回去修复你的krb5.conf,直到它。

用kdestroy摆脱那张票。

一旦这个工作,你可以在AD创build一个用户帐户。 确保它不必更改密码,并且密码不会过期。

然后,我们使用pipe理工具的Windows主机上的setspn.exe或域控制器中的服务主体名称(spn)HTTP / host.adrealm.tld,将该服务主体名称(spn)HTTP / host.adrealm.tld绑定到具有足够特权的pipe理员或帐户:

 setspn -A HTTP/host.adrealm.tld username [enter] Registering ServicePrincipalNames for CN=username,OU=service_accounts,dc=adrealm,DC=tld HTTP/host.adrealm.tld Updated object 

现在我们可以使用ktpass.exe(仍在Windowspipe理主机或域控制器中)为此对象生成密钥表:

 ktpass -princ HTTP/[email protected] -pass xxxxx -mapuser username -Ptype KRB5_NT_PRINCIPAL -out host_adrealm_tld.keytab [enter] Targeting domain controller: DCname.Adrealm.tld Successfully mapped HTTP/host.adrealm.tld to username. Password succesfully set! Key created. Output keytab to host_adrealm_tld.keytab: Keytab version: 0x502 keysize 75 HTTP/[email protected] ptype 1 (KRB5_NT_PRINCIPAL) vno 3 etype 0x17 (RC4-HMAC) keylength 16 (0x037da0f7493b97966e4a19636304064d) 

将该文件传输到centos主机,并在/etc/httpd/conf.d/中以640个权限(root:apache)进行放置。 如果启用了selinux,请运行restorecon -rv / etc以最终修复selinux上下文。

您可以使用以下validation密钥表文件:

 $ klist -k -t host_adrealm_tld.keytab Keytab name: FILE:host_adrealm_tld.keytab KVNO Timestamp Principal ---- ----------------- -------------------------------------------------------- 3 01/01/70 01:00:00 HTTP/[email protected] 

你甚至可以更进一步的使用它来login:

 # kinit -k -t host_adrealm_tld.keytab -p HTTP/[email protected] # klist Ticket cache: FILE:/tmp/krb5cc_0 Default principal: HTTP/[email protected] Valid starting Expires Service principal 11/04/14 21:45:41 11/05/14 07:45:41 krbtgt/[email protected] renew until 11/05/14 21:45:41 

在你的dns基础结构(也可能是在AD dns中),创build一个指向centos主机的host.realm.tld(如果你使用sambajoin主机,它应该为你创build它,确保它是正确的)。

确保您的Centos主机安装了mod_auth_kerb。

Whant是你编辑apache的(虚拟)主机的apache conf文件之一。

在这种情况下,让我们保护文件夹http://host.adrealm.tld/topsecret :

 Alias /topsecret/ "/path/to/topsecret/" <Directory "/path/to/topsecret/"> AuthType Kerberos KrbAuthRealms YOURAD.TLD KrbServiceName HTTP Krb5Keytab /etc/httpd/conf.d/host_adrealm_tld.keytab KrbMethodNegotiate on KrbMethodK5Passwd off require valid-user </Directory> 

在centos主机的文件系统中创buildtopsecret文件夹。 在那里设置几个虚拟文件。 如果你使用selinux启动,确保该文件夹具有正确的安全上下文为apache(如果文件夹在/ var / www / html应该是一个正在运行的restorecon -rv / var / www / html将最终修复任何selinux问题)。

validationapache2语法通过:

 apachectl -t 

如果你得到'Syntax OK'的警告,说明你不能够可靠地确定主机fqdn,那么你很好(如果你愿意,你可以修复它,这不是关键)。 重新加载apache:

 apachectl graceful 

validation您的本地防火墙允许httpd connexxions。

这应该是。 现在你需要configuration客户端。 如果您的networking中已经有了“Windows身份validation”的networking服务器,那么您已经设置好了,进入最高密码的url,如果您拥有有效的Kerberos票据,您应该可以看到这些文件,否则您将被拒绝访问。