# Google Cloud Storage

Have each new build of VPNDetection's databases written to your Google Cloud Storage bucket by a service account you grant, once a file proves it's yours.

VPNDetection writes each new build of the databases you choose to a Google Cloud Storage bucket of yours, as its service account `delivery@vpndetection-io.iam.gserviceaccount.com`. There's no key to create or hand over: you grant that account access to the bucket. What lands in it, and when, is on [Database Delivery](/integrations/database-delivery#what-a-storage-destination-receives).

Every customer grants the same account, so before writing anywhere VPNDetection checks that the bucket is yours: it has to hold a verification file with a token that only your destination knows. That check keeps another organization from pointing its destination at your bucket.

## Before you begin

- The **Manage database delivery** permission in your organization, which owners and admins have.
- A license for at least one database. Every organization holds the Open databases from the start.
- The bucket, the `gcloud` CLI, and the right to change the bucket's IAM policy and to write to it.

## 1. Add the destination

In the [console](https://app.vpndetection.io/database/delivery), under **Database** > **Delivery**, click **Add destination** and pick **Google Cloud Storage**.

## 2. Enter the bucket

Under **Connection**, enter the **Bucket** and the **Folder** to deliver to, then click **Save**. The destination then shows both commands below with your bucket, folder and token filled in. Here the bucket is `acme-data` and the folder `databases`.

## 3. Let the service account write to the bucket

Grant the service account a role on the bucket:

```bash
gcloud storage buckets add-iam-policy-binding gs://acme-data \
  --member=serviceAccount:delivery@vpndetection-io.iam.gserviceaccount.com \
  --role=roles/storage.objectUser
```

`roles/storage.objectUser` is the narrowest predefined role that can replace an object, which Cloud Storage counts as a delete. Both uniform and fine-grained access control work, since VPNDetection sets no ACLs on what it writes.

## 4. Prove the bucket is yours

Put the destination's token in the folder, as `.vpndetection-verify`:

```bash
echo -n vpndetection-1a2b3c4d5e6f7a8b9c0d1e2f | gcloud storage cp - gs://acme-data/databases/.vpndetection-verify
```

Leave the verification file in place, since each test reads it again.

## 5. Choose the databases and files

Under **Databases**, tick each database in the formats you want, **CSV**, **MMDB** or both. Under **Files**, choose **Latest only** to keep one copy of each file, or **Every build** to keep a dated folder per build, then click **Save**.

## 6. Test and activate

Click **Test connection**. It reads the verification file, writes `vpndetection-connection-test.txt` and deletes it, and **Activate** opens once it passes. The current build goes out first once you activate.

## Verify that a build arrived

A small database lands within a pass or two of activating, and a large one takes as long as its transfer. To confirm it, open the destination's **History** tab: each file sent reads **New build** under **Why** and **Delivered** under **Result**, and the destination's row shows the time under **Last delivered**.

In the bucket's folder, each file sits beside its `.sha256`, and `manifest.json` lists them all. Download a file and its `.sha256` together, and `sha256sum -c vpn_ip_v1.mmdb.sha256` confirms that it's intact.

## When delivery fails

The test result and the **Detail** column in **History** say what failed, in words, and a `database.delivery_failed` event carries the same failure as an `error_code`. The common ones are these:

| `error_code` | Cause | What to do |
| --- | --- | --- |
| `VERIFY_MISSING` | The verification file isn't in the bucket's folder yet. | Write it as step 4 shows, into the folder the destination names. |
| `VERIFY_MISMATCH` | The verification file doesn't hold this destination's token. | Write the token this destination shows, since each destination has its own. |
| `ACCESS_DENIED` | The service account can't write to that bucket or folder. | Grant it `roles/storage.objectUser` on the bucket, as step 3 shows. |
| `BUCKET_NOT_FOUND` | The bucket doesn't exist. | Check the bucket's name. |

A failed delivery is tried again on a schedule, and after three days of failures the destination is paused until someone resumes it, as [When delivery fails](/integrations/database-delivery#when-delivery-fails) explains.

## Next steps

Your bucket now receives each new build of the databases you chose. To act on each delivery as it lands, add a [webhook](/integrations/webhooks) and watch for `database.delivered`, or point a job at `manifest.json`, which changes only once a whole pass is in place.
