我有一个在 Google Cloud(第 2 代)上运行的 python 函数。我正在从我的 iOS 应用程序(在 Swift 上使用 URLSession)和 Web 应用程序(在 JavaScript 上使用 axios)调用该函数作为常规 REST API。最初,我无法访问它,所以我在使用 gcloud CLI 部署时设置了标志
--allow-unauthenticated
。现在,我要把我的应用程序推到生产环境,我想确保这个功能不能被所有人访问。
如何为我的云功能设置身份验证并在我的 iOS 和 Web 应用程序中实施?
有关更多上下文,这是我用于部署函数的命令。
gcloud beta functions deploy function_name --region=us-central1 --source=src --runtime=python311 --gen2 --entry-point=main --memory=512Mb --min-instances=1 --max-instances=100 --timeout=120s --trigger-http --allow-unauthenticated --cpu=1 --concurrency=100
Cloud Functions gen2 在 Cloud Run 上得到支持。因此,Cloud Run认证机制适用。
因为你使用了Firebase auth,你可以参考那个解释如何实现它的页面: https://cloud.google.com/run/docs/authenticating/end-users