# container-evidence / oci / t1 "Standard" # # Evidence from a compromised container on OKE: a bucket with a retention rule # you can schedule to lock, encrypted with your own key, responder groups that # can back up node volumes and add evidence but not read or delete it, and # capture.sh, which runs the steps in order and logs each one. # # Kubernetes rights come from the incident-responder cluster role in the # Kubernetes evidence template. Bind it to each responder group by OCID # (kind: Group, name: ). # # terraform output capture the command to run # terraform output verify checks on a test pod data "oci_containerengine_cluster" "this" { cluster_id = var.cluster_id } data "oci_objectstorage_namespace" "this" { compartment_id = local.evidence_compartment } locals { tags = merge({ owner = var.owner environment = var.environment data_classification = "restricted" managed_by = "terraform" }, var.extra_tags) cluster_compartment = data.oci_containerengine_cluster.this.compartment_id node_compartment = var.node_compartment_ocid != "" ? var.node_compartment_ocid : local.cluster_compartment evidence_compartment = var.evidence_compartment_ocid != "" ? var.evidence_compartment_ocid : local.cluster_compartment groups = [for g in var.responder_group_ocids : "group id ${g}"] } resource "random_id" "suffix" { byte_length = 3 } # Retention rules cannot be added to a bucket with versioning on, and a locked # rule blocks every delete and overwrite until each object is old enough. resource "oci_objectstorage_bucket" "evidence" { compartment_id = local.evidence_compartment namespace = data.oci_objectstorage_namespace.this.namespace name = "container-evidence-${random_id.suffix.hex}" access_type = "NoPublicAccess" storage_tier = "Standard" versioning = "Disabled" kms_key_id = oci_kms_key.evidence.id freeform_tags = local.tags retention_rules { display_name = "evidence-retention" duration { time_amount = var.retention_days time_unit = "DAYS" } # Empty means unlocked. A date means locked from that moment, permanently. time_rule_locked = var.lock_at == "" ? null : var.lock_at } lifecycle { prevent_destroy = true } depends_on = [oci_identity_policy.storage_uses_key] } # A policy only reaches its own compartment and those below it, so each # compartment gets its own. # Persistent volumes from the block volume CSI driver live in the cluster's # compartment, and their backups land beside them. resource "oci_identity_policy" "cluster" { compartment_id = local.cluster_compartment name = "container-evidence-${random_id.suffix.hex}-cluster" description = "Lets incident responders fetch a kubeconfig and back up persistent volumes. The incident-responder cluster role sets what they may do inside." freeform_tags = local.tags statements = flatten([for g in local.groups : [ "Allow ${g} to use clusters in compartment id ${local.cluster_compartment}", "Allow ${g} to use volumes in compartment id ${local.cluster_compartment}", "Allow ${g} to read volume-backups in compartment id ${local.cluster_compartment}", "Allow ${g} to manage volume-backups in compartment id ${local.cluster_compartment} where request.permission = 'VOLUME_BACKUP_CREATE'", ]]) } # Find a node's volumes and back them up: the grants in Oracle's own backup # example, less deleting backups. resource "oci_identity_policy" "nodes" { compartment_id = local.node_compartment name = "container-evidence-${random_id.suffix.hex}-nodes" description = "Lets incident responders read worker nodes and back up their volumes. No deletes." freeform_tags = local.tags statements = flatten([for g in local.groups : [ "Allow ${g} to read instances in compartment id ${local.node_compartment}", "Allow ${g} to inspect volume-attachments in compartment id ${local.node_compartment}", "Allow ${g} to use volumes in compartment id ${local.node_compartment}", "Allow ${g} to read boot-volume-backups in compartment id ${local.node_compartment}", "Allow ${g} to manage boot-volume-backups in compartment id ${local.node_compartment} where request.permission = 'BOOT_VOLUME_BACKUP_CREATE'", "Allow ${g} to read volume-backups in compartment id ${local.node_compartment}", "Allow ${g} to manage volume-backups in compartment id ${local.node_compartment} where request.permission = 'VOLUME_BACKUP_CREATE'", ]]) } # Add objects and list their names. Not read, overwrite, or delete them. resource "oci_identity_policy" "evidence" { compartment_id = local.evidence_compartment name = "container-evidence-${random_id.suffix.hex}-bucket" description = "Lets incident responders add evidence to the bucket. Not read, overwrite, or delete it." freeform_tags = local.tags statements = flatten([for g in local.groups : [ "Allow ${g} to read buckets in compartment id ${local.evidence_compartment} where target.bucket.name = '${oci_objectstorage_bucket.evidence.name}'", "Allow ${g} to manage objects in compartment id ${local.evidence_compartment} where all {target.bucket.name = '${oci_objectstorage_bucket.evidence.name}', any {request.permission = 'OBJECT_CREATE', request.permission = 'OBJECT_INSPECT'}}", ]]) }