Skip to content

Commit c5bed2f

Browse files
committed
Put proxy in front of vault
1 parent 7dc82e2 commit c5bed2f

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

main.tf

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ terraform {
1616
}
1717

1818
locals {
19-
image_name = format("%s-docker.pkg.dev/%s/%s/vault-server:latest", var.country, var.project, var.repository)
20-
kms_key = "vault"
19+
image_name = format("%s-docker.pkg.dev/%s/%s/vault-server:latest", var.country, var.project, var.repository)
20+
vault_proxy = "jcorall/vault-proxy:main"
21+
kms_key = "vault"
2122
}
2223

2324
## Create the GSA the Vault CloudRun deployment will run as
@@ -78,6 +79,10 @@ resource "docker_registry_image" "vault" {
7879
}
7980
}
8081

82+
data "docker_registry_image" "vault-proxy" {
83+
name = local.vault_proxy
84+
}
85+
8186
## Create KMS keys
8287
resource "google_kms_key_ring" "vault-server" {
8388
name = "vault-server"
@@ -115,10 +120,16 @@ module "vault" {
115120
min_instances = 0
116121
max_instances = 1
117122
containers = tolist([
123+
{
124+
name = "proxy",
125+
image = format("%s@%s", local.vault_proxy, data.docker_registry_image.vault-proxy.sha256_digest)
126+
port = 8080
127+
memory = "512Mi"
128+
cpu = "500m"
129+
},
118130
{
119131
name = "vault",
120132
image = format("%s@%s", local.image_name, docker_registry_image.vault.sha256_digest)
121-
port = 8200
122133
memory = "2Gi"
123134
cpu = "2000m"
124135
}
@@ -132,10 +143,13 @@ module "vault" {
132143
{
133144
name = "GOOGLE_STORAGE_BUCKET"
134145
value = google_storage_bucket.vault["data"].name
146+
},
147+
{
148+
name = "VAULT_PROXY_YAML"
149+
value = replace(var.vault_proxy_yaml, "__GCLOUD_PROJECT__", var.project)
135150
}
136151
])
137152

138-
139153
depends_on = [google_kms_crypto_key_iam_member.vault, docker_registry_image.vault]
140154
}
141155

variables.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,25 @@ variable "country" {
3030
type = string
3131
default = "us"
3232
}
33+
34+
# e.g. https://github.com/libops/vault-proxy/blob/main/config.example.yaml
35+
variable "vault_proxy_yaml" {
36+
type = string
37+
sensitive = true
38+
default = <<EOT
39+
vault_addr: http://127.0.0.1:8200
40+
port: 8080
41+
admin_emails:
42+
- joe@libops.io
43+
- github@__GCLOUD_PROJECT__.iam.gserviceaccount.com
44+
- vault-server@__GCLOUD_PROJECT__.iam.gserviceaccount.com
45+
public_routes:
46+
- /.well-known/
47+
- /v1/identity/oidc/
48+
- /v1/auth/oidc/
49+
- /v1/auth/userpass/
50+
# this should always be set, as the docker healthcheck relies on it
51+
# the healthcheck checks both the proxy is working and vault is unsealed
52+
- /v1/sys/health
53+
EOT
54+
}

0 commit comments

Comments
 (0)