# siem-ingest / oci / t1 "Standard" # # Every audit event in the tenancy, plus any other logs you name, copied into # a stream in a pool of its own with the Kafka API on, optionally encrypted # with your own key, read by the SIEM's group only, and an email when the # connector fails to write or falls behind. locals { tags = merge({ owner = var.owner environment = var.environment data_classification = "restricted" managed_by = "terraform" }, var.extra_tags) } resource "oci_streaming_stream_pool" "siem" { compartment_id = var.compartment_ocid name = "siem" freeform_tags = local.tags kafka_settings { auto_create_topics_enable = false log_retention_hours = 168 } dynamic "custom_encryption_key" { for_each = var.kms_key_id == "" ? [] : [var.kms_key_id] content { kms_key_id = custom_encryption_key.value } } } # Seven days is the most a stream keeps. A SIEM outage longer than that loses # events. resource "oci_streaming_stream" "siem" { name = "siem-events" stream_pool_id = oci_streaming_stream_pool.siem.id partitions = var.partitions retention_in_hours = 168 freeform_tags = local.tags } resource "oci_identity_policy" "siem" { compartment_id = var.tenancy_ocid name = "siem-ingest" description = "Lets the SIEM connector write to its stream, and the SIEM group read it." freeform_tags = local.tags statements = [ "Allow any-user to use stream-push in compartment id ${var.compartment_ocid} where all {request.principal.type='serviceconnector', target.stream.id='${oci_streaming_stream.siem.id}', request.principal.compartment.id='${var.compartment_ocid}'}", "Allow group ${var.siem_group} to use stream-pull in compartment id ${var.compartment_ocid} where target.stream.id='${oci_streaming_stream.siem.id}'", "Allow group ${var.siem_group} to read streams in compartment id ${var.compartment_ocid}", "Allow group ${var.siem_group} to read stream-pools in compartment id ${var.compartment_ocid}", ] } resource "oci_sch_service_connector" "siem" { compartment_id = var.compartment_ocid display_name = "siem-events" description = "Copies audit events and the named logs to the SIEM stream." freeform_tags = local.tags source { kind = "logging" log_sources { compartment_id = var.tenancy_ocid log_group_id = "_Audit_Include_Subcompartment" } dynamic "log_sources" { for_each = var.extra_log_sources content { compartment_id = log_sources.value.compartment_id log_group_id = log_sources.value.log_group_id log_id = log_sources.value.log_id == "" ? null : log_sources.value.log_id } } } target { kind = "streaming" stream_id = oci_streaming_stream.siem.id } depends_on = [oci_identity_policy.siem] } # --------------------------------------------------------------------------- # An email when the connector fails to write or falls behind # --------------------------------------------------------------------------- # Deleting this topic stops both alarms, and neither can report it. The # daily drift plan in Hardened is what notices. resource "oci_ons_notification_topic" "siem" { compartment_id = var.compartment_ocid name = "siem-ingest" description = "Problems with the SIEM connector." freeform_tags = local.tags } resource "oci_ons_subscription" "email" { compartment_id = var.compartment_ocid topic_id = oci_ons_notification_topic.siem.id protocol = "EMAIL" endpoint = var.alert_email freeform_tags = local.tags } locals { alarms = { write-errors = { summary = "The SIEM connector could not write to its stream." query = "ErrorsAtTarget[5m]{connectorId = \"${oci_sch_service_connector.siem.id}\"}.sum() > 0" } # DataFreshness is the age of the newest record moved, in milliseconds. falling-behind = { summary = "The newest event the SIEM connector moved is more than 15 minutes old." query = "DataFreshness[5m]{connectorId = \"${oci_sch_service_connector.siem.id}\"}.max() > 900000" } } } resource "oci_monitoring_alarm" "connector" { for_each = local.alarms compartment_id = var.compartment_ocid metric_compartment_id = var.compartment_ocid display_name = "siem-ingest-${each.key}" alarm_summary = each.value.summary namespace = "oci_service_connector_hub" query = each.value.query severity = "CRITICAL" pending_duration = "PT5M" is_enabled = true destinations = [oci_ons_notification_topic.siem.id] freeform_tags = local.tags }