配置审计使用自定义条件规则作为规则部署实施的方式之一,自定义条件规则由资源(Resource)、条件(Condition)、调试(DryRun)等基本元素组成。
条件(Condition)是自定义条件规则的重点元素,由条件子句构成,多个子句之间可以通过逻辑与(and)和逻辑或(or) 一起构成更为复杂的逻辑结构。由逻辑符串联的一组子句称为条件组。子句是整个条件组的精华,由特征(featurePath)、操作符(operator)和预期值(desiredValue) 组成。
| 元素名称 | 是否必选 | 描述 | 
| 是 | 资源特征。取自资源(Resource)的属性或其相关的来源特征,通过JSONPath描述,例如:资源状态属性为Status, 用特征描述为 | |
| 是 | 资源特征的来源。 | |
| 是 | 条件的操作符。 | |
| 否 | 一目操作符的情况。允许为空,例如:操作符为IsStringEmpty。 | 
特征(featurePath)
权限策略支持JSONPath格式。当您创建或更新权限策略时,配置审计会检查JSONPath格式的正确。您也可以使用第三方JSONPath格式验证器和编辑器自行检查JSONPath格式的正确性。关于JSONPath语法标准,请参见JSONPath。
| JSONPath | Description | 
| $ | the root object/element | 
| @ | the current object/element | 
| . or [] | child operator | 
| .. | recursive descent. JSONPath borrows this syntax from E4X. | 
| * | wildcard. All objects/elements regardless their names. | 
| [] | subscript operator. XPath uses it to iterate over element collections and for predicates. In Javascript and JSON it is the native array operator. | 
| [,] | Union operator in XPath results in a combination of node sets. JSONPath allows alternate names or array indices as a set. | 
| [start:end:step] | array slice operator borrowed from ES4. | 
| ?() | applies a filter (script) expression. | 
| () | script expression, using the underlying script engine. | 
- 示例1:ACS::ECS::Instance状态特征 - $.Status类型判定为String,会推荐String类型的操作符。
- 示例2:ACS::ECS::Instance标签特征 - $.Tags[*].TagKey,结果为Array。
- 示例3:ACS::ECS::SecurityGroup安全组权限配置特征 - $.Permissions.Permission[?(@.Policy=='Accept')][?(@.IpProtocol=='TCP' || @.IpProtocol=='UDP')][?(@.SourceCidrIp=='0.0.0.0/0')].PortRange,表示允许条目为TCP或UDP协议且来源IP为任意IP的端口,可以配置端口是否包括22和3389等。- { "featureSource": "CONFIGURATION", "desired": "21/21,22/22,23/23,3389/3389,445/445,-1/-1", "children": [], "operator": "ExcludeAll", "featurePath": "$.Permissions.Permission[?(@.Policy=='Accept')][?(@.IpProtocol=='TCP' || @.IpProtocol=='UDP')][?(@.SourceCidrIp=='0.0.0.0/0')].PortRange" }
特征来源(featureSource)
资源特征的来源,具体如下:
- CONFIGURATION(默认值):资源属性配置。空值也按照资源属性处理。 
- RESOURCE_RELATIONSHIP_${targetResourceType}:资源关系,例如:- RESOURCE_RELATIONSHIP_ACS::ECS::DISK。
操作符(operator)
操作符包括逻辑操作符和计算操作符,逻辑操作符包括逻辑与(and)和逻辑或(or),计算操作符如下表所示。
| 操作符 | 描述 | 
| SizeLess | 数组元素个数小于 | 
| DistinctSizeGreater | 元素去重后个数大于 | 
| AllGreaterOrEquals | 元素全部大于等于 | 
| InAllItem | 所有元素包含 | 
| AllLessOrEquals | 元素全部小于等于 | 
| AllGreater | 元素全部大于 | 
| SizeGreater | 数组元素个数大于 | 
| NotContainsIP | 数组中不包含指定的IP地址 | 
| ContainsIP | 数组中包含指定的IP地址 | 
| ContainsAny | 数组中不包含目标数组中的任意对象 | 
| NotContainsNull | 数组中不包含空元素 | 
| NotContainsInternetCidr | 不包含公网IP地址段 | 
| IsNotEmpty | 不为空 | 
| AllIn | 全部存在 | 
| IsEmpty | 为空 | 
| ExcludeAll | 排除全部 | 
| ContainsAll | 包含全部 | 
| NotIn | 不存在 | 
| In | 存在 | 
| NotContains | 不包含 | 
| Contains | 包含 | 
| NotBase64Contains | 不包含 | 
| Base64Contains | 包含 | 
| NotBoolEquals | 不等于 | 
| BoolEquals | 等于 | 
| NotEquals | 不等于 | 
| Equals | 等于 | 
| LessOrEquals | 小于等于 | 
| Less | 小于 | 
| Greater | 大于 | 
| GreaterOrEquals | 大于等于 | 
| StringItemSizeGreater | 字符串分割元素个数大于指定值 | 
| StringMatch | 匹配正则 | 
| NotStringTrimIn | 有效值不存在 | 
| StringTrimIn | 有效值存在 | 
| IsNotStringEmpty | 不为空 | 
| IsStringEmpty | 为空 | 
| NotStringContains | 不包含 | 
| StringContains | 包含 | 
| NotStringIn | 不存在 | 
| StringIn | 存在 | 
| NotStringEquals | 不等于 | 
| StringEquals | 等于 | 
预期值(desired)
允许为空,例如:操作符为IsStringEmpty。