编写配置化合规包模板

配置化合规包模板功能为您提供了强大的合规管理能力,允许您定义和导入导出符合自身业务需求的官方规则模板集和灵活的自定义条件规则集,来满足业务合规性要求。通过深入理解合规包模板结构和字段含义,您可以更加高效地定制符合自身业务场景的各种合规规则集。

模板结构

导出的合规包模板是一个JSON格式文件,以合规包名字为文件名,以.json为后缀。您可以导入后缀为.txt.json的文件(该文件必须小于等于1 MB),文件的结构包括compliancePackTemplate(非必填)和configRuleTemplates(必填)两部分。

compliancePackTemplate

compliancePackTemplate包括合规包的名称、描述和风险等级,其定义的JSON结构如下:

{
  "riskLevel": 1,
  "compliancePackName": "合规包的名称",
  "description": "合规包的描述",
  "scope": {
    "complianceResourceTypes": [
      "适配的资源类型"
    ],
    "complianceResourceIds": [
      "评估的资源ID"
    ],
    "complianceExcludeResourceIds": [
      "排除的资源ID"
    ],
    "complianceRegionIds": [
      "评估的指定地域ID"
    ],
    "complianceExcludeRegionIds": [
      "排除的指定地域ID"
    ],
    "complianceResourceGroupIds": [
      "评估的指定资源组ID"
    ],
    "complianceExcludeResourceGroupIds": [
      "排除的指定资源组ID"
    ],
    "complianceTagsScope": [
      {
        "tagKey": "生效标签Key",
        "tagValue": "生效标签KeyValue"
      }
    ],
    "complianceExcludeTagsScope": [
      {
        "tagKey": "排除标签Key",
        "tagValue": "排除标签Value"
      }
    ]
  }
}

参数

是否必填

说明

compliancePackName

合规包名称。建议使用合规场景定义,合规包的命名有以下两种方式:

  • 如果API与该配置文件均未填写合规包名称,则合规包默认以毫秒级时间戳.json命名。

  • 如果API与该配置文件均已填写合规包名称,则以配置文件的合规包命名为第一选择。

riskLevel

合规包风险等级。用于区分不同合规包的重要性,取值:

  • 1:低风险。

  • 2:中风险。

  • 3:高风险。

description

合规包描述。用于补充描述合规包的应用场景。

scope

关联设置规则应用范围。

示例如下:

{
  "configRuleTemplates": [],
  "compliancePackTemplate": {
    "riskLevel": 2,
    "compliancePackName": "配置化合规包模版编写测试",
    "scope": {
      "complianceResourceIds": [
        "i-t4n3u1pz97547xg****.i-t4n3u1pz97547xg0****.",
        "i-t4n1bxf3xr70wjh5****",
        "i-t4n133q6k9czgun****",
        "i-t4n3s3qqti2zaxu****"
      ],
      "complianceResourceGroupIds": [
        "rg-aek2yl36l*****"
      ],
      "complianceTagsScope": [
        {
          "tagKey": "config",
          "tagValue": "configTest"
        }
      ],
      "complianceRegionIds": [
        "ap-southeast-1"
      ]
    },
    "description": "配置化合规包模版编写测试-导入导出测试"
  }
}

configRuleTemplates

合规包中规则在configRuleTemplates中定义为JSON数组,结构如下:

[
  {
    "configRuleName": "规则名称",
    "scope": {
      "complianceResourceTypes": [
        "适配的资源类型"
      ],
      "complianceResourceIds": [
        "评估的资源ID"
      ],
      "complianceExcludeResourceIds": [
        "排除的资源ID"
      ],
      "complianceRegionIds": [
        "评估的指定地域ID"
      ],
      "complianceExcludeRegionIds": [
        "排除的指定地域ID"
      ],
      "complianceResourceGroupIds": [
        "评估的指定资源组ID"
      ],
      "complianceExcludeResourceGroupIds": [
        "排除的指定资源组ID"
      ],
      "complianceTagsScope": [
        {
          "tagKey": "生效标签Key",
          "tagValue": "生效标签Value"
        }
      ],
      "complianceExcludeTagsScope": [
        {
          "tagKey": "排除标签Key",
          "tagValue": "排除标签Value"
        }
      ]
    },
    "description": "规则描述",
    "source": {
      "owner": "规则的来源",
      "identifier": "规则的标识符",
      "sourceDetails": [
        {
          "messageType": "规则触发类型",
          "maximumExecutionFrequency": "触发周期"
        },
        {
          "messageType": "规则触发类型"
        }
      ],
      "conditions": "自定义条件规则的内容"
    },
    "inputParameters": {
      "paramName1": "参数值1",
      "paramName2": "参数值2"
    }
  }
]

参数

是否必填

说明

configRuleName

规则名称。

scope.complianceResourceTypes

规则适配的资源类型,可以是多值数组。

description

规则描述。

source.owner

规则的来源。取值:

  • ALIYUN:来自官方的规则模板。

  • CUSTOM_CONFIGURATION:来自用户自己编写的自定义条件规则。合规包模板支持用户自定义的条件规则。用户可以在conditions字段中使用JSON字符串定义复杂的合规条件,以满足特定的业务场景。

source.identifier

规则的标识符。包括以下两种:

  • 自定义条件规则:固定值,填写为acs-config-configuration。

  • 官方的规则模板:规则模板的标识符,例如:oss-bucket-referer-limit。关于配置审计支持的所有规则模板,请参见规则模板列表

source.sourceDetails.messageType

规则触发机制。取值:

  • ConfigurationItemChangeNotification:配置变更。仅当资源配置发生实际变化时触发评估。

  • ScheduledNotification:周期执行。周期触发评估,需要同时指定maximumExecutionFrequency

source.sourceDetails.maximumExecutionFrequency

规则执行周期。取值:

  • One_Hour:1 小时。

  • Three_Hours:3 小时。

  • Six_Hours:6 小时。

  • Twelve_Hours:12 小时。

  • TwentyFour_Hours:24 小时。

说明

source.sourceDetails.messageType设置为ScheduledNotification时,需要设置该参数。

source.conditions

自定义条件规则的内容。

说明

source.identifier为自定义条件规则时,需要设置该参数。

inputParameters

规则入参。在规则模板列表的每条规则的规则详情规则入参中可以看到需要填写的规则入参,所有规则入参均为字符串类型输入。

scope

关联设置规则应用范围。

示例如下:

{
  "configRuleTemplates": [
    {
      "configRuleName": "ECS实例开启释放保护",
      "scope": {
        "complianceResourceIds": [
          "i-t4n3u1pz97547xg0****.i-t4n3u1pz97547xg0****",
          "i-t4n1bxf3xr70wjh5****",
          "i-t4n133q6k9czgun****",
          "i-t4n3s3qqti2zaxu****"
        ],
        "complianceResourceGroupIds": [
          "rg-aek2yl36lg****"
        ],
        "complianceTagsScope": [
          {
            "tagKey": "config",
            "tagValue": "configTest"
          }
        ],
        "complianceRegionIds": [
          "ap-southea****"
        ],
        "complianceResourceTypes": [
          "ACS::ECS::Instance"
        ]
      },
      "description": "ECS实例开启释放保护,视为“合规”。",
      "source": {
        "owner": "ALIYUN",
        "identifier": "ecs-instance-deletion-protection-enabled",
        "sourceDetails": [
          {
            "messageType": "ConfigurationItemChangeNotification"
          }
        ]
      },
      "inputParameters": {}
    }
  ],
  "compliancePackTemplate": {
    "riskLevel": 2,
    "compliancePackName": "配置化合规包模版编写测试",
    "scope": {
      "complianceResourceIds": [
        "i-t4n3u1pz97547xg****.i-t4n3u1pz97547xg****",
        "i-t4n1bxf3xr70wjh5****",
        "i-t4n133q6k9czgunx****",
        "i-t4n3s3qqti2zaxux****"
      ],
      "complianceResourceGroupIds": [
        "rg-aek2yl36lgo****"
      ],
      "complianceTagsScope": [
        {
          "tagKey": "config",
          "tagValue": "configTest"
        }
      ],
      "complianceRegionIds": [
        "ap-southeast-1"
      ]
    },
    "description": "配置化合规包模版编写测试-导入导出测试"
  }
}

完整示例

{
  "configRuleTemplates": [
    {
      "configRuleName": "ECS实例付费类型为包年包月",
      "scope": {
        "complianceResourceIds": [
          "i-t4n3u1pz97547xg0****.i-t4n3u1pz97547xg*****",
          "i-t4n1bxf3xr70wjh5*****",
          "i-t4n133q6k9czgun*****",
          "i-t4n3s3qqti2zaxu*****"
        ],
        "complianceResourceGroupIds": [
          "rg-aek2yl36l*****"
        ],
        "complianceTagsScope": [
          {
            "tagKey": "config",
            "tagValue": "configTest"
          }
        ],
        "complianceRegionIds": [
          "ap-southeast-1"
        ],
        "complianceResourceTypes": [
          "ACS::ECS::Instance"
        ]
      },
      "description": "检测ECS实例的付费类型,若实例付费类型为包年包月,视为“合规”。",
      "source": {
        "owner": "ALIYUN",
        "identifier": "ecs-instance-chargetype-check",
        "sourceDetails": [
          {
            "messageType": "ConfigurationItemChangeNotification"
          }
        ]
      },
      "inputParameters": {}
    },
    {
      "configRuleName": "ECS实例禁止绑定公网地址",
      "scope": {
        "complianceResourceIds": [
          "i-t4n3u1pz97547x*****.i-t4n3u1pz97547*****",
          "i-t4n1bxf3xr70w*****",
          "i-t4n133q6k9czg*****",
          "i-t4n3s3qqti2zax******"
        ],
        "complianceResourceGroupIds": [
          "rg-aek2yl36l*****"
        ],
        "complianceTagsScope": [
          {
            "tagKey": "config",
            "tagValue": "configTest"
          }
        ],
        "complianceRegionIds": [
          "ap-southeast-1"
        ],
        "complianceResourceTypes": [
          "ACS::ECS::Instance"
        ]
      },
      "description": "ECS实例没有直接绑定IPv4公网IP或弹性公网IP,视为“合规”。",
      "source": {
        "owner": "ALIYUN",
        "identifier": "ecs-instance-no-public-ip",
        "sourceDetails": [
          {
            "messageType": "ConfigurationItemChangeNotification"
          }
        ]
      },
      "inputParameters": {}
    },
    {
      "configRuleName": "ECS实例开启释放保护",
      "scope": {
        "complianceResourceIds": [
          "i-t4n3u1pz9754*****.i-t4n3u1pz97547x*****",
          "i-t4n1bxf3xr70wj*****",
          "i-t4n133q6k9czgu*****",
          "i-t4n3s3qqti2zaxu*****"
        ],
        "complianceResourceGroupIds": [
          "rg-aek2yl36l****"
        ],
        "complianceTagsScope": [
          {
            "tagKey": "config",
            "tagValue": "configTest"
          }
        ],
        "complianceRegionIds": [
          "ap-southeast-1"
        ],
        "complianceResourceTypes": [
          "ACS::ECS::Instance"
        ]
      },
      "description": "ECS实例开启释放保护,视为“合规”。",
      "source": {
        "owner": "ALIYUN",
        "identifier": "ecs-instance-deletion-protection-enabled",
        "sourceDetails": [
          {
            "messageType": "ConfigurationItemChangeNotification"
          }
        ]
      },
      "inputParameters": {}
    }
  ],
  "compliancePackTemplate": {
    "riskLevel": 2,
    "compliancePackName": "配置化合规包模版编写测试",
    "scope": {
      "complianceResourceIds": [
        "i-t4n3u1pz97547xg0*****.i-t4n3u1pz97547xg******",
        "i-t4n1bxf3xr70w******",
        "i-t4n133q6k9czgun*****",
        "i-t4n3s3qqti2zaxux*****"
      ],
      "complianceResourceGroupIds": [
        "rg-aek2yl36l******"
      ],
      "complianceTagsScope": [
        {
          "tagKey": "config",
          "tagValue": "configTest"
        }
      ],
      "complianceRegionIds": [
        "ap-southeast-1"
      ]
    },
    "description": "配置化合规包模版编写测试-导入导出测试"
  }
}

导入导出

您可以通过导入.json.txt文件的方式将合规包模板导入配置审计。您还可以导出.json格式的合规包模板,导出的模板文件可以方便地分享和备份,提高规则管理的灵活性和便捷性。