# forensic-workstation / oci / t0 "Quick start" # # A workstation for examining evidence with no route to anything live: a VCN # with no internet gateway and no NAT gateway, a private subnet, and one route # to a service gateway. Nothing on it can reach the internet, and you reach it # through a Bastion port-forwarding session. # # The Oracle Cloud Agent is switched off on the machine, so nothing on Oracle's # side can run a command on it. Port forwarding is the session type that works # without the agent. # # Change the six values below, then: # terraform init && terraform apply (credentials from ~/.oci/config) # terraform output connect # # Verify, inside the session: # curl -m 5 -sI https://example.com # fails: no route out # oci os object list -bn --auth instance_principal # # Two things this does not stop. Oracle's own services stay reachable on 443, # because a bastion needs the service gateway and an instance principal needs # the identity service, and that includes Object Storage in any tenancy: a # pre-authenticated request carries no credentials. And Oracle's resolver # answers public names for instances with no internet access, so a lookup can # carry data out. Both are on the template page, with what to do about them. locals { tenancy_ocid = "ocid1.tenancy.oc1..replace-me" # change me compartment_ocid = "ocid1.compartment.oc1..replace-me" # change me: a compartment kept for forensics region = "us-ashburn-1" # change me evidence_bucket = "your-evidence-bucket" # change me: such as the evidence capture template's analyst_ssh_key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAVLSNVHxwTkfF6QlOHKLaAYXoPNlChUBMMleVjJvDyi replace-me" # change me: your key; nobody has this one analyst_cidr = "203.0.113.0/24" # change me: where you open sessions from cidr = "10.252.0.0/24" tags = { owner = "security-operations" environment = "prod" data_classification = "restricted" managed_by = "terraform" } } terraform { required_version = ">= 1.6" required_providers { oci = { source = "oracle/oci" version = "~> 9.0" } } } provider "oci" { region = local.region } data "oci_identity_availability_domains" "this" { compartment_id = local.tenancy_ocid } # Every Oracle service CIDR label the region offers. A service gateway takes # one 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 is outside the Object Storage label. A bastion needs the gateway too. data "oci_core_services" "all" {} locals { availability_domain = data.oci_identity_availability_domains.this.availability_domains[0].name 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] } # A new VCN has an empty route table, so nothing leaves until a rule says so. # No internet gateway and no NAT gateway are created here, and neither can be # reached by a rule that does not exist. resource "oci_core_vcn" "forensics" { compartment_id = local.compartment_ocid display_name = "forensics-isolated" cidr_blocks = [local.cidr] dns_label = "forensics" freeform_tags = local.tags } resource "oci_core_service_gateway" "osn" { compartment_id = local.compartment_ocid vcn_id = oci_core_vcn.forensics.id display_name = "forensics-oracle-services" freeform_tags = local.tags services { service_id = local.osn.id } } # The one route out. A service gateway route must name the label the gateway # was given, and it carries no internet traffic. resource "oci_core_route_table" "forensics" { compartment_id = local.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." } } # Security rules in Oracle Cloud only allow; there is no deny rule. What is # not allowed here does not pass. resource "oci_core_security_list" "forensics" { compartment_id = local.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 = local.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 = local.compartment_ocid vcn_id = oci_core_vcn.forensics.id display_name = "forensics-isolated" cidr_block = local.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 } # Only the bastion may open a connection to the workstation. This sits on the # machine's own interface, so it is checked whatever the subnet allows. resource "oci_core_network_security_group" "workstation" { compartment_id = local.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 } } } # The way in. A port-forwarding session needs no agent on the machine, so the # machine runs none. resource "oci_bastion_bastion" "forensics" { compartment_id = local.compartment_ocid bastion_type = "standard" name = "forensics" target_subnet_id = oci_core_subnet.forensics.id client_cidr_block_allow_list = [local.analyst_cidr] max_session_ttl_in_seconds = 10800 dns_proxy_status = "DISABLED" freeform_tags = local.tags } data "oci_core_images" "ol" { compartment_id = local.compartment_ocid operating_system = "Oracle Linux" operating_system_version = "9" shape = "VM.Standard.E5.Flex" sort_by = "TIMECREATED" sort_order = "DESC" state = "AVAILABLE" # Platform images include GPU and Arm builds, whose drivers a Secure Boot # machine will not load. This takes the newest plain build. filter { name = "display_name" values = ["^Oracle-Linux-[0-9.]+-20[0-9]{6}\\.[0-9]+$"] regex = true } } resource "oci_core_instance" "workstation" { compartment_id = local.compartment_ocid availability_domain = local.availability_domain display_name = "forensic-workstation" shape = "VM.Standard.E5.Flex" freeform_tags = local.tags # Traffic between the machine and its boot volume is encrypted too. is_pv_encryption_in_transit_enabled = true shape_config { ocpus = 4 memory_in_gbs = 64 } source_details { source_type = "image" source_id = data.oci_core_images.ol.images[0].id boot_volume_size_in_gbs = "256" } create_vnic_details { subnet_id = oci_core_subnet.forensics.id assign_public_ip = "false" nsg_ids = [oci_core_network_security_group.workstation.id] display_name = "forensic-workstation" freeform_tags = local.tags } metadata = { ssh_authorized_keys = local.analyst_ssh_key } # Nothing on Oracle's side runs commands here: no Run Command, no OS # Management, no scanning agent. agent_config { are_all_plugins_disabled = true is_management_disabled = true is_monitoring_disabled = true } instance_options { are_legacy_imds_endpoints_disabled = true } platform_config { type = "AMD_VM" is_secure_boot_enabled = true is_measured_boot_enabled = true is_trusted_platform_module_enabled = true } # Oracle replaces platform images as new ones are published. Replace the # workstation on purpose, never because a plan noticed a new image. lifecycle { ignore_changes = [source_details[0].source_id] } } # The machine reads the evidence as itself. Read means list and get; it cannot # add, replace, or delete an object. resource "oci_identity_dynamic_group" "workstation" { compartment_id = local.tenancy_ocid name = "forensic-workstation" description = "The forensic workstation" matching_rule = "ALL {instance.id = '${oci_core_instance.workstation.id}'}" freeform_tags = local.tags } resource "oci_identity_policy" "read_evidence" { compartment_id = local.compartment_ocid name = "forensic-workstation-reads-evidence" description = "Lets the forensic workstation read one evidence bucket, and nothing else." freeform_tags = local.tags statements = [ "Allow dynamic-group ${oci_identity_dynamic_group.workstation.name} to read objects in compartment id ${local.compartment_ocid} where target.bucket.name = '${local.evidence_bucket}'", ] depends_on = [oci_identity_dynamic_group.workstation] } output "connect" { description = "Open a session, then SSH through it." value = <<-EOT oci bastion session create-port-forwarding --bastion-id ${oci_bastion_bastion.forensics.id} \ --target-resource-id ${oci_core_instance.workstation.id} --target-port 22 \ --ssh-public-key-file ~/.ssh/id_ed25519.pub --session-ttl 10800 # The command the session prints opens the tunnel. Then, in another terminal: ssh -i ~/.ssh/id_ed25519 -p opc@localhost EOT } output "verify" { description = "Proof the workstation reaches the evidence and nothing else." value = <<-EOT In the session: curl -m 5 -sI https://example.com # times out: no route out oci os object list -bn ${local.evidence_bucket} --auth instance_principal # lists the evidence oci os object put -bn ${local.evidence_bucket} --name x --file /etc/hostname --auth instance_principal # refused: read only EOT }