1

I am getting a 403 PERMISSION_DENIED response from GCP when running the deployment manager to create a deployment that creates a project, two service accounts and sets IAM policy for it using the cloud resource manager API.

- code: RESOURCE_ERROR
  location: /deployments/test-deployment/resources/dm-test-project
  message: '{"ResourceType":"cloudresourcemanager.v1.project","ResourceErrorCode":"403","ResourceErrorMessage":{"code":403,"message":"The
    caller does not have permission","status":"PERMISSION_DENIED","statusMessage":"Forbidden","requestPath":"https://cloudresourcemanager.googleapis.com/v1/projects/dm-test-project","httpMethod":"GET"}}'

Before, I created a project 'DM Project Creation', enable some APIs, assign the Billing Account to it and then create a Service Account. I already had an Organization node created, so I added the created Service Account in the org node and gave the following IAM roles: - Project Creator - Billing Account User

I was actually following this examples from Google Cloud Platform: https://github.com/GoogleCloudPlatform/deploymentmanager-samples/tree/master/examples/v2/project_creation

https://github.com/GoogleCloudPlatform/deploymentmanager-samples/blob/master/community/cloud-foundation/templates/project/README.md

I run the following command to authenticate with the Service Account:

gcloud auth activate-service-account dm-project-creation@dm-creation-project-0.iam.gserviceaccount.com --key-file=/Users/famedina/Downloads/dm-creation-project-0-f1f92dd070ce.json

Then run the deployment manager passing the configuration file: gcloud deployment-manager deployments create test-deployment --config config.yaml

imports:
- path: project.py

resources:
  # The "name" property below will be the ID of the new project
  # If you want your project to have a different name, use the "project-name"
  # property.
  - name: dm-test-project
    type: project.py
    properties:
        # Change this to your organization ID.
        organization-id: "<MY_ORG_ID"
        # You can also create the project in a folder.
        # If both organization-id and parent-folder-id are provided,
        # the project will be created in parent-folder-id.
        #parent-folder-id: "FOLDER_ID"

        # Change the following to your organization's billing account
        billing-account-name: billingAccounts/<MY_BILLING_ACC_ID>

        # The apis to enable in the new project.
        # To see the possible APIs, use: gcloud services list --available
        apis:
          - compute.googleapis.com
          - deploymentmanager.googleapis.com
          - pubsub.googleapis.com
          - storage-component.googleapis.com
          - monitoring.googleapis.com
          - logging.googleapis.com

        # The service accounts you want to create in the project
        service-accounts:
          - my-service-account-1
          - my-service-account-2

        bucket-export-settings:
            create-bucket: true
            # If using an already existing bucket, specify this
            # bucket: <my bucket name>

        # Makes the service account that Deployment Manager would use in the
        # generated project when making deployments in this new project a
        # project owner.
        set-dm-service-account-as-owner: true

        # The patches to apply to the project's IAM policy. Note that these are
        # always applied as a patch to the project's current IAM policy, not as a
        # diff with the existing properties stored in DM. This means that removing
        # a binding from the 'add' section will not remove the binding on the
        # project during the next update. Instead it must be added to the 'remove'
        # section.
        iam-policy-patch:
            # These are the bindings to add.
            add:
              - role: roles/owner
                members:
                  # NOTE: The DM service account that is creating this project will
                  # automatically be added as an owner.
                  - serviceAccount:98765432100@cloudservices.gserviceaccount.com
              - role: roles/viewer
                members:
                  - user:iamtester@deployment-manager.net
            # The bindings to remove. Note that these are idempotent, in the sense
            # that any binding here that is not actually on the project is considered
            # to have been removed successfully.
            remove:
              - role: roles/owner
                members:
                  # This is already not on the project, but in case it shows up, let's
                  # remove it.
                  - serviceAccount:1234567890@cloudservices.gserviceaccount.com```
famedina
  • 21
  • 5
  • How many projects do you already have? If you attempt to create this project in the console, are you getting an error that the max number of projects has been reached (pulling the message from my memory)? Unless you have increased your quota the limit is 5. – John Hanley May 04 '19 at 02:56
  • I already solved the issue based on the follwing thread: https://stackoverflow.com/questions/55355848/gcp-project-creation-via-deploymentmanager – famedina May 06 '19 at 08:26
  • I was trying to deploy running ```gcloud deployment-manager deployments create test-deployment --config examples/my_project.yaml``` and then, when receive the stated error I was deleting the deployment running the following command: ```gcloud deployment-manager deployments delete test-deployment```. Apparently, the Project ID is already "fixed" and we can't reuse it anymore when trying to deploy again, so I changed it and it finally worked. – famedina May 06 '19 at 08:28
  • The reason you cannot reuse the same project ID is that deleted projects can be undeleted. I don't remember the recovery time, something like 20 days. – John Hanley May 06 '19 at 09:35
  • I wonder how was considered as created the project if I was getting the 403 PERMISSION_DENIED error message since the beginning, so it should allows to reuse the same Project ID even if I tried to delete the deployment later. – famedina May 06 '19 at 11:40

1 Answers1

0

I ran into this as well, and the error message is not actually explaining the underlying problem. The key thing is that this is a GET operation, not an attempt to create the project. This is to verify global uniqueness of the project-id requested, and if not unique, PERMISSION_DENIED is thrown.

- code: RESOURCE_ERROR
  location: /deployments/test-deployment/resources/dm-test-project
  message: '{"ResourceType":"cloudresourcemanager.v1.project","ResourceErrorCode":"403","ResourceErrorMessage":{"code":403,"message":"The
    caller does not have permission","status":"PERMISSION_DENIED","statusMessage":"Forbidden","requestPath":"https://cloudresourcemanager.googleapis.com/v1/projects/dm-test-project","httpMethod":"**GET**"}}'

Alot of room for improvement in the resulting error towards the end user.

koma
  • 6,486
  • 2
  • 27
  • 53