Security Command Center 및 커스텀 모듈 작업을 수행할 수 있을 뿐만 아니라 securitycenter.securityhealthanalyticscustommodules.test 권한을 포함하는 Identity and Access Management(IAM) 역할이 사용자 계정에 하나 이상 부여되어 있어야 합니다.
커스텀 모듈 작업에 필요한 권한과 역할에 대한 자세한 내용은 필요한 IAM 권한을 참조하세요.
커스텀 모듈 테스트를 위한 API 호출에는 할당량이 적용됩니다. 자세한 내용은 커스텀 모듈 할당량을 참조하세요.
YAML 파일로 테스트 리소스 만들기
커스텀 모듈을 테스트하려면 허위 리소스 정의나 허위 정책 정의 또는 둘 다 YAML 파일에 정의합니다.
이러한 정의는 실제 리소스 또는 정책 인스턴스에 해당하지 않지만 정의가 커스텀 모듈에 지정된 리소스 또는 정책 유형의 스키마를 준수해야 합니다.
테스트 정의에서 지정해야 하는 유일한 속성은 커스텀 모듈이 평가하는 속성입니다. 커스텀 모듈이 참조하지 않는 리소스 속성은 포함할 필요가 없습니다.
커스텀 모듈에서 CEL 표현식을 테스트하려면 CEL 표현식을 true로 결정되게 만드는 속성 값을 테스트 파일에 지정합니다.
테스트 데이터의 형식
첫 번째 줄에서 testData:로 시작하고 이후 하나 이상의 - asset 정의로 이어지는 파일을 시작합니다.
ARBITRARY_ASSET_NAME_N: 테스트가 성공할 때 테스트 결과에 표시되는 임의 값입니다.
RESOURCE_TYPE_N: API 서비스 엔드포인트의 도메인 이름과 리소스 이름(예: cloudkms.googleapis.com/CryptoKey)으로 지정되어 커스텀 모듈이 검사하는 애셋 또는 리소스의 유형입니다.
PROPERTIES_TO_TEST_N: 발견 항목을 트리거하기 위해 커스텀 모듈의 감지 논리에 사용되는 속성입니다.
PROPERTY_VALUE_N: 발견 항목을 트리거하는 속성의 값입니다.
SUB_PROPERTY: 리소스 정의에서 대상 리소스가 참조하는 다른 리소스의 하위 속성 또는 속성입니다.
테스트 정의 예시
이 섹션에는 테스트 리소스 정의 및 테스트 정책 정의 예시가 포함되어 있습니다. 두 예시가 개별 파일에 정의된 것으로 표시되지만 리소스 및 정책의 asset 정의는 단일 testData 파일로 조합할 수 있습니다.
리소스 정의 예시
다음 테스트 리소스 정의 예시는 CryptoKey 리소스의 rotationPeriod 속성이 2592000초(30일)를 초과하는지 검사하는 커스텀 모듈을 테스트합니다. 정의에 표시된 다른 속성은 커스텀 모듈에 사용되지 않지만 리소스 스키마를 준수합니다. 이 예시가 테스트하는 커스텀 모듈의 전체 정의는 커스텀 모듈 정의 예시를 참조하세요.
testData:
- asset:
resource: THE CRYPTOKEY TEST WAS SUCCESSFUL!
assetType: cloudkms.googleapis.com/CryptoKey
resourceData:
nextRotationTime: '2020-02-05T12:00:55.192645Z'
primary:
state: 'ENABLED'
purpose: 'ENCRYPT_DECRYPT'
rotationPeriod: '2592001s'
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-03-06(UTC)"],[],[],null,["| Premium and Enterprise [service tiers](/security-command-center/docs/service-tiers)\n\nThis page explains how to test Security Health Analytics custom modules in the\nGoogle Cloud console by uploading a YAML file that contains test data.\n\nBefore you begin\n\nBefore you can test custom modules, you need to satisfy the following\nprerequisites:\n\n- All of the general prerequisites that apply to using Security Health Analytics custom modules. For the full list of prerequisites, see [Using custom modules for Security Health Analytics](/security-command-center/docs/custom-modules-sha-create#before_you_begin).\n- Your user account must be granted one or more Identity and Access Management (IAM) roles that allow you to not only work with Security Command Center and custom modules, but also includes the `securitycenter.securityhealthanalyticscustommodules.test` permission. For more about the permissions and roles you need to work with custom modules, see [Required IAM permissions](/security-command-center/docs/custom-modules-sha-create#iam-for-custom-modules).\n- API calls to test custom modules are subject to a quota. For more information, see [Custom module quotas](/security-command-center/docs/custom-modules-sha-overview#custom_module_quotas).\n\nCreate test resources in a YAML file\n\nTo test a custom module, you define fake resource definitions, fake policy\ndefinitions, or both in a YAML file.\n\nThe definitions do not correspond to real resource or policy instances, but the\ndefinitions must conform to the schemas of the resource or policy types\nthat are specified in your custom modules.\n\nIn your test definitions, the only properties that you need to specify are\nthe properties that your custom modules evaluate. You don't need to include\nresource properties that the custom module doesn't reference.\n\nTo test your CEL expressions in the custom module, specify property values\nin the test file that cause the CEL expressions to resolve to `true`.\n\nFormat of the test data\n\nStart the file with `testData:` on the first line, followed by\none or more `- asset` definitions. \n\n```\ntestData:\n- asset:\n resource: ARBITRARY_ASSET_NAME_1\n assetType: RESOURCE_TYPE_1\n resourceData:\n PROPERTIES_TO_TEST_1: PROPERTY_VALUE_1\n SUB_PROPERTY: SUB_PROPERTY_VALUE\n PROPERTIES_TO_TEST_2: PROPERTY_VALUE_2\n- asset:\n resource: ARBITRARY_ASSET_NAME_2\n assetType: RESOURCE_TYPE_2\n iamPolicyData:\n PROPERTIES_TO_TEST_3: PROPERTY_VALUE_3\n PROPERTIES_TO_TEST_4: PROPERTY_VALUE_4\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eARBITRARY_ASSET_NAME_N\u003c/var\u003e: An arbitrary value that displays in the test results when the test is successful.\n- \u003cvar translate=\"no\"\u003eRESOURCE_TYPE_N\u003c/var\u003e: The type of asset or resource that the custom module checks, specified as the domain name of the API's service endpoint and resource name---for example, `cloudkms.googleapis.com/CryptoKey`.\n- \u003cvar translate=\"no\"\u003ePROPERTIES_TO_TEST_N\u003c/var\u003e: The properties that are used in the detection logic of the custom module to trigger a finding.\n- \u003cvar translate=\"no\"\u003ePROPERTY_VALUE_N\u003c/var\u003e: A value of the property that triggers a finding.\n- \u003cvar translate=\"no\"\u003eSUB_PROPERTY\u003c/var\u003e: A sub-property or property of another resource that the target resource references in its resource definition.\n\nExample test definitions\n\nThis section contains an example of a test resource definition and a\ntest policy definition. Although the two examples are shown as being defined\nin separate files, `asset` definitions for resources and policies can be\ncombined in a single `testData` file.\n\nExample resource definition\n\nThe following example of a test resource definition, tests a custom module\nthat checks whether the `rotationPeriod` property of\n`CryptoKey` resources exceeds `2592000` seconds (30 days). The other\nproperties in the definition are not used in the custom module, but still\nconform to the schema of the resource. For the full\ndefinition of the custom module that this example tests, see\n[Example custom module definition](/security-command-center/docs/custom-modules-sha-code#example_custom_module_definition). \n\n```\ntestData:\n- asset:\n resource: THE CRYPTOKEY TEST WAS SUCCESSFUL!\n assetType: cloudkms.googleapis.com/CryptoKey\n resourceData:\n nextRotationTime: '2020-02-05T12:00:55.192645Z'\n primary:\n state: 'ENABLED'\n purpose: 'ENCRYPT_DECRYPT'\n rotationPeriod: '2592001s'\n```\n\nExample policy definition\n\nThe following is an example of a test definition for an\nIAM policy: \n\n```\ntestData:\n- asset:\n resource: //cloudresourcemanager.googleapis.com/projects/fake-project\n assetType: cloudresourcemanager.googleapis.com/Project\n iamPolicyData:\n bindings:\n - role: \"roles/viewer\"\n members:\n - \"serviceAccount:fake-service-account@compute-system.iam.gserviceaccount.com\"\n - \"user:fake-email-account\"\n```\n\nTest a custom module\n\nYou can test new custom modules or existing custom modules in the\nGoogle Cloud console.\n\nTo test a custom module, follow these steps:\n\n1. Go to the Security Health Analytics **Modules** page in Security Command Center\n settings.\n\n [Go to Modules](https://console.cloud.google.com/security/command-center/config/services/security-health-analytics/modules)\n2. Open or create a custom module for testing:\n\n - To create a new custom module, click **Create module** and follow the instructions in [Create custom modules](/security-command-center/docs/custom-modules-sha-create#create_module).\n - To open an existing custom module, click the edit (*edit* ) icon under **Actions** on the right side of the row for the module you want to test.\n3. Select the **Test module** tab.\n\n4. Under **Upload the YAML file** , click **Browse** to upload a file that\n contains sample asset data. The test runs as soon as the YAML file is uploaded.\n\n5. Under **Test results preview**, check the results.\n\n - If there are syntax or other errors in your YAML file, a floating error message displays near the bottom of the browser page.\n - If the test is a success, the test returns the following information:\n\n - The display name of the custom module.\n - The arbitrary name that you specify on the `resource` property in the test data file.\n - The organization, folder, or project in which the custom module was, or will be, created.\n\n Test results are not stored or written to Security Command Center.\n\nWhat's next\n\n- To work with custom modules, see [Using custom modules for Security Health Analytics](/security-command-center/docs/custom-modules-sha-create)\n- To work with findings in the Google Cloud console, see [Work with findings](/security-command-center/docs/how-to-work-with-findings-in-the-dashboard)"]]