Search code examples
google-cloud-platformgcloudgoogle-cloud-buildgoogle-cloud-api-gateway

Gcloud comportament differ from shell to cloudbuild.yaml


I have been trying to list all the API gateways config on gcloud, and something wrong is happening.

When I run the following command on the terminal with my user logged in, it works like a charm.

gcloud api-gateway api-configs list --api=$API --project=$PROJECT_ID --format="table(name)"

But when I run the same command from inside this cloudbuild.yaml

steps:
  - name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
    entrypoint: "bash"
    args:
      - "-c"
      - |
        gcloud api-gateway api-configs list --api=logistics-homolog --project=$PROJECT_ID \
        --filter=serviceConfigId:logistics-mobile-places-* --format="table(name)"

It gives me the following error:

ERROR: (gcloud.api-gateway.api-configs.list) PERMISSION_DENIED: Permission 'apigateway.apiconfigs.list' denied on 'projects/$PROJECT_ID/locations/global/apis/logistics-homolog/configs'

What's wrong with it?!


Solution

  • You need to grant the Cloud Build default service account (pattern: @cloudbuild.gserviceaccount.com) the required permissions for your command.

    Have a look on your IAM page to update that.