我有一个带有地图集示例数据库的MongoDB实例,我正在尝试在它上配置Restheart。
我已经用mongoRealmAuthenticator和MongoAclAuthorizer配置了restheart,在restheart数据库中配置了ACL和用户集合,以及下面的mongo挂载:
- what: /sample_weatherdata
where: /sample_weatherdata
用户集合具有管理用户和具有用户角色的名为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从sample_weatherdata db (curl -k -u sample_weatherdata:secret -X get weatherdata?page=1)获取信息时,我在restheart日志上得到了一个错误:
21:01:22.702 XNIO-1任务-1调试o.r.s.authorizers.FileAclAuthorizer -角色用户、权限(roles=user、predicate=method(GET)和路径-模板(‘/{userid}’)和相等(@user.userid,${userid})和qparams-包含(页)和qparams-黑名单(筛选器,排序),解析假 21:01:22.716 XNIO-1任务-1调试o.r.s.authorizers.MongoAclAuthorizer -角色用户,权限id BsonString{value='userCanGetOwnCollection'},解析false 21:01:22.718 XNIO-1任务-1 INFO org.restheart.handlers.RequestLogger -从/10.100.200.100:55555 => status=403 elapsed=26ms contentLength=0 username=sample_weatherdata roles=user获取weatherdata?page=1
知道我是否遗漏了什么或者如何配置ACL以允许查询吗?
发布于 2022-03-18 01:14:17
如果使用默认身份验证器(即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是@user.userid ( fileRealmAuthenticator )和@user._id ( mongoRealmAuthenticator )
我是RESTHeart的主要提交者,考虑到现在mongoRealmAuthenticator
是默认身份验证器,我刚刚更新了示例acl.json和相关文档以使用@user._id
https://stackoverflow.com/questions/71518532
复制相似问题