OCI pentest: tenancy and IAM enumeration
Brief
The first hour in an Oracle Cloud tenancy asks the same four questions as any cloud: who am I, what can I do, where are the secrets, and is anyone watching. In OCI the answers live in policy statements written in plain sentences, so most of the work is reading which statements reach the whole tenancy and which dynamic groups let a machine act as an administrator.
On this page
- Situation
- An OCI user with an API key in the CLI config, given by the client for a configuration review or found on another test whose rules let us follow it, with
inspectandreadrights across the tenancy. Every command on this page is a read: we never create a policy, change a group or fetch a secret bundle, we print secret names and never contents, and we review only the tenancy and regions the scope letter names. - Goal
- A tenancy map: the identity and its groups, every policy statement that reaches the whole tenancy, each dynamic group with its matching rule and grants, Vault secret names with the groups that can read them, public buckets and pre-authenticated requests, and where audit events go.
- Outputs
- Representative examples on placeholder hosts, trimmed to the lines that matter. Not captured from a public fixture yet.
Check first
- The tenancy OCID, the home region and the regions the tenancy subscribes to, from the client.
- Whether the tenancy uses identity domains, since groups then sit inside a domain such as
Default. - The groups the client expects to be administrators, written down before we read anything.
- Whether Cloud Guard and Security Zones are on, and who reviews their findings.
- Where audit events are meant to end up beyond the console.
Steps
OCI
Who am I, and which groups and compartments do I see?
U=$(awk -F= '/^user=/{print $2; exit}' ~/.oci/config); T=$(awk -F= '/^tenancy=/{print $2; exit}' ~/.oci/config)
oci iam user list-groups --user-id "$U" --all | jq -r '.data[].name'
oci iam compartment list --compartment-id "$T" --compartment-id-in-subtree true --access-level ANY --all | jq '.data | length'
Expected output
ops-team
ci-deployers # <- a CI group on a human user's key
37
OCI has no "who am I" call, so the user and tenancy OCIDs come from the profile we were given, and the profile's key file path is never opened. Group membership is what every policy refers to, and the compartment count tells us how much tree the policies below have to cover.
Negative result. One review group with read rights, and nothing that also grants deployment or administration.
Fix. Give review and automation work separate users or, better, instance and resource principals, and keep human users out of CI groups.
Which policy statements reach the whole tenancy?
oci iam policy list --compartment-id "$T" --all \
| jq -r '.data[] | .name as $n | .statements[] | [$n, .] | @tsv' | grep -iE 'in tenancy|any-user'
Expected output
Tenant Admin Policy Allow group Administrators to manage all-resources in tenancy
ops-policy Allow group ops-team to manage all-resources in tenancy # <- a second administrator group
ops-policy Allow group ci-deployers to manage policies in tenancy
data-policy Allow any-user to read buckets in tenancy
Statements in tenancy scope can only be attached at the root compartment, so this one read finds every tenancy-wide grant. manage all-resources in tenancy is administrator under another name, and manage policies reaches the same place in one write, since the group can grant itself anything. any-user means every principal in the tenancy, users and resources alike, unless a where clause narrows it.
Negative result. Only the default administrators statement, plus narrow read statements, at tenancy scope.
Fix. Move grants into the compartments they serve, restrict manage policies, manage groups and manage dynamic-groups to the administrators group, and add a where condition to every any-user statement.
Which dynamic groups let a machine act as an administrator?
oci iam dynamic-group list --compartment-id "$T" --all | jq -r '.data[] | [.name, ."matching-rule"] | @tsv'
oci iam policy list --compartment-id "$T" --all | jq -r '.data[].statements[]' | grep -i 'dynamic-group'
Expected output
dev-instances ANY {instance.compartment.id = 'ocid1.compartment.oc1..aaaadev'}
Allow dynamic-group dev-instances to manage all-resources in tenancy # <- any VM in dev is a tenancy administrator
A dynamic group turns instances or functions into principals, and an instance principal needs no key: anyone with a shell on a matching VM gets its rights from the metadata service. A rule that matches a whole compartment includes every future instance a developer launches there. We record the path and stop; we do not log on to an instance to show it.
Negative result. Dynamic groups that match named instances or tags under a tag namespace only administrators control, with grants scoped to one compartment.
Fix. Match on instance OCIDs or a protected defined tag, grant the dynamic group only the resource types it uses, and never in tenancy scope.
Which Vault secrets exist, and who can read them?
oci vault secret list --compartment-id "$C" --all | jq -r '.data[] | [."secret-name", ."lifecycle-state", ."time-created"] | @tsv'
oci iam policy list --compartment-id "$C" --all | jq -r '.data[].statements[]' | grep -iE 'secret-(family|bundles)'
Expected output
prod-db-admin-password ACTIVE 2024-03-11T09:14:02+00:00
Allow group ops-team to read secret-family in compartment prod # <- read on the family includes reading secret contents
We run this per compartment, with $C set from the compartment list. secret list returns metadata only; contents come from GetSecretBundle, which we never call. read secret-family grants that call, while inspect only lists, so a broad read is where the exposure is.
Negative result. Each secret readable only by the dynamic group of the workload that uses it, and people holding inspect at most.
Fix. Grant read secret-bundles on named secrets to workload principals, rotate any secret older than the client's policy, and alert on GetSecretBundle from users.
Which buckets are public, and which pre-authenticated requests are live?
for b in $(oci os bucket list --compartment-id "$C" --all | jq -r '.data[].name'); do
oci os bucket get --bucket-name "$b" | jq -r '.data | [.name, ."public-access-type"] | @tsv'
oci os preauth-request list --bucket-name "$b" --all | jq -r '.data[] | [" par", .name, ."access-type", ."time-expires"] | @tsv'
done
Expected output
web-assets ObjectRead
exports NoPublicAccess
par partner-share AnyObjectRead 2031-01-01T00:00:00+00:00 # <- a link anyone can use until 2031
ObjectRead and ObjectReadWithoutList make a bucket public. A pre-authenticated request is a bearer link that works for anyone holding it, and the list never shows its URL, which is returned only when it is created.
Negative result. NoPublicAccess everywhere except buckets the client lists as public, and requests that expire within days.
Fix. Set buckets to NoPublicAccess, put security zones on data compartments to block public buckets, and replace long requests with short ones.
Is anyone watching, and for how long?
oci audit config get --compartment-id "$T" | jq '.data'
oci sch service-connector list --compartment-id "$T" --all | jq '.data.items | length'
Expected output
{
"retention-period-days": 365
}
0 # <- no service connector: audit events stay in OCI for a year and reach no SIEM
Audit is always on and keeps a year of events, so the question is whether anyone reads them and whether they outlive that year. A service connector from the _Audit log group to Object Storage or a stream is how they leave OCI.
Negative result. A connector moving audit events to the client's SIEM or to locked storage in a separate compartment.
Fix. Add a service connector for _Audit in every subscribed region, and alert on policy and dynamic group changes.
The defender sees
Every read above is an audit event under our user, named after the API operation: ListPolicies, ListDynamicGroups, ListSecrets, GetBucket and ListPreauthenticatedRequests, from one address in a few minutes. Cloud Guard may raise problems for the public bucket and the wide policies but not for the enumeration. The cloud first hour covers the same questions for AWS and Azure, and the persistence audit what to look for once someone has used a path like these. If the client cannot see these reads, missing audit export is a finding of its own.
Done when
The user's groups are known, every tenancy-wide statement is listed with its policy, every dynamic group is matched to the statements that name it, secrets are listed by name with their readers, every public bucket and live pre-authenticated request is recorded, and audit export is known.
Not covered
Using any path found here, OCI Kubernetes Engine and Functions code, and identity domain sign-on policies in depth; the outputs shown are representative examples on a placeholder tenancy, not captured runs.