監査設定の変更ログとアラートの確認

監査対象の変更を記録し、必要な運用担当者に通知してください。

説明

Google Cloud で監査対象の設定が変更されたら、運用担当者に通知するようにします。

想定される影響

監査範囲の縮小に気付くのが遅れると、その間の操作を調査するための記録が不足します。

対処方法

実際の監査ログで SetIamPolicy と auditConfigDeltas を確認し、該当する項目をログベースの指標で数えます。アラート条件からその指標を参照し、notification_channels に通知先を設定します。承認済みの変更でログ、指標のカウント、通知を確認します。

例

最初の例はメソッド名が誤っており、アラート条件も不完全です。変更後の var.audit_monitored_resource_type には指標に現れるリソースタイプを指定し、取り込みの遅延に合わせて 10 分間の集計窓を調整します。

変更前

hcl
resource "google_logging_metric" "audit_config_change" {
  name        = "audit_config_change"
  description = "Detects changes to audit configurations via SetIamPolicy"
  filter      = "protoPayload.methodName=\"wrong_method\" AND protoPayload.serviceData.policyDelta.auditConfigDeltas:*"
}

resource "google_monitoring_alert_policy" "audit_config_alert" {
  display_name = "Audit Config Change Alert"
  combiner     = "OR"

  conditions {
    display_name = "Audit Config Change Condition"

    condition_threshold {
      filter = "resource.type=\"gce_instance\" AND metric.type=\"logging.googleapis.com/user/audit_config_change\""
    }
  }
}

変更後

hcl
resource "google_logging_metric" "audit_config_change" {
  name        = "audit_config_change"
  description = "Detects changes to audit configurations via SetIamPolicy"
  filter      = "protoPayload.methodName=\"SetIamPolicy\" AND protoPayload.serviceData.policyDelta.auditConfigDeltas:*"
}

resource "google_monitoring_alert_policy" "audit_config_alert" {
  display_name          = "Audit Config Change Alert"
  combiner              = "OR"
  notification_channels = [google_monitoring_notification_channel.security_ops.name]

  conditions {
    display_name = "Matching audit events"
    condition_threshold {
      filter = "metric.type=\"logging.googleapis.com/user/${google_logging_metric.audit_config_change.name}\" AND resource.type=\"${var.audit_monitored_resource_type}\""
      comparison      = "COMPARISON_GT"
      threshold_value = 0
      duration        = "0s"
      aggregations {
        alignment_period   = "600s"
        per_series_aligner = "ALIGN_SUM"
      }
    }
  }
}

参考資料