# Object reads on the buckets you name, request by request, with the caller. # The Audit service does not record object reads; Object Storage's read log # does, and it is billed by volume. It carries no byte count, so a bulk # download is counted in objects. locals { reads = length(var.sensitive_buckets) > 0 buckets = { for b in var.sensitive_buckets : "${b.compartment_ocid}/${b.bucket_name}" => b } } resource "oci_logging_log_group" "reads" { count = local.reads ? 1 : 0 compartment_id = var.tenancy_ocid display_name = "insider-data-theft-reads" description = "Object reads on the sensitive buckets" freeform_tags = local.tags } resource "oci_logging_log" "reads" { for_each = local.buckets display_name = "reads-${substr(replace(each.value.bucket_name, "/[^A-Za-z0-9_-]/", "-"), 0, 50)}-${substr(sha1(each.key), 0, 6)}" log_group_id = oci_logging_log_group.reads[0].id log_type = "SERVICE" is_enabled = true retention_duration = var.read_retention_days freeform_tags = local.tags configuration { compartment_id = each.value.compartment_ocid source { category = "read" resource = each.value.bucket_name service = "objectstorage" source_type = "OCISERVICE" } } } # Every GET of an object counts once, with the caller as a dimension. resource "oci_sch_service_connector" "reads" { count = local.reads ? 1 : 0 compartment_id = var.tenancy_ocid display_name = "insider-object-reads" description = "Counts object reads on the sensitive buckets into a metric" state = "ACTIVE" freeform_tags = local.tags source { kind = "logging" log_sources { compartment_id = var.tenancy_ocid log_group_id = oci_logging_log_group.reads[0].id } } tasks { kind = "logRule" condition = "data.requestAction='GET'" } target { kind = "monitoring" compartment_id = var.tenancy_ocid metric_namespace = local.namespace metric = "object_reads" dimensions { name = "principal" dimension_value { kind = "jmesPath" path = "logContent.data.principalName" } } } depends_on = [oci_identity_policy.connector] } resource "oci_monitoring_alarm" "bulk_read" { count = local.reads ? 1 : 0 compartment_id = var.tenancy_ocid metric_compartment_id = var.tenancy_ocid display_name = "insider-bulk-read" namespace = local.namespace query = "object_reads[5m]${local.exclude}.groupBy(principal).count() > ${var.bulk_read_threshold}" severity = "CRITICAL" is_enabled = true is_notifications_per_metric_dimension_enabled = true destinations = [oci_ons_notification_topic.insider.id] message_format = "ONS_OPTIMIZED" body = "One principal read more than ${var.bulk_read_threshold} objects from the sensitive buckets in five minutes. The saved search insider-bulk-read shows who, from where, and which buckets." freeform_tags = local.tags }