RestHeart ACL - 数据库的用户访问控制

RestHeart ACL - User access controls for databases

我正在使用带有 mongoAclAuthorizer 和 mongoRealmAuthenticator 的 restheart 6。

我管理用户或数据库没有问题,但我不明白如何限制用户只能访问我允许的数据库。

我正在阅读有关 ACL 的文档 (https://restheart.org/docs/security/authorization/),但没有找到我需要的内容。 通过查看示例,看起来角色“用户”的用户将能够访问所有数据库。

我想答案就在谓词中。 假设我有两个用户:userAuserB两者都具有“用户”角色。我希望 userA 访问 database1userB 访问 database2.

文档显示的方式,好像缺少我在括号中写的东西,我知道它不存在,只是为了举例)([user=userA] 和 [user=userB]) .

role: user
predicate: [user=userA] and path-prefix[path="/database1"] and method[value="GET"] 
role: user
predicate: [user=userB] and path-prefix[path="/database2"] and method[value="GET"]

谁能帮帮我?

这比看起来容易。 “管理员”和“用户”角色不是强制性的。 您可以创建自己的角色并根据需要使用它们。

在我上面的例子中,我创建了四个新角色:role-database1-rw, role-database1-ro, role-database2-rw and role-database2-ro.

并且我已将 userA 附加到角色 role-database1-rw role-database2-ro,以及 userB 到角色 role-database1-ro角色数据库2-rw.

然后,我创建了 ACL:

roles: role-database1-rw
predicate: "path-prefix[/database1] and (method[GET] or method[POST] or method[PUT] or method[DELETE])"

roles: role-database1-ro
predicate": "path-prefix[/database1] and method[GET]"

roles: role-database2-rw
predicate: "path-prefix[/database2] and (method[GET] or method[POST] or method[PUT] or method[DELETE])"

roles: role-database2-ro
predicate: "path-prefix[/database2] and method[GET]"

这样,用户A就可以从数据库1和数据库2读取,在数据库1上写入了。 userB 可以从数据库 1 和 2 读取并在数据库 2 上写入。