gcloud - ERROR: (gcloud.app.deploy) Permissions error fetching application

13,927

Solution 1

The default Cloud Build service account does not allow access to deploy App Engine. You need to enable the Cloud Build service account to perform actions such as deploy.

The Cloud Build service account is formatted like this:

[PROJECT_NUMBER]@cloudbuild.gserviceaccount.com
  • Go to the Google Cloud Console -> IAM & admin -> IAM.
  • Locate the service account and click the pencil icon.
  • Add the role "App Engine Deployer" to the service account.

Wait a couple of minutes for the service account to update globally and then try again.

Solution 2

The most common way to deploy an app to App Engine is to use gcloud app deploy ....

When you use gcloud app deploy against App Engine Flex, the service uses Cloud Build.

It's entirely possible|reasonable to use Cloud Build to do your deployments too, it's just more involved.

I've not tried this but I think that, if you wish to use Cloud Build to perform the deployment, you will need to ensure that the Cloud Build service account has permissions to deploy to App Engine.

Here's an example of what you would need to do, specifically granting Cloud Build's service account the correct role.

Solution 3

I had this same error today and the way I resolve it was by running: $ gcloud auth login on the console.

This will open a new browser tab for you to login with the credentials that has access to the project you're trying to deploy.

I was able to deploy to gcloud after that.

ps.: I'm not sure this is the best approach, but I'm leaving this as a possible solution as this is how I usually go around this problem. Worst case, I'll stand corrected and learn something new.

Solution 4

Two commands can handle the perms needed (run in your terminal if you have gcloud sdk installed and authenticated or run in cloud shell for your project):

export PROJECT_ID=[[put your project id here]]
export PROJECT_NUMBER=$(gcloud projects describe $PROJECT_ID --format="value(projectNumber)")

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}
```
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
--member=serviceAccount:${PROJECT_NUMBER}@cloudbuild.gserviceaccount.com \
--role=roles/appengine.appAdmin 
Share:
13,927

Related videos on Youtube

Sachin Vairagi
Author by

Sachin Vairagi

We are specialized in web applications, web development, mobile apps development, website design, e-commerce business portals, CMS Solutions, instant chat, social-networking & user-generated content, and customized software solutions. Zeeweesoft is an emerging IT firm in central India adopting, learning & delivering quality software development services to our clients. We are equipped with an experienced team of developers in trending IT technologies. We offer full-stack development, mobile app development, SEO and consultancy services. Our team is expert in: :- Website development team - Java Technologies, ReactJs, Angular, NodeJsPHP, Laravel, Codeigniter, JavaScript, Wordpress, HTML5, CSS3 :- Web designing team - Photoshop, Illustrator, HTML5, CSS3, Bootstrap, Material design :- Mobile App Development - React Native,Android & iOS Native application development We follow standard working ethics while understanding the client's requirements. We are looking forward to having a business association with you. Team Zeeweesoft

Updated on June 04, 2022

Comments

  • Sachin Vairagi
    Sachin Vairagi almost 2 years

    I am trying to deploy node js app on google cloud but getting following error -

    Step #1: ERROR: (gcloud.app.deploy) Permissions error fetching application [apps
    /mytest-240512]. Please make sure you are using the correct project ID and that
    you have permission to view applications on the project.
    

    I am running following command -

    gcloud builds submit . --config cloudbuild.yaml
    

    My cloudbuild.yaml file looks like -

    steps:
      #install
      - name: 'gcr.io/cloud-builders/npm'
        args: ['install']
    
       #deploy
      - name: 'gcr.io/cloud-builders/gcloud'
        args: ['app', 'deploy']
    
  • Sachin Vairagi
    Sachin Vairagi almost 5 years
    'gcloud app deploy' is working fine, I am able to deploy app via terminal at my local system. But I want to set 'cloud build triggers' to auto deploy from GitHub
  • Sachin Vairagi
    Sachin Vairagi almost 5 years
    Thank you for your response John, I have to also enable - App engine API but now getting following message - Step #1: ERROR: (gcloud.app.deploy) Your deployment has succeeded, but promoting the new version to default failed. You may not have permissions to change traffic splits. Changing traffic splits requires the Owner, Editor, App Engine Admin, or App Engine Service Admin role. Please contact your project owner and use the gcloud app services set-traffic --splits <version>=1 command to redirect traffic to your newly deployed version.
  • Sachin Vairagi
    Sachin Vairagi almost 5 years
    working now, after adding "App Engine Admin" role to [PROJECT_NUMBER]@cloudbuild.gserviceaccount.com
  • John Hanley
    John Hanley almost 5 years
    I had assumed that you already had set up App Engine, which requires region selection, enabling services, etc. Now that you have an app deployed you should not need anything other than gcloud app deploy and App Engine Deployer permissions. It is OK to leave Cloud Build with App Engine Admin as that is a secure service controlled by Google.
  • DazWilkin
    DazWilkin almost 5 years
    OK. Please see the link that I referenced. This shows how to grant the Cloud Build service account the permission to deploy to App Engine.
  • Sachin Vairagi
    Sachin Vairagi almost 5 years
    is there any option in package.json to run command after build like heroku-postbuild
  • John Hanley
    John Hanley almost 5 years
    I am not sure. What are you trying to do? Note: I would create a new question for this to get a better chance of a good answer.
  • Cole Peterson
    Cole Peterson over 3 years
    Thank you Daz. You fixed my issue. What a nightmare user experience.
  • hamx0r
    hamx0r over 3 years
    @SachinVairagi I found that the "Project Editor" plus "App Engine Deployer" permissions were sufficient to use Cloud Builder to deploy to GAE Standard Environment.
  • Sachin Vairagi
    Sachin Vairagi over 3 years
    @hamx0r - Thank you for sharing your solution, it might help others.
  • fIwJlxSzApHEZIl
    fIwJlxSzApHEZIl over 2 years
    There are actually multiple permissions that you need to grant to the default app engine service account because the builder does multiple things like upload to cloud storage as well as build.
  • DFB
    DFB about 2 years
    Thanks! This resolved my issue.
  • James Joyce
    James Joyce almost 2 years
    Thanks - worked well - just needed to remove the ``` to allow the full command to execute!