Skip to content

Commit

Permalink
Move FAST security delegated admins to iam_bindings_additive
Browse files Browse the repository at this point in the history
  • Loading branch information
juliocc committed Sep 16, 2023
1 parent 61da9d1 commit 9b874d8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
27 changes: 6 additions & 21 deletions fast/stages/2-security/core-dev.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ module "dev-sec-project" {
iam = {
"roles/cloudkms.viewer" = local.dev_kms_restricted_admins
}
iam_bindings_additive = {
for member in local.dev_kms_restricted_admins :
"kms_restricted_admin.${member}" => merge(local.kms_restricted_admin_template, {
member = member
})
}
labels = { environment = "dev", team = "security" }
services = local.project_services
}
Expand All @@ -47,24 +53,3 @@ module "dev-sec-kms" {
}
keys = local.kms_locations_keys[each.key]
}

# TODO(ludo): add support for conditions to Fabric modules

resource "google_project_iam_member" "dev_key_admin_delegated" {
for_each = toset(local.dev_kms_restricted_admins)
project = module.dev-sec-project.project_id
role = "roles/cloudkms.admin"
member = each.key
condition {
title = "kms_sa_delegated_grants"
description = "Automation service account delegated grants."
expression = format(
"api.getAttribute('iam.googleapis.com/modifiedGrantsByRole', []).hasOnly([%s]) && resource.type == 'cloudkms.googleapis.com/CryptoKey'",
join(",", formatlist("'%s'", [
"roles/cloudkms.cryptoKeyEncrypterDecrypter",
"roles/cloudkms.cryptoKeyEncrypterDecrypterViaDelegation"
]))
)
}
depends_on = [module.dev-sec-project]
}
32 changes: 14 additions & 18 deletions fast/stages/2-security/core-prod.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ module "prod-sec-project" {
iam = {
"roles/cloudkms.viewer" = local.prod_kms_restricted_admins
}
iam_bindings_additive = {
for member in local.prod_kms_restricted_admins :
"kms_restricted_admin.${member}" => merge(local.kms_restricted_admin_template, {
member = member
})
}
labels = { environment = "prod", team = "security" }
services = local.project_services
}
Expand All @@ -49,21 +55,11 @@ module "prod-sec-kms" {

# TODO(ludo): add support for conditions to Fabric modules

resource "google_project_iam_member" "prod_key_admin_delegated" {
for_each = toset(local.prod_kms_restricted_admins)
project = module.prod-sec-project.project_id
role = "roles/cloudkms.admin"
member = each.key
condition {
title = "kms_sa_delegated_grants"
description = "Automation service account delegated grants."
expression = format(
"api.getAttribute('iam.googleapis.com/modifiedGrantsByRole', []).hasOnly([%s]) && resource.type == 'cloudkms.googleapis.com/CryptoKey'",
join(",", formatlist("'%s'", [
"roles/cloudkms.cryptoKeyEncrypterDecrypter",
"roles/cloudkms.cryptoKeyEncrypterDecrypterViaDelegation"
]))
)
}
depends_on = [module.prod-sec-project]
}
# resource "google_project_iam_member" "prod_key_admin_delegated" {
# for_each = toset(local.prod_kms_restricted_admins)
# project = module.prod-sec-project.project_id
# role = "roles/cloudkms.admin"
# member = each.key
# // condition
# depends_on = [module.prod-sec-project]
# }
19 changes: 19 additions & 0 deletions fast/stages/2-security/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@
*/

locals {
# additive IAM binding for delegated KMS admins
kms_restricted_admin_template = {
role = "roles/cloudkms.admin"
condition = {
title = "kms_sa_delegated_grants"
description = "Automation service account delegated grants."
expression = format(
<<-EOT
api.getAttribute('iam.googleapis.com/modifiedGrantsByRole', []).hasOnly([%s]) &&
resource.type == 'cloudkms.googleapis.com/CryptoKey'
EOT
, join(",", formatlist("'%s'", [
"roles/cloudkms.cryptoKeyEncrypterDecrypter",
"roles/cloudkms.cryptoKeyEncrypterDecrypterViaDelegation"
]))
)
}
}

# list of locations with keys
kms_locations = distinct(flatten([
for k, v in var.kms_keys : v.locations
Expand Down

0 comments on commit 9b874d8

Please sign in to comment.