Fork of kelseyhightower/serverless-vault-with-cloud-run, reimagined as a terraform module to deploy Vault using Google Cloud Run.
In your existing terraform code, add something like what's seen in the example
The GCP project needs the following non-standard APIs enabled:
- Artifact Registry API
- Cloud Run API
- Google Cloud KMS API
- Identity and Access Management (IAM) API
After this module has been ran, the Vault server is up and running and has been initialized. The root token is encrypted in a GCS bucket.
If you list the GCS storage bucket you will see a new set of directories created by Vault:
$ gsutil ls gs://${TF_VAR_project}-data
gs://XXXXXX-data/core/
gs://XXXXXX-data/logical/
gs://XXXXXX-data/sys/
Vault can be configured using the Vault UI by visiting the vault-server service URL in browser:
gcloud run services describe vault-server \
--platform managed \
--region ${TF_VAR_region} \
--project ${TF_VAR_project} \
--format 'value(status.url)'
You can also use the vault command line tool as described in the next section.
Download the Vault binary and add it to your path:
$ vault version
Vault v1.12.3 (209b3dd99fe8ca320340d08c70cff5f620261f9b), built 2023-02-02T09:07:27Z
Configure the vault CLI to use the vault-server Cloud Run service URL by setting the VAULT_ADDR environment variable:
export VAULT_ADDR=$(gcloud run services describe vault-server \
--platform managed \
--region ${TF_VAR_region} \
--project ${TF_VAR_project} \
--format 'value(status.url)')
We also need to set the VAULT_TOKEN
gsutil cp gs://${TF_VAR_project}-key/root-token.enc . > /dev/null 2>&1
base64 -d root-token.enc > root-token.dc
gcloud kms decrypt --key=vault --keyring=vault-server --location=global \
--project=${TF_VAR_project} \
--ciphertext-file=root-token.dc \
--plaintext-file=root-token
export VAULT_TOKEN=$(cat root-token)
rm root-token root-token.enc root-token.dc
Now you can retrieve the status of the remote Vault server:
$ vault status
Key Value
--- -----
Recovery Seal Type shamir
Initialized true
Sealed false
Total Recovery Shares 1
Threshold 1
Version 1.12.3
Build Date 2023-02-02T09:07:27Z
Storage Type gcs
Cluster Name vault-cluster-XXXXXXXX
Cluster ID XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
HA Enabled false
| Name | Version |
|---|---|
| docker | >= 3.0.1 |
| >= 7.22.0 | |
| google-beta | >= 7.22.0 |
| Name | Version |
|---|---|
| docker | >= 3.0.1 |
| >= 7.22.0 | |
| google-beta | >= 7.22.0 |
| Name | Source | Version |
|---|---|---|
| vault | git::https://github.com/libops/terraform-cloudrun-v2 | 0.3.4 |
| Name | Type |
|---|---|
| docker_image.vault | resource |
| docker_registry_image.vault | resource |
| google-beta_google_cloud_run_v2_job.vault-init | resource |
| google_artifact_registry_repository.private | resource |
| google_kms_crypto_key.key | resource |
| google_kms_crypto_key_iam_member.vault | resource |
| google_kms_key_ring.vault-server | resource |
| google_service_account.gsa | resource |
| google_storage_bucket.vault | resource |
| google_storage_bucket_iam_member.member | resource |
| docker_registry_image.vault-proxy | data source |
| google_artifact_registry_repository.my-repo | data source |
| google_client_openid_userinfo.current | data source |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| admin_emails | List of emails (users or service accounts) that are allowed to access non-public routes by passing X-Admin-Token header with a google access token. | list(string) |
[] |
no |
| country | n/a | string |
"us" |
no |
| create_repository | Whether or not the AR repo needs to be created by this terraform | bool |
true |
no |
| init_image | n/a | string |
"libops/vault-init:1.0.0" |
no |
| project | The GCP project to create or deploy the GCP resources into | string |
n/a | yes |
| public_routes | List of Vault API paths that should be accessible without X-Admin-Token header. | list(string) |
[ |
no |
| region | The region to deploy CloudRun | string |
"us-east5" |
no |
| repository | The AR repo to create or push the vault image into | string |
"private" |
no |
| Name | Description |
|---|---|
| gsa | The GSA the Vault instance runs as. |
| key_bucket | n/a |
| repo | n/a |
| vault-url | The URL to the Vault instance. |
