首页 > 解决方案 > 30 天后 Firestore 中的安全规则

问题描述

我一直在 Firestore 中开展一个项目,当我开始时,我选择了 Firestore 的测试模式,显然可以为您提供 30 天的“试用”,之后我必须更改安全内容,但我已经编写了所有收集数据和我的 Firestore 中已经有其他功能了。如果我在安全部分添加一行代码,我会得到这 30 天的“试用”吗?
我去更改了安全规则,所以我不会丢失我的数据库,正常的规则是:

rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {

// This rule allows anyone on the internet to view, edit, and delete
// all data in your Firestore database. It is useful for getting
// started, but it is configured to expire after 30 days because it
// leaves your app open to attackers. At that time, all client
// requests to your Firestore database will be denied.
//
// Make sure to write security rules for your app before that time, or else
// your app will lose access to your Firestore database
match /{document=**} {
  allow read, write: if request.time < timestamp.date(2020, 6, 2);
}
}
 }

如果我将此规则添加到此,我不会丢失我拥有的 Firestore 东西吗?

match /users/{uid} {
    allow read;
  allow write: if request.auth.uid == uid;
}

这是最终代码的样子:

rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {

// This rule allows anyone on the internet to view, edit, and delete
// all data in your Firestore database. It is useful for getting
// started, but it is configured to expire after 30 days because it
// leaves your app open to attackers. At that time, all client
// requests to your Firestore database will be denied.
//
// Make sure to write security rules for your app before that time, or else
// your app will lose access to your Firestore database
match /{document=**} {
  allow read, write: if request.time < timestamp.date(2020, 6, 2);
}

match /users/{uid} {
    allow read;
  allow write: if request.auth.uid == uid;
}
}
}

标签: google-cloud-firestorefirebase-security

解决方案


如果您的目标是延长您的“试用期”(实际上并非如此 - 它提醒您确实应该制定适当的规则),那么您所要做的就是延长编码到您的规则中的日期'已经给了。

如果您没有完全删除该原始规则并提出适当的规则,您将继续收到来自 Firebase 的电子邮件,提醒您您的规则存在严重的安全问题。如果你只是给它添加规则,那不会改善这种情况,因为规则实际上是让世界完全可以访问其他所有东西,无论如何。 您最终将需要删除规则并将其替换为准确描述系统安全要求的内容。


推荐阅读