# breakglass-identity / gcp / t1 "Standard" # # Break-glass accounts with organisation rights, an alert on anything they do, # and a second alert when anyone changes an IAM grant that names them, which # is how someone would remove or borrow the access quietly. locals { members = [for a in var.break_glass_accounts : "user:${a}"] acted = join(" OR ", [for a in var.break_glass_accounts : "protoPayload.authenticationInfo.principalEmail=\"${a}\""]) named = join(" OR ", [for m in local.members : "protoPayload.serviceData.policyDelta.bindingDeltas.member=\"${m}\""]) iam_about = "protoPayload.methodName:\"SetIamPolicy\" AND (${local.named})" detections = { used = { filter = "(${local.acted})", doc = "A break-glass account acted." } changed = { filter = local.iam_about, doc = "Someone changed an IAM grant that names a break-glass account." } } } resource "google_organization_iam_member" "break_glass" { for_each = toset(local.members) org_id = var.org_id role = "roles/resourcemanager.organizationAdmin" member = each.value } resource "google_logging_project_bucket_config" "break_glass" { project = var.security_project location = "global" bucket_id = "break-glass-activity" retention_days = var.retention_days locked = false description = "Everything the break-glass accounts did, and every IAM change that names them." } resource "google_logging_organization_sink" "break_glass" { org_id = var.org_id name = "break-glass-activity" destination = "logging.googleapis.com/${google_logging_project_bucket_config.break_glass.id}" filter = "(${local.acted}) OR (${local.iam_about})" include_children = true } resource "google_project_iam_member" "sink_writes" { project = var.security_project role = "roles/logging.bucketWriter" member = google_logging_organization_sink.break_glass.writer_identity } resource "google_logging_metric" "detection" { for_each = local.detections project = var.security_project name = "break-glass-${each.key}" bucket_name = google_logging_project_bucket_config.break_glass.id filter = each.value.filter metric_descriptor { metric_kind = "DELTA" value_type = "INT64" } } resource "google_monitoring_notification_channel" "email" { for_each = toset(var.alert_emails) project = var.security_project display_name = "Break-glass alerts: ${each.value}" type = "email" labels = { email_address = each.value } } resource "google_monitoring_alert_policy" "detection" { for_each = local.detections project = var.security_project display_name = "Break-glass: ${each.key}" combiner = "OR" notification_channels = [for c in google_monitoring_notification_channel.email : c.id] conditions { display_name = each.value.doc condition_threshold { filter = "metric.type=\"logging.googleapis.com/user/${google_logging_metric.detection[each.key].name}\"" comparison = "COMPARISON_GT" threshold_value = 0 duration = "0s" aggregations { alignment_period = "60s" per_series_aligner = "ALIGN_SUM" cross_series_reducer = "REDUCE_SUM" } } } documentation { content = "${each.value.doc} Open the break-glass-activity bucket in ${var.security_project} to see the entry." } }