![](/img/trans.png)
[英]Firebase cloud function "Your client does not have permission to get URL /200 from this server"
[英]GCP API Gateway to Cloud Functions default service account authentication: "Your client does not have permission to the requested URL""
我正在尝试在 Cloud Functions 前面使用 API 网关,但当 Cloud Functions 不可公开访问时收到 401 响应。
我将网关设置为使用默认的 AppEngine 服务帐户身份 ( project-id @appspot.gserviceaccount.com),并为该服务帐户授予 IAM 中的Cloud Functions Invoker角色。 我还可以在 Cloud Functions Permissions 选项卡下的调用者中看到它。 当调用网关端点时,我收到一个 401 响应,其中包含格式错误的 HTML 负载,内容为“您的客户端没有请求的 URL [url]”的权限。 不幸的是,网关日志也没有指出问题所在。 当我公开 Cloud Function 并等待几分钟时,调用成功。
我已多次阅读本指南的“保护后端服务”部分,但看不出我遗漏了什么。
ps:这不是 JWT 问题,那部分效果很好
找到问题的根源:这是内部 JWT 中的aud
声明。 我想利用 Cloud Functions 的灵活可寻址性,例如,称为a
的 function 处理以a/...
开头的每个请求。 在我的示例中,function 被称为hello
,我想从网关调用它作为/hello/example
。
The internal JWT sets the Audience claim to the address given in the OpenAPI specs ( https://...cloudfunctions.net/hello/example
), which does not exactly match the base URL of the Cloud Function (which is only https://...cloudfunctions.net/hello
)。 因此,Cloud Functions 授权方拒绝 JWT,即使 Audience 是一个有效的 URL,实际上由这个 function 提供服务。
显而易见的解决方案是在从 API 网关调用 Cloud Functions 时不使用变量后缀。
顺便说一句,你可以使用 jwt_audience。
将 jwt_audience 设置为 https://...cloudfunctions.net/hello
请参阅https://cloud.google.com/endpoints/docs/openapi/openapi-extensions#jwt_audience_disable_auth
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.