# Google Cloud

The Google Cloud collector reads the certificates and encryption keys in a
Google Cloud project, so they count toward your post-quantum readiness
alongside everything else Mesh knows about.

Google Cloud keeps them in three separate services: the certificates your
websites and services present sit in Certificate Manager, the keys protecting
your data sit in Cloud KMS, and a private certificate authority, if you run
one, sits in Certificate Authority Service. Mesh reads all three and gives you
one list.

## What it collects

Each row is a switch on the **Collect** step.

| What Mesh reads | What it tells you | Collected by default |
|---|---|---|
| **Certificate Manager** | The certificates protecting your websites and services, with their key algorithm and validity | Yes |
| **Encryption keys (Cloud KMS)** | The keys protecting your data, and what kind of key each one is | Yes |
| **Certificate Authority Service** | Your own certificate authorities and their CA pools, if you run any | Yes |
| **Key rotation** | Whether each key renews itself on a schedule, and when it next does | No — switch it on if you want it |
| **Storage encryption** | How the Cloud Storage buckets you name encrypt new files | No — switch it on if you want it |

> **note**
Mesh reads certificate and key *metadata* — algorithm, size, validity,
rotation schedule. Cloud KMS has no way to export the key material it holds,
and Mesh never asks Certificate Manager or Certificate Authority Service for a
private key. It never creates, changes or deletes anything in Google Cloud.

## Before you start

Ask your Google Cloud administrator for:

- **The project ID** of the project you want read. It is a name such as
  `example-project-123456`, shown at the top of the Google Cloud console — not
  the project number.
- **A service account key file, in JSON format**, for a read-only service
  account. How to create it is below.
- **The names of the Cloud Storage buckets** you want read, only if you plan to
  switch on storage encryption.

You also need a Mesh administrator account that can manage connectors.

One connector reads one project. To read several projects, add a connector for
each.

## Set up read-only access in Google Cloud

Do this in the Google Cloud console, or ask your Google Cloud administrator to.

### 1. Make sure the services' APIs are enabled

Mesh reads each service through its API, so the API has to be enabled in the
project. Under **APIs & Services › Enabled APIs & services**, check:

| Service | API |
|---|---|
| Certificate Manager | Certificate Manager API |
| Cloud KMS | Cloud Key Management Service (KMS) API |
| Certificate Authority Service | Certificate Authority API |

If your project does not use one of these services, you do not need to enable
its API — switch that service off on the **Collect** step instead.

### 2. Create a service account

1. Go to **IAM & Admin › Service accounts**, and select **Create service
   account**.
2. Give it a name you will recognize, for example `crypto-inventory-reader`, and
   select **Create and continue**.

### 3. Grant it read-only roles on the project

Grant the service account these roles on the project, under **IAM & Admin ›
IAM**:

| Switch | Role to grant |
|---|---|
| Certificate Manager | **Certificate Manager Viewer** |
| Encryption keys (Cloud KMS) | **Cloud KMS Viewer** |
| Certificate Authority Service | **CA Service Auditor** |
| Key rotation | Nothing extra — it is read from the same key listing as Cloud KMS |
| Storage encryption | A role with the `storage.buckets.get` permission on each bucket you name, for example a custom role with only that permission |

Each of these is read-only. Grant only what you plan to collect: a role you
leave out costs only the row that needs it, and the rest of the collection
still runs.

### 4. Create a JSON key

1. Open the service account, then **Keys › Add key › Create new key**.
2. Choose **JSON**, and select **Create**. The key file downloads to your
   computer.

Keep the file safe — it is the credential. You paste its contents into Mesh in
the next part, and Mesh stores it encrypted.

> **tip**
Some organizations turn off service account key creation with an organization
policy. If **Create new key** is unavailable, ask your Google Cloud
administrator to allow it for this service account.

## Add the connector in Mesh

1. Select the settings icon, the gear at the top right of Mesh.

   ![The settings icon at the top right of Mesh, beside the search boxes](/img/connectors/crypto/crypto-01-settings-gear.png)

2. In **Settings**, open **Integrations**, then **Connectors**.

   ![The Settings menu with Integrations expanded and Connectors selected](/img/connectors/crypto/crypto-02-integrations-connectors.png)

3. Select **Add connector**, then **Crypto collectors**.

   ![The Add connector panel, with Crypto collectors at the top of the list](/img/connectors/crypto/crypto-03-add-connector.png)

4. Choose **Google Cloud**.

   ![The Crypto collectors panel, offering Kubernetes, Amazon Web Services, Microsoft Azure, Google Cloud and CrowdStrike endpoints](/img/connectors/crypto/crypto-04-crypto-collectors.png)

The wizard has six steps — **Get ready**, **Identify**, **Authenticate**,
**Collect**, **Tuning** and **Review**. The rail on the left tracks where you
are. Steps after **Authenticate** stay locked until the connection test passes.

### Step 1 — Get ready

A checklist of what to have ready. Nothing to fill in.

![Step 1, Get ready, listing the project ID and service account key to gather](/img/connectors/crypto-gcp/gcp-02-step1-get-ready.png)

### Step 2 — Identify

| Field | Required | What to enter |
|---|---|---|
| **Connector name** | Yes | A label of your choosing. It appears in the connector list and in reports |
| **Project ID** | Yes | The project ID, for example `example-project-123456` |

![Step 2, Identify, with the connector name and project ID fields](/img/connectors/crypto-gcp/gcp-03-step2-identify.png)

> **warning**
It identifies the source of everything Mesh reads through this connector, so it
cannot be changed later. To read a second project, add a second connector.

### Step 3 — Authenticate

| Field | Required | What to enter |
|---|---|---|
| **Service account key** | Yes | Open the JSON key file in a text editor and paste **everything**, including the opening and closing braces. Stored encrypted, and never shown again |

Select **Test connection**. You cannot continue until it passes.

![Step 3, Authenticate, showing a successful connection test](/img/connectors/crypto-gcp/gcp-04-step3-authenticate.png)

The test makes a small read of each service in the project. It passes as
long as Google Cloud accepts the key and at least one service answers, because
a service account granted some services and not others is a valid setup. A
service it cannot read is reported on the first collection.

If it fails, the wizard shows the reason.

![Step 3 reporting that the pasted key could not be used](/img/connectors/crypto-gcp/gcp-05-step3-error.png)

In the example above, the pasted text was not a complete key file — part of
the private key was missing. Paste the whole file again, exactly as it was
downloaded. See [Troubleshooting](#troubleshooting) for the other messages.

### Step 4 — Collect

Choose what Mesh reads. **Certificate Manager**, **Encryption keys (Cloud KMS)**
and **Certificate Authority Service** are on by default; **Key rotation** and
**Storage encryption** are off until you switch them on.

![Step 4, Collect, with a switch for each Google Cloud service. Every switch has been turned on in this example](/img/connectors/crypto-gcp/gcp-06-step4-collect.png)

Each row also says how Mesh knows what it reports — whether it saw the real
certificate or key, or read a configuration rule.

**Key rotation** is read onto each key's own record, so it applies only while
**Encryption keys (Cloud KMS)** is on. Turn Cloud KMS off and the rotation row
is switched off with it.

### Step 5 — Tuning

| Setting | Shown when | What to enter |
|---|---|---|
| **How often should Mesh read?** | Always | Every hour by default. Every 15 minutes for a project that changes often; twice a day or once a day for fewer Google Cloud calls |
| **Storage buckets** | **Storage encryption** is on | Comma-separated bucket names, for example `prod-data, prod-logs`. At least one is required |
| **Owner label keys** | Always (optional) | The Google Cloud labels that name who owns each certificate and key. Leave empty to use `owner` |

![Step 5, Tuning, with the four frequency choices and the storage buckets field](/img/connectors/crypto-gcp/gcp-07-step5-tuning.png)

> **note**
Mesh does not look for buckets on its own. A bucket you leave out of this list
is not read, so name every bucket whose encryption you want to see.

Google Cloud label keys are always lower case. List them most authoritative
first, for example `owner,team` — the first one present on a certificate or key
wins.

#### Locations

Google Cloud keeps certificates and keys separately in each location, such as
`us-central1` or `global`. Further down the same step, choose how Mesh finds
them.

![Step 5, Tuning, scrolled down to the owner label keys and the two location choices](/img/connectors/crypto-gcp/gcp-08-step5-locations.png)

| Choice | What Mesh does |
|---|---|
| **Let Mesh find the locations** (recommended) | At the start of every run, Mesh asks Google Cloud which locations each service uses in your project, and reads all of them. New locations are picked up automatically |
| **Only these locations** | Mesh reads only the comma-separated locations you type, for example `us-central1, global`. Include `global` for resources that are not tied to a region |

> **caution**
With **Only these locations**, anything outside your list is not read, and
nothing in Mesh can tell you it exists. There is no "all" value — to read
everything, let Mesh find the locations.

If Mesh cannot reach Google Cloud to ask about locations, it marks the run
unfinished and tries again later, rather than showing you a list that quietly
missed part of your project.

### Step 6 — Review

Check the summary, then select **Save connector**.

![Step 6, Review, summarizing the connector before saving](/img/connectors/crypto-gcp/gcp-09-step6-review.png)

## Check the first collection

The connector appears in the list and starts its first collection straight
away.

![The connector list showing the new Google Cloud connector starting its first collection](/img/connectors/crypto-gcp/gcp-10-connector-list.png)

## Manage the connector

Everything you do to a connector after it is saved is on its row menu — the
**⋯** button at the end of its row.

![The connector row menu, open, showing View collections, Logs, Edit, Remove and Re-sync](/img/connectors/crypto-gcp/gcp-11-row-menu.png)

| Choose | What it does |
|---|---|
| **View collections** | A summary of the last run and what it brought back. Compare the counts with what you expect in the project |
| **Logs** | Every run this connector has made, newest first, with the detail of each one |
| **Edit** | Opens the connector's settings. See [Edit a connector](#edit-a-connector) |
| **Remove** | Stops the connector collecting. You are asked for a reason first |
| **Re-sync** | Starts a fresh, complete collection now instead of waiting for the next scheduled run |

A count lower than you expect is usually a missing role, an API that is not
enabled, or a location that was left out, rather than a connection problem.

### Re-sync

Use **Re-sync** after you grant a role, enable an API or replace the key, so you
see the result without waiting for the next run.

- **The connector has to be enabled.** On a disabled connector the action is
  unavailable.
- **Nothing visible happens at once.** A message confirms the re-sync has
  started, and the result arrives when the run finishes. Open **View
  collections** or **Logs** again to see it.

### Remove

Removing a connector stops it collecting and hides it from your connector list.
Certificates and keys it already collected stay in Mesh, so your history and
reports stay accurate, and nothing is changed in Google Cloud. To bring a
removed connector back, or to have its collected data deleted, contact Axiad
support.

To pause collection without removing the connector, switch its **Status** off
instead.

## Edit a connector

Open the row menu and choose **Edit**. The settings are in three tabs, and
nothing is kept until you select **Save**.

### Connection

| Setting | Can you change it | What to know |
|---|---|---|
| **Connector name** | Yes | A label. Nothing depends on it |
| **Project ID** | No | To read a different project, add a second connector |
| **Authentication** | Yes | Select **Replace credential** and paste the whole new JSON key file. **Keep current credential** backs out |

The key is stored encrypted and is never shown again.

> **caution**
The Edit panel does not check the key. After you replace it, use **Re-sync** to
find out straight away whether it works.

### Collection

The **Locations** to read (leave empty to let Mesh find them), the same five
switches as the **Collect** step, each with the Google Cloud role it needs
written beside it, and the **Storage buckets** list. Changes apply the next time
Mesh reads the project.

### Advanced

How often Mesh reads, and the **Owner label keys** — the same choices as the
**Tuning** step.

## Troubleshooting

| What you see | What it means |
|---|---|
| The connection test says the service account key could not be used | The pasted text is not a complete key file. Paste the whole JSON file again, including the braces, without changing anything in it |
| The test says *GCP rejected the service account key* | The key has been deleted or disabled, or the service account was removed. If only the key is gone, create a new key and paste it. If the service account itself was deleted, create a new one — it does not inherit the old account's roles — grant it the roles in [step 3](#3-grant-it-read-only-roles-on-the-project), then create a key and paste it |
| The test says *GCP does not recognise* the project or a location | The project ID is mistyped — use the project ID, not the project name or number — or a location is spelled differently from how Google Cloud writes it, for example `us-central1` |
| The test says *GCP refused every service Mesh reads* | The service account has none of the roles in [step 3](#3-grant-it-read-only-roles-on-the-project), or none of the APIs in [step 1](#1-make-sure-the-services-apis-are-enabled) is enabled. The test needs at least one service it can read: grant the roles and enable the APIs for the services you use. Services you do not use can be switched off afterwards, on the **Collect** step or the Edit panel's **Collection** tab |
| One service is reported as not readable on every run | Its role was not granted, or its API is not enabled. Fix it in Google Cloud, or switch that service off on the Edit panel's **Collection** tab, then **Re-sync** |
| Keys are listed, but none has a rotation schedule | **Key rotation** is off, or the keys have no automatic rotation set. Only symmetric encryption keys support automatic rotation in Cloud KMS |
| Storage encryption reports a bucket as not found | The bucket name is misspelled, or the bucket was deleted |
| Certificates and keys arrive with no owner | They carry none of the labels in **Owner label keys** |
| Collection worked, then stopped | The key was deleted or disabled in Google Cloud. Create a new key, enter it under **Replace credential**, then **Re-sync** |

If a problem persists, contact Axiad support with the connector name and the
time of the failed collection.
