我有一个父项目,它有一个为 docker 配置的工件注册表。
一个子项目有一个云运行服务,需要从父拉取它的镜像。
子 项目还有一个服务帐户,该帐户被授权通过 IAM 角色 roles/artifactregistry.writer 访问存储库。
当我尝试启动我的服务时,我收到一条错误消息:
Google Cloud Run Service Agent must have permission to read the image, europe-west1-docker.pkg.dev/test-parent-project/docker-webank-private/node:custom-1. Ensure that the provided container image URL is correct and that the above account has permission to access the image. If you just enabled the Cloud Run API, the permissions might take a few minutes to propagate. Note that the image is from project [test-parent-project], which is not the same as this project [test-child-project]. Permission must be granted to the Google Cloud Run Service Agent from this project.
我已经测试了手动连接 docker login 并使用服务帐户的私钥和 docker pull 命令在我的 PC 上完美运行。
cat $GOOGLE_APPLICATION_CREDENTIALS | docker login -u _json_key --password-stdin https://europe-west1-docker.pkg.dev
> Login succeeded
docker pull europe-west1-docker.pkg.dev/bfb-cicd-inno0/docker-webank-private/node:custom-1
> OK
服务帐户也附加到云运行服务:
最佳答案
您在 Cloud Run 中使用了 2 种类型的服务帐户:
在您的解释和屏幕截图中,您谈到了运行时服务帐户,服务在运行和调用 Google Cloud API 时将使用的身份。
但是 在运行之前,必须部署服务。这一次,它是一个 Google Cloud Run 内部进程,用于拉取容器、创建修订并执行所有必需的内部操作。为了完成这项工作,还存在一个服务帐户,它被命名为“服务代理”。
在IAM控制台可以找到:格式如下
service-<PROJECT_NUMBER>@serverless-robot-prod.iam.gserviceaccount.com
不要忘记勾选右上角的复选框以包含 Google 托管服务帐户
如果您希望此部署服务帐户能够在另一个项目中拉取图像,请为其授予正确的权限,而不是在运行时服务帐户上。
关于docker - GCP Cloud Run 无法从其他项目的 Artifact Registry 中拉取镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70433003/