# forensic-workstation / oci / t1 "Standard" # # The quick start's isolated network, plus: every flow recorded, an alert the # moment the workstation tries to reach anything it may not, several analysts, # a key of your own on the boot volume, and a bastion that injects nothing. data "oci_identity_availability_domains" "this" { compartment_id = var.tenancy_ocid } data "oci_core_services" "all" {} locals { tags = merge({ owner = var.owner environment = var.environment data_classification = "restricted" managed_by = "terraform" }, var.extra_tags) availability_domain = data.oci_identity_availability_domains.this.availability_domains[0].name evidence_compartment = var.evidence_compartment_ocid != "" ? var.evidence_compartment_ocid : var.compartment_ocid # A service gateway takes one service CIDR label. Object Storage alone would # be narrower. An instance principal has to reach the identity service to turn # its certificate into a token, and that address sits outside the Object # Storage label. A bastion needs the gateway too. So the whole Oracle Services # Network is reachable on 443, which includes Object Storage in any tenancy: # a pre-authenticated request needs no credentials, so that is a way out for # anything running here. Treat the machine as able to reach Oracle, and the # read-only volume as the path for evidence you will not risk. osn = [for s in data.oci_core_services.all.services : s if length(regexall("^all-[a-z0-9-]+-services-in-oracle-services-network$", s.cidr_block)) > 0][0] metric_namespace = "forensic_workstation" reject_metric = "refused_egress" } resource "oci_core_vcn" "forensics" { compartment_id = var.compartment_ocid display_name = "forensics-isolated" cidr_blocks = [var.cidr] dns_label = "forensics" freeform_tags = local.tags } resource "oci_core_service_gateway" "osn" { compartment_id = var.compartment_ocid vcn_id = oci_core_vcn.forensics.id display_name = "forensics-oracle-services" freeform_tags = local.tags services { service_id = local.osn.id } } resource "oci_core_route_table" "forensics" { compartment_id = var.compartment_ocid vcn_id = oci_core_vcn.forensics.id display_name = "forensics-oracle-services-only" freeform_tags = local.tags route_rules { destination = local.osn.cidr_block destination_type = "SERVICE_CIDR_BLOCK" network_entity_id = oci_core_service_gateway.osn.id description = "Oracle services over Oracle's own network. No internet route exists." } } resource "oci_core_security_list" "forensics" { compartment_id = var.compartment_ocid vcn_id = oci_core_vcn.forensics.id display_name = "forensics-isolated" freeform_tags = local.tags egress_security_rules { destination = local.osn.cidr_block destination_type = "SERVICE_CIDR_BLOCK" protocol = "6" description = "HTTPS to Oracle services, for the evidence and for the instance principal's token." tcp_options { min = 443 max = 443 } } # The bastion's own endpoint sits in this subnet, and its traffic to the # workstation is subject to these rules too. egress_security_rules { destination = var.cidr destination_type = "CIDR_BLOCK" protocol = "6" description = "SSH inside the subnet, so the bastion can reach the workstation." tcp_options { min = 22 max = 22 } } } resource "oci_core_subnet" "forensics" { compartment_id = var.compartment_ocid vcn_id = oci_core_vcn.forensics.id display_name = "forensics-isolated" cidr_block = var.cidr dns_label = "analysis" route_table_id = oci_core_route_table.forensics.id security_list_ids = [oci_core_security_list.forensics.id] prohibit_public_ip_on_vnic = true prohibit_internet_ingress = true freeform_tags = local.tags } resource "oci_core_network_security_group" "workstation" { compartment_id = var.compartment_ocid vcn_id = oci_core_vcn.forensics.id display_name = "forensic-workstation" freeform_tags = local.tags } resource "oci_core_network_security_group_security_rule" "ssh_from_bastion" { network_security_group_id = oci_core_network_security_group.workstation.id direction = "INGRESS" protocol = "6" source = "${oci_bastion_bastion.forensics.private_endpoint_ip_address}/32" source_type = "CIDR_BLOCK" description = "SSH from the bastion's own address, and nowhere else." tcp_options { destination_port_range { min = 22 max = 22 } } } resource "oci_bastion_bastion" "forensics" { compartment_id = var.compartment_ocid bastion_type = "standard" name = "forensics" target_subnet_id = oci_core_subnet.forensics.id client_cidr_block_allow_list = var.analyst_cidrs max_session_ttl_in_seconds = var.session_ttl_in_seconds dns_proxy_status = "DISABLED" freeform_tags = local.tags } # Every flow, allowed and refused, on the analysis subnet. resource "oci_logging_log_group" "forensics" { compartment_id = var.compartment_ocid display_name = "forensics" description = "Flow logs for the isolated analysis network" freeform_tags = local.tags } # A flow log needs a capture filter, and the filter needs at least one rule. # This one keeps everything, accepted and refused, at full rate. resource "oci_core_capture_filter" "flow" { compartment_id = var.compartment_ocid display_name = "forensics-all-flows" filter_type = "FLOWLOG" freeform_tags = local.tags flow_log_capture_filter_rules { priority = 0 rule_action = "INCLUDE" flow_log_type = "ALL" sampling_rate = 1 is_enabled = true } } resource "oci_logging_log" "flow" { display_name = "forensics-flow-logs" log_group_id = oci_logging_log_group.forensics.id log_type = "SERVICE" is_enabled = true retention_duration = var.log_retention_days freeform_tags = local.tags configuration { compartment_id = var.compartment_ocid source { category = "all" resource = oci_core_subnet.forensics.id service = "flowlogs" source_type = "OCISERVICE" parameters = { capture_filter = oci_core_capture_filter.flow.id enablementPointType = "Subnet" } } } } # A refused flow becomes a metric, and the metric becomes an alert. This sees # what the security list turned away. Traffic the rules allow, which means # HTTPS to Oracle's own services, is accepted and raises nothing. resource "oci_ons_notification_topic" "alerts" { compartment_id = var.compartment_ocid name = "forensic-workstation-alerts" description = "The workstation tried to reach something it may not" freeform_tags = local.tags } resource "oci_ons_subscription" "alerts" { for_each = toset(var.alert_emails) compartment_id = var.compartment_ocid topic_id = oci_ons_notification_topic.alerts.id protocol = "EMAIL" endpoint = each.value freeform_tags = local.tags } # A connector reads its source and writes its target as itself, so both ends # need naming in a policy. Deleting this policy or the topic stops the alarm, # and so does moving the connector to another compartment, which drops its # grant. Nothing reports it. The daily drift plan in Hardened is what notices. resource "oci_identity_policy" "connector" { compartment_id = var.compartment_ocid name = "forensic-workstation-connector" description = "Lets the refused-traffic connector read the flow log and write its metric." freeform_tags = local.tags statements = [ "Allow any-user to read log-content in compartment id ${var.compartment_ocid} where all {request.principal.type='serviceconnector', request.principal.compartment.id='${var.compartment_ocid}'}", "Allow any-user to use metrics in compartment id ${var.compartment_ocid} where all {request.principal.type='serviceconnector', target.metrics.namespace='${local.metric_namespace}', request.principal.compartment.id='${var.compartment_ocid}'}", ] } # Monitoring alarms read metrics, never logs, so the refused flows are counted # into a metric first. resource "oci_sch_service_connector" "refused_egress" { compartment_id = var.compartment_ocid display_name = "forensic-workstation-refused-egress" description = "Counts refused flows from the analysis subnet into a metric" freeform_tags = local.tags source { kind = "logging" log_sources { compartment_id = var.compartment_ocid log_group_id = oci_logging_log_group.forensics.id log_id = oci_logging_log.flow.id } } tasks { kind = "logRule" condition = "data.action='REJECT'" } target { kind = "monitoring" compartment_id = var.compartment_ocid metric_namespace = local.metric_namespace metric = local.reject_metric } depends_on = [oci_identity_policy.connector] } resource "oci_monitoring_alarm" "refused_egress" { compartment_id = var.compartment_ocid metric_compartment_id = var.compartment_ocid display_name = "forensic-workstation-refused-egress" namespace = local.metric_namespace query = "${local.reject_metric}[1m].count() > 0" severity = "CRITICAL" is_enabled = true destinations = [oci_ons_notification_topic.alerts.id] message_format = "ONS_OPTIMIZED" body = "Something on the forensic workstation tried to reach an address the rules refuse. Look at the flow log for the destination, and treat the sample under examination as live." freeform_tags = local.tags }