如何将规则应用于 Firebase 服务帐号

huangapple 未分类评论70阅读模式
英文:

How to apply rules to service account Firebase

问题

如何将Cloud Firestore规则应用于服务帐户?就像从Java管理员API中连接到数据库的唯一方法是使用绕过所有规则的服务帐户。这没有任何意义,我错过了什么?或者是否有一些不使用这种方式连接到数据库的不同方法?

FirebaseOptions options = new FirebaseOptions.Builder()
    .setCredentials(GoogleCredentials.fromStream(ServiceAccount.json))
    .setDatabaseUrl("DataBaseURL")
    .build();

FirebaseApp.initializeApp(options);

我想将这个添加到开源项目中,所以每个人都可以访问数据库并不是理想的。因此,我希望规则能够应用,但我不知道如何做?如果只能使用服务帐户,又怎么能应用规则呢?

如果无法将规则应用于服务帐户,那么如何在没有服务帐户的情况下建立连接?如果这也是不可能的,那么规则的意义是什么?

编辑:很遗憾没有办法将规则应用于服务帐户,在Java Admin SDK中,您无法直接连接到数据库而不使用服务帐户,因此唯一的方法是创建某种Rest API,在那里您发送一个请求,然后它将执行该请求。

英文:

How can i put the Cloud-Firestore rules to apply to the service accounts? Like from the java admin API the only way to form connection to the database is to use the service account which bypasses all the rules. It doesnt make any sense what am i missing? Or is there some different way to form connection to the database without using the service account like this

FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(ServiceAccount.json))
.setDatabaseUrl("DataBaseURL")
.build();

FirebaseApp.initializeApp(options);

I want to like add this to a open source project so it would be not ideal that everyone has full access to the database. So i want the rules to apply but idk how? if you can only use the service accounts.

If its not possible to apply the rules to the service accounts then how do i form a connection without the service account? if thats impossible too then whats the point of the rules

Edit: Theres no way of applying the rules to the service account which is a shame also in the java-Admin SDK You cant form connection directly to the database without the service account so the only way of doing this would make some kind of Rest API where you send an request and it will execute it.

答案1

得分: 0

安全规则适用于从客户端SDK(如Android、iOS和客户端JavaScript)直接访问Firestore的任何访问。

无法将安全规则应用于使用服务帐户访问Firestore的客户端,例如使用Java、Go和Node.js的Admin SDKs。这种客户端以管理员特权运行,假定在特权环境中运行,例如您的开发计算机、您控制的服务器或Cloud Functions。这些连接从定义上绕过安全规则,并且无法更改此行为。

英文:

Security rules are applied to any access to Firestore directly from client-side SDKs, such as the ones for Android, iOS, and client-side JavaScript.

There is no way to apply security rules to a client that accesses Firestore with a service account, like with the Admin SDKs for Java, Go and Node.js. Such clients run with administrative privileges in what is assumed to be a privileged environment, such as your development machine, a server you control, or Cloud Functions. These connections by definition bypasses security rules, and there's no way to change this behavior.

huangapple
  • 本文由 发表于 2020年8月14日 23:31:49
  • 转载请务必保留本文链接:https://java.coder-hub.com/63415778.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定