Important
On a 在mongod instance, the localhost exception only applies when there are no users or roles created in the MongoDB instance.mongod实例上,localhost异常仅在MongoDB实例中没有创建用户或角色时适用。
The localhost exception allows you to enable access control and then create the first user or role in the system. After you enable access control, connect to the localhost interface and create the first user in the localhost异常允许您启用访问控制,然后在系统中创建第一个用户或角色。启用访问控制后,连接到localhost接口并在admin database.admin数据库中创建第一个用户。
If you create a user first, the user must have privileges to create other users. The 如果先创建用户,则该用户必须具有创建其他用户的权限。userAdmin or userAdminAnyDatabase role both confer the privilege to create other users.userAdmin或userAdminAnyDatabase角色都授予创建其他用户的权限。
Warning
Connections using the localhost exception have access to create only the first user or role.使用localhost异常的连接只能创建第一个用户或角色。
Once you create any user or role, the localhost exception is disabled. If you need to create a user and a role, you must create the user first using one of the builtin 创建任何用户或角色后,localhost异常将被禁用。如果需要创建用户和角色,则必须首先使用内置的userAdmin or userAdminAnyDatabase roles. If you create a role first, you won't be able to create a user.userAdmin或userAdminAnyDatabase角色之一创建用户。如果先创建角色,则无法创建用户。
The ability to create a role first with the 使用db.createRole() method is specifically for users authorizing with LDAP. See LDAP Authorization for more information.db.createRole()方法首先创建角色的能力是专门为使用LDAP授权的用户提供的。有关更多信息,请参阅LDAP授权。
Localhost Exception for Sharded Clusters分片群集的本地主机异常
Important
On a在mongos, the localhost exception only applies when there are no sharded cluster users or roles created.mongos上,localhost异常仅在没有创建分片集群用户或角色时适用。In a sharded cluster, the localhost exception applies to each shard individually as well as to the cluster as a whole.在分片集群中,localhost异常单独适用于每个分片,也适用于整个集群。
Once you create a sharded cluster and add a user administrator through the 一旦你创建了一个分片集群,并通过mongos instance, you must still prevent unauthorized access to the individual shards. mongos实例添加了一个用户管理员,你仍然必须防止对单个分片的未经授权的访问。To prevent unauthorized access to individual shards, follow one of the following steps for each shard in your cluster:为了防止未经授权访问单个分片,请对集群中的每个分片执行以下步骤之一:
Create a user administrator on the shard's primary.在分片的主服务器上创建一个用户管理员。Disable the localhost exception at startup. To disable the localhost exception, set the启动时禁用localhost异常。要禁用localhost异常,请将enableLocalhostAuthBypassparameter to0.enableLocalhostAuthBypass参数设置为0。