mongokerberos 验证工具
mongokerberos 程序提供了一种便捷的方法,以验证您的平台的 Kerberos 配置是否与 MongoDB 一起使用,并测试 MongoDB 客户端的 Kerberos 身份验证是否按预期运行。
mongokerberos工具可以帮助诊断常见配置问题,并且是对 Kerberos 配置进行故障排除时建议入手的工具。 有关更多信息,请参阅mongokerberos文档。
mongokerberos 仅在 MongoDB Enterprise 中可用。
Kerberos 配置调试策略
如果您在使用 Kerberosmongod mongos启动 或 或对其进行身份验证时遇到困难,请考虑以下操作:
确保您运行的是 MongoDB Enterprise,而不是 MongoDB Community Edition。 Kerberos 身份验证是 MongoDB Enterprise 的一项功能,不适用于 MongoDB Community Edition 二进制文件。
要验证您是否使用 MongoDB Enterprise,请将
--version命令行选项传递给mongod或mongos:mongod --version 在该命令的输出中,请查找字符串
modules: subscription或modules: enterprise,以确认您使用的是 MongoDB Enterprise 二进制文件。On Linux, ensure that the primary component of the service principal name (SPN) of the SPN is
mongodb. If the primary component of the SPN is notmongodb, you must specify the primary component using--setParameter saslServiceName.
On Linux, ensure that the instance component of the service principal name (SPN) in the keytab file matches the canonical system hostname of the
mongodormongosinstance. If themongodormongosinstance's system hostname is not in the keytab file, authentication will fail with aGSSAPI error acquiring credentials.error message.如果 返回的
mongod或mongos实例的主机名不是完全限定的,请在启动hostname -f--setParameter saslHostName或mongod时使用mongos设置实例的完全限定域名。确保托管 MongoDB 实例和 Kerberos 基础架构的服务器上的时钟在最大时间偏差内:默认为 5 分钟。 大于最大时间偏差的时间差会阻止身份验证成功。
确保Linux KRB5 密钥表包含以
@<KERBEROS REALM>结尾的主体名称。要验证 SPN,请在 Active Directory 上运行setspn -Q <spn>。如果配置正确,此命令会为附加到该 SPN 的帐户返回一个标识名。如果在Linux上运行klist -k <keytab>,则<spn>@<KERBEROS REALM>会出现在密钥表中。如果使用 Active Directory 作为KDC ,请确保 MongoDB 服务帐户是用户帐户,而不是计算机帐户。
If you use AES encryption with Active Directory, enable AES on the MongoDB service account with either the
msDS-SupportedEncryptionTypesproperty or the "Network Security: Configure Encryption types allowed for Kerberos" policy setting.Kerberos 对其密钥生成算法进行盐化处理,以确保具有相同密码的两个用户生成不同的密钥。 Linux 和 Active Directory (AD) 上的
ktutil不使用相同的进程来生成盐。 跨 Linux 和 Windows 环境工作时,这种差异可能会导致身份验证失败。 要缓解此问题,您可以:在 AD 服务器上生成 keytab 文件,并将生成的文件移动到 Linux 服务器。
ktpass /out <outfile.keytab> /princ <spn>@<KERBEROS REALM> /mapuser <current userPrincipalName> /crypto ALL /ptype KRB5_NT_PRINCIPAL +rndpass 注意
这会将
userPrincipalName更改为/princ中的值。在 Linux 上使用
ktutil并强制其使用正确的盐。 要强制ktutil使用正确的盐:生成使用
userPrincipalName作为主体名称的密钥表条目。ktutil: add_entry -password -p <userPrincipalName>@<KERBEROS REALM> -e aes256-cts-hmac-sha1-96 -k <KVNO> Password for <userPrincipalName>@<KERBEROS REALM>: ktutil: list -k slot KVNO Principal Hexdump 密钥。
创建一个新的 keytab 条目,使用
<spn>@<KERBEROS REALM>作为主体名称,并使用十六进制转储的密钥。1 <KVNO> <userPrincipalName>@<KERBEROS REALM>(0x<HEXDUMP>) ktutil: add_entry -key -p <spn>@<KERBEROS REALM> -e aes256-cts-hmac-sha1-96 -k <KVNO> Key for <spn>@<KERBEROS REALM> (hex): <HEXDUMP> ktutil: write_kt mongodb_ad.keytab
使用 RC 4 -HMAC,它不使用盐,但不建议这样做。
Linux 上的 Kerberos 跟踪日志记录
MIT Kerberos provides the KRB5_TRACE environment variable for trace logging output. If you are having persistent problems with MIT Kerberos on Linux, you can set KRB5_TRACE when starting your mongod, mongos, or mongosh instances to produce verbose logging.
例如,以下命令启动一个独立运行的实例mongod ,其密钥表文件位于默认路径/etc/krb5.keytab,并将KRB5_TRACE设置为写入/logs/mongodb-kerberos.log :
env KRB5_KTNAME=/etc/krb5.keytab \ KRB5_TRACE=/logs/mongodb-kerberos.log \ mongod --dbpath /data/db --logpath /data/db/mongodb.log \ --auth --setParameter authenticationMechanisms=GSSAPI \ --bind_ip localhost,<hostname(s)|ip address(es)> --fork
常见错误消息
在某些情况下,如果 Kerberos 服务出现问题,MongoDB 会从 GSSAPI 接口返回错误消息。 一些常见的错误消息如下: