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

问题描述 投票:0回答:2

我正在编写一个 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 }}

我遇到了这个错误:

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

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

gcloud projects add-iam-policy-binding XXX --member=serviceAccount:XXX --role=roles/serviceusage.serviceUsageAdmin

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

google-cloud-platform github-actions
2个回答
5
投票

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

我在将 Workload Identity 设置为 Github Action 时遇到此错误。错误消息很奇怪,但问题出在工作流模板中。该模板指示您授予存储对象管理员,但从模板中也链接的所需权限页面,它说我们需要授予存储管理员

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


0
投票
ACL(细粒度)

存储桶访问权限更改为统一。 并重新启动 GitHub 操作(无需更改代码)。 工作了。没有错误。日志会传输至 GitHub Actions。

© www.soinside.com 2019 - 2024. All rights reserved.