-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
122 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
resource "vault_mount" "kv_v1" { | ||
path = "kv-v1" | ||
path = "secret" | ||
type = "kv" | ||
|
||
options = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
# allow GCP auth access to paths in the GSA's project | ||
# https://developer.hashicorp.com/vault/api-docs/auth/gcp#sample-payload-5 | ||
resource "vault_policy" "project-read-kv" { | ||
name = "kv-v1-per-project" | ||
locals { | ||
policy_files = fileset("policies", "*.hcl") | ||
} | ||
|
||
data "local_file" "policy_docs" { | ||
for_each = local.policy_files | ||
filename = "policies/${each.value}" | ||
} | ||
|
||
resource "vault_policy" "policies" { | ||
for_each = data.local_file.policy_docs | ||
|
||
policy = <<-EOT | ||
path "kv-v1/{{identity.entity.metadata.project_id}}/*" { | ||
capabilities = ["create", "read", "update", "delete", "list"] | ||
} | ||
EOT | ||
name = basename(replace(each.value.filename, ".hcl", "")) | ||
policy = each.value.content | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
resource "vault_jwt_auth_backend" "gsuite" { | ||
path = "jwt" | ||
oidc_discovery_url = "https://accounts.google.com" | ||
bound_issuer = "https://accounts.google.com" | ||
default_role = "default" | ||
} | ||
|
||
resource "vault_jwt_auth_backend_role" "admin" { | ||
backend = vault_jwt_auth_backend.gsuite.path | ||
role_type = "jwt" | ||
role_name = "admin" | ||
user_claim = "email" | ||
bound_audiences = [ | ||
"32555940559.apps.googleusercontent.com" | ||
] | ||
bound_claims = { | ||
email = "[email protected]" | ||
} | ||
token_policies = [ | ||
vault_policy.policies["admin.hcl"].name, | ||
vault_policy.policies["ci.hcl"].name | ||
] | ||
} | ||
|
||
resource "vault_jwt_auth_backend_role" "ci" { | ||
backend = vault_jwt_auth_backend.gsuite.path | ||
role_type = "jwt" | ||
role_name = "ci" | ||
user_claim = "email" | ||
bound_audiences = [ | ||
"vault/ci" | ||
] | ||
bound_claims = { | ||
email = local.ci_gsa | ||
} | ||
token_policies = [ | ||
vault_policy.policies["ci.hcl"].name | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
path "secret/*" { | ||
capabilities = ["create", "read", "update", "delete", "list"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
path "auth/token/create" { | ||
capabilities = ["update"] | ||
} | ||
|
||
path "auth/*" { | ||
capabilities = ["create", "read", "update", "delete", "list"] | ||
} | ||
|
||
path "sys/policies/acl/*" { | ||
capabilities = ["create", "read", "update", "delete", "list"] | ||
} | ||
|
||
path "sys/auth/*" { | ||
capabilities = ["create", "read", "update", "delete", "list"] | ||
} | ||
|
||
path "sys/mounts/*" { | ||
capabilities = ["create", "read", "update", "delete", "list"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
path "secret/{{identity.entity.metadata.project_id}}/*" { | ||
capabilities = ["create", "read", "update", "delete", "list"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
ROLE="${1:-admin}" | ||
ID_TOKEN="${2:-$(gcloud auth print-identity-token)}" | ||
|
||
export VAULT_TOKEN=$(vault write -format=json "auth/jwt/login" \ | ||
role="$ROLE" \ | ||
jwt="$ID_TOKEN" \ | ||
| jq -r .auth.client_token) | ||
|
||
terraform init -upgrade | ||
if [ "$ROLE" = "ci" ]; then | ||
terraform apply -auto-approve | ||
else | ||
terraform apply | ||
fi |