查看 2022 年 Google I/O 大会上介绍的 Firebase 新动态。
了解详情
不同环境的一般安全准则
本页面介绍了跨环境安全的最重要的最佳实践,但请查看安全清单以获取有关安全和 Firebase 的更详细和全面的指导。
预生产环境的安全性
在不同的 Firebase 项目中分离环境的一个好处是,能够访问您的预生产环境的恶意行为者将无法访问真实的用户数据。以下是对预生产环境采取的最重要的安全预防措施:
限制对预生产环境的访问。对于移动应用程序,使用应用程序分发(或类似的东西)将应用程序分发给特定的一组人。 Web 应用程序更难限制;考虑为 pre-prod 环境设置阻止功能,以限制对具有特定于您域的电子邮件地址的用户的访问。或者,如果您使用 Firebase 托管,请设置您的生产前工作流程以使用临时预览网址。
当环境不需要持久化并且仅由一个人使用(或在测试的情况下由一台机器使用)时,请使用Firebase Local Emulator Suite 。这些模拟器更安全、更快,因为它们可以完全在 localhost 上工作,而不是使用云资源。
确保您在预生产环境中设置了Firebase 安全规则,就像在 prod 中一样。一般来说,规则在不同环境中应该是相同的,但需要注意的是,由于规则会随着代码的变化而变化,因此管道中的早期规则可能还不存在于生产环境中。
生产环境的安全性
生产数据始终是目标,即使应用程序晦涩难懂。遵循这些准则并不会使恶意行为者无法获取您的数据,但会使其变得更加困难:
为您使用的所有支持它的产品启用并强制执行App Check 。 App Check 确保对您的后端服务的请求来自您的正版应用程序。为了使用它,您需要使用 App Check 注册您的应用程序的每个版本。在拥有用户之前进行设置更容易,因此请尽快进行设置。
编写强大的Firebase 安全规则。实时数据库、Cloud Firestore 和 Cloud Storage 都依赖于开发者配置的规则来强制谁应该和不应该能够访问数据。编写好的规则对您的安全至关重要。如果您不确定如何操作,请从这个codelab开始。
查看安全清单以获取有关生产环境安全性的更多建议。
下一步
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-08-04 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"没有我需要的信息"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"太复杂/步骤太多"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"内容需要更新"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"翻译问题"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"示例/代码问题"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"其他"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"易于理解"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"解决了我的问题"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"其他"
}]