# guardrail-baseline / gcp / t1 "Standard" # # A set of organisation policy constraints for an organisation, a folder, or a # project. Starts in dry run, so you can see what each would block before it # blocks anything. locals { # Boolean constraints: on or off. enforced = { "iam.disableServiceAccountKeyCreation" = "No new service account keys" "iam.disableServiceAccountKeyUpload" = "No uploading your own service account keys" "iam.automaticIamGrantsForDefaultServiceAccounts" = "Default service accounts are not made project editors" "storage.publicAccessPrevention" = "No public buckets" "storage.uniformBucketLevelAccess" = "One permission model per bucket" "compute.requireOsLogin" = "SSH only through OS Login" "compute.skipDefaultNetworkCreation" = "New projects start with no default network" "sql.restrictPublicIp" = "No public IP on Cloud SQL" } } resource "google_org_policy_policy" "enforced" { for_each = local.enforced name = "${var.parent}/policies/${each.key}" parent = var.parent dynamic "spec" { for_each = var.dry_run ? [] : [1] content { rules { enforce = "TRUE" } } } dynamic "dry_run_spec" { for_each = var.dry_run ? [1] : [] content { rules { enforce = "TRUE" } } } } resource "google_org_policy_policy" "no_external_ips" { name = "${var.parent}/policies/compute.vmExternalIpAccess" parent = var.parent dynamic "spec" { for_each = var.dry_run ? [] : [1] content { rules { deny_all = "TRUE" } } } dynamic "dry_run_spec" { for_each = var.dry_run ? [1] : [] content { rules { deny_all = "TRUE" } } } } # Stops access being granted to accounts outside your own directory, such as a # personal Gmail address added by mistake or by an attacker. resource "google_org_policy_policy" "member_domains" { count = length(var.allowed_member_customer_ids) > 0 ? 1 : 0 name = "${var.parent}/policies/iam.allowedPolicyMemberDomains" parent = var.parent dynamic "spec" { for_each = var.dry_run ? [] : [1] content { rules { values { allowed_values = var.allowed_member_customer_ids } } } } dynamic "dry_run_spec" { for_each = var.dry_run ? [1] : [] content { rules { values { allowed_values = var.allowed_member_customer_ids } } } } } resource "google_org_policy_policy" "locations" { count = length(var.allowed_locations) > 0 ? 1 : 0 name = "${var.parent}/policies/gcp.resourceLocations" parent = var.parent dynamic "spec" { for_each = var.dry_run ? [] : [1] content { rules { values { allowed_values = var.allowed_locations } } } } dynamic "dry_run_spec" { for_each = var.dry_run ? [1] : [] content { rules { values { allowed_values = var.allowed_locations } } } } }