OSS Spotlight: Cloud Custodian (c7n)

OSS Spotlight: Cloud Custodian (c7n)

An open-source policy engine that turns "we should really block public S3 buckets across every account" from a recurring audit into a five-line YAML file.

Cloud Custodian — usually just called c7n — is a rules engine for managing AWS, Azure, and GCP resources through policy-as-code. It's a CNCF Incubating project, Apache 2.0 licensed, led by a community of hundreds of contributors, and sitting at just over 6,000 stars on GitHub. It doesn't get the mainstream coverage that a CSPM product pitch deck does, but it's doing real work quietly in a lot of environments that would otherwise be running the same manual audit script every quarter.

How it works

Every c7n policy is YAML, and every policy follows the same three-part shape:

That's the whole model. No custom scripting language to learn, no SDK boilerplate — just declare what you're looking for and what should happen when you find it.

A concrete example

Here's a real policy from the project's own README — it finds S3 buckets with cross-account access and strips it out:

policies:
 - name: s3-cross-account
   description: |
     Checks S3 for buckets with cross-account access and
     removes the cross-account access.
   resource: aws.s3
   region: us-east-1
   filters:
     - type: cross-account
   actions:
     - type: remove-statements
       statement_ids: matched

Five lines of actual policy, and it directly covers one of the access-control items in our S3 hardening cheat sheet — instead of manually reviewing bucket policies for stray cross-account grants, this runs on a schedule and fixes them.

Getting started

python3 -m venv custodian
source custodian/bin/activate
pip install c7n

Then, before running anything with real consequences, run it in dry-run mode:

custodian run --dryrun -s out policy.yml

--dryrun applies the filters and shows you exactly which resources would be affected, without touching anything. It's the equivalent of terraform plan before terraform apply — and given that c7n's own example gallery includes policies that terminate EC2 instances outright (an actual example: auto-terminating any new instance whose EBS volumes aren't encrypted), dry-run isn't optional caution, it's the normal way to develop a policy before trusting it with the actions block live.

The honest caveats

For a team already comfortable with YAML and looking to stop manually re-running the same audit checklist every quarter, it's a genuinely useful tool — not flashy, just quietly doing the job.


Sources: Cloud Custodian documentation · cloud-custodian/cloud-custodian on GitHub · Cloud Custodian — Getting Started

Marselis A. Reed

Marselis A. Reed

B.S. in Computer Science, with 10 years of production experience — including 5 years in healthcare information security.

Get the Next Issue

Cloud hardening, vendor watch, and OSS tooling — every week.