You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用gcloud CLI调用Cloud Function时服务账号模拟遇401未授权错误

gcloud functions call 模拟服务账号调用时触发401未授权错误

问题详情

已为目标服务账号授予"roles/cloudfunctions.invoker"甚至"roles/cloudfunctions.admin"角色,同时为该服务账号配置了自身的Service Token Creator和User权限,但执行以下gcloud命令时仍返回未授权错误:

gcloud functions call <function> --impersonate-service-account='xxxx@xxxx.iam.gserviceaccount.com'

具体报错信息:

ERROR: gcloud crashed (HTTPError): 401 Client Error: Unauthorized for url: https://xxxx.a.run.app/

直接使用用户账号授权调用函数可正常执行,仅在模拟服务账号调用认证函数时出现该问题,推测是gcloud CLI未生成正确的请求令牌。

临时解决方案

目前可通过curl命令绕过该问题,命令如下:

curl -H "Authorization: Bearer $(gcloud auth print-identity-token --impersonate-service-account=<GSA>)" <FUNCTION_URL>

官方说明

官方已确认该问题属于gcloud CLI的已知缺陷,会在后续版本修复,但暂未给出具体修复时间。

内容的提问来源于stack exchange,提问作者red888

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 19:22:04