# data-perimeter / oci / t0 "Quick start" # # A perimeter around one compartment's Object Storage. From outside the # networks you name, objects cannot be read and buckets cannot be changed, # whatever a credential would otherwise allow. Nobody can mint a # pre-authenticated request, the link that reads an object with no # credential at all. Stolen credentials still work, but only from inside. # # This is a deny policy. Oracle Cloud policies are allow-only until deny # policies are switched on for the tenancy, which is done once, in the # console, and cannot be undone. A deny policy wins over every allow, in # every compartment below it. The Administrators group of the default domain # is exempt, so a mistake here cannot lock the tenancy's owners out. # # Change the values below. Credentials come from ~/.oci/config. Then: # terraform init && terraform apply # # Verify, with any credential allowed to read the bucket: # oci os object get --bucket-name --name --file - # from an office address: the object # The same command from anywhere else: NotAuthorizedOrNotFound. # oci os preauth-request create --bucket-name --name probe --access-type AnyObjectRead --time-expires 2030-01-01T00:00:00Z # Expect: refused, from anywhere. # # Before applying, list the compartment's pre-authenticated requests and # delete any you did not mean. Afterwards only the default domain's # Administrators can. # # Needs: a member of the default domain's Administrators group, or the # principal that enabled deny policies. Enabling them also makes a deny # policy that lets no one else manage deny policies. locals { tenancy_ocid = "ocid1.tenancy.oc1..aaaaaaaa" # change me compartment_ocid = "ocid1.compartment.oc1..aaaaaaaa" # change me: the compartment to protect region = "us-ashburn-1" # change me: the home region office_cidrs = ["203.0.113.0/24"] # change me: your office or VPN egress } terraform { required_version = ">= 1.6" required_providers { oci = { source = "oracle/oci" version = "~> 9.0" } } } provider "oci" { region = local.region } # The networks that count as inside. Network sources live in the tenancy's # root, in the home region, and their names are unique in the tenancy. resource "oci_identity_network_source" "inside" { compartment_id = local.tenancy_ocid name = "data-perimeter" description = "Networks from which this tenancy's data may be read" public_source_list = local.office_cidrs } # The perimeter. Three statements: # reads of objects from outside the network source are refused, for every # principal, with every permission it otherwise has; # changes to buckets from outside are refused, so a stolen credential # cannot make a bucket public and read it with no credential at all; # pre-authenticated requests cannot be made. # Denying these permissions leaves the rest. Services and pipelines that # write objects, such as log connectors, go on writing. # # Policy names are unique in the tenancy, so the name carries the # compartment. resource "oci_identity_policy" "perimeter" { compartment_id = local.compartment_ocid name = "data-perimeter-${substr(sha1(local.compartment_ocid), 0, 8)}" description = "Objects here are read and buckets changed from the named networks only. No pre-authenticated requests." statements = [ "Deny any-user to { OBJECT_READ } in compartment id ${local.compartment_ocid} where request.networkSource.name != '${oci_identity_network_source.inside.name}'", "Deny any-user to { BUCKET_UPDATE } in compartment id ${local.compartment_ocid} where request.networkSource.name != '${oci_identity_network_source.inside.name}'", "Deny any-user to { PAR_MANAGE } in compartment id ${local.compartment_ocid}", ] } output "verify" { description = "How to prove the perimeter works." value = <<-EOT From ${join(", ", local.office_cidrs)}: oci os object get --bucket-name --name --file - returns the object. From anywhere else, with the same credential: NotAuthorizedOrNotFound. From anywhere else: oci os bucket update --name --public-access-type ObjectRead is refused. From anywhere: oci os preauth-request create --bucket-name --name probe --access-type AnyObjectRead --time-expires 2030-01-01T00:00:00Z is refused. A member of the default domain's Administrators group passes all of these: that group is exempt from every deny policy. EOT }