firebase - Firestore 最近的哪些变化使它抱怨“重叠递归通配符匹配语句”?
问题描述
今天我注意到我无法部署我的 Firestore 规则,即使它们到目前为止运行良好并且我没有更改它们。这是它不喜欢的部分的摘录:
match /databases/{database}/documents {
function userMatchesId(userId) {
return request.auth != null
&& request.auth.uid == userId
}
function userIsAdmin() {
return request.auth != null
&& get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == "admin"
}
// === Admins ====
// Admin users are allowed to access everythings.
// Writes should be performed via code executed by a service account
match /{document=**} {
allow read: if userIsAdmin()
}
// ==== Private ====
// Collections private to the user. Documents read access is matched
// with the authenticated user id.
match /users/{userId} {
allow get: if userMatchesId(userId)
}
match /userCredits/{userId} {
allow get: if userMatchesId(userId)
}
}
在实践中,这些规则就像我想象的那样有效。允许管理员从非管理员无法直接查询的集合中读取。但是,现在我在部署期间收到此错误:
错误:firestore.rules 中的编译错误:
[W] 42:5 - 重叠递归通配符匹配语句。
我不太明白这里的问题。你会如何解决这个问题?
解决方案
(这里是 Google 员工) 这是我们的一个错误。我们正在向规则添加新的编译器警告,以帮助您注意可能引入的错误。许多人没有意识到,如果您有多个match
与特定路径匹配的语句,那么这些块中的规则是OR'ed
在一起的。该警告应该可以帮助您发现这一点。
但是,如果您了解自己在做什么,这绝不是为了阻止您部署有效规则!我们会解决这个问题。
太平洋标准时间 8 月 1 日上午 11:50 更新
我们在这里做了两个改变:
- 我们正在发布 CLI (npm
firebase-tools
) 版本4.0.2
,并修复此问题以使警告不致命。这应该暂时发生。 - 我们将更改服务器行为以撤消/澄清此行为,直到我们正确为止。
推荐阅读
- ftps - powershell ftps 上传导致流关闭时出现错误“数据连接终止而 ssl 关闭”
- python - 如何将自定义操作添加到图中并使其自动执行?
- java - AWS S3 - 带输入流的分段上传
- apache - 处理从 apache 到 NodeJS HTTP 服务器的连接
- javascript - 根据环境变量阻止 JEST 运行
- laravel-5.8 - 如何检索经过身份验证的用户的角色/状态?
- java - Java think 单选按钮始终处于选中状态
- java - Beam runner 如何确定 PCollection 的每个捆绑包的大小
- jquery - jQuery如何以可调整大小获取每个停止事件的值
- kubernetes - Grafana 为 Prometheus 数据源抛出 HTTP Error Bad Gateway