Configure Self-Managed MongoDB with Kerberos Authentication on Windows在Windows上配置具有Kerberos身份验证的自管理MongoDB
Overview概述
MongoDB Enterprise supports authentication using a Kerberos service. Kerberos is an industry standard authentication protocol for large client/server systems. MongoDB Enterprise支持使用Kerberos服务进行身份验证。Kerberos是用于大型客户端/服务器系统的行业标准身份验证协议。Kerberos allows MongoDB and applications to take advantage of existing authentication infrastructure and processes. Kerberos允许MongoDB和应用程序利用现有的身份验证基础设施和流程。MongoDB Enterprise only supports the MIT implementation of Kerberos.MongoDB Enterprise仅支持Kerberos的MIT实现。
Prerequisites先决条件
Setting up and configuring a Kerberos deployment is beyond the scope of this document. 设置和配置Kerberos部署超出了本文档的范围。This tutorial assumes have configured a Kerberos service principal for each 本教程假设已经为每个mongod.exe and mongos.exe instance.mongod.exe和mongos.exe实例配置了Kerberos服务主体。
For replica sets and sharded clusters, ensure that your configuration uses fully qualified domain names (FQDN) rather than IP addresses or unqualified hostnames. You must use the FQDN for GSSAPI to correctly resolve the Kerberos realms and allow you to connect.对于副本集和分片群集,请确保配置使用完全限定域名(FQDN),而不是IP地址或非限定主机名。您必须使用GSSAPI的FQDN来正确解析Kerberos领域并允许您连接。
Procedures过程
Start mongod.exe without Kerberos.在没有Kerberos的情况下启动mongod.exe。
mongod.exe without Kerberos.For the initial addition of Kerberos users, start 对于最初添加的Kerberos用户,请在不支持Kerberos的情况下启动mongod.exe without Kerberos support.mongod.exe。
If a Kerberos user is already in MongoDB and has the privileges required to create a user, you can start 如果Kerberos用户已经在MongoDB中,并且具有创建用户所需的权限,则可以使用Kerberos支持启动mongod.exe with Kerberos support.mongod.exe。
Include additional settings as appropriate to your deployment.根据部署情况包括其他设置。
Note
mongod and 和mongos bind to localhost by default. 默认情况下绑定到localhost。If the members of your deployment are run on different hosts or if you wish remote clients to connect to your deployment, you must specify 如果部署的成员在不同的主机上运行,或者希望远程客户端连接到部署,则必须指定--bind_ip or net.bindIp.--bind_ip或net.bindIp。
Connect to mongod.连接到mongod。
mongod.Connect 将mongosh to the mongod.exe instance. mongosh连接到mongod.exe实例。If 如果mongod.exe has --auth enabled, ensure you connect with the privileges required to create a user.mongod.exe启用了--auth,请确保您具有创建用户所需的权限进行连接。
Add Kerberos Principal(s) to MongoDB.将Kerberos主体添加到MongoDB。
Add a Kerberos principal, 将Kerberos主体<username>@<KERBEROS REALM>, to MongoDB in the $external database. Specify the Kerberos realm in ALL UPPERCASE. <username>@<KERBEROS REALM>添加到$external数据库中的MongoDB。在所有大写字母中指定Kerberos领域。The $external database allows mongod.exe to consult an external source (e.g. Kerberos) to authenticate. To specify the user's privileges, assign roles to the user.$external数据库允许mongod.exe查询外部源(例如Kerberos)进行身份验证。要指定用户的权限,请为用户分配角色。
To use Client Sessions and Causal Consistency Guarantees with 要对$external authentication users (Kerberos, LDAP, or X.509 users), usernames cannot be greater than 10k bytes.$external身份验证用户(Kerberos、LDAP或X.509用户)使用客户端会话和因果一致性保证,用户名不能大于10k字节。
The following example adds the Kerberos principal 以下示例添加了Kerberos主体reportingapp@EXAMPLE.NET with read-only access to the records database:reportingapp@EXAMPLE.NET具有对records数据库的只读访问权限:
use $external
db.createUser(
{
user: "reportingapp@EXAMPLE.NET",
roles: [ { role: "read", db: "records" } ]
}
)
Add additional principals as needed. For every user you want to authenticate using Kerberos, you must create a corresponding user in MongoDB. For more information about creating and managing users, see User Management Commands.根据需要添加其他主体。对于每个要使用Kerberos进行身份验证的用户,您必须在MongoDB中创建一个相应的用户。有关创建和管理用户的详细信息,请参阅用户管理命令。
Start mongod.exe with Kerberos support.使用Kerberos支持启动mongod.exe。
mongod.exe with Kerberos support.You must start 您必须将mongod.exe as the service principal account.mongod.exe作为服务主体帐户启动。
To start 要启动支持Kerberos的mongod.exe with Kerberos support, set the mongod.exe parameter authenticationMechanisms to GSSAPI:mongod.exe,请将mongod.exe参数authenticationMechanisms设置为GSSAPI:
mongod.exe --setParameter authenticationMechanisms=GSSAPI <additional mongod.exe options>
Include additional options as required for your configuration. For instance, if you wish remote clients to connect to your deployment or your deployment members are run on different hosts, specify the 根据配置要求,包括其他选项。例如,如果您希望远程客户端连接到部署,或者部署成员在不同的主机上运行,请指定--bind_ip.--bind_ip。
For example, the following starts a standalone 例如,以下内容启动了一个支持Kerberos的独立mongod.exe instance with Kerberos support:mongod.exe实例:
mongod.exe --auth --setParameter authenticationMechanisms=GSSAPI --bind_ip localhost,<hostname(s)|ip address(es)>Connect mongosh.exe shell to mongod.exe and authenticate.将mongosh.exe shell连接到mongod.exe并进行身份验证。
mongosh.exe shell to mongod.exe and authenticate.Connect the 将mongosh shell client as the Kerberos principal application@EXAMPLE.NET.mongosh shell客户端连接为Kerberos主体application@EXAMPLE.NET。
You can connect and authenticate from the command line.您可以通过命令行进行连接和身份验证。
Using 使用cmd.exe:cmd.exe:
mongosh.exe --host hostname.example.net --authenticationMechanism=GSSAPI --authenticationDatabase=$external --username reportingapp@EXAMPLE.NET
Using 使用Windows PowerShell:Windows PowerShell:
mongosh.exe --host hostname.example.net --authenticationMechanism=GSSAPI --authenticationDatabase='$external' --username reportingapp@EXAMPLE.NET
If you are connecting to a system whose hostname matches the Kerberos name, ensure that you specify the fully qualified domain name (FQDN) for the 如果要连接到主机名与Kerberos名称匹配的系统,请确保为--host option, rather than an IP address or unqualified hostname.--host选项指定完全限定域名(FQDN),而不是IP地址或非限定主机名。
If you are connecting to a system whose hostname does not match the Kerberos name, first connect the 如果要连接到主机名与Kerberos名称不匹配的系统,请首先将mongosh shell to mongod.exe, and then from the mongosh shell, use the db.auth() method to authenticate in the $external database.mongosh shell连接到mongod.exe,然后从mongosh shell使用db.auth()方法在$external数据库中进行身份验证。
use $external
db.auth( { mechanism: "GSSAPI", user: "reportingapp@EXAMPLE.NET" } )Additional Considerations其他注意事项
Configure mongos.exe for Kerberos为Kerberos配置mongos.exe
mongos.exe for KerberosTo start 要使用Kerberos支持启动mongos.exe with Kerberos support, set the mongos.exe parameter authenticationMechanisms to GSSAPI. mongos.exe,请将mongos.exe参数authenticationMechanisms设置为GSSAPI。You must start 您必须将mongos.exe as the service principal account:mongos.exe作为服务主体帐户启动:
mongos.exe --setParameter authenticationMechanisms=GSSAPI <additional mongos options>
Include additional options as required for your configuration. For instance, if you wish remote clients to connect to your deployment or your deployment members are run on different hosts, specify the 根据配置要求,包括其他选项。例如,如果您希望远程客户端连接到部署,或者部署成员在不同的主机上运行,请指定--bind_ip.--bind_ip。
For example, the following starts a 例如,以下代码启动了一个支持Kerberos的mongos instance with Kerberos support:mongos实例:
mongos.exe --setParameter authenticationMechanisms=GSSAPI --configdb shard0.example.net, shard1.example.net,shard2.example.net --keyFile C:\<path>\mongos.keyfile --bind_ip localhost,<hostname(s)|ip address(es)>
Modify or include any additional 根据配置需要修改或包含任何其他mongos.exe options as required for your configuration. mongos.exe选项。For example, instead of using 例如,您可以使用X.509成员身份验证,而不是使用--keyFile for internal authentication of sharded cluster members, you can use X.509 member authentication instead.--keyFile对分片集群成员进行内部身份验证。
Assign Service Principal Name to MongoDB Windows Service为MongoDB Windows服务分配服务主体名称
Use 使用setspn.exe to assign the service principal name (SPN) to the account running the mongod.exe and the mongos.exe service:setspn.exe将服务主体名称(SPN)分配给运行mongod.exe和mongos.exe服务的帐户:
setspn.exe -S <service>/<fully qualified domain name> <service account name>
Example示例
If 如果mongod.exe runs as a service named mongodb on testserver.mongodb.com with the service account name mongodtest, assign the SPN as follows:mongod.exe作为名为mongodb的服务在testserver.mongodb.com上以服务帐户名mongodtest运行,请按如下方式分配SPN:
setspn.exe -S mongodb/testserver.mongodb.com mongodtestIncorporate Additional Authentication Mechanisms加入其他身份验证机制
Kerberos authentication (GSSAPI (Kerberos)) can work alongside:Kerberos身份验证(GSSAPI(Kerberos))可以与以下内容一起工作:
MongoDB's SCRAM authentication mechanism:MongoDB的SCRAM认证机制:MongoDB's authentication mechanism for LDAP:MongoDB的LDAP身份验证机制:- PLAIN (LDAP SASL)
MongoDB's authentication mechanism for X.509:MongoDB的X.509认证机制:
Specify the mechanisms as follows:按如下方式指定机制:
--setParameter authenticationMechanisms=GSSAPI,SCRAM-SHA-256
Only add the other mechanisms if in use. This parameter setting does not affect MongoDB's internal authentication of cluster members.仅在使用时添加其他机制。此参数设置不会影响MongoDB对集群成员的内部身份验证。
Testing and Verification测试与验证
After completing the configuration steps, you can validate your configuration with the 完成配置步骤后,您可以使用mongokerberos tool.mongokerberos工具验证配置。
mongokerberos provides a convenient method to verify your platform's Kerberos configuration for use with MongoDB, and to test that Kerberos authentication from a MongoDB client works as expected. 提供了一种方便的方法来验证平台与MongoDB一起使用的Kerberos配置,并测试来自MongoDB客户端的Kerberos身份验证是否按预期工作。See the 有关更多信息,请参阅mongokerberos documentation for more information.mongokerberos文档。
mongokerberos is available in MongoDB Enterprise only.仅在MongoDB Enterprise中可用。