Required GCP permissions
A GCP resource handler uses two identities: the credential you give it, and a service account that Cloud Management Platform (CMP) creates in each imported project
10 minute read
Cloud Management Platform (CMP) works with GCP projects, where each imported project becomes a CMP environment that users can order into. Connect via an OAuth client ID or a service account key. With a service account key, CMP can list your projects immediately. With an OAuth client ID, you authorize in Google first and import projects afterward.
CMP accepts an OAuth client ID or a service account key. Create one of them in Google Cloud before you add the resource handler.
https://<your CMP host>/google-oauth2/. For a CMP instance at https://example.com, that is https://example.com/google-oauth2/. CMP builds the redirect URI from the address you use to reach it, so register that exact scheme and hostname. Google does not accept private IP addresses, so use a resolvable hostname.Create a service account in the project you want CMP to manage, and download its key in JSON format. Grant the account the roles listed in Required GCP permissions.
Start by going to Admin > Resource Handlers, select Add, then select Google Cloud Platform under Public Cloud.
The submit button reads Import, or Save if you choose to enter the JSON directly.
Google returns a refresh token only the first time an account authorizes a given CMP instance. If CMP reports that the connection was established but cannot be maintained, remove the application from your Google account access list, then select Verify Connection on the handler’s Overview tab to authorize it again.
There is no Google consent screen on this route, because the key authorizes CMP directly.
Import at least one project to use a GCP resource handler. The Projects tab shows a warning icon until you import a project. Importing a project creates a CMP environment.
Projects imported this way do not include their networks. Open each project and use Import Networks on its Networks tab.
The Projects tab lists each project’s name, project ID, project number, and environments. Select a project name to open it, or use the plus icon in the Environment column to create another environment.
A project has Overview, Networks, and Servers tabs. The Overview tab is where you verify the project’s connection, edit it, or remove it from CMP.
A project that is not a Shared VPC host also has a Shared VPC tab, with Sync shared subnets for pulling in the subnets its host project shares. A host project has no Shared VPC tab; its Networks tab lists every subnet.
The Create GCP Project blueprint orders a new project in Google Cloud. Choosing a billing account on the order form requires the billing account permission in GCP.
Importing a project brings its images. Use the handler’s Images tab to add more from private projects or from Google’s public image projects.
debian-cloud, rhel-cloud, ubuntu-os-cloud, and windows-cloud. Select Add Custom to name one that is not listed, then select Save. Images from the projects you select appear in the Import Images dialog.Shared images are listed when the GCP user has a role that can see them.
CMP caches GCP image data using the Fetch and Cache Available GCP Images rule, which is enabled by default and can take 20 to 30 minutes per project. If Import Images reports that no images are available, go to Admin > Rules and run that rule.
The GCP user associated with the resource handler needs the Compute Image User role, granted in IAM & Admin > IAM in Google Cloud.
Grant it in the project that holds the image. If you have imported Project A and the image lives in Project B, add the user to Project B and grant the role there.
Add the DNS Domain parameter to the environment for your project, and CMP sets each new server’s hostname in GCP to {name}.{dns_domain}.
If the parameter has no value, CMP falls back to the DNS domain set on the server’s network.
CMP passes startup scripts to GCP as instance metadata during provisioning. Each script is a parameter you add to the environment; the parameter decides the script language and when GCP runs it.
Go to Admin > Environments and open the GCP project environment.
On the Parameters tab, select Add and choose the parameter for the script you want to run.
| Parameter | What you supply | When it runs |
|---|---|---|
| GCP Initial Batch File Script | A batch file script of up to 256 KB. | During the initial boot. |
| GCP Initial Command Shell Script | A command shell script of up to 256 KB. | During the initial boot. |
| GCP Initial PowerShell Script | An unsigned PowerShell script of up to 256 KB. | During the initial boot. |
| GCP Initial Windows Script URL | A URL to a batch file, command shell, or signed or unsigned PowerShell script held in Cloud Storage, for scripts over 256 KB. | During the initial boot. |
| GCP Startup Batch File Script | A batch file script of up to 256 KB. | During each boot after the initial boot. |
| GCP Startup Command Shell Script | A command shell script of up to 256 KB. | During each boot after the initial boot. |
| GCP Startup PowerShell Script | An unsigned PowerShell script of up to 256 KB. | During each boot after the initial boot. |
| GCP Startup Windows Script URL | A URL to a batch file, command shell, or signed or unsigned PowerShell script held in Cloud Storage, for scripts over 256 KB. | During each boot after the initial boot. |
| GCP Startup Linux Script | A Linux script, run after the instance starts. | On every boot. |
| GCP Startup Linux Script URL | A URL to a Linux script, run after the instance starts. | On every boot. |
For example, this GCP Startup Linux Script writes the server’s hostname to a file:
#!/usr/bin/env bash
hostname=$(hostname)
echo $hostname > /tmp/vmname.host
Select Add.
In the Options column, select the pencil icon next to No options.
Paste in your script or its URL, depending on the chosen parameter, and select Save.
CMP supports two-way tagging of GCP servers. GCP calls these tags labels. Add tag mappings from the handler’s Tags tab; tags are applied at provision time and refreshed when the server syncs.
Tags appear in the Google Cloud Platform Details section of a provisioned server. Editing a tag value in CMP updates the label in GCP at the next sync.
CMP calculates GCP server rates from pricing data published by Google. Google controls what pricing data is available, so the rates CMP can reach may lag current prices. To check a figure, use the Google Cloud pricing calculator.
A GCP resource handler manages projects, servers, networks, and images. To deploy other Google Cloud services from CMP, download one of these blueprints from the Content Library.
| Blueprint | What it deploys |
|---|---|
| Create GCP Project | Orders a new GCP project. See Create a project from CMP for the order form and the billing account permission it needs. |
| GCP Storage | Creates and deletes Cloud Storage buckets, discovers existing ones, and manages their objects: upload, download, copy, move, rename, and delete. |
| Google Cloud Firewall | Creates Google Cloud firewall rules and discovers existing ones. |
| Google Cloud SQL Database | Creates and manages Cloud SQL instances. Every service account that runs this blueprint needs the Cloud SQL Admin role. |
| Google Kubernetes Engine Cluster | Provisions a GKE cluster into an existing GCP environment. CMP imports the cluster as a container orchestrator and its nodes as servers. The account used by the resource handler needs the Kubernetes Engine Admin role. |
| Google Storage | Creates and deletes Cloud Storage buckets. GCP Storage covers the same ground and adds discovery and object management, so prefer it unless you have a reason to use this one. |
| Issue | Solution |
|---|---|
| Remote scripts at the end of provisioning fail with a connection refused error. | GCP reports a new server as ready before it has finished booting, so services such as SSH may not be listening yet. Add the Post Provisioning Delay parameter to the environment with a single option of 30 to make CMP wait 30 seconds before it runs scripts. |
| The Import GCP Projects dialog reports that no projects were found. | Select Sync Projects on the Projects tab first. The dialog lists only projects CMP has already synced and not yet imported. |
A GCP resource handler uses two identities: the credential you give it, and a service account that Cloud Management Platform (CMP) creates in each imported project