Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloud Build fails to deploy to Google App Engine - You do not have permission to act as @appspot.gserviceaccount.com

This morning I made a PR which triggered a Cloud Build for my staging enviroment but failed to deploy the results to GAE.

The error was as follows:

ERROR: (gcloud.app.deploy) PERMISSION_DENIED: You do not have permission to act as '[redacted]@appspot.gserviceaccount.com' Step #4: - '@type': type.googleapis.com/google.rpc.ResourceInfo Step #4: description: You do not have permission to act as this service account. Step #4: resourceName: [redacted]@appspot.gserviceaccount.com Step #4: resourceType: serviceAccount

When I look at https://console.cloud.google.com/cloud-build/settings/service-account Cloud build has the follow service account permissions ENABLED:

  • App Engine Admin
  • Cloud KMS

Checking https://console.cloud.google.com/iam-admin/iam I can see that the cloudbuild service account has the following roles:

  • App Engine Admin
  • App Engine Deployer
  • Cloud Build Service Account
  • Cloud KMS CryptoKey Decrypter
like image 401
Lawson Taylor Avatar asked Oct 07 '20 02:10

Lawson Taylor


People also ask

Does not have permission to access apps instance or it may not exist ): The caller does not have permission?

The caller does not have permission to access projectThis error occurs if the account that you used to deploy your app does not have permission to deploy apps for the current project. To resolve this issue, grant the App Engine Deployer ( roles/appengine. deployer ) role to the account.

Why do I not have permission to access an app instance?

Cloud Build does not have permission to access my App Engine instance. To fix this, go into Settings under Cloud Build and enable access to App Engine, and any other cloud service you use in conjunction with Cloud Build. Then wait a moment for the settings to take effect and rerun the build.

What is Cloudbuild Gserviceaccount com?

[PROJECT-ID]@cloudbuild.gserviceaccount.com is assigned the Cloud Build Service Account Role, and is referred to in the Cloud Build documentation as the service account to which you want to grant additional permissions if you need your builds to perform functions such as deploying to AppEngine or Cloud Functions.


1 Answers

According to the provided error, it seems like you need to add some delegation to your service account. This means that the service account can act on behalf of another service account. Do not add this permission on the project level, since it poses a security risk! Below you can find an example of how to add roles/iam.serviceAccountUser on another service account.

PROJECT_ID=xxxxxx  PROJECT_NUMBER=$(gcloud projects list \   --format="value(projectNumber)" \   --filter="projectId=${PROJECT_ID}")  gcloud iam service-accounts add-iam-policy-binding \     ${PROJECT_ID}@appspot.gserviceaccount.com \     --member=serviceAccount:${PROJECT_NUMBER}@cloudbuild.gserviceaccount.com \     --role=roles/iam.serviceAccountUser \     --project=${PROJECT_ID} 

To summarize, the service account must have the iam.serviceAccounts.actAs permission, which is included in the roles/iam.serviceAccountUser role. Updated Google documentation can be found here.

like image 72
Nebulastic Avatar answered Sep 17 '22 19:09

Nebulastic