如何使用 CentOS Linux 版本 7.6.1810(核心)设置利用来自 Active Directory KDC 的 Kerberos 身份验证的 NFS4 服务器

如何使用 CentOS Linux 版本 7.6.1810(核心)设置利用来自 Active Directory KDC 的 Kerberos 身份验证的 NFS4 服务器

如何从 Active Directory 设置带有 Kerberos 的 NFS4 服务器?

我可以安装和配置 NFS4 服务器并连接到它,但在 Active Directory 控制 KDC 的任何情况下,我都无法让 Kerberos 工作。即使是在我自己设置 Active Directory 的新安装的 Windows Server 上,也无法工作。

我对为公司 Active Directory 设置的服务器进行了大量调试,其中很多内容都记录在这里:Linux NFS 服务器实现的 setclientid 是如何工作的? 对于装有 Active Directory 的新 Windows 服务器,结果是一样的 - 但令人惊讶的是(也许并不那么令人惊讶)如果我安装其他类型的 KDC,它就可以工作。

我有一个大约 8 个月前安装的工作服务器(如 NFS4 和来自 Active Directory 的 Kerberos),它也运行 CentOS 7.6.1810 - 但即使我将我所做的一切复制到那个服务器上,我也无法让它工作。

我已经使用了 SSSD、PBIS Open 和 Kerberos 的手动配置。

几乎所有操作都会导致“权限被拒绝”,这似乎来自 RPC 的错误代码 -13。我检查过的所有 Kerberos 票证看起来都是正确的。

在 CentOS Linux 版本 7.6.1810(核心)上配置 NFS4 服务器以使用来自 Active Directory 的 Kerberos 需要采取哪些具体步骤?

答案1

我在 Linux(ubuntu)和 FreeBSD 上都使用过这种方法,所以我很确定它们对于类 UN*X 系统来说是相当通用的。

首先,您需要确保 DNS 正常工作,并且主机名正确。确保没有指向 127.0.1.1 的指针指向 hostname.domain.name

另外,请确保您的系统设置为使用 nfs4 和 sec=krb5(或 krb5i 或 krb5p)。

您需要为 nfs 设置一个 SPN。有一个名为 msktutil 的 unix 命令可以处理它。它可能在 centos 中可用。我知道它在 ubuntu 的标准存储库中可用。请参阅https://github.com/msktutil/msktutil

我有一个脚本可以处理这一切。

确保您已加入域并且一切正常。(当然,除了使用 Kerberos 的 nfs4。)我通常会执行以下操作:

kinit Administrator
(enter password)

klist 应该显示您的管理员票。

在运行脚本之前,请备份 /etc/krb5.keytab。

之后我运行这个脚本:(您将加入域两次,以便您的 /etc/krb5.keytab 得到正确更新。我不确定是否严格需要它。)

#!/bin/bash

HOST_NAME=`hostname -s`
DOMAIN_NAME=`hostname -d`
FULL_NAME=`hostname -A`
DC=your-dc.your.domain
kinit Administrator;

rm -f /etc/krb5.keytab

msktutil \
--delegation --dont-expire-password --no-pac --computer-name $HOST_NAME \
--enctypes 0x1F -b "OU=Services" -k /etc/krb5.keytab \
-h $HOST_NAME -s nfs/$FULL_NAME --upn nfs/$FULL_NAME --verbose

net ads join -k

之后,您就可以开始了!(假设您的 nfs 服务器已正确设置。以及 kerberos 和其他一切。例如,在 ubuntu 18.04 上,/etc/default/nfs-kernel-server 在我的系统上看起来像这样。

# Number of servers to start up
RPCNFSDCOUNT=8

# Runtime priority of server (see nice(1))
RPCNFSDPRIORITY=0

# Options for rpc.mountd.
# If you have a port-based firewall, you might want to set up
# a fixed port here using the --port option. For more information,
# see rpc.mountd(8) or http://wiki.debian.org/SecuringNFS
# To disable NFSv4 on the server, specify '--no-nfs-version 4' here
RPCMOUNTDOPTS="--manage-gids"

# Do you want to start the svcgssd daemon? It is only required for Kerberos
# exports. Valid alternatives are "yes" and "no"; the default is "no".
NEED_SVCGSSD="yes"

# Options for rpc.svcgssd.
#RPCSVCGSSDOPTS=""

# Options for rpc.nfsd.
RPCNFSDOPTS=""
RPCSVCGSSDOPTS="-k /etc/krb5.keytab"

我的 /etc/idmapd.conf 如下所示:

[General]   

Verbosity = 1   
Pipefs-Directory = /run/rpc_pipefs   
# set your own domain here, if id differs from FQDN minus hostname.   
# Domain = localdomain    
Domain = my.domain 
Local-Realms = MY.DOMAIN   
[Mapping]

Nobody-User = nobody
Nobody-Group = nogroup

[Translation]

Method = nsswitch

/etc/default/nfs-common 如下所示:(centos 可能有类似的内容)

# If you do not set values for the NEED_ options, they will be attempted
# autodetected; this should be sufficient for most people. Valid alternatives
# for the NEED_ options are "yes" and "no".


# Options for rpc.statd.
#   Should rpc.statd listen on a specific port? This is especially useful
#   when you have a port-based firewall. To use a fixed port, set this
#   this variable to a statd argument like: "--port 4000 --outgoing-port 4001".    
#   For more information, see rpc.statd(8) 
STATDOPTS=
NEED_IDMAPD=yes
# Do you want to start the gssd daemon? It is required for Kerberos mounts.
NEED_GSSD=yes
RPCSVCGSSDOPTS="-k /etc/krb5.keytab"

希望这可以帮助!

相关内容