IBM Cloud Docs
定义定制规则

定义定制规则

自 2025 年 6 月 16 日起,您不能在本产品的此版本中创建新实例。 Security and Compliance Center Workload Protection 的更新体验中提供了所有功能。 更多信息,请参阅 过渡文档

通过 IBM Cloud® Security and Compliance Center,您可以创建定制规则以确定确保合规性所需的准确配置属性的目标。

准备工作

开始之前,请确保您具有查看和管理规则所需的访问级别。 要创建规则,您需要 Writer 服务角色或更高版本。 您还必须具有存在于供应资源的同一区域中的 Activity Tracker 实例。

格式化规则

规则由多个不同的构建块组成,包括一个目标,一个或多个属性条件和一个值。 例如,假设您要创建一个规则,用于评估对美国南部区域中 Cloud Object Storage 存储区的网络访问是否仅限于特定 IP 地址。

要构建规则,请首先使用 CRN 限定名将 Cloud Object Storage 作为服务作为目标,然后将存储区定义为资源类型。 要确保仅为美国南部的那些存储区配置规则,请提供其他属性。

"target": {
		"service_name": "cloud-object-storage",
		"resource_kind": "bucket",
		"additional_target_attributes": [
			{
				"name": "location",
				"operator": "string_equals",
				"value": "us-south"
			}
		]
	}

在必需的配置对象中,提供要评估的特定条件。 为要评估的每个配置提供 propertyoperatorvalueproperty 是适用于特定资源的配置变量,可用的选项取决于要作为目标的服务和资源类型。 value 是在评估 property 期间使用的变量。 operator 是将 propertyvalue 进行比较的方式。 有时,您不需要提供 value-例如,当 operator 是布尔值时。

"required_config": {
   "and": [
      {
         "property": "firewall.allowed_ip",
         "operator": "ips_in_range",
         "value": [
            "10.0.0.0/8",
            "172.16.0.0/12",
            "192.168.0.0/16"
         ]
      }
   ]
}

可用运算符

运算符是要在属性与其值之间进行比较的类型。 请查看下表以了解有关每种类型的更多信息。

基于字符串的运算符区分大小写。

支持的操作符类型
运算符 类型 描述 需要 value 参数
is_empty 常规 属性值未指定,为 null 或为空字符串
is_not_empty 常规 属性值是指定的,不是 null,也不是空字符串 (任何值)。
is_true 布尔值 属性值为 true。
is_false 布尔值 属性值为 false。
string_equals[1] 字符串 属性值与条件值完全匹配。
string_not_equals[2] 字符串 属性值与条件值不完全匹配。
string_match 字符串 属性值通过使用 Krauss 通配符算法来匹配条件值。
string_not_match 字符串 属性值与使用 Krauss 通配符算法的条件值不匹配。
string_contains 字符串 属性值包含部分条件值。
string_not_contains 字符串 属性值包含部分条件值。
不推荐 strings_in_list[3] 字符串列表 所有属性值都在条件值列表中。
strings_allowed[4] 字符串列表 所有属性值都在条件值列表中。
strings_required[5] 字符串列表 所有条件值都在属性值列表中。
ips_in_range[6] IP 列表 所有属性值 (采用 IPv4 或 IPv6 格式) 都在条件值列表中。
ips_equals[7] 字符串 属性值与条件值完全匹配。
ips_not_equals[8] 字符串 属性值与条件值不完全匹配。
num_equals[9] 数值 属性值与条件值数字匹配。
num_not_equals[10] 数值 属性值在数字上与条件值不匹配。
num_less_than 数值 属性值在数字上小于条件值。
num_less_than_equals 数值 属性值在数字上小于或等于条件值。
num_greater_than 数值 属性值在数字上大于条件值。
num_greater_than_equals 数值 属性值在数字上大于或等于条件值。
days_less_than 数值 属性值小于条件值。

格式化复杂规则

通常,规则比单个属性更复杂。 要创建更复杂的方案,可以包含多个条件。 要在单个规则中定义多个属性条件,可以使用逻辑运算符 andor 来表示它们之间的关系。 例如,以下场景都将评估为合规性。

  1. 如果所有三个 A,B 和 C 都为真。
  2. 如果三个选项中的任何一个为 true。
  3. 如果 A 为 true 或 B 和 C 均为 true。

此图显示多个条件之间的关联。 周围的文字传达了相关信息。
属性之间的关联方式。

创建规则

您可以使用 Security and Compliance Center UI 来定义要针对 IBM Cloud 资源监视的配置规则。 有关可以为哪些服务配置规则的更多信息,请参阅 我可以评估什么?

您可以使用规则构建器或直接编辑 JSON。

  1. 在 IBM Cloud 控制台中,转到 Resource list 页面并选择 Security and Compliance Center 实例。

  2. 在 Security and Compliance Center 实例中,转到 Rules 页面并单击 Create

  3. 给你的规则起一个有意义的名称和描述。

  4. 可选: 添加可用于组织和搜索类似规则的一个或多个标签,然后单击 下一步

  5. 以您的资源为目标。

    1. 目标服务 下拉列表中,选择服务。 例如 Cloud Object Storage.

    2. 资源类型 下拉列表中,选择要为其创建规则的资源类型。 例如,存储区

    3. 可选: 添加其他目标属性以进一步限定要作为目标的资源。

      例如,要将美国南部位置中的所有 Cloud Object Storage 存储区作为目标,您将进行以下选择: 属性: Location: string_equals,并输入 us_south 作为

    4. 单击添加到规则

  6. 配置属性。

    要向规则添加其他属性,请重复此步骤。 您最多可以选择 5 个不同的条件和 16 个属性来创建规则。

    1. 选择条件

      • : 选择 作为条件时,您添加到规则的所有属性配置都必须求值为 true 才能使规则合规。
      • : 当您选择 作为条件时,只有规则的一部分必须求值为 true 才能符合条件。
    2. 通过指定 属性运算符来定义规则。

      要查看可用于所选服务的所有属性,可以在 定义 步骤中单击 可用属性

    3. 单击添加到规则

  7. 单击下一步

  8. 查看您的选择,然后单击“创建”。

使用应用程序接口创建规则

您可以使用 Security and Compliance Center API 来定义要针对 IBM Cloud 资源监视的配置规则。 有关可以为哪些服务配置规则的更多信息,请参阅 我可以评估什么?

curl -X POST
   --location --header "Authorization: Bearer {iam_token}"
   --header "Accept: application/json"
   --header "Content-Type: application/json"
   --data '{
               "account_id": "130003ea8bfa43c5aacea07a86da3000",
               "description": "Example rule",
               "rule_type": "user_defined",
               "import": {
                  "parameters": [
                     {
                        "name": "hard_quota",
                        "display_name": "The Cloud Object Storage bucket quota.",
                        "description": "The maximum bytes that are allocated to the Cloud Object Storage bucket.",
                        "type": "numeric"
                        }
                     ]
                  },
               "target": {
                  "service_name": "cloud-object-storage",
                  "resource_kind": "bucket",
                  "additional_target_attributes":  ]
               },
               "required_config": {
                  "description": "The Cloud Object Storage rule.",
                  "and": [
                     {
                        "property": "hard_quota",
                        "operator": "num_equals",
                        "value": "{hard_quota}"
                        }
                     ]
                  },
               "labels":  
            ],
            "version": "1.0.0"
         }'
"https://us-south.compliance.cloud.ibm.com/instances/{instance_id}/v3/rules"

(securityAndComplianceCenterApi *SecurityAndComplianceCenterApiV3) CreateRule(createRuleOptions *CreateRuleOptions) (result *Rule, response *core.DetailedResponse, err error)
AdditionalTargetAttribute additionalTargetAttributeModel = new AdditionalTargetAttribute.Builder()
  .name("location")
  .operator("string_equals")
  .value("us-east")
  .build();
TargetPrototype targetPrototypeModel = new TargetPrototype.Builder()
  .serviceName("cloud-object-storage")
  .resourceKind("bucket")
  .additionalTargetAttributes(java.util.Arrays.asList(additionalTargetAttributeModel))
  .build();
RequiredConfigItemsRequiredConfigBase requiredConfigItemsModel = new RequiredConfigItemsRequiredConfigBase.Builder()
  .property("hard_quota")
  .operator("num_equals")
  .value("{hard_quota}")
  .build();
RequiredConfigAnd requiredConfigModel = new RequiredConfigAnd.Builder()
  .description("The Cloud Object Storage rule.")
  .and(java.util.Arrays.asList(requiredConfigItemsModel))
  .build();
Parameter parameterModel = new Parameter.Builder()
  .name("hard_quota")
  .displayName("The Cloud Object Storage bucket quota.")
  .description("The maximum bytes that are allocated to the Cloud Object Storage bucket.")
  .type("numeric")
  .build();
Import importModel = new Import.Builder()
  .parameters(java.util.Arrays.asList(parameterModel))
  .build();
CreateRuleOptions createRuleOptions = new CreateRuleOptions.Builder()
  .description("Example rule")
  .target(targetPrototypeModel)
  .requiredConfig(requiredConfigModel)
  .version("1.0.0")
  .xImport(importModel)
  .labels(java.util.Arrays.asList())
  .build();

Response<Rule> response = securityAndComplianceCenterApiService.createRule(createRuleOptions).execute();
Rule rule = response.getResult();

System.out.println(rule);
// Request models needed by this operation.

// AdditionalTargetAttribute
const additionalTargetAttributeModel = {
  name: 'location',
  operator: 'string_equals',
  value: 'us-east',
};

// Target
const targetModel = {
  service_name: 'cloud-object-storage',
  resource_kind: 'bucket',
  additional_target_attributes: [additionalTargetAttributeModel],
};

// RequiredConfigItemsRequiredConfigBase
const requiredConfigItemsModel = {
  property: 'hard_quota',
  operator: 'num_equals',
  value: '{hard_quota}',
};

// RequiredConfigRequiredConfigAnd
const requiredConfigModel = {
  description: 'The Cloud Object Storage rule.',
  and: [requiredConfigItemsModel],
};

// Parameter
const parameterModel = {
  name: 'hard_quota',
  display_name: 'The Cloud Object Storage bucket quota.',
  description: 'The maximum bytes that are allocated to the Cloud Object Storage bucket.',
  type: 'numeric',
};

// Import
const importModel = {
  parameters: [parameterModel],
};

const params = {
  description: 'Example rule',
  target: targetModel,
  requiredConfig: requiredConfigModel,
  version: '1.0.0',
  _import: importModel,
  labels: [],
};

let res;
try {
  res = await securityAndComplianceCenterApiService.createRule(params);
  console.log(JSON.stringify(res.result, null, 2));
} catch (err) {
  console.warn(err);
}
profile_controls_prototype_model = {
  'control_library_id': control_library_id_link,
  'control_id': '1fa45e17-9322-4e6c-bbd6-1c51db08e790',
}

default_parameters_prototype_model = {
  'assessment_type': 'Automated',
  'assessment_id': 'rule-a637949b-7e51-46c4-afd4-b96619001bf1',
  'parameter_name': 'session_invalidation_in_seconds',
  'parameter_default_value': '120',
  'parameter_display_name': 'Sign out due to inactivity in seconds',
  'parameter_type': 'numeric',
}

response = security_and_compliance_center_api_service.create_profile(
  profile_name='test_profile1',
  profile_description='test_description1',
  profile_type='custom',
  controls=[profile_controls_prototype_model],
  default_parameters=[default_parameters_prototype_model],
)
profile = response.get_result()

print(json.dumps(profile, indent=2))

成功响应将返回规则列表以及其他元数据。 有关必需和可选请求参数的更多信息,请查看 API 文档

使用 CLI 创建规则

您可以使用 Security and Compliance Center CLI 来定义要针对 IBM Cloud 资源监视的配置规则。 有关可以为哪些服务配置规则的更多信息,请参阅 我可以评估什么?

ibmcloud security-compliance rule create
--description='Example rule'
--target='{
  "service_name": "cloud-object-storage",
  "service_display_name": "exampleString",
  "resource_kind": "bucket",
  "additional_target_attributes": [
    {
      "name": "location",
      "operator": "string_equals",
      "value": "us-east"
      }
    ]
  }'
--required-config='{
  "description": "The Cloud Object Storage rule.",
  "and": [
    {
      "description": "exampleString",
      "property": "hard_quota",
      "operator": "num_equals",
      "value": "${hard_quota}"
      }
    ]
  }'
--type=user_defined
--version=1.0.0
--import='{
  "parameters": [
    {
      "name": "hard_quota",
      "display_name": "The Cloud Object Storage bucket quota.",
      "description": "The maximum bytes that are allocated to the Cloud Object Storage bucket.",
      "type": "numeric"
      }
    ]
  }'
--labels=foo,bar
--x-correlation-id=exampleString
--x-request-id=exampleString

请参阅 CLI 参考 以获取更多信息。

使用 Terraform 创建规则

您可以使用 Terraform 为 IBM Cloud 资源定义要监视的配置规则。 有关可以为哪些服务配置规则的更多信息,请参阅 我可以评估什么?

resource "ibm_scc_rule" "scc_rule_instance" {
  description = "Example rule"
  import {
		parameters {
			name = "name"
			display_name = "display_name"
			description = "description"
			type = "string"
		}
  }
  required_config {
		description = "description"
		and {
			description = "description"
			or {
				description = "description"
				property = "property"
				operator = "string_equals"
				value = "anything as a string"
			}
		}
  }
  target {
		service_name = "service_name"
		service_display_name = "service_display_name"
		resource_kind = "resource_kind"
		additional_target_attributes {
			name = "name"
			operator = "string_equals"
			value = "value"
		}
  }
  version = "1.0.0"
}

有关更多信息,请查看 Terraform 参考

后续步骤

既然您已创建规则,请通过将其与规范相关联来将其添加到库中。 然后,通过将其附加到作用域来启动监视。


  1. 要包含多个值,请使用数组。 例如,{"value": ["A", "B," "C"]}↩︎

  2. 要包含多个值,请使用数组。 例如,{"value": ["A", "B," "C"]}↩︎

  3. 要创建具有支持 strings_in_list 运算符的属性的规则,请包含 value 参数的字符串列表。 例如,{"value": ["A", "B," "C"]}↩︎

  4. 要创建具有支持 strings_in_list 运算符的属性的规则,请包含 value 参数的字符串列表。 例如,{"value": ["A", "B," "C"]}↩︎

  5. 要创建具有支持 strings_in_list 运算符的属性的规则,请包含 value 参数的字符串列表。 例如,{"value": ["A", "B," "C"]}↩︎

  6. 要创建具有支持 ips_in_range 运算符的属性的规则,请包含 value 参数的 CIDR 或 IP 地址列表。 例如,{"value": ["10.168.175.0/24", "2000:db8:ffff:ffff:ffff:ffff:ffff:ffff"]}↩︎

  7. 要创建具有支持 ips_equals 运算符的属性的规则,请包含 value 参数的 CIDR 或 IP 地址列表。 例如,{"value": ["10.168.175.0/24", "2000:db8:ffff:ffff:ffff:ffff:ffff:ffff"]}↩︎

  8. 要创建具有支持 ips_not_equals 运算符的属性的规则,请包含 value 参数的 CIDR 或 IP 地址列表。 例如,{"value": ["10.168.175.0/24", "2000:db8:ffff:ffff:ffff:ffff:ffff:ffff"]}↩︎

  9. 要包含多个值,请使用数组。 例如,{"value": ["1", "2," "3"]}↩︎

  10. 要包含多个值,请使用数组。 例如,{"value": ["1", "2," "3"]}↩︎