Skip to content

Commit 1d43b39

Browse files
committed
build yaml with vars
1 parent c5bed2f commit 1d43b39

2 files changed

Lines changed: 33 additions & 21 deletions

File tree

main.tf

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,27 @@ terraform {
1515
}
1616
}
1717

18+
data "google_client_openid_userinfo" "current" {}
19+
1820
locals {
1921
image_name = format("%s-docker.pkg.dev/%s/%s/vault-server:latest", var.country, var.project, var.repository)
2022
vault_proxy = "jcorall/vault-proxy:main"
2123
kms_key = "vault"
24+
25+
# see https://github.com/libops/vault-proxy/blob/main/config.example.yaml
26+
vault_proxy_config = {
27+
vault_addr = "http://127.0.0.1:8200"
28+
port = 8080
29+
admin_emails = concat(
30+
var.admin_emails,
31+
[data.google_client_openid_userinfo.current.email]
32+
)
33+
public_routes = concat(
34+
var.public_routes,
35+
["/v1/sys/health"] # Essential for health checks
36+
)
37+
}
38+
vault_proxy_yaml = yamlencode(local.vault_proxy_config)
2239
}
2340

2441
## Create the GSA the Vault CloudRun deployment will run as
@@ -146,7 +163,7 @@ module "vault" {
146163
},
147164
{
148165
name = "VAULT_PROXY_YAML"
149-
value = replace(var.vault_proxy_yaml, "__GCLOUD_PROJECT__", var.project)
166+
value = local.vault_proxy_yaml
150167
}
151168
])
152169

variables.tf

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,19 @@ variable "country" {
3131
default = "us"
3232
}
3333

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
34+
variable "admin_emails" {
35+
description = "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."
36+
type = list(string)
37+
default = []
38+
}
39+
40+
variable "public_routes" {
41+
description = "List of Vault API paths that should be accessible without X-Admin-Token header."
42+
type = list(string)
43+
default = [
44+
"/.well-known/",
45+
"/v1/identity/oidc/",
46+
"/v1/auth/oidc/",
47+
"/v1/auth/userpass/",
48+
]
5449
}

0 commit comments

Comments
 (0)