简体   繁体   English

是否可以检索 Firebase Cloud Function 源代码?

[英]Is it possible to retrieve Firebase Cloud Function source code?

I'm writing some Firebase Cloud Functions but I have need to hide a private key, including from Firebase project admins.我正在编写一些 Firebase Cloud Functions,但我需要隐藏私钥,包括来自 Firebase 项目管理员的私钥。

If I embedded this key into my source code and uploaded the code myself, would it be possible for anyone to retrieve the source code and thus the key?如果我将此密钥嵌入到我的源代码中并自己上传代码,那么任何人都可以检索到源代码和密钥吗? Either via Firebase or Google?通过 Firebase 还是 Google?

Many thanks非常感谢

The code for your Cloud Functions is never accessible to users of your app.您的应用程序用户永远无法访问您的 Cloud Functions 代码。

It is however accessible for the collaborators on your Firebase project.但是,您的 Firebase 项目的协作者可以访问它。 See Get code from firebase console which I deployed earlier请参阅从我之前部署的 firebase 控制台获取代码

I don't think there's any way to hide such configuration values from collaborators.我认为没有任何方法可以向合作者隐藏此类配置值。 Since they can see/deploy code, and the code needs access to this private key, they by definition have access to the key too.由于他们可以查看/部署代码,并且代码需要访问此私钥,因此根据定义,他们也可以访问该密钥。

Maybe setting an environmental variable:也许设置一个环境变量:

Oficial Doc 官方文件

Answering precisely to your question: Yes, they can .准确回答您的问题:是的,他们可以

The step by step to achieve that is relatively simple一步一步实现那个比较简单

  1. Go into the GCP Functions page进入GCP 函数页面
  2. Select the function you want to inspect选择要检查的函数
  3. Click on source (From there you should be able to see all the files and the code used by that function), or;单击源(从那里您应该能够看到该函数使用的所有文件和代码),或者;
  4. Click on variables (From there you should see all environment variables used by your function)单击变量(从那里你应该看到你的函数使用的所有环境变量)

If that approach seems like problematic to you, here's a way to make things more secure :如果这种方法对您来说似乎有问题,这里有一种使事情更安全的方法

You can build on what you already and start encrypting those keys before adding them to the codebase or the environment variables.您可以在已有的基础上构建并开始加密这些密钥,然后再将它们添加到代码库或环境变量中。 After that, you can use an encryption service such as KMS to decrypt those keys at runtime.之后,您可以使用KMS等加密服务在运行时解密这些密钥。 In KMS itself you can have a stricter policy in there, only allowing yourself and the function to access that service.在 KMS 本身中,您可以制定更严格的政策,只允许您自己和该功能访问该服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM