对云安全的检测中,最重要的一个组成部分就是对配置的验证,今天来介绍一个开源的规则检测引擎项目,CloudCustodian。一、CloudCustodian是什么CloudCustodian是用于管理公有云帐户和资源的规则引擎。规则策略用简单的YAML格式,使用户能够指定资源类型(EC2、ASG、Redshift、CosmosDB、PubSub主题)的策略,并由过滤器和操作的词汇表构建。官方的CloudCustodian可用于管理AWS、Azure和GCP环境,我们在此基础上新增了阿里云、华为云、腾讯云、火山云、金山云、百度云、青云、七牛云、UCloud、OpenStack、VMwarevSphere等。二、CloudCustodian项目结构 Custodian特征对公共云服务和资源的全面支持,具有丰富的操作和过滤器库,可用于构建策略。支持对具有嵌套布尔条件的资源进行任意过滤。试运行任何政策,看看它会做什么。自动配置无服务器函数和事件源(AWSCloudWatchEvents、AWSConfigRules、AzureEventGrid、GCPAuditLog和PubSub等)与策略匹配的资源上的云提供商本机指标输出将结构化输出到云原生对象存储中,其资源与策略相匹配。智能缓存使用以最小化api调用。支持多账户订阅项目使用。经过实战测试在一些非常大的云环境中进行生产。三、CloudCustodian快速安装python3mvenvcustodiansourcecustodianbinactivate(custodian)pipinstallc7n(custodian)pipinstalletoolsc7naliyun(custodian)pipinstalletoolsc7nhuawei(custodian)pipinstalletoolsc7ntencent(custodian)pipinstalletoolsc7nbaidu四、CloudCustodian用法 使用CloudCustodian的第一步是编写包含您要运行的策略的YAML文件。每个策略指定策略将运行的资源类型,一组控制资源将受此策略影响的过滤器,策略对匹配资源采取的操作,以及控制策略执行方式的模式。 最好的入门指南是云提供商特定的教程。 作为快速浏览,下面是AWS资源的一些示例策略将强制所有S3存储桶都没有启用跨账户访问。将终止任何新启动的没有加密EBS卷的EC2实例。将在四天内停止任何没有跟随标签Environment、AppId和OwnerContact或DeptID的EC2实例。policies:name:s3crossaccountdescription:ChecksS3forbucketswithcrossaccountaccessandremovesthecrossaccountaccess。resource:aws。s3region:useast1filters:type:crossaccountactions:type:removestatementsstatementids:matchedname:ec2requirenonpublicandencryptedvolumesresource:aws。ec2description:Provisionalambdaandcloudwatcheventtargetthatlooksatallnewinstancesandterminatesthosewithunencryptedvolumes。mode:type:cloudtrailrole:CloudCustodianQuickStartevents:RunInstancesfilters:type:ebskey:Encryptedvalue:falseactions:terminatename:tagcomplianceresource:aws。ec2description:Schedulearesourcethatdoesnotmeettagcompliancepoliciestobestoppedinfourdays。Noteaseparatepolicyusingthemarkedforopfilterisrequiredtoactuallystoptheinstancesafterfourdays。filters:State。Name:runningtag:Environment:absenttag:AppId:absentor:tag:OwnerContact:absenttag:DeptID:absentactions:type:markforopop:stopdays:4 您可以使用以下命令使用示例策略验证、测试和运行CloudCustodianValidatetheconfiguration(notethishappensbydefaultonrun)custodianvalidatepolicy。ymlDryrunonthepolicies(noactionsexecuted)toseewhatresourcesmatcheachpolicy。custodianrundryrunsoutpolicy。ymlRunthepolicycustodianrunsoutpolicy。yml 您也可以通过Docker运行CloudCustodianDownloadtheimagedockerpullcloudcustodianc7nmkdiroutputRunthepolicyThiswillrunthepolicyusingonlytheenvironmentvariablesforauthenticationdockerrunitv(pwd)output:homecustodianoutputv(pwd)policy。yml:homecustodianpolicy。ymlenvfile(envgrepAWSAZUREGOOGLE)cloudcustodianc7nrunvshomecustodianoutputhomecustodianpolicy。ymlRunthepolicy(usingAWSsgeneratedcredentialsfromSTS)NOTE:Wemountthe。awscredentialsand。awsconfigdirectoriestothedockercontainertosupportauthenticationtoAWSusingthesamecredentialscredentialsthatareavailabletothelocaluserifauthenticatingwithSTS。dockerrunitv(pwd)output:homecustodianoutputv(pwd)policy。yml:homecustodianpolicy。ymlv(cdpwd)。awscredentials:homecustodian。awscredentialsv(cdpwd)。awsconfig:homecustodian。awsconfigenvfile(envgrepAWS)cloudcustodianc7nrunvshomecustodianoutputhomecustodianpolicy。yml五、项目地址Github项目地址:https:github。comhummerriskcloudcustodiantreehummerriskCloudCustodian官方文档:https:cloudcustodian。iodocsindex。html HummerRisk对CloudCustodian的操作进行可视化的处理,更加的便捷和简单,并且增强了多个方面的能力,如果想体验相关的能力,我们建议直接入手HummerRisk。关于HummerRisk HummerRisk是开源的云原生安全平台,以非侵入的方式解决云原生的安全和治理问题,核心能力包括混合云的安全治理和K8S容器云安全检测。