Resolve Namespace and Compartment Context Explicitly
The first segment of an Object Storage request is a string nobody chose. A request is addressed as n/<namespace>/b/<bucket>/o/<key>, and the namespace is assigned to the tenancy when the account is created. It is not the tenancy OCID, and it is not the compartment that holds the bucket.
One namespace covers every compartment in every region. The string is identical in Phoenix and Frankfurt, while the service endpoint itself is regional. Bucket names must be unique inside the namespace, and because the service is regional, the same name in two regions is two different buckets with two independent lifecycles.
Namespace, compartment, region and bucket name answer four different questions. None of them substitutes for another, and only one of them is a permission boundary.
| Layer | Answers | Owned by | Can it change? |
|---|---|---|---|
| Namespace | which tenancy is being addressed | Oracle, at tenancy creation | no, and no rename request exists |
| Compartment | who may manage the bucket | tenancy administrator | yes, a bucket can be moved |
| Region | where the bytes live | tenancy and realm | no, a bucket stays in its region |
| Bucket name | which container inside the namespace | data owner | no, a rename is a new bucket |
Resolve the namespace with a data source, once per root. oci_objectstorage_namespace returns the caller's namespace, and an optional compartment OCID asks for another tenancy's namespace, which needs a namespace read grant. Pass the value into modules rather than re-deriving it, because a literal in a variable file is an unlabelled tenancy selector.
The namespace can never separate environments. Tenants routinely host development, staging and production in one tenancy, and all three share the same string. Environment separation lives in the compartment, the bucket name and the policy scope; a namespace check proves only which tenancy answered the call.
A bucket name is create-only. The provider exposes no update path for the name, so a rename is a migration with a new URL and a new lifecycle policy. The scope setting decides whether the name is reserved only inside your namespace or across every tenancy in the region, which matters when a partner expects a fixed name.
A bucket can move compartments without moving bytes. The compartment identifier is updatable, so an apply can change the permission boundary while the request URL stays the same. The data does not move; the set of identities that can manage it does.
Figure 1 turns that into a sequence of questions. A missing answer at any step produces a bucket that exists but is not the bucket the plan intended.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
A["Apply names a bucket
and nothing else"] --> B{"Namespace read
from the tenancy?"}
B -- "hardcoded string" --> X1["Wrong tenancy or 404
the bucket is never created"]
B -- "data source" --> C{"Provider region
pinned?"}
C -- "no" --> X2["Bucket lands in the
runner's default region"]
C -- "yes" --> D{"Compartment passed
as a value?"}
D -- "no" --> X3["Missing required argument
the plan stops"]
D -- "yes" --> E["Address: namespace, region,
compartment, bucket name"]
E --> F{"Same name used in
another region?"}
F -- "yes" --> W1["Two buckets, two lifecycles
neither is a replica"]
F -- "no" --> OK["One bucket, one owner record"]
OK --> G["Record all four values
beside the bucket"]
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class B,C,D,F primary;
class A,E secondary;
class OK,G ok;
class X1,X2,X3 danger;
class W1 warn;
Figure 2 shows why the layers cannot stand in for each other. The namespace locates the tenancy, the compartment governs permission, and the region fixes the address; the URL carries only two of the four.
Trace IAM, Bucket Settings and Object Access
Access is decided in three places, and they fail differently. IAM decides whether the caller may perform the verb, the bucket's settings decide what the bucket exposes, and the object request decides whether a key is created or overwritten. A plan can set all three correctly and still fail because the Object Storage service itself lacks a grant.
The verbs are cumulative, and each one buys a different API surface. A team that is granted read has inspect as well; a team that is granted manage has everything below it.
| Verb | Buckets | Objects | Typical holder |
|---|---|---|---|
| inspect | list and head buckets | list keys, head an object | inventory and audit tooling |
| read | bucket settings, lifecycle, retention, replication | download an object | readers and backup jobs |
| use | update the bucket, delete the lifecycle policy | overwrite an existing key | narrow writers that never create |
| manage | create and delete buckets, PARs, retention rules | create, delete, rename, restore, re-tier | data owners and upload pipelines |
The trap is use objects on a writer. That verb allows an overwrite but not the creation of a new key, because creation needs a permission that only manage carries. A pipeline holding use alone therefore succeeds when the artifact already exists and fails on every first upload, which looks like a flaky network and is really a policy gap.
Scope a writer with a bucket condition and an object pattern. The bucket variable is case-insensitive, so two bucket names that differ only by case share one condition. The object variable accepts patterns, which is how a release identity is confined to a prefix without a second bucket.
Do not put network addresses in the policy. The IP and VCN request variables are deprecated in favour of network sources, and a policy copied from an old runbook can still parse while restricting nothing. Reference the network source by name and review it with the same care as the statement.
Public read is a bucket setting, not a grant. The access type defaults to no public access; the two public values serve anonymous reads, and one of them also lists keys. An anonymous GET never consults IAM, so a strict policy and a public bucket can coexist without either being wrong on its own terms.
A public bucket is a distribution choice with no expiry. A pre-authenticated request can be scoped, expired and revoked; public read stays open until someone edits the bucket. Review the access type on every bucket, not only the ones with a content delivery network in front of them.
The service needs its own grant. Lifecycle actions run as the regional Object Storage service, not as your runner, so the tenancy root needs a statement for that service in each region where rules run. Encryption with a customer key has the same shape: the service must be able to use the key, and the caller's policy does not cover that.
| Principal | Grant | Required for |
|---|---|---|
| Object Storage service, per region | manage the object family in the compartment | lifecycle archive, tier and delete actions |
| Object Storage service, per location | encrypt and decrypt on the vault key | reads and writes of an SSE-KMS bucket |
| Object Storage service, per location | read on the key as well | re-encrypting a bucket or an object |
Encryption is a separate decision with a separate owner. Object Storage always encrypts at rest with AES-256 and cannot be switched off, so the choice is only which master key wraps each object's data key. An Oracle-managed key needs no extra grant, a vault key adds the service-principal dependency above, and a customer-provided key is supplied per object and never stored, which makes losing it equivalent to losing the data. A bucket key cuts key-service calls for high-volume SSE-KMS buckets, but it only affects new writes until the bucket is re-encrypted.
A not-found response is not proof of absence. OCI commonly answers an unauthorized object request as if the object did not exist, which avoids leaking names. Test with an identity that should succeed, then with one that should fail, and compare the pair rather than trusting a single status code.
Figure 3 places the three gates beside the service principal. The caller's grant and the service's grant are checked at different moments, so one missing grant can look exactly like the other from a pipeline log.
Figure 4 follows one request through those gates. The create branch is the expensive one: a writer that can overwrite but not create passes every retry of an old artifact and fails every new release.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
R["Request to n / b / o"] --> C{"Credential
presented?"}
C -- "none" --> P{"Bucket access type
public read?"}
P -- "no public access" --> N1["404, no object returned"]
P -- "public read" --> OK["Read allowed
IAM never consulted"]
C -- "PAR URI" --> PC{"Creator still exists
and still permitted?"}
PC -- "no" --> N1
PC -- "yes" --> PF{"Key inside the
PAR prefix?"}
PF -- "no" --> N1
PF -- "yes" --> OP
C -- "IAM principal" --> IAM{"Policy allows the verb
on this bucket?"}
IAM -- "no" --> N1
IAM -- "yes" --> OP{"Which object
operation?"}
OP -- "create a new key" --> MC{"Create permission
granted?"}
MC -- "no, use objects only" --> N2["Denied on the first write
the retry of an old key succeeds"]
MC -- "yes" --> OK2["Write allowed
object appears"]
OP -- "overwrite" --> MO{"Overwrite permission
granted?"}
MO -- "yes" --> OK2
MO -- "no" --> N1
OP -- "delete" --> MD{"Delete or version-delete
granted?"}
MD -- "no" --> N1
MD -- "yes" --> OK3["Delete allowed
a version id removes bytes"]
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class C,P,PC,PF,IAM,OP,MC,MO,MD primary;
class R secondary;
class OK,OK2,OK3 ok;
class N1,N2 danger;
Choose Versioning, Lifecycle and Retention with Recovery Evidence
Start with the data contract, not the bucket arguments. Four questions decide the settings: can an overwrite be undone, must a record be provably unaltered, how fast must a restore finish, and who may destroy data. The answers pick versioning or retention, and OCI does not let one bucket carry both.
Versioning and retention are mutually exclusive. OCI refuses retention rules on a bucket whose versioning is enabled, and refuses versioning on a bucket with active retention. Retention can be added after versioning is suspended, but versioning cannot resume while retention is active.
| Requirement | Versioning | Retention rule |
|---|---|---|
| Undo an accidental overwrite | yes, the old bytes remain a previous version | no, the overwrite itself is refused |
| Prove bytes were not altered | weak, an authorized caller can delete versions | strong, a locked rule binds every caller |
| Keep a history of edits | yes, every version is retained and billed | no, exactly one live object |
| Destroy data before a date | yes, with the version-delete grant | no, not inside the window |
| Use the other mechanism | not while retention is active | not while versioning is enabled |
Versioning has three states and no way back to the first. A bucket moves from disabled to enabled, and from enabled only to suspended. Suspended behaves like disabled for new writes and deletes, but the versions created earlier remain, and versioning can be resumed.
A delete is a marker until you name a version. Deleting without a version identifier makes the current bytes a previous version and inserts a delete marker; deleting the marker makes those bytes the latest version again. Deleting by version identifier is permanent, and lifecycle deletion of the latest version leaves the same marker behind.
Every retained version is billed. That includes versions hidden behind delete markers, which is why a bucket can look nearly empty in a listing and still carry a large bill. A lifecycle rule targeting previous versions is the cost control, not an optional tidy-up.
Retention is a bucket-wide promise measured per object. The duration runs from each object's last modification, so one rule protects a new object longer than an old one. An indefinite rule is applied before any time-bound rule and cannot be locked; a bucket accepts up to one hundred rules.
A retention rule is active the moment it is created. The lock does not switch protection on; it freezes the rule so it cannot be shortened or removed. That distinction matters in review, because applying an unlocked rule already changes what the application may overwrite.
The lock is a date, not a checkbox. The rule-lock field takes a timestamp, and OCI enforces a mandatory fourteen-day delay before the lock takes effect. After that point not even a tenancy administrator or Oracle Support can delete the rule, the duration can only increase, and the rule leaves only when the bucket is deleted.
Locking creates a lifetime floor for the bucket. A bucket cannot be deleted while it holds objects, and a locked rule blocks deletion until each object passes its window. For retention alone, the destroy therefore succeeds only after the longest window in the bucket has expired, which is a date the design should state before the first apply.
Lifecycle is the cost control, and it replaces rather than appends. A bucket has one policy of up to one thousand rules, and the API call replaces the whole policy, so two owners means the last writer wins. Rules run once a day, changes take up to twenty-four hours to take effect, and a lifecycle delete cannot be recovered.
| Rule target | Allowed actions | What it cleans |
|---|---|---|
| objects | archive, infrequent access, delete | current keys |
| previous object versions | archive, infrequent access, delete | history behind delete markers |
| multipart uploads | abort only | uncommitted parts |
Narrow policies need two extra permissions. Deleting previous versions through lifecycle requires the version-delete permission, and re-tiering requires the tier-update permission; the caller also needs bucket update plus object create and delete. The service principal grant is separate again, and without it the policy call is the thing that fails.
Archive is a tier, not a backup. Archive objects carry a ninety-day minimum, so an early delete is billed for the full period. A restore returns the object to the standard tier for a download window of 1 to 240 hours, 24 by default, with the first byte available in at most an hour, and the restored copy bills at the standard rate. Lifecycle can archive an object but cannot restore it.
A replica is not a version backup. Replication copies the current object to a destination bucket that is read-only, and previous versions are not replicated. Recovery from an accidental overwrite therefore depends on versioning or retention in the source bucket, not on the second region.
Recovery evidence is a rehearsal, not a setting. For versioning, delete a marker and compare a checksum. For retention, prove that a delete is refused and record the date it will be allowed. For archive, time the restore against the objective, because a recovery plan that assumes instant access is a plan for a different storage class.
Assign Content Uploads and Pre-Authenticated Requests Separately
Terraform builds the container; a pipeline moves the cargo. Every object declared as a resource becomes a state address that is refreshed on later plans, and the object's content either lands in the state file or is read from a path that exists only on the runner. Neither is a good fit for a data lake.
Keep a small, deliberate bootstrap in state. A manifest pointer, a small configuration file or a marker that must exist before the first pipeline run is a reasonable object resource. Pin its checksum, keep it in a separate root, and never let a routine data sync share that state.
Anything larger than fifty GiB needs multipart. The single-request upload limit is well below the largest object the service stores, so a large artifact is uploaded in parts. Parts that never commit are invisible to a normal listing, still billable, and they block bucket deletion until aborted.
Publish by immutable key, then move a pointer. Write the new artifact under a key that contains its content hash, verify the checksum, and update the small manifest readers resolve. Overwriting a live key gives readers a torn view and leaves no clean rollback target.
A pre-authenticated request is a bearer URL with an expiry. The expiry is required and has no upper limit, the request cannot be edited after creation, and a prefix limits what the holder may read or write. Listing is off by default, and the request can never delete an object.
The request's permissions belong to its creator. Every use re-checks the creator's grants, so deleting that identity or removing its access breaks the URL even though nothing about the URL changed. Deleting the request itself is the only reliable revocation.
That dependency survives in Terraform state. The access URI is an exported attribute, so the state file becomes a working credential for anyone who can read it, and a plan after the creator is deleted still shows no drift. Treat the state as secret material, keep the request in its own root, and never emit the URI to a log.
A request also blocks bucket deletion. A bucket with an associated pre-authenticated request cannot be deleted, and the same is true for a replication policy and uncommitted parts. Cleanup has to remove all of them, not just the visible objects.
| Access type | Scope | Listing |
|---|---|---|
| ObjectRead | one object | not applicable |
| ObjectWrite | one object | not applicable |
| ObjectReadWrite | one object | not applicable |
| AnyObjectRead | bucket or prefix | off unless explicitly enabled |
| AnyObjectReadWrite | bucket or prefix | off unless explicitly enabled |
Figure 5 shows the failure that no plan catches. The request is created by an identity, the identity leaves, and the resource remains healthy in state while every caller receives a not-found response.
The state file is the credential store in this design. A reader with state access can use the URI without ever holding an API key, which is a different blast radius from a policy grant. Keep the request out of the root that uploads data, and audit who can read that state.
Restore Disposable Objects and Review Non-Empty Cleanup
A restore is a metadata move or a copy, depending on the protection. Versioning recovers by removing a delete marker or copying an older version forward; retention has nothing to restore because the object was never altered; archive restores the object to the standard tier for a limited window.
Destroy is the least reversible step, and the provider does not soften it. The bucket resource has no force-destroy switch, so a delete is refused while objects, versions, pre-authenticated requests, a replication policy or uncommitted parts remain. The refusal may name only one of them, so the fix is to enumerate all of them rather than retry.
The object resource can delete versions, but only as a blunt instrument. A flag on that resource removes every version of that one object during destroy. It is acceptable in a disposable lab and unacceptable in a shared bucket, where a single object name may carry the only copy of a record.
Retention outranks every destroy path. A locked rule blocks deletion for every caller, including the bucket owner, so a plan that tries to destroy a protected bucket fails rather than overriding the policy. That is the correct behaviour, and it should be tested on a disposable bucket before a rule is ever locked.
Cleanup is a review, not a command. The reviewer names the bucket, the versions, the requests, the replication destination and the owner who approved the deletion. If any of those is shared or unknown, the answer is no.
Restore Disposable Objects and Review Non-Empty Cleanup
Execution status: design-only. This trace was written against Terraform 1.17.1 and oracle/oci 9.12.1 on 6 November 2026. No tenancy was queried and no bucket was created, so every expected result below is documented behaviour rather than a measurement.
Prerequisites. A disposable compartment, a group with manage on buckets and objects scoped to it, a second group with use on objects only, and a bucket name with a unique suffix. Leave every retention rule unlocked, and do not point the lab at a shared bucket or a bucket that holds the only copy of anything.
- Baseline the bucket. Create it with no public access, versioning disabled, an Oracle-managed key and object events off. Plan again and expect no changes; record the namespace, region, compartment and bucket name as one address.
- Prove the namespace. Read it through the data source and compare it with the CLI's namespace command. Expect the same string, and expect it to stay the same when you switch region.
- Prove the allowed write. As the writer group, upload one small file under the lab input prefix. Expect success and a checksum you can compare later.
- Prove the denied read. As the same writer, read a key under the private prefix. Expect a not-found or not-authorized response, and record which one.
- Prove create against overwrite. As the use-only group, upload a new key and expect a denial; then overwrite the key created in step 3 and expect success. This pair is the evidence that use is not a writer grant.
- Prove version recovery. Enable versioning, overwrite the object twice, list the versions, then delete without a version identifier. Expect a not-found read, a delete marker in the listing, and the earlier bytes back after the marker is removed.
- Prove revocation. Create a read-only request scoped to the lab input prefix, fetch the object through it, then delete the request and fetch again. Expect success first and not-found second, and never print the URI.
- Prove the retention boundary. Attempt to add a retention rule to the versioned bucket and expect the service to refuse it. On a second, unversioned bucket, add a one-day time-bound rule without a lock, attempt an overwrite and expect a refusal, then delete the rule and confirm the overwrite succeeds.
- Prove the cleanup gate. Destroy the versioned bucket while objects remain and expect a refusal; record which blocker the console or the error reports. Remove the versions, markers, requests and parts, then destroy and confirm the bucket is absent from the list.
| Check | Passing result | Failing result means |
|---|---|---|
| Namespace read | data source and CLI agree | the CLI profile and the provider use different credentials |
| Writer upload | object exists under the prefix | the object grant is missing or the prefix is wrong |
| Private read | not found or not authorized | the policy is wider than the bucket condition |
| Use-only create | denied, while overwrite succeeds | the group holds manage, so the test is void |
| Version recovery | marker removed, checksum matches | versioning was off or the wrong version was chosen |
| Request revocation | works before delete, not after | the request was never deleted, or a public bucket is serving the read |
| Retention on versioned bucket | refused | versioning was suspended, not enabled |
| Destroy while non-empty | refused, blocker reported | cleanup ran before the review |
Expected observation. The allowed paths succeed, each denied path fails at the layer that owns it, the marker removal returns the earlier checksum, and the non-empty destroy stops before the bucket disappears. The retention attempt against the versioned bucket is refused, which is the mutual-exclusion rule showing up as an API error rather than a surprise in production.
Failure check. If the private read succeeds, check the bucket access type before editing the policy, because public read bypasses IAM entirely. If the use-only overwrite fails as well as the create, the group lacks the overwrite permission and the test proves nothing. If the request keeps working after deletion, confirm you deleted the request and not a second one with a similar name.
Cost dimensions. Every retained version bills, requests during the lab bill, and an SSE-KMS bucket adds key operations that a bucket key can reduce. Archive objects carry a ninety-day minimum, so keep archive out of this lab unless the exercise is specifically about restore time. Destroy the bucket and its versions the same day, and check the bill for residual storage rather than assuming the destroy cleared it.
Cleanup and evidence. Remove every version and marker, abort incomplete parts, delete the requests and the lifecycle policy, then destroy the bucket and confirm it is gone from the list. Keep the plan output, the policy listing, the version listing before cleanup and the empty state list after destroy as the evidence; sanitize the namespace, OCIDs and any URI before sharing.
Sources. Namespace scope follows the Object Storage namespaces guide, and permission mapping follows the Object Storage policy reference. Lifecycle behaviour follows Object Lifecycle Management, retention follows data retention rules, and versioning follows Object Storage versioning.
More sources. Pre-authenticated requests follow the PAR guide, deletion blockers follow deleting a bucket, and archive timing follows the Archive Storage overview. Resource fields were checked against the oracle/oci 9.12.1 bucket documentation.
Next in the Series
In OCI Persistent Services: Volumes, File Storage and Managed Databases, we'll explore Choose data durability and migration boundaries before provisioning stateful resources.