MongoDB、ACL 和用户的 Restheart

发布于 2025-01-15 00:09:15 字数 1572 浏览 3 评论 0原文

我有一个带有 atlas 示例数据库的 MongoDB 实例,我正在尝试在其上配置 Restheart。
我使用 mongoRealmAuthenticator 和 MongoAclAuthorizer 配置了 Restheart,并在 Restheart 数据库中配置了 ACL 和 USERS 集合,以及以下 mongo-mounts:

- what: /sample_weatherdata  
  where: /sample_weatherdata

Users 集合具有 admin 用户和具有 user 角色的名为 Sample_weatherdata 的用户。 ACL 集合具有以下 ACL。

{
        "_id" : "userCanGetOwnCollection",
        "roles" : [
                "user"
        ],
        "predicate" : "method(GET) and path-template('/{userid}') and equals(@user.userid, ${userid})",
        "priority" : 100,
        "_etag" : ObjectId("62322951a40a5c34cad71769")
}

但是,当我尝试使用curl(curl -k -u Sample_weatherdata:secret -X GET https://xxxxx:4443/sample_weatherdata?page=1)从sample_weatherdata数据库获取信息时,我在restheart上收到错误日志:

21:01:22.702 [XNIO-1 task-1] DEBUG orsauthorizers.FileAclAuthorizer - 角色用户、权限(roles=[user]、predicate=method(GET) 和 path-template('/{userid}')和 equals(@user.userid, ${userid}) 和 qparams-contain(page) 和 qparams-blacklist(filter, sort) ), 解决错误

21:01:22.716 [XNIO-1 task-1] DEBUG orsauthorizers.MongoAclAuthorizer - 角色用户,权限 ID BsonString{value='userCanGetOwnCollection'},解析 false

21:01:22.718 [XNIO-1 task-1] INFO org.restheart.handlers.RequestLogger - 从 /10.100.200.100:55555 获取 https://xxxxxxx:4443/sample_weatherdata?page=1 => status=403 elapsed=26ms contentLength=0 用户名=sample_weatherdata 角色=[用户]

知道我是否遗漏了某些内容或如何配置 ACL 以允许查询吗?

I have a MongoDB instance with the atlas sample databases and I'm trying to configure Restheart on it.
I have restheart configured with mongoRealmAuthenticator and MongoAclAuthorizer, with ACL and USERS collections in the restheart database, and the following mongo-mounts:

- what: /sample_weatherdata  
  where: /sample_weatherdata

The Users collection have the admin user and a user called sample_weatherdata with user role. The ACL collection have the following ACL.

{
        "_id" : "userCanGetOwnCollection",
        "roles" : [
                "user"
        ],
        "predicate" : "method(GET) and path-template('/{userid}') and equals(@user.userid, ${userid})",
        "priority" : 100,
        "_etag" : ObjectId("62322951a40a5c34cad71769")
}

But when I try to get the information from the sample_weatherdata db with curl (curl -k -u sample_weatherdata:secret -X GET https://xxxxx:4443/sample_weatherdata?page=1), I'm getting an error on the restheart logs:

21:01:22.702 [XNIO-1 task-1] DEBUG o.r.s.authorizers.FileAclAuthorizer - role user, permission (roles=[user],predicate=method(GET) and path-template('/{userid}') and equals(@user.userid, ${userid}) and qparams-contain(page) and qparams-blacklist(filter, sort)
), resolve false

21:01:22.716 [XNIO-1 task-1] DEBUG o.r.s.authorizers.MongoAclAuthorizer - role user, permission id BsonString{value='userCanGetOwnCollection'}, resolve false

21:01:22.718 [XNIO-1 task-1] INFO org.restheart.handlers.RequestLogger - GET https://xxxxxxx:4443/sample_weatherdata?page=1 from /10.100.200.100:55555 => status=403 elapsed=26ms contentLength=0 username=sample_weatherdata roles=[user]

Any idea if I'm missing something or how to configure the ACLs to allow the query?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满天都是小星星 2025-01-22 00:09:15

如果您使用默认的身份验证器,即 mongoRealmAuthenticator 用户的正确 id 属性是 @user._id

所以您的权限应该是:

{
        "_id" : "userCanGetOwnCollection",
        "roles" : [ "user" ],
        "predicate" : "method(GET) and path-template('/{userid}') and equals(@user._id, ${userid})",
        "priority" : 100
}

在示例中 acl.json 你有:

注意:用户的 id 是带有 fileRealmAuthenticator 的 @user.userid 和带有 mongoRealmAuthenticator 的 @user._id

我是 RESTHeart 的主要提交者,鉴于现在 mongoRealmAuthenticator 是默认的身份验证器,我刚刚更新了示例 acl.json 和相关文档以使用 @user._id

If you use the default authenticator, i.e. mongoRealmAuthenticator the correct id property of the user is @user._id

So your permission should be:

{
        "_id" : "userCanGetOwnCollection",
        "roles" : [ "user" ],
        "predicate" : "method(GET) and path-template('/{userid}') and equals(@user._id, ${userid})",
        "priority" : 100
}

In the example acl.json you have:

NOTE: the id of the user is @user.userid with fileRealmAuthenticator and @user._id with mongoRealmAuthenticator

I'm the main committer of RESTHeart, and given that now mongoRealmAuthenticator is the default authenticator, I have just updated the example acl.json and related documentation to use @user._id

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文