翻译或纠错本页面
  • 安全 >
  • Role-Based Access Control

Role-Based Access Control

MongoDB支持基于角色的访问控制(RBAC)来管理对MongoDB系统的访问。一个用户可以被授权一个或者多个:ref:角色 <roles> 以决定该用户对数据库资源和操作的访问权限。在权限以外,用户是无法访问系统的。

Enable Access Control

MongoDB does not enable access control by default. You can enable authorization using the --auth or the security.authorization setting. Enabling internal authentication also enables client authorization.

Once access control is enabled, users must authenticate themselves.

角色

A role grants privileges to perform the specified actions on resource. Each privilege is either specified explicitly in the role or inherited from another role or both.

权限

每个权限包括一些 *操作*以及这些操作所适用的资源。

A resource is a database, collection, set of collections, or the cluster. If the resource is the cluster, the affiliated actions affect the state of the system rather than a specific database or collection. For information on the resource documents, see Resource Document.

An action specifies the operation allowed on the resource. For available actions see Privilege Actions.

继承的权限

一个角色的定义中可以包含一个或者多个角色,这种情况下这个角色会继承所有其包含的角色的所有权限。

一个角色可以继承其数据库中其他角色的权限。一个在``admin``数据库中建立的角色可以继承任意数据库角色中的权限。

View Role’s Privileges

You can view the privileges for a role by issuing the rolesInfo command with the showPrivileges and showBuiltinRoles fields both set to true.

MongoDB将每个用户局限于其所生成的数据库中。MongoDB讲所有用户的定义都储存在 admin 数据库中,无论该用户适用于哪个数据库。所有MongoDB将用户储存于 ``admin``数据库 system.users 集合 中。请务必不要直接访问该集合,而使用 角色管理命令 查看和编辑角色。

数据库中第一个被指定的用户应当是:authrole:userAdmin 或者 userAdminAnyDatabase。这个用户之后可以用来建立系统中所有其他用户。参见 /tutorial/add-user-administrator

MongoDB将用户和角色信息储存在受保护的 admin.system.rolesadmin.system.users 集合。使用 用户管理方法 查看或编辑这些信息。

注解

如果你关闭访问控制,**请勿**使用 insert()update() 等常规操作手段编辑 admin.system.rolesadmin.system.users 集合

Built-In Roles and User-Defined Roles

MongoDB provides built-in roles that provide set of privileges commonly needed in a database system.

If these built-in-roles cannot provide the desired set of privileges, MongoDB provides methods to create and modify user-defined roles.