我的客户端/服务器都运行 Ubuntu 14.04,kerberos 用户身份验证按预期工作。常规 nfs4 挂载也运行良好。所有机器都在运行 heimdal 库。
我还无法让 Kerberos 化的 nfs4 工作。
当挂载共享时,我在日志中收到以下条目:
NFS4 服务器:
Jun 22 11:25:13 SERVER rpc.svcgssd[7349]: leaving poll
Jun 22 11:25:13 SERVER rpc.svcgssd[7349]: handling null request
Jun 22 11:25:13 SERVER rpc.svcgssd[7349]: svcgssd_limit_krb5_enctypes: Calling gss_set_allowable_enctypes with 7 enctypes from the kernel
Jun 22 11:25:13 SERVER rpc.svcgssd[7349]: WARNING: gss_accept_sec_context failed
Jun 22 11:25:13 SERVER rpc.svcgssd[7349]: ERROR: GSS-API: error in handle_nullreq: gss_accept_sec_context(): GSS_S_FAILURE (Unspecified GSS failure. Minor code may provide more information) - Wrong principal in request
Jun 22 11:25:13 SERVER rpc.svcgssd[7349]: sending null reply
Jun 22 11:25:13 SERVER rpc.svcgssd[7349]: writing message: \x \x6082029206092a864886f71201020201006e8202813082027da003020105a10302010ea20703050020000000a382017a6182017630820172a003020105a10b1b09504f4f4c532e534749a22b3029a003020101a12230201b036e66731b197073692e696e666f726d6174696b2e756e692d756c6d2e6465a382012f3082012ba003020112a103020101a282011d04820119a832e1fb8bf9170fa8a1f689868e2e4bacd8d4d1490c1d336b8bd90a61a11c8b669c5204fe73339f0fdab3d4770b78fdd745f5186a94ea55db90dbde79dc6c5b68c7c1ecba74f723c3fa3eb90ea412518c5da92497276b8a6e369ebb381ebdffa5d1d81e635c4e772892541f4c44475a5d87fc352c43c6e7dc6c0b37875383ec828a2d896948588fd84d442b6bf84b988f5e9bd251d2f71ea582709ecae4bd226705d263081f1036a85d0f13c240d740bf4377f7b6409dde7bd52acdcb396ea181cd54146bd93457801dd9edd0fcb1e27467e0f6ef615dae3f69a96060c463128875cbd414d6bf83af55c5132c814b9af5584852e21373fa774c05760e2c58eb719873c06c26acb2858dd6c4a81c89389cfede089df28f3e7ba481e93081e6a003020112a281de0481dbeedce4152a95ffbd19cccdb67033950e3b1c4aa2dca3b4ad147c9676286b726b02d8cc95b5fd842a2676551e10696ed4f3dfd2c91ec0f674a2017e97ab102aa13fefe02281de5116e8a4e62f93a4e0aff431155ae8b77229f71a6c03278e265eb7752b742b491adbbe5589263e19cf61f7b99cb615c97acc5b87a6008151c52ae4d6dd702a2d545cd23425df58ee37609930e0399fb4cf391a07fa08aa66da40a48491ce1fe6a9f58c30d4af039d191aa4f7b8e7c912ab76fcff685fc0ed6a82559f58b454d4cf61c28d3f962bfc43b265ce7d50ca769e1087bbfe 1403429173 851968 2529639056 \x \x
Jun 22 11:25:13 SERVER rpc.svcgssd[7349]: finished handling null request
Jun 22 11:25:13 SERVER rpc.svcgssd[7349]: entering poll
Jun 22 11:25:13 SERVER rpc.svcgssd[7349]: leaving poll
Jun 22 11:25:13 SERVER rpc.svcgssd[7349]: handling null request
Jun 22 11:25:13 SERVER rpc.svcgssd[7349]: svcgssd_limit_krb5_enctypes: Calling gss_set_allowable_enctypes with 7 enctypes from the kernel
Jun 22 11:25:13 SERVER rpc.svcgssd[7349]: WARNING: gss_accept_sec_context failed
Jun 22 11:25:13 SERVER rpc.svcgssd[7349]: ERROR: GSS-API: error in handle_nullreq: gss_accept_sec_context(): GSS_S_FAILURE (Unspecified GSS failure. Minor code may provide more information) - Wrong principal in request
Jun 22 11:25:13 SERVER rpc.svcgssd[7349]: sending null reply
Jun 22 11:25:13 SERVER rpc.svcgssd[7349]: writing message: \x \x6082029206092a864886f71201020201006e8202813082027da003020105a10302010ea20703050020000000a382017a6182017630820172a003020105a10b1b09504f4f4c532e534749a22b3029a003020101a12230201b036e66731b197073692e696e666f726d6174696b2e756e692d756c6d2e6465a382012f3082012ba003020112a103020101a282011d04820119a832e1fb8bf9170fa8a1f689868e2e4bacd8d4d1490c1d336b8bd90a61a11c8b669c5204fe73339f0fdab3d4770b78fdd745f5186a94ea55db90dbde79dc6c5b68c7c1ecba74f723c3fa3eb90ea412518c5da92497276b8a6e369ebb381ebdffa5d1d81e635c4e772892541f4c44475a5d87fc352c43c6e7dc6c0b37875383ec828a2d896948588fd84d442b6bf84b988f5e9bd251d2f71ea582709ecae4bd226705d263081f1036a85d0f13c240d740bf4377f7b6409dde7bd52acdcb396ea181cd54146bd93457801dd9edd0fcb1e27467e0f6ef615dae3f69a96060c463128875cbd414d6bf83af55c5132c814b9af5584852e21373fa774c05760e2c58eb719873c06c26acb2858dd6c4a81c89389cfede089df28f3e7ba481e93081e6a003020112a281de0481dbfb0d5aa8041f95bbe86f7b8e6dcfb68a1c214d89bb8b5a7712b12e1346289ecf947595d783de2e5ceb32146a5a20c900097b495869d6d3b0533eed0407d71ecf7034a0e18805b5bfbdf3f5f543a70dbe86825d5bda491b4cbbe2ace745f4ae1d0e4d60a7fcc2089915236f59d9357f4ec549022c4aab322ed47b168507003fb5768b9e4c77c57b88b7f74b007dc0837ed560d9af6103aa105f53ecbc7b53c5e9170ad0add67b14a988b1388f93558cc43c4622eea107482e4f320ebbee3fe48acceb5e3e70a33f5ac7a5923c4251b1625e75179096c8b3de7fd934 1403429173 851968 2529639056 \x \x
Jun 22 11:25:13 SERVER rpc.svcgssd[7349]: finished handling null request
Jun 22 11:25:13 SERVER rpc.svcgssd[7349]: entering poll
导出文件:
/srv XXX.XXX.209.0/24(fsid=0,rw,no_subtree_check,root_squash,async,sec=sys:krb5:krb5i:krb5p)
/srv tip*.example.com(fsid=0,rw,no_subtree_check,root_squash,async,sec=sys:krb5:krb5i:krb5p)
/srv pclab*.example.com(fsid=0,rw,no_subtree_check,root_squash,async,sec=sys:krb5:krb5i:krb5p)
/srv/home XXX.XXX.209.0/24(rw,no_subtree_check,root_squash,async,sec=sys:krb5:krb5i:krb5p)
/srv/home tip*.example.com(rw,no_subtree_check,root_squash,async,sec=sys:krb5:krb5i:krb5p)
/srv/home pclab*.example.com(rw,no_subtree_check,root_squash,async,sec=sys:krb5:krb5i:krb5p)
/srv/home XXX.XXX.208.0/24(rw,no_subtree_check,root_squash,async,sec=sys:krb5:krb5i:krb5p)
/srv/home wslab*.example.com(rw,no_subtree_check,root_squash,async,sec=sys:krb5:krb5i:krb5p)
/srv/grpdrvs XXX.XXX.209.0/24(rw,no_subtree_check,root_squash,async,sec=sys:krb5:krb5i:krb5p)
/srv/grpdrvs tip*.example.com(rw,no_subtree_check,root_squash,async,sec=sys:krb5:krb5i:krb5p)
/srv/grpdrvs pclab*.example.com(rw,no_subtree_check,root_squash,async,sec=sys:krb5:krb5i:krb5p)
/srv/grpdrvs XXX.XXX.208.0/24(rw,no_subtree_check,root_squash,async,sec=sys:krb5:krb5i:krb5p)
在 /etc/hosts 中:
127.0.0.1 localhost
XXX.XXX.209.52 SERVER.example.com SERVER
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
服务器和客户端:
在 /etc/idmapd 中:
[General]
Verbosity = 5
Pipefs-Directory = /run/rpc_pipefs
# set your own domain here, if id differs from FQDN minus hostname
Domain = example.com
Local-Realms = REALM
[Mapping]
Nobody-User = nobody
Nobody-Group = nogroup
NFS4 客户端:
安装请求:
mount -t nfs4 -o sec=krb5 SERVER:/ /mnt/temp/ -vvvv
mount: fstab path: "/etc/fstab"
mount: mtab path: "/etc/mtab"
mount: lock path: "/etc/mtab~"
mount: temp path: "/etc/mtab.tmp"
mount: UID: 0
mount: eUID: 0
mount: spec: "SERVER:/"
mount: node: "/mnt/temp/"
mount: types: "nfs4"
mount: opts: "sec=krb5"
mount: external mount: argv[0] = "/sbin/mount.nfs4"
mount: external mount: argv[1] = "SERVER:/"
mount: external mount: argv[2] = "/mnt/temp/"
mount: external mount: argv[3] = "-v"
mount: external mount: argv[4] = "-o"
mount: external mount: argv[5] = "rw,sec=krb5"
mount.nfs4: timeout set for Sun Jun 22 11:24:33 2014
mount.nfs4: trying text-based options 'sec=krb5,addr=XXX.XXX.XXX.52,clientaddr=XXX.XXX.XXX.42'
mount.nfs4: mount(2): Permission denied
mount.nfs4: access denied by server while mounting SERVER:/
客户端日志:
Jun 22 11:25:13 CLIENT rpc.gssd[708]: handling gssd upcall (/run/rpc_pipefs/nfs/clnt0)
Jun 22 11:25:13 CLIENT rpc.gssd[708]: handle_gssd_upcall: 'mech=krb5 uid=0 enctypes=18,17,16,23,3,1,2 '
Jun 22 11:25:13 CLIENT rpc.gssd[708]: handling krb5 upcall (/run/rpc_pipefs/nfs/clnt0)
Jun 22 11:25:13 CLIENT rpc.gssd[708]: process_krb5_upcall: service is '<null>'
Jun 22 11:25:13 CLIENT rpc.gssd[708]: Full hostname for 'SERVER.example.com' is 'SERVER.example.com'
Jun 22 11:25:13 CLIENT rpc.gssd[708]: Full hostname for 'CLIENT.example.com' is 'CLIENT.example.com'
Jun 22 11:25:13 CLIENT rpc.gssd[708]: No key table entry found for CLIENT$@REALM while getting keytab entry for 'CLIENT$@'
Jun 22 11:25:13 CLIENT rpc.gssd[708]: No key table entry found for root/CLIENT.example.com@REALM while getting keytab entry for 'root/CLIENT.example.com@'
Jun 22 11:25:13 CLIENT rpc.gssd[708]: Success getting keytab entry for 'nfs/CLIENT.example.com@'
Jun 22 11:25:13 CLIENT rpc.gssd[708]: INFO: Credentials in CC 'FILE:/tmp/krb5ccmachine_REALM' are good until 1403514481
Jun 22 11:25:13 CLIENT rpc.gssd[708]: INFO: Credentials in CC 'FILE:/tmp/krb5ccmachine_REALM' are good until 1403514481
Jun 22 11:25:13 CLIENT rpc.gssd[708]: using FILE:/tmp/krb5ccmachine_REALM as credentials cache for machine creds
Jun 22 11:25:13 CLIENT rpc.gssd[708]: using environment variable to select krb5 ccache FILE:/tmp/krb5ccmachine_REALM
Jun 22 11:25:13 CLIENT rpc.gssd[708]: creating context using fsuid 0 (save_uid 0)
Jun 22 11:25:13 CLIENT rpc.gssd[708]: creating tcp client for server SERVER.example.com
Jun 22 11:25:13 CLIENT rpc.gssd[708]: DEBUG: port already set to 2049
Jun 22 11:25:13 CLIENT rpc.gssd[708]: creating context with server [email protected]
Jun 22 11:25:13 CLIENT rpc.gssd[708]: WARNING: Failed to create krb5 context for user with uid 0 for server SERVER.example.com
Jun 22 11:25:13 CLIENT rpc.gssd[708]: WARNING: Failed to create machine krb5 context with credentials cache FILE:/tmp/krb5ccmachine_REALM for server SERVER.example.com
Jun 22 11:25:13 CLIENT rpc.gssd[708]: WARNING: Machine cache is prematurely expired or corrupted trying to recreate cache for server SERVER.example.com
Jun 22 11:25:13 CLIENT rpc.gssd[708]: Full hostname for 'SERVER.example.com' is 'SERVER.example.com'
Jun 22 11:25:13 CLIENT rpc.gssd[708]: Full hostname for 'CLIENT.example.com' is 'CLIENT.example.com'
Jun 22 11:25:13 CLIENT rpc.gssd[708]: No key table entry found for CLIENT$@REALM while getting keytab entry for 'CLIENT$@'
Jun 22 11:25:13 CLIENT rpc.gssd[708]: No key table entry found for root/CLIENT.example.com@REALM while getting keytab entry for 'root/CLIENT.example.com@'
Jun 22 11:25:13 CLIENT rpc.gssd[708]: Success getting keytab entry for 'nfs/CLIENT.example.com@'
Jun 22 11:25:13 CLIENT rpc.gssd[708]: INFO: Credentials in CC 'FILE:/tmp/krb5ccmachine_REALM' are good until 1403514481
Jun 22 11:25:13 CLIENT rpc.gssd[708]: INFO: Credentials in CC 'FILE:/tmp/krb5ccmachine_REALM' are good until 1403514481
Jun 22 11:25:13 CLIENT rpc.gssd[708]: using FILE:/tmp/krb5ccmachine_REALM as credentials cache for machine creds
Jun 22 11:25:13 CLIENT rpc.gssd[708]: using environment variable to select krb5 ccache FILE:/tmp/krb5ccmachine_REALM
Jun 22 11:25:13 CLIENT rpc.gssd[708]: creating context using fsuid 0 (save_uid 0)
Jun 22 11:25:13 CLIENT rpc.gssd[708]: creating tcp client for server SERVER.example.com
Jun 22 11:25:13 CLIENT rpc.gssd[708]: DEBUG: port already set to 2049
Jun 22 11:25:13 CLIENT rpc.gssd[708]: creating context with server [email protected]
Jun 22 11:25:13 CLIENT rpc.gssd[708]: WARNING: Failed to create krb5 context for user with uid 0 for server SERVER.example.com
Jun 22 11:25:13 CLIENT rpc.gssd[708]: WARNING: Failed to create machine krb5 context with credentials cache FILE:/tmp/krb5ccmachine_REALM for server SERVER.example.com
Jun 22 11:25:13 CLIENT rpc.gssd[708]: WARNING: Failed to create machine krb5 context with any credentials cache for server SERVER.example.com
Jun 22 11:25:13 CLIENT rpc.gssd[708]: doing error downcall
Jun 22 11:25:13 CLIENT rpc.gssd[708]: destroying client /run/rpc_pipefs/nfs/clnte
Jun 22 11:25:13 CLIENT rpc.gssd[708]: destroying client /run/rpc_pipefs/nfsd4_cb/clntd
Jun 22 11:25:13 CLIENT rpc.gssd[708]: destroying client /run/rpc_pipefs/nfsd4_cb/clnt7
Jun 22 11:25:13 CLIENT rpc.gssd[708]: destroying client /run/rpc_pipefs/nfsd4_cb/clnt6
Jun 22 11:25:13 CLIENT rpc.gssd[708]: destroying client /run/rpc_pipefs/nfsd4_cb/clnt5
客户端密钥表:
% ktutil list
FILE:/etc/krb5.keytab:
Vno Type Principal Aliases
1 aes256-cts-hmac-sha1-96 host/CLIENT.example.com@REALM
1 des3-cbc-sha1 host/CLIENT.example.com@REALM
1 arcfour-hmac-md5 host/CLIENT.example.com@REALM
1 aes256-cts-hmac-sha1-96 nfs/CLIENT.example.com@REALM
1 des3-cbc-sha1 nfs/CLIENT.example.com@REALM
1 arcfour-hmac-md5 nfs/CLIENT.example.com@REALM
客户端凭证缓存:
% klist -c /tmp/krb5ccmachine_REALM
Credentials cache: FILE:/tmp/krb5ccmachine_REALM
Principal: nfs/CLIENT.example.com@REALM
Issued Expires Principal
Jun 22 13:55:01 2014 Jun 23 13:55:01 2014 krbtgt/REALM@REALM
Jun 22 13:55:01 2014 Jun 23 13:55:01 2014 nfs/SERVER.example.com@REALM
客户端 /etc/hosts:
127.0.0.1 localhost
XXX.XXX.209.17 CLIENT.example.com CLIENT
DNS 相关:
反向 DNS:
% host XXX.XXX.209.17
17.209.XXX.XXX.in-addr.arpa domain name pointer CLIENT.example.com.
% host XXX.XXX.209.52
52.209.XXX.XXX.in-addr.arpa domain name pointer SERVER.example.com.
从服务器获取主机信息:
root@SERVER:~# getent hosts CLIENT.example.com
XXX.XXX.209.17 CLIENT.example.com
root@SERVER:~# getent hosts SERVER.example.com
XXX.XXX.209.52 SERVER.example.com SERVER
从客户端获取主机信息:
CLIENT 00:03:32 # getent hosts SERVER.example.com
XXX.XXX.209.52 SERVER.example.com
CLIENT 00:03:41 # getent hosts CLIENT.example.com
XXX.XXX.209.17 CLIENT.example.com CLIENT
我已经调试这个问题好几个星期了,但至今还没有找到解决方案。
答案1
我找到了解决方案:
查看 rpc.svcgssd 守护进程的 strace,我发现在出现错误之前打开的最后一个文件/etc/krb5.keytab
。
服务器上的 keytab 是使用kadmin
“kadmin/admin”的 kinit 生成的。
服务器上的Akinit -k -t /etc/krb5.keytab nfs/SERVER.example.com@REALM
导致密码无效错误。因此我删除了密钥表并使用 生成了一个新的密钥kadmin -l
表。我的用户的密钥表可能有问题kadmin/admin
,导致密钥表损坏。我还没有调查这个问题。
我创建了新的keytab之后,nfs4+krb5挂载成功。
谢谢您的回答,它们对缩小问题范围有很大帮助。
因此对于遇到类似问题的人来说:
尝试
kinit
使用以下方式在每个涉及的主机上获取服务票证kinit -k -t /etc/krb5.keytab nfs/SERVER.example.com@REALM
执行
strace -p $(pidof rpc.svcgssd) -s4096 -e trace=open,close,read,write
并检查错误发生之前发生的情况。据我所知,“错误主体”错误通常发生在机器
127.0.0.1
与其主机名有映射的情况下。
答案2
您正在使用联机帮助页中标记为 DEPRECATED 的语法exports(5)
:
RPCSEC_GSS security
You may use the special strings "gss/krb5", "gss/krb5i", or "gss/krb5p" to restrict
access to clients using rpcsec_gss security. However, this syntax is deprecated; on
linux kernels since 2.6.23, you should instead use the "sec=" export option:
sec= The sec= option, followed by a colon-delimited list of security flavors, restricts the export to clients using those flavors. Available security flavors include sys (the default--no cryptographic secu‐
rity), krb5 (authentication only), krb5i (integrity protection), and krb5p (privacy protection). For the purposes of security flavor negotiation, order counts: preferred flavors should be listed first.
The order of the sec= option with respect to the other options does not matter, unless you want some options to be enforced differently depending on flavor. In that case you may include multiple sec=
options, and following options will be enforced only for access using flavors listed in the immediately preceding sec= option. The only options that are permitted to vary in this way are ro, rw,
no_root_squash, root_squash, and all_squash.
因此你的出口应该是:
/srv XXX.XXX.209.0/24(fsid=0,rw,no_subtree_check,root_squash,async,sec=krb5)
/srv/home XXX.XXX.209.0/24(rw,no_subtree_check,root_squash,async,sec=krb5)
fsid=0
和导出的资源都应具有正确的安全配置,这一点很重要。选择适合krb5/krb5i/krb5p
您设置的配置。
错误“请求中的主体错误”可能是由错误的名称解析引起的。如果您使用的是本地解析,请检查您的/etc/hosts
文件。
答案3
处理此类问题的人通常会这样做:
- DNS 名称和主机的 FQDN 必须为小写,即使您的 DNS 支持 FQDN 中的大写。
- 您应该有一个与您的机器名称类似的主体,例如:
[email protected]
,并相应地添加到 keytab 中(全部大写并以 结尾$
) - 您应该有主体
host/your-machine.your.domain.name
和nfs/your-machine.your.domain.name
,并相应地将此主体添加到密钥表。 - 您的
/etc/hosts
名字不能大写,并且如果有的话,FQDN 应该是第一个,而不是短名称。