配置GitHub触发器的Cloud Build异常:testIamPermissions接口404未找到
Cloud Build部署Cloud Run时出现404错误(testIamPermissions接口找不到)
问题描述
使用Python和Google Cloud Run开发的自动化程序运行正常,为实现自动部署配置了Cloud Build的GitHub触发器。已按官方文档创建Dockerfile、cloudbuild.yaml、requirements.txt等文件,流程初期文件均可正确调用,但在构建步骤2时出现404错误,具体错误如下:
Step #2: Status: Downloaded newer image for gcr.io/google.com/cloudsdktool/cloud-sdk:latest Step #2: gcr.io/google.com/cloudsdktool/cloud-sdk:latest Step #2: ERROR: (gcloud.run.deploy) HTTPError 404: <!DOCTYPE html> Step #2: <html lang=en> Step #2: <meta charset=utf-8> Step #2: <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width"> Step #2: <title>Error 404 (Not Found)!!1</title> Step #2: <style> Step #2: *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px} Step #2: </style> Step #2: <a href=//www.google.com/><span id=logo aria-label=Google></span></a> Step #2: <p><b>404.</b> <ins>That’s an error.</ins> Step #2: <p>The requested URL <code>/v1/projects/[prject-id]/locations/REGION/services/[application]:testIamPermissions</code> was not found on this server. <ins>That’s all we know.</ins> Step #2: Finished Step #2 ERROR ERROR: build step 2 "gcr.io/google.com/cloudsdktool/cloud-sdk" failed: step exited with non-zero status: 1
已尝试授予必要权限,但问题仍未解决。
解决方案
修正区域参数
确认cloudbuild.yaml中gcloud run deploy命令的--region参数为Cloud Run支持的可用区域(如us-central1、europe-west1),避免使用REGION这类占位符或拼写错误的区域名称。检查项目ID和服务名称拼写
错误信息中[prject-id]存在拼写错误(应为project-id),排查配置中所有涉及项目ID、服务名称的部分,确保与GCP控制台中的名称完全一致。验证Cloud Build服务账号权限
- 找到Cloud Build服务账号(格式:
[PROJECT_NUMBER]@cloudbuild.gserviceaccount.com),确保其拥有Cloud Run Admin角色(roles/run.admin),或至少包含run.services.setIamPolicy、run.services.getIamPolicy权限。 - 确保权限授予在项目级别,而非未创建的目标服务上(部署前权限检查无法找到未存在的服务)。
- 找到Cloud Build服务账号(格式:
启用Cloud Run Admin API
进入GCP控制台的API库,搜索并启用Cloud Run Admin API,未启用API会导致接口调用返回404。更新gcloud SDK版本
构建步骤中使用的latest标签可能存在兼容性问题,可指定稳定版本镜像(如gcr.io/google.com/cloudsdktool/cloud-sdk:440.0.0),或在构建步骤中添加gcloud components update命令确保SDK为最新版本。
内容的提问来源于stack exchange,提问作者Danilo Steckelberg
相关产品推荐
相关产品推荐

