【问题标题】:Can google cloud function do anything as a backend server?谷歌云功能可以作为后端服务器做任何事情吗?
【发布时间】:2018-11-11 01:45:10
【问题描述】:

我将使用nodejs 开发一个具有复杂逻辑的新网络应用程序。

firebase 吸引了我,因为它方便的用户身份验证/登录(google、facebook、twitter、电子邮件通行证登录/注册只需几行代码和设置)

如果我在服务器端使用google cloud function 有什么问题吗?

  • Q1:firestore 是否完全安全?我有使用firebase realtime database 的经验。但是使用firebase realtime database,所有用户一旦登录(使用任何帐户)就拥有几乎相似的权限。这是严重的安全问题

  • Q2:使用google cloud function可以解决上述安全问题吗?

  • Q3:我可以在google cloud function 中执行任何逻辑,即requireing 任何外部库吗?与独立的nodejs 服务器相比,google cloud function 是否有任何限制?

  • Q4(可能与主题无关):我是否应该将我的应用设计为依赖 firebase authentication,这也意味着我的应用必须调用 firebase API 来检查用户凭据和客户端 Web 需求加载 Firebase SDK。这是提高应用性能和可扩展性的良好做法吗?

非常感谢您

【问题讨论】:

  • 您能详细说明 Q1 吗?以我的经验,可以在Firebase's security rules language 中实现许多安全场景。虽然 Firestore 的规则语言不同,但概念是相同的。

标签: node.js firebase firebase-authentication google-cloud-firestore google-cloud-functions


【解决方案1】:

理论上是的,您可以使用函数作为 Firestore 的入口点,以便处理数据。但是,您可以使用 RTDB 和 Firestore 编写复杂的安全规则……我的意思是您最终会得到一个庞大的 .rules 文件,但您完全可以。仅作为示例:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if false;
    }
    match /profiles/{uid} {
      allow read, update: if request.auth.uid == uid;
    }
    match /bookmarks/{key} {
      allow create: if request.auth.uid != null && request.auth.uid == request.resource.data.uid;
      allow read: if request.auth.uid != null && request.auth.uid == resource.data.uid;
      allow update: if request.auth.uid != null && request.resource.data.uid == resource.data.uid;
    }
}

我的意思是您可以继续构建规则,甚至验证字段,但这几乎只允许文档的所有者进行任何更改或创建。并且绝对防止删除。

您还可以在 Firebase Functions 上有效地使用用于 node 服务器的任何内容。 (或 Google Cloud Functions)我也会看看这个 answer

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-29
    • 1970-01-01
    • 2018-09-22
    • 2014-10-26
    • 1970-01-01
    • 2021-02-05
    • 1970-01-01
    • 2021-10-31
    相关资源
    最近更新 更多