记个 Firebase Cloud Function 在 App 调用的笔记

问题

我定义了几个 Firebase Cloud Functions,并 deploy 到了服务器

但是,每次在 iOS 等 App 里调用都会出现 UNAUTHENTICATED 或者 401 Unauthorized 的 error,反复查找

喷一句:Google Cloud 文档是一坨屎

概念疏理

  1. Firebase Cloud Function:它本质是部署在 Google Cloud 上的服务,这里就会出现几个新的概念 Cloud Run、Cloud Run function、IAM
  2. Cloud Run:在 Google Cloud 上运行 Container 的服务
  3. Cloud Run function:在 Google Cloud 上直接运行 Serverless function 的服务 👈 也是 Firebase Cloud Function 依赖的服务
  4. IAM:全名 Identity and Access Management,用来管理云服务 access control 和 permission 的服务(在云服务里都很常见)

问题归因

2024年5月3日创建的 Organization,Google Cloud 增加了一些安全规则,即

Note : If your organization was created on or after May 3, 2024, then the iam.allowedPolicyMemberDomains predefined constraint is enforced by default, with your domain listed as the only allowed value. 👉 LINK

而一个 cloud function invoker 默认是被限制在这个 constraint 里的,即无法设置 allUsersallAuthenticatedUsers。即无法被设置为 publicly accessible,也就无法被 App 调用

再说清楚一点:

  1. Organization policy 自动开启了 iam.allowedPolicyMemberDomains 限制
  2. Project policy 默认 inherit Organization policy,所以也有限制
  3. Cloud Functions 默认要遵守这个 Project policy,因此无法被设置 Cloud Run Invoker permission 到 allUsersallAuthenticatedUsers
  4. 无法被 App 正常调用

问题解决

  1. 在 Project policy 里 override iam.allowedPolicyMemberDomainsAllow All
  2. 在 Cloud Functions 上增加 Cloud Run Invoker permission 到 allUsers

当然, 这里是有点小风险的,后续要解决

AI Agent 能解决吗?

其实比较好的新 AI 工具 Grok 3、Claude 3.7 在思考中都已经把每一步可能的问题思考到了,并引导我去解决,但是:

  1. 互联网上这个问题被描述清楚的文章很少(Stackoverflow、GitHub)
  2. 官方 Google Cloud 文档一坨屎
  3. Google Cloud IAM 权限设置等都很复杂,得和 AI Agent 一步一步地一起解决(我会截图和它 confirm 对不对)

简言之,脑子、逻辑、知识储备都没问题,但会被已有互联网内容的缺失影响,以及功能这种非文本内容的知识要让 AI 怎么学会?

笔记结束:Google Cloud 这种"重"云服务在 AI 生成代码不断轻量简化的时代里大概率要被 Vercel、Bolt.new 取代,包括 Firebase 明显是个套壳怪,不是轻量化、AI 化的本质!

相关推荐
Mac的实验室4 天前
(2026年最新)解决谷歌账号注册设备扫码短信发送失败无法验证难题(100%通过无需扫码验证)
android·google·程序员
晨欣4 天前
单卡 48GB 实测:Gemma 4 26B A4B、Gemma 4 31B、gpt-oss-20b 三模型部署与并发对比
google·openai·nvidia·vllm·llama.cpp·gpt-oss-20b·gemma4
天工开物开源基金会4 天前
Google重磅发布Gemma 4:Apache 2.0许可证带来的开源“权力转移“
google·gemma
gutsyang16 天前
Google Stitch:最佳实践
人工智能·google·gemini·stitch
$Qw18 天前
google firebase service account json
android·google
spencer_tseng21 天前
google chrome show virtual keyboard
chrome·google
人道领域22 天前
2026年Q1大模型深度复盘:OpenAI,Gemini2.0,字节跳动,与“多模态Agent”元年
人工智能·ai·google·chatgpt·gemini
用户693717500138423 天前
Room 3.0:这次不是升级,是重来
android·前端·google
码路飞25 天前
Gemini 开放香港了,大陆开发者的 API 能跟着薅吗?实测 3 种方案
google·api·gemini
Carson带你学Android1 个月前
Android 17 重磅发布:详解四大颠覆性变革与保姆级适配指南
google