GCP - Cloud Run:“错误:禁止用户访问存储桶”

max*_*tSO 3 google-cloud-platform github-actions

我正在编写一个 GitHub Action,将我的应用程序部署到 GCP 的“Cloud Run”服务。

name: Deploy to production

on:
  push:
    branches:
      - master

env:
  PROJECT_ID: XXX
  SERVICE_NAME: XXX
  RUN_REGION: XXX
  PACKAGE_VERSION : XXX

permissions:
  contents: read
  id-token: write

jobs:
  deployment-job:
    runs-on: ubuntu-latest
    environment: production
    steps:
      - uses: actions/checkout@v2
      - name: Authenticate to Google Cloud
        uses: google-github-actions/auth@v0
        with:
          workload_identity_provider: XXX
          service_account: XXX
      - name: Deploy to Cloud Run
        uses: google-github-actions/deploy-cloudrun@v0
        with:
          service: ${{ env.SERVICE_NAME }}
          source: gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE_NAME }}:${{ env.PACKAGE_VERSION }} # equivalent to "gcloud builds submit ..."
          region: ${{ env.RUN_REGION }}
          tag: ${{ env.PACKAGE_VERSION }}

Run Code Online (Sandbox Code Playgroud)

我遇到这个错误:

ERROR: (gcloud.beta.run.deploy) The user is forbidden from accessing the bucket [XXX]. Please check your organization's policy or if the user has the "serviceusage.services.use" permission
Run Code Online (Sandbox Code Playgroud)

我尝试将此权限添加到我的服务帐户,但我仍然遇到相同的错误:

ERROR: (gcloud.beta.run.deploy) The user is forbidden from accessing the bucket [XXX]. Please check your organization's policy or if the user has the "serviceusage.services.use" permission
Run Code Online (Sandbox Code Playgroud)

我通过本教程设置了工作负载身份联合。

Ron*_*ira 5

存储管理员角色授予服务帐户而不是存储对象管理员,以允许使用工作流模板部署您的 Github 操作。

我在将 Workload Identity 设置为 Github Action 时遇到此错误。错误消息很奇怪,但问题出在工作流模板中。该模板指示您授予Storage Objects Admin,但从模板中链接的所需权限页面来看,它表示我们需要授予Storage Admin

您可能还需要授予服务使用消费者角色;我已经有了,所以我不确定是否需要它。