Localhost ExceptionLocalhost异常
On this page本页内容
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
角色都授予创建其他用户的权限。
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. 一旦创建了任何用户或角色,就会禁用localhost异常。If you need to create a user and a role, you must create the user first using one of the builtin 如果需要创建用户和角色,则必须首先使用内置的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. db.createRole()
方法首先创建角色的功能专门用于使用LDAP进行授权的用户。See LDAP Authorization for more information.有关详细信息,请参阅LDAP授权。
Localhost Exception for Sharded Clusters共享群集的Localhost异常
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. To prevent unauthorized access to individual shards, follow one of the following steps for each shard in your cluster:mongos
实例添加了一个用户管理员,您仍然必须防止对单个分片的未经授权的访问。为了防止未经授权访问单个分片,请对集群中的每个分片执行以下步骤之一:
Create a user administrator on the shard's primary.在分片的主上创建一个用户管理员。Disable the localhost exception at startup. To disable the localhost exception, set the在启动时禁用localhost异常。要禁用localhost异常,请将enableLocalhostAuthBypass
parameter to0
.enableLocalhostAuthBypass
参数设置为0
。