cloudcustodian/policystream、标签策略,以及通过清理未使用资源和非工作时间资源管理实现成本优化。
Custodian策略通过简单的YAML配置文件定义,指定资源类型(如EC2、ASG、Redshift、CosmosDB、PubSub Topic),并由过滤器(filters)和操作(actions)构成。策略文件基本结构如下:
yamlpolicies: - name: 策略名称 resource: 资源类型(如aws.ec2、azure.cosmosdb) description: 策略描述 filters: 资源过滤条件 actions: 匹配资源后执行的操作 mode: 执行模式(如serverless、cron)
以下是AWS环境的策略示例,涵盖S3跨账户访问控制、EC2未加密卷终止和标签合规管理:
yamlpolicies: - name: s3-cross-account description: 检查S3存储桶的跨账户访问并移除相关权限 resource: aws.s3 region: us-east-1 filters: - type: cross-account actions: - type: remove-statements statement_ids: matched - name: ec2-require-non-public-and-encrypted-volumes resource: aws.ec2 description: 部署Lambda和CloudWatch事件目标,终止带有未加密卷的新实例 mode: type: cloudtrail role: CloudCustodian-QuickStart events: - RunInstances filters: - type: ebs key: Encrypted value: false actions: - terminate - name: tag-compliance resource: aws.ec2 description: 标记不符合标签策略的资源,计划4天后停止 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
shellcustodian validate policy.yml
shellcustodian run --dryrun -s out policy.yml
shellcustodian run -s out policy.yml
shelldocker pull cloudcustodian/c7n
shellmkdir output 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
shellmkdir output 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
Custodian项目还开发和维护了一系列附加工具,扩展其功能:
Cloud Custodian由社区维护,拥有数百名贡献者,包括多家云提供商的专门团队。如需贡献代码或参与讨论,请访问:
本项目遵循Open Code of Conduct。参与本项目即表示您同意遵守此准则。
manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务