【问题标题】:gcloud builds submit of Django website results in error "does not have storage.objects.get access"gcloud 构建 Django 网站的提交导致错误“没有 storage.objects.get 访问”
【发布时间】:2021-12-09 22:54:52
【问题描述】:

我正在尝试使用 Cloud Run 部署我的 Django 网站,如 Google Cloud Platform's documentation 中所述,但在运行命令 gcloud builds submit --config cloudmigrate.yaml --substitutions _INSTANCE_NAME=trouwfeestwebsite-db,_REGION=europe-west6 时出现错误 Error 403: 934957811880@cloudbuild.gserviceaccount.com does not have storage.objects.get access to the Google Cloud Storage object., forbidden

命令的完整输出是:(错误在底部)

Creating temporary tarball archive of 119 file(s) totalling 23.2 MiB before compression.
Some files were not included in the source upload.

Check the gcloud log [C:\Users\Sander\AppData\Roaming\gcloud\logs\2021.10.23\20.53.18.638301.log] t
o see which files and the contents of the
default gcloudignore file used (see `$ gcloud topic gcloudignore` to learn
more).

Uploading tarball of [.] to [gs://trouwfeestwebsite_cloudbuild/source/1635015198.74424-eca822c138ec
48878f292b9403f99e83.tgz]
ERROR: (gcloud.builds.submit) INVALID_ARGUMENT: could not resolve source: googleapi: Error 403: 934957811880@cloudbuild.gserviceaccount.com does not have storage.objects.get access to the Google Cloud Storage object., forbidden

在我的存储桶级别,我授予 934957811880@cloudbuild.gserviceaccount.com 存储对象查看器权限,正如我在 https://cloud.google.com/storage/docs/access-control/iam-roles 上看到的那样,这涵盖了 storage.objects.get 访问权限。 我还尝试授予 Storage Object Admin 和 Storage Admin。

我还在 IAM 级别 (https://console.cloud.google.com/iam-admin/iam) 上为 934957811880@cloudbuild.gserviceaccount.com 添加了“查看者”角色,正如 https://stackoverflow.com/a/68303613/5433896https://github.com/google-github-actions/setup-gcloud/issues/105 中所建议的那样,但我觉得给这个帐户这样的帐户有点可疑广泛的作用。

我在 Cloud Build 权限选项卡中启用了 Cloud run:https://console.cloud.google.com/cloud-build/settings/service-account?project=trouwfeestwebsite

通过这些更改,我在运行 gcloud builds submit 命令时仍然遇到相同的错误。

我不明白在凭据/身份验证方面我可能做错了什么 (https://stackoverflow.com/a/68293734/5433896)。自从我初始化该 SDK 以来,我没有更改我的 Google 帐户密码,也没有撤销该帐户对 Google Cloud SDK 的权限。

你知道我错过了什么吗?

cloudmigrate.yaml的内容是:

steps:
  - id: "build image"
    name: "gcr.io/cloud-builders/docker"
    args: ["build", "-t", "gcr.io/${PROJECT_ID}/${_SERVICE_NAME}", "."]

  - id: "push image"
    name: "gcr.io/cloud-builders/docker"
    args: ["push", "gcr.io/${PROJECT_ID}/${_SERVICE_NAME}"]

  - id: "apply migrations"
    name: "gcr.io/google-appengine/exec-wrapper"
    args:
      [
        "-i",
        "gcr.io/$PROJECT_ID/${_SERVICE_NAME}",
        "-s",
        "${PROJECT_ID}:${_REGION}:${_INSTANCE_NAME}",
        "-e",
        "SETTINGS_NAME=${_SECRET_SETTINGS_NAME}",
        "--",
        "python",
        "manage.py",
        "migrate",
      ]

  - id: "collect static"
    name: "gcr.io/google-appengine/exec-wrapper"
    args:
      [
        "-i",
        "gcr.io/$PROJECT_ID/${_SERVICE_NAME}",
        "-s",
        "${PROJECT_ID}:${_REGION}:${_INSTANCE_NAME}",
        "-e",
        "SETTINGS_NAME=${_SECRET_SETTINGS_NAME}",
        "--",
        "python",
        "manage.py",
        "collectstatic",
        "--verbosity",
        "2",
        "--no-input",
      ]

substitutions:
  _INSTANCE_NAME: trouwfeestwebsite-db
  _REGION: europe-west6
  _SERVICE_NAME: invites-service
  _SECRET_SETTINGS_NAME: django_settings

images:
  - "gcr.io/${PROJECT_ID}/${_SERVICE_NAME}"

非常感谢您的帮助。

【问题讨论】:

  • 该错误似乎部分来自您的gcloud builds submit 命令。请包括那个。 googleapi 很好奇。这应该是googleapis,但不清楚为什么gcloud builds submit 会引用它。尽管错误显示 GCS,但它是错误的|无法引用错误中的存储桶,因此我认为这可能是一个红鲱鱼(误导)。
  • 我的命令是gcloud builds submit --config cloudmigrate.yaml --substitutions _INSTANCE_NAME=trouwfeestwebsite-db,_REGION=europe-west6。问题中列出了引用的 cloudmigrate.yaml,我错过了哪些其他引用的东西? gcloud --version 返回:Google Cloud SDK 361.0.0、bq 2.0.71、核心 2021.10.15、gsutil 5.4。感谢您帮助我!

标签: django google-cloud-platform gcloud google-cloud-run google-cloud-build


【解决方案1】:

以下解决了我的问题。

  1. DazWilkin 说得对:

    不正确|无法引用存储桶

    (为此点赞,谢谢!!)。在我的秘密中(在 Secret Manager 上配置;或者您可以将其放在项目根文件夹级别的 .env 文件中,并确保您不会将该文件排除在 .gcloudignore 文件中进行部署),我现在 已设置:

    GS_BUCKET_NAME=trouwfeestwebsite_sasa-trouw-bucket(项目ID+下划线+存储桶ID)

    而不是 GS_BUCKET_NAME=sasa-trouw-bucket

    虽然教程实际上说我必须设置第一个,但我设置了后者,因为我发现下划线拆分很奇怪,在教程中我没有看到类似的东西,我认为这是教程中的错误。

    适配GS_BUCKET_NAME将gcloud构建提交的错误改为:

    Creating temporary tarball archive of 412 file(s) totalling 41.6 MiB before compression.
    Uploading tarball of [.] to [gs://trouwfeestwebsite_cloudbuild/source/1635063996.982304-d33fef2af77a4744a3bb45f02da8476b.tgz]
    ERROR: (gcloud.builds.submit) PERMISSION_DENIED: service account "934957811880@cloudbuild.gserviceaccount.com" has insufficient permission to execute the build on project "trouwfeestwebsite"
    

    这意味着至少现在找到了存储桶,只是缺少一个权限。

    编辑(几个小时后):我注意到这个 GS_BUCKET_NAME=trouwfeestwebsite_sasa-trouw-bucket(项目 ID + 下划线 + 存储桶 ID)设置然后在部署的后期阶段造成了问题,当部署静态文件时(cloudmigrate 的最后一步.yaml)。这似乎对两者都有效(请注意,项目 ID 不再位于 GS_BUCKET_NAME 中,而是位于其单独的环境变量中):

    DATABASE_URL=postgres://myuser:mypassword@//cloudsql/mywebsite:europe-west6:mywebsite-db/mydb
    GS_PROJECT_ID=trouwfeestwebsite
    GS_BUCKET_NAME=sasa-trouw-bucket
    SECRET_KEY=my123Very456Long789Secret0Key
    
  2. 然后,好像真的还有权限问题:

  3. 如果您有同样的问题:我认为我的问题中提到的一些事情也可以帮助您 - 例如,我认为这样做可能也很重要:

    我在 Cloud Build 权限选项卡中启用了 Cloud run: https://console.cloud.google.com/cloud-build/settings/service-account?project=trouwfeestwebsite

【讨论】:

    猜你喜欢
    • 2021-04-24
    • 1970-01-01
    • 1970-01-01
    • 2022-10-15
    • 2020-04-18
    • 2019-06-20
    • 1970-01-01
    • 1970-01-01
    • 2022-01-26
    相关资源
    最近更新 更多