- Notifications
You must be signed in to change notification settings - Fork1.5k
Rules engine for cloud security, cost optimization, and governance, DSL in yaml for policies to query, filter, and take actions on resources
License
cloud-custodian/cloud-custodian
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Cloud Custodian, also known as c7n, is a rules engine for managingpublic cloud accounts and resources. It allows users to definepolicies to enable a well managed cloud infrastructure, that's bothsecure and cost optimized. It consolidates many of the adhoc scriptsorganizations have into a lightweight and flexible tool, with unifiedmetrics and reporting.
Custodian can be used to manage AWS, Azure, and GCP environments byensuring real time compliance to security policies (like encryption andaccess requirements), tag policies, and cost management via garbagecollection of unused resources and off-hours resource management.
Custodian also supports running policies on infrastructure as code assetsto provide feedback directly on developer workstations or within CI pipelines.
Custodian policies are written in simple YAML configuration files thatenable users to specify policies on a resource type (EC2, ASG, Redshift,CosmosDB, PubSub Topic) and are constructed from a vocabulary of filtersand actions.
It integrates with the cloud native serverless capabilities of eachprovider to provide for real time enforcement of policies with builtinprovisioning. Or it can be run as a simple cron job on a server toexecute against large existing fleets.
Cloud Custodian is a CNCF Incubating project, lead by a community of hundredsof contributors.
- Comprehensive support for public cloud services and resources with arich library of actions and filters to build policies with.
- Run policies on infrastructure as code (terraform, etc) assets.
- Supports arbitrary filtering on resources with nested booleanconditions.
- Dry run any policy to see what it would do.
- Automatically provisions serverless functions and event sources (AWS CloudWatchEvents, AWS Config Rules, Azure EventGrid, GCPAuditLog & Pub/Sub, etc)
- Cloud provider native metrics outputs on resources that matched apolicy
- Structured outputs into cloud native object storage of whichresources matched a policy.
- Intelligent cache usage to minimize api calls.
- Supports multi-account/subscription/project usage.
- Battle-tested - in production on some very large cloud environments.
Custodian is published on pypi as a series of packages with thec7n
prefix, its also available as a docker image.
$ python3 -m venv custodian$source custodian/bin/activate(custodian) $ pip install c7n
The first step to using Cloud Custodian (c7n) is writing a YAML filecontaining the policies that you want to run. Each policy specifiesthe resource type that the policy will run on, a set of filters whichcontrol resources will be affected by this policy, actions which the policywith take on the matched resources, and a mode which controls whichhow the policy will execute.
The best getting started guides are the cloud provider specific tutorials.
As a quick walk through, below are some sample policies for AWS resources.
- will enforce that no S3 buckets have cross-account access enabled.
- will terminate any newly launched EC2 instance that do not have an encrypted EBS volume.
- will tag any EC2 instance that does not have the follow tags"Environment", "AppId", and either "OwnerContact" or "DeptID" tobe stopped in four days.
policies: -name:s3-cross-accountdescription:| Checks S3 for buckets with cross-account access and removes the cross-account access.resource:aws.s3region:us-east-1filters: -type:cross-accountactions: -type:remove-statementsstatement_ids:matched -name:ec2-require-non-public-and-encrypted-volumesresource:aws.ec2description:| Provision a lambda and cloud watch event target that looks at all new instances and terminates those with unencrypted volumes.mode:type:cloudtrailrole:CloudCustodian-QuickStartevents: -RunInstancesfilters: -type:ebskey:Encryptedvalue:falseactions: -terminate -name:tag-complianceresource:aws.ec2description:| Schedule a resource that does not meet tag compliance policies to be stopped in four days. Note a separate policy using the`marked-for-op` filter is required to actually stop the instances after four days.filters: -State.Name:running -"tag:Environment":absent -"tag:AppId":absent -or: -"tag:OwnerContact":absent -"tag:DeptID":absentactions: -type:mark-for-opop:stopdays:4
You can validate, test, and run Cloud Custodian with the example policy with these commands:
# Validate the configuration (note this happens by default on run)$ custodian validate policy.yml# Dryrun on the policies (no actions executed) to see what resources# match each policy.$ custodian run --dryrun -s out policy.yml# Run the policy$ custodian run -s out policy.yml
You can run Cloud Custodian via Docker as well:
# Download the image$ docker pull cloudcustodian/c7n$ mkdir output# Run the policy## This will run the policy using only the environment variables for authentication$ docker run -it \ -v$(pwd)/output:/home/custodian/output \ -v$(pwd)/policy.yml:/home/custodian/policy.yml \ --env-file<(env| grep"^AWS\|^AZURE\|^GOOGLE") \ cloudcustodian/c7n run -v -s /home/custodian/output /home/custodian/policy.yml# Run the policy (using AWS's generated credentials from STS)## NOTE: We mount the ``.aws/credentials`` and ``.aws/config`` directories to# the docker container to support authentication to AWS using the same credentials# credentials that are available to the local user if authenticating with STS.$ docker run -it \ -v$(pwd)/output:/home/custodian/output \ -v$(pwd)/policy.yml:/home/custodian/policy.yml \ -v$(cd~&& pwd)/.aws/credentials:/home/custodian/.aws/credentials \ -v$(cd~&& pwd)/.aws/config:/home/custodian/.aws/config \ --env-file<(env| grep"^AWS") \ cloudcustodian/c7n run -v -s /home/custodian/output /home/custodian/policy.yml
Thecustodian casktool is a go binarythat provides a transparent front end to docker that mirors the regularcustodian cli, but automatically takes care of mounting volumes.
Consult the documentation for additional information, or reach out on gitter.
For specific instructions for AWS, Azure, and GCP, visit the relevant getting started page.
- GitHub - (This page)
- Slack - Real time chat if you're looking for help or interested in contributing to Custodian!
- Gitter - (Older real time chat, we're likely migrating away from this)
- Linen.dev - Follow our discussions on Linen
- Mailing List - Our project mailing list, subscribe here for important project announcements, feel free to ask questions
- Reddit - Our subreddit
- StackOverflow - Q&A site for developers, we keep an eye on the
cloudcustodian
tag - YouTube Channel - We're working on adding tutorials and other useful information, as well as meeting videos
We have a regular community meeting that is open to all users and developers of every skill level.Joining themailing list will automatically send you a meeting invite.See the notes below for more technical information on joining the meeting.
- Community Meeting Videos
- Community Meeting Notes Archive
- Upcoming Community Events
- Cloud Custodian Annual Report 2021 - Annual health check provided to the CNCF outlining the health of the project
- Ada Logics Third Party Security Audit
The Custodian project also develops and maintains a suite of additionaltools herehttps://github.com/cloud-custodian/cloud-custodian/tree/master/tools:
Org: Multi-account policy execution.
ShiftLeft: Shift Left ~ run policies against Infrastructure as Code assets like terraform.
PolicyStream: Git history as stream of logical policy changes.
Salactus: Scale out s3 scanning.
Mailer: A reference implementation of sending messages to users to notify them.
Trail Creator: Retroactive tagging of resources creators from CloudTrail
TrailDB: Cloudtrail indexing and time series generation for dashboarding.
LogExporter: Cloud watch log exporting to s3
Cask: Easy custodian exec via docker
Guardian: Automated multi-account Guard Duty setup
Omni SSM: EC2 Systems Manager Automation
Mugc: A utility used to clean up Cloud Custodian Lambda policies that are deployed in an AWS environment.
Seehttps://cloudcustodian.io/docs/contribute.html
If you've found a security related issue, a vulnerability, or apotential vulnerability in Cloud Custodian please let the CloudCustodian Security Team know withthe details of the vulnerability. We'll send a confirmation email toacknowledge your report, and we'll send an additional email when we'veidentified the issue positively or negatively.
This project adheres to theCNCF Code of Conduct
By participating, you are expected to honor this code.
About
Rules engine for cloud security, cost optimization, and governance, DSL in yaml for policies to query, filter, and take actions on resources