system.users
集合在自托管部署中
在 admin
数据库中的 system.users
集合存储用户身份验证 和 授权 信息。为了管理此集合中的数据,MongoDB 提供了 用户管理命令。
system.users
架构
system.users
集合中的文档具有以下架构
{ _id: <system defined id>, userId : <system assigned UUID>, user: "<name>", db: "<database>", credentials: { <authentication credentials> }, roles: [ { role: "<role name>", db: "<database>" }, ... ], customData: <custom information>, authenticationRestrictions : [ <documents> ] }
每个 system.users
文档包含以下字段
admin.system.users.user
用户名。一个用户在单个逻辑数据库(见
admin.system.users.db
) 的上下文中存在,但可以通过roles
数组中指定的角色在其他数据库上访问。
admin.system.users.credentials
用户的认证信息。对于使用外部存储的认证凭证的用户,例如使用Kerberos或x.509证书进行认证的用户,该用户的
system.users
文档不包含credentials
字段。对于SCRAM用户凭证,信息包括机制、迭代次数和认证参数。
示例
考虑以下位于system.users
集合中的文档
{ "_id" : "home.Kari", "userId" : UUID("ec1eced7-055a-4ca8-8737-60dd02c52793"), "user" : "Kari", "db" : "home", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "S/xM2yXFosynbCu4GzFDgQ==", "storedKey" : "Ist4cgpEd1vTbnRnQLdobgmOsBA=", "serverKey" : "e/0DyzS6GPboAA2YNBkGYm87+cg=" }, "SCRAM-SHA-256" : { "iterationCount" : 15000, "salt" : "p1G+fZadAeYAbECN8F/6TMzXGYWBaZ3DtWM0ig==", "storedKey" : "LEgLOqZQmkGhd0owm/+6V7VdJUYJcXBhPUvi9z+GBfk=", "serverKey" : "JKfnkVv9iXwxyc8JaapKVwLPy6SfnmB8gMb1Pr15T+s=" } }, "authenticationRestrictions" : [ { "clientSource" : [ "69.89.31.226" ], "serverAddress" : [ "172.16.254.1" ] } ], "customData" : { "zipCode" : "64157" }, "roles" : [ { "role" : "read", "db" : "home" }, { "role" : "readWrite", "db" : "test" } ] }
该文档显示用户 Kari
的认证数据库是 home
数据库。Kari
在 home
数据库中具有 read
角色权限,在 test
数据库中具有 readWrite
角色权限。