Capital One是一家庞大的机构。为了成为一家金融服务公司,Capital One 需要满足许多合规性问题。该公司同时也是亚马逊 AWS 云计算服务的客户。关于使用 AWS,该公司需要一款工具,制定高效的规则和策略。
Custodian是AWS 规则引擎,是跟AWS各项服务紧耦合的。安装其项目主页的描述“Policy rules engine for aws management, policies in yaml for query, filter, and take actions on resources” 是一款基于aws管理的规则引擎,基于yaml配置文件,能对aws资源进行查询,过滤,并采取某种操作。
我们看看针对ec2的使用例子,主要是Query,filter,action:
- Query
|
|
查询模板中可以制定,region,镜像,实例状态,实例组等等。
- Filters
|
|
举个例子,onhour就是基于对实例的运行时间进行过滤的
Actions:
Start
1Start a set of instances (presumably) already stopped, the start action will automatically filter instances to those that are already in the correct state.1This example will restart all stopped instances.1policies:name: ec2-start
12resources: ec2actions:- start
Stop
Will stop the instances. Stopped instances do not incur EC2 instance costs.
Terminate
1Will terminate the instances. Use with caution!
可以根据过滤后的资源,采取行动,对ec2实例进行开启,停止,终止。
yaml文件例子:
1policies:name: remediate-extant-keys
description: |12Scan through all s3 buckets in an account and ensure all objectsare encrypted (default to AES256).resource: s3
actions:encrypt-keys
name: ec2-require-non-public-and-encrypted-volumes
resource: ec2
description: |123Provision a lambda and cloud watch event targetthat looks at all new instances not in an autoscale groupand terminates those with unencrypted volumes.mode:
12type: cloudtrailevents:- RunInstances
filters:
- RunInstances
Encrypted: false
1actions:- terminate
name: tag-compliance
resource: ec2
description:12Schedule a resource that does not meet tag compliance policiesto be stopped in four days.filters:
- State.Name: running
- “tag:Environment”: absent
- “tag:AppId”: absent
- or:
- “tag:OwnerContact”: absent
- “tag:DeptID”: absent
actions:
- type: mark-for-op
op: stop
days: 4
- 第一个是针对s3进行定义的,是扫描所有s3中的bucket,并将所有对象进行加密
- 第二是底层调用了aws的lamda和cloud watch,目标是所有新的没有在autoscale group里边的实例,并且终止掉那些未被加密的volume卷。
- 第三个是进行一个调度任务,找出符合条件tag的资源,然后在4天之内关闭。
我的理解,cloud-custodian工具底层基于aws提供的api进行封装的脚本工具,能够进行对aws资源进行查询,过滤,根据筛选出来的资源,采取某种操作的一款“规则引擎”。目前来看custodian跟aws是紧耦合的,它是针对aws资源进行筛选调度,更好的管理资源,提高资源利用率。