OCI IAM Policy Drift Auditor
Description
As OCI environments grow across multiple compartments, teams often accumulate IAM policies over time. While these policies enable teams to move quickly, they can also introduce configuration drift, privilege creep or inconsistencies between intended and actual access controls.
The OCI IAM Policy Drift Auditor is a lightweight Python automation tool built on top of the OCI SDK to systematically audit IAM policies across compartments and detect drift. It captures a structured snapshot of IAM policies, compares them against a defined baseline or expected configuration and produces human-readable and machine-readable outputs for review and automation.
The project is intentionally designed to be safe and read only, focusing purely on inspection and reporting. It does not modify or enforce changes. Instead, it helps security teams and cloud administrators gain visibility into policy state and identify potential deviations early.
I thought it would be useful to share this codebase for anyone managing IAM governance in OCI environments.
Codebase
Why This Is Useful
In many Oracle Cloud Infrastructure environments, IAM policies are created by multiple teams over time. As projects scale, new compartments are added and services evolve, policy sprawl can become difficult to manage.
Common challenges include:
-
Policies that differ from a security baseline
-
Overly broad permissions that were meant to be temporary
-
Policies added in emergency scenarios and never reviewed
-
Inconsistencies across compartments
-
Difficulty understanding what changed and when
Without automation, reviewing IAM policies manually is time consuming and error prone.
The OCI IAM Policy Drift Auditor addresses this by providing:
-
A repeatable method to snapshot IAM policies
-
A structured way to detect deviations from expected configurations
-
Clear, auditable reporting artifacts
-
A foundation for governance and compliance workflows
This is especially helpful for security reviews, internal audits, regulated environments and DevSecOps workflows where least privilege access matters.
What The Tool Does
The tool connects to OCI using the OCI Python SDK and retrieves IAM policy definitions across one or more compartments.
At a high level, it performs the following steps:
-
Authenticates using standard OCI configuration
-
Enumerates IAM policies within the target tenancy or compartments
-
Captures policy metadata and statements
-
Compares policies against a baseline (if configured)
-
Flags potential drift or unexpected changes
-
Generates structured reports
The output includes both:
-
A human readable summary for quick review
-
A structured JSON artifact suitable for automation, diffing or CI/CD pipelines
Because the output is structured, you can:
-
Track policy evolution over time
-
Integrate with Git-based workflows
-
Feed the results into dashboards or compliance systems
-
Trigger alerts if drift is detected
High Level Architecture
The OCI IAM Policy Drift Auditor is intentionally simple and portable. It can be executed from:
-
A local developer machine
-
OCI Cloud Shell
-
A CI/CD pipeline runner
-
A scheduled automation job
The workflow looks like this:
-
Authentication Layer
Uses the OCI SDK with standard configuration (~/.oci/config) or compatible authentication methods. -
Policy Collection Layer
Calls OCI IAM APIs to retrieve policy definitions and statements across target compartments. -
Drift Analysis Layer
Normalizes and compares collected policies against a known baseline or expected state. -
Reporting Layer
Generates JSON and optionally Markdown summaries for review and archival.
Prerequisites
To run this project, you will need:
-
Python 3.x
-
An OCI account with IAM read permissions
-
Access to the compartments you wish to audit
-
OCI authentication configured (e.g.,
~/.oci/config)
Depending on your workflow, you may optionally integrate this tool with:
-
Git repositories for policy baselines
-
CI/CD systems for scheduled audits
-
Object Storage buckets for snapshot archiving
Expected Output
Each execution produces structured artifacts that reflect the IAM policy state at the time of the run.
Typical outputs include:
-
A JSON snapshot containing full policy definitions
-
A drift report highlighting differences from baseline
-
A human-readable summary for quick inspection
The JSON artifact enables:
-
Git-based diffing across runs
-
Change tracking over time
-
Automated validation checks
-
Compliance reporting
This makes it easy to answer questions like:
-
What policies exist right now?
-
What changed since last week?
-
Which statements differ from our security baseline?
-
Are any new permissions broader than expected?
Comments
Post a Comment