--- policy: /ce/ca/aws/account/aws-support-role logic: /ce/ca/aws/account/aws-support-role/prod.logic.yaml executionTime: 2026-06-06T12:02:25.546633369Z generationMs: 104 executionMs: 1643 rows: - id: test1 match: true status: expected: COMPLIANT actual: COMPLIANT conditionIndex: expected: 199 actual: 199 conditionText: expected: CA10__AWS_IAM_Policies__r.has(COMPLIANT) && CA10__AWS_IAM_Role_Policy_Attachments__r.has(COMPLIANT) actual: CA10__AWS_IAM_Policies__r.has(COMPLIANT) && CA10__AWS_IAM_Role_Policy_Attachments__r.has(COMPLIANT) runtimeError: {} - id: test2 match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 299 actual: 299 conditionText: expected: CA10__AWS_IAM_Policies__r.has(INCOMPLIANT) actual: CA10__AWS_IAM_Policies__r.has(INCOMPLIANT) runtimeError: {} - id: test3 match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 399 actual: 399 conditionText: expected: CA10__AWS_IAM_Role_Policy_Attachments__r.has(INCOMPLIANT) actual: CA10__AWS_IAM_Role_Policy_Attachments__r.has(INCOMPLIANT) runtimeError: {} - id: test4 match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 399 actual: 399 conditionText: expected: CA10__AWS_IAM_Role_Policy_Attachments__r.has(INCOMPLIANT) actual: CA10__AWS_IAM_Role_Policy_Attachments__r.has(INCOMPLIANT) runtimeError: {} - id: test5 match: true status: expected: UNDETERMINED actual: UNDETERMINED conditionIndex: expected: 400 actual: 400 conditionText: expected: otherwise actual: otherwise runtimeError: {} - id: test6 match: true status: expected: UNDETERMINED actual: UNDETERMINED conditionIndex: expected: 400 actual: 400 conditionText: expected: otherwise actual: otherwise runtimeError: {} usedFiles: - path: /ce/ca/aws/account/aws-support-role/policy.yaml md5Hash: 716635CD06FB1E5A2CDEE9D9593346E2 content: | --- names: full: "AWS Support Role is not created" contextual: "AWS Support Role is not created" description: "AWS provides a support center that can be used for incident notification and response, as well as\ \ technical support and customer services. Create an IAM Role, with the appropriate policy assigned, to allow\ \ authorized users to manage incidents with AWS Support." type: "COMPLIANCE_POLICY" categories: - "SECURITY" frameworkMappings: - "/frameworks/cis-aws-v7.0.0/02/15" - "/frameworks/cloudaware/identity-and-access-governance/rbac-management" similarPolicies: internal: - dec-x-9146aafe cloudConformity: - url: "https://www.trendmicro.com/cloudoneconformity-staging/knowledge-base/aws/IAM/support-role.html" name: "IAM Support Role" - path: /ce/ca/aws/account/aws-support-role/prod.logic.yaml md5Hash: 9943351315AC9919A904BC5A4E9D0A59 content: "---\ninputType: \"CA10__CaAwsAccount__c\"\ntestData:\n - file: test-data.json\n\ conditions:\n - status: \"COMPLIANT\"\n currentStateMessage: \"The AWS account\ \ has a support role for managing incidents with AWS Support.\"\n check:\n\ \ AND:\n args:\n - RELATED_LIST_HAS:\n status:\ \ \"COMPLIANT\"\n relationshipName: \"CA10__AWS_IAM_Policies__r\"\ \n - RELATED_LIST_HAS:\n status: \"COMPLIANT\"\n \ \ relationshipName: \"CA10__AWS_IAM_Role_Policy_Attachments__r\"\n \ \ - status: \"INCOMPLIANT\"\n currentStateMessage: \"The AWSSupportAccess\ \ IAM policy for managing incidents with AWS Support does not exist.\"\n \ \ remediationMessage: \"Create the AWSSupportAccess IAM policy.\"\n check:\n\ \ RELATED_LIST_HAS:\n status: \"INCOMPLIANT\"\n relationshipName:\ \ \"CA10__AWS_IAM_Policies__r\"\n - status: \"INCOMPLIANT\"\n currentStateMessage:\ \ \"The AWSSupportAccess IAM policy is not attached to any IAM role.\"\n \ \ remediationMessage: \"Attach the AWSSupportAccess IAM policy to an IAM role\ \ dedicated to managing AWS Support incidents.\"\n check:\n RELATED_LIST_HAS:\n\ \ status: \"INCOMPLIANT\"\n relationshipName: \"CA10__AWS_IAM_Role_Policy_Attachments__r\"\ \notherwise:\n status: \"UNDETERMINED\"\n currentStateMessage: \"There are\ \ no active IAM roles or IAM policies.\"\nrelatedLists:\n - relationshipName:\ \ \"CA10__AWS_IAM_Policies__r\"\n importExtracts:\n - file: /types/CA10__CaAwsIamPolicy__c/object.extracts.yaml\n\ \ conditions:\n - status: \"COMPLIANT\"\n currentStateMessage: \"\ This is the AWSSupportAccess IAM policy.\"\n check:\n IS_EQUAL:\n\ \ left: \n EXTRACT: \"CA10__arn__c\"\n right: \n\ \ TEXT: arn:aws:iam::aws:policy/AWSSupportAccess\n otherwise:\n\ \ status: \"INCOMPLIANT\"\n currentStateMessage: \"The AWSSupportAccess\ \ IAM policy is not found.\"\n - relationshipName: \"CA10__AWS_IAM_Role_Policy_Attachments__r\"\ \n importExtracts:\n - file: /types/CA10__CaAwsIamRolePolicyAttachment__c/object.extracts.yaml\n\ \ conditions:\n - status: \"COMPLIANT\"\n currentStateMessage:\ \ \"An IAM role is attached to the AWSSupportAccess IAM policy.\"\n check:\n\ \ AND:\n args:\n - NOT_EMPTY_LOOKUP: \"CA10__role__r\"\ \n - NOT_EMPTY_LOOKUP: \"CA10__policy__r\"\n - IS_EQUAL:\n\ \ left:\n EXTRACT: CA10__policyArn__c\n \ \ right:\n TEXT: arn:aws:iam::aws:policy/AWSSupportAccess\n\ \ otherwise:\n status: \"INCOMPLIANT\"\n currentStateMessage: \"\ No IAM role is attached to the AWSSupportAccess IAM policy.\"\n" - path: /ce/ca/aws/account/aws-support-role/test-data.json md5Hash: E56AD00C43DCB0E44A11562E7B007179 content: |- [ { "expectedResult": { "status": "COMPLIANT", "conditionIndex": "199", "conditionText": "CA10__AWS_IAM_Policies__r.has(COMPLIANT) && CA10__AWS_IAM_Role_Policy_Attachments__r.has(COMPLIANT)", "runtimeError": null }, "context": { "snapshotTime": "2024-07-10T20:44:00Z" }, "Id": "test1", "CA10__AWS_IAM_Policies__r": [ { "Id": "policy1", "CA10__disappearanceTime__c": null, "CA10__arn__c": "arn:aws:iam::aws:policy/AWSSupportAccess", "CA10__account__c": "test1" } ], "CA10__AWS_IAM_Role_Policy_Attachments__r": [ { "Id": "test1_1", "CA10__disappearanceTime__c": null, "CA10__role__c": "role1", "CA10__roleArn__c": "arn:aws:iam::1234567890:role/service-role/roleName1", "CA10__policy__c": "policy1", "CA10__policyArn__c": "arn:aws:iam::aws:policy/AWSSupportAccess", "CA10__account__c": "test1", "CA10__role__r": { "Id": "role1", "CA10__disappearanceTime__c": null }, "CA10__policy__r": { "Id": "policy1", "CA10__disappearanceTime__c": null } } ] }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "299", "conditionText": "CA10__AWS_IAM_Policies__r.has(INCOMPLIANT)", "runtimeError": null }, "context": { "snapshotTime": "2024-07-10T20:44:00Z" }, "Id": "test2", "CA10__AWS_IAM_Policies__r": [ { "Id": "policy2", "CA10__disappearanceTime__c": null, "CA10__arn__c": "arn:aws:iam::aws:policy/policyName2", "CA10__account__c": "test2" } ], "CA10__AWS_IAM_Role_Policy_Attachments__r": [ { "Id": "test2_1", "CA10__disappearanceTime__c": null, "CA10__role__c": "role2", "CA10__roleArn__c": "arn:aws:iam::1234567890:role/service-role/roleName2", "CA10__policy__c": "policy2", "CA10__policyArn__c": "arn:aws:iam::aws:policy/policyName2", "CA10__account__c": "test2", "CA10__role__r": { "Id": "role2", "CA10__disappearanceTime__c": null }, "CA10__policy__r": { "Id": "policy2", "CA10__disappearanceTime__c": null } } ] }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "399", "conditionText": "CA10__AWS_IAM_Role_Policy_Attachments__r.has(INCOMPLIANT)", "runtimeError": null }, "context": { "snapshotTime": "2024-07-10T20:44:00Z" }, "Id": "test3", "CA10__AWS_IAM_Policies__r": [ { "Id": "policy3", "CA10__disappearanceTime__c": null, "CA10__arn__c": "arn:aws:iam::aws:policy/AWSSupportAccess", "CA10__account__c": "test3" } ], "CA10__AWS_IAM_Role_Policy_Attachments__r": [ { "Id": "test3_1", "CA10__disappearanceTime__c": null, "CA10__role__c": "role3", "CA10__roleArn__c": "arn:aws:iam::1234567890:role/service-role/roleName3", "CA10__policy__c": "policy3", "CA10__policyArn__c": "arn:aws:iam::aws:policy/policyName3", "CA10__account__c": "test3", "CA10__role__r": { "Id": "role3", "CA10__disappearanceTime__c": null }, "CA10__policy__r": { "Id": "policy3", "CA10__disappearanceTime__c": null } } ] }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "399", "conditionText": "CA10__AWS_IAM_Role_Policy_Attachments__r.has(INCOMPLIANT)", "runtimeError": null }, "context": { "snapshotTime": "2024-07-10T20:44:00Z" }, "Id": "test4", "CA10__AWS_IAM_Policies__r": [ { "Id": "policy4", "CA10__disappearanceTime__c": "2024-07-10T20:44:00Z", "CA10__arn__c": "arn:aws:iam::aws:policy/AWSSupportAccess", "CA10__account__c": "test4" } ], "CA10__AWS_IAM_Role_Policy_Attachments__r": [ { "Id": "test4_1", "CA10__disappearanceTime__c": null, "CA10__role__c": "role4", "CA10__roleArn__c": "arn:aws:iam::1234567890:role/service-role/roleName4", "CA10__policy__c": "policy4", "CA10__policyArn__c": "arn:aws:iam::aws:policy/policyName4", "CA10__account__c": "test4", "CA10__role__r": { "Id": "role4", "CA10__disappearanceTime__c": null }, "CA10__policy__r": { "Id": "policy4", "CA10__disappearanceTime__c": null } } ] }, { "expectedResult": { "status": "UNDETERMINED", "conditionIndex": "400", "conditionText": "otherwise", "runtimeError": null }, "context": { "snapshotTime": "2024-07-10T20:44:00Z" }, "Id": "test5", "CA10__AWS_IAM_Policies__r": [ { "Id": "policy5", "CA10__disappearanceTime__c": null, "CA10__arn__c": "arn:aws:iam::aws:policy/AWSSupportAccess", "CA10__account__c": "test5" } ], "CA10__AWS_IAM_Role_Policy_Attachments__r": [ { "Id": "test5_1", "CA10__disappearanceTime__c": "2024-07-10T20:44:00Z", "CA10__role__c": "role5", "CA10__roleArn__c": "arn:aws:iam::1234567890:role/service-role/roleName5", "CA10__policy__c": "policy5", "CA10__policyArn__c": "arn:aws:iam::aws:policy/policyName5", "CA10__account__c": "test5", "CA10__role__r": { "Id": "role5", "CA10__disappearanceTime__c": null }, "CA10__policy__r": { "Id": "policy5", "CA10__disappearanceTime__c": null } } ] }, { "expectedResult": { "status": "UNDETERMINED", "conditionIndex": "400", "conditionText": "otherwise", "runtimeError": null }, "context": { "snapshotTime": "2024-07-10T20:44:00Z" }, "Id": "test6", "CA10__AWS_IAM_Policies__r": [ { "Id": "policy6", "CA10__disappearanceTime__c": "2024-07-10T20:44:00Z", "CA10__arn__c": "arn:aws:iam::aws:policy/AWSSupportAccess", "CA10__account__c": "test6" } ], "CA10__AWS_IAM_Role_Policy_Attachments__r": [ { "Id": "test6_1", "CA10__disappearanceTime__c": "2024-07-10T20:44:00Z", "CA10__role__c": "role6", "CA10__roleArn__c": "arn:aws:iam::1234567890:role/service-role/roleName6", "CA10__policy__c": "policy6", "CA10__policyArn__c": "arn:aws:iam::aws:policy/policyName6", "CA10__account__c": "test6", "CA10__role__r": { "Id": "role6", "CA10__disappearanceTime__c": null }, "CA10__policy__r": { "Id": "policy6", "CA10__disappearanceTime__c": null } } ] } ] - path: /types/CA10__CaAwsIamPolicy__c/object.extracts.yaml md5Hash: 0275D0984133394A8FDEB9F7EF7CF4FC content: "# yaml-language-server: $schema=../../schema/Extracts.schema.json\n\ ---\nextracts:\n# Not Nullable. Can't have no Access, retrieved via iam:ListPolicies\n\ - name: \"CA10__name__c\"\n value: \n FIELD:\n path: \"CA10__name__c\"\ \n undeterminedIf:\n isEmpty: \"Corrupted data. Policy Name cannot\ \ be empty.\"\n# Not Nullable. Can't have no Access, retrieved via iam:ListPolicies\n\ - name: \"CA10__policyType__c\"\n value:\n FIELD:\n path: \"CA10__policyType__c\"\ \n undeterminedIf:\n isEmpty: \"Corrupted data. Policy Type cannot\ \ be empty.\"\n# Checkbox. Can't have no Access, retrieved via iam:ListPolicies\n\ - name: \"CA10__attachable__c\"\n value: \n FIELD:\n path: \"CA10__attachable__c\"\ \n- name: \"CA10__attachmentCount__c\"\n value: \n FIELD:\n path: \"\ CA10__attachmentCount__c\"\n- name: \"CA10__policyDocument__c\"\n value: \n\ \ FIELD:\n path: CA10__policyDocument__c\n returnType: BYTES\n\ \ undeterminedIf:\n noAccessDelegate:\n path: \"CA10__policyDocument__c\"\ \n currentStateMessage: \"Unable to determine the Policy Document.\ \ Possible permission issue with iam:GetPolicyVersion\"\n- name: \"caJsonFrom_policyDocument__c\"\ \n value:\n JSON_FROM:\n arg:\n EXTRACT: \"CA10__policyDocument__c\"\ \n undeterminedIf:\n isInvalid: \"IAM policy document JSON is invalid\"\ \n# Not Nullable. Can't have no Access, retrieved via iam:ListPolicies\n- name:\ \ \"CA10__arn__c\"\n value: \n FIELD:\n path: CA10__arn__c\n undeterminedIf:\n\ \ isEmpty: \"Corrupted data. Policy ARN cannot be empty.\"\n" - path: /types/CA10__CaAwsIamRolePolicyAttachment__c/object.extracts.yaml md5Hash: 3B1645AD49B1ED98D792A387F70B5AA5 content: "# yaml-language-server: $schema=../../schema/Extracts.schema.json\n\ ---\nextracts:\n- name: CA10__policyArn__c\n value: \n FIELD:\n path:\ \ CA10__policyArn__c\n- name: CA10__role__c\n value: \n FIELD:\n path:\ \ CA10__role__c\n- name: CA10__policy__c\n value: \n FIELD:\n path:\ \ CA10__policy__c" script: |- CREATE TEMP FUNCTION mock_ExpectedResult() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "Id" : "test1", "expectedResult" : { "status" : "COMPLIANT", "conditionIndex" : "199", "conditionText" : "CA10__AWS_IAM_Policies__r.has(COMPLIANT) && CA10__AWS_IAM_Role_Policy_Attachments__r.has(COMPLIANT)", "runtimeError" : null } }, { "Id" : "test2", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "299", "conditionText" : "CA10__AWS_IAM_Policies__r.has(INCOMPLIANT)", "runtimeError" : null } }, { "Id" : "test3", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "399", "conditionText" : "CA10__AWS_IAM_Role_Policy_Attachments__r.has(INCOMPLIANT)", "runtimeError" : null } }, { "Id" : "test4", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "399", "conditionText" : "CA10__AWS_IAM_Role_Policy_Attachments__r.has(INCOMPLIANT)", "runtimeError" : null } }, { "Id" : "test5", "expectedResult" : { "status" : "UNDETERMINED", "conditionIndex" : "400", "conditionText" : "otherwise", "runtimeError" : null } }, { "Id" : "test6", "expectedResult" : { "status" : "UNDETERMINED", "conditionIndex" : "400", "conditionText" : "otherwise", "runtimeError" : null } } ]; """; CREATE TEMP FUNCTION mock_CA10__CaAwsIamPolicy__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "CA10__arn__c" : "arn:aws:iam::aws:policy/AWSSupportAccess", "CA10__account__c" : "test1", "Id" : "policy1" }, { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "CA10__arn__c" : "arn:aws:iam::aws:policy/policyName2", "CA10__account__c" : "test2", "Id" : "policy2" }, { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "CA10__arn__c" : "arn:aws:iam::aws:policy/AWSSupportAccess", "CA10__account__c" : "test3", "Id" : "policy3" }, { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "CA10__disappearanceTime__c" : new Date("2024-07-10T20:44:00Z"), "CA10__arn__c" : "arn:aws:iam::aws:policy/AWSSupportAccess", "CA10__account__c" : "test4", "Id" : "policy4" }, { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "CA10__arn__c" : "arn:aws:iam::aws:policy/AWSSupportAccess", "CA10__account__c" : "test5", "Id" : "policy5" }, { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "CA10__disappearanceTime__c" : new Date("2024-07-10T20:44:00Z"), "CA10__arn__c" : "arn:aws:iam::aws:policy/AWSSupportAccess", "CA10__account__c" : "test6", "Id" : "policy6" } ]; """; CREATE TEMP FUNCTION mock_CA10__CaAwsIamRolePolicyAttachment__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "CA10__role__c" : "role1", "CA10__roleArn__c" : "arn:aws:iam::1234567890:role/service-role/roleName1", "CA10__policy__c" : "policy1", "CA10__policyArn__c" : "arn:aws:iam::aws:policy/AWSSupportAccess", "CA10__account__c" : "test1", "Id" : "test1_1" }, { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "CA10__role__c" : "role2", "CA10__roleArn__c" : "arn:aws:iam::1234567890:role/service-role/roleName2", "CA10__policy__c" : "policy2", "CA10__policyArn__c" : "arn:aws:iam::aws:policy/policyName2", "CA10__account__c" : "test2", "Id" : "test2_1" }, { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "CA10__role__c" : "role3", "CA10__roleArn__c" : "arn:aws:iam::1234567890:role/service-role/roleName3", "CA10__policy__c" : "policy3", "CA10__policyArn__c" : "arn:aws:iam::aws:policy/policyName3", "CA10__account__c" : "test3", "Id" : "test3_1" }, { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "CA10__role__c" : "role4", "CA10__roleArn__c" : "arn:aws:iam::1234567890:role/service-role/roleName4", "CA10__policy__c" : "policy4", "CA10__policyArn__c" : "arn:aws:iam::aws:policy/policyName4", "CA10__account__c" : "test4", "Id" : "test4_1" }, { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "CA10__disappearanceTime__c" : new Date("2024-07-10T20:44:00Z"), "CA10__role__c" : "role5", "CA10__roleArn__c" : "arn:aws:iam::1234567890:role/service-role/roleName5", "CA10__policy__c" : "policy5", "CA10__policyArn__c" : "arn:aws:iam::aws:policy/policyName5", "CA10__account__c" : "test5", "Id" : "test5_1" }, { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "CA10__disappearanceTime__c" : new Date("2024-07-10T20:44:00Z"), "CA10__role__c" : "role6", "CA10__roleArn__c" : "arn:aws:iam::1234567890:role/service-role/roleName6", "CA10__policy__c" : "policy6", "CA10__policyArn__c" : "arn:aws:iam::aws:policy/policyName6", "CA10__account__c" : "test6", "Id" : "test6_1" } ]; """; CREATE TEMP FUNCTION mock_CA10__CaAwsRole__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "Id" : "role1" }, { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "Id" : "role2" }, { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "Id" : "role3" }, { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "Id" : "role4" }, { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "Id" : "role5" }, { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "Id" : "role6" } ]; """; CREATE TEMP FUNCTION mock_CA10__CaAwsAccount__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "Id" : "test1" }, { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "Id" : "test2" }, { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "Id" : "test3" }, { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "Id" : "test4" }, { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "Id" : "test5" }, { "context" : { "snapshotTime" : new Date("2024-07-10T20:44:00Z") }, "Id" : "test6" } ]; """; CREATE TEMP FUNCTION process_CA10__CaAwsAccount__c( obj STRUCT< CA10__AWS_IAM_Policies__r ARRAY >>, CA10__AWS_IAM_Role_Policy_Attachments__r ARRAY, CA10__role__c STRING, CA10__roleArn__c STRING, CA10__policy__r STRUCT< Id STRING, CA10__disappearanceTime__c TIMESTAMP >, CA10__policy__c STRING, CA10__policyArn__c STRING, CA10__account__c STRING, Id STRING, result STRUCT >>, Id STRING >, snapshotTime TIMESTAMP ) RETURNS STRUCT DETERMINISTIC LANGUAGE js AS r""" var references1 = []; // condition[0], conditionIndex:[0..99] if (false) { return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared()", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } var count_CA10__AWS_IAM_Role_Policy_Attachments__r_COMPLIANT3 = 0; if (obj.CA10__AWS_IAM_Role_Policy_Attachments__r != null) { for (var i4 = 0; i4 < obj.CA10__AWS_IAM_Role_Policy_Attachments__r.length; i4++) { if (typeof(obj.CA10__AWS_IAM_Role_Policy_Attachments__r[i4].status) !== 'undefined') { if (obj.CA10__AWS_IAM_Role_Policy_Attachments__r[i4].status == 'COMPLIANT') { count_CA10__AWS_IAM_Role_Policy_Attachments__r_COMPLIANT3 += obj.CA10__AWS_IAM_Role_Policy_Attachments__r[i4].count; } } else { if (obj.CA10__AWS_IAM_Role_Policy_Attachments__r[i4].result.status == 'COMPLIANT') { count_CA10__AWS_IAM_Role_Policy_Attachments__r_COMPLIANT3 += 1; } } } } var count_CA10__AWS_IAM_Policies__r_COMPLIANT2 = 0; if (obj.CA10__AWS_IAM_Policies__r != null) { for (var i5 = 0; i5 < obj.CA10__AWS_IAM_Policies__r.length; i5++) { if (typeof(obj.CA10__AWS_IAM_Policies__r[i5].status) !== 'undefined') { if (obj.CA10__AWS_IAM_Policies__r[i5].status == 'COMPLIANT') { count_CA10__AWS_IAM_Policies__r_COMPLIANT2 += obj.CA10__AWS_IAM_Policies__r[i5].count; } } else { if (obj.CA10__AWS_IAM_Policies__r[i5].result.status == 'COMPLIANT') { count_CA10__AWS_IAM_Policies__r_COMPLIANT2 += 1; } } } } // condition[1], conditionIndex:[100..199] references1.push('Related list [CA10__AWS_IAM_Policies__r] ' + (count_CA10__AWS_IAM_Policies__r_COMPLIANT2 > 0 ? 'has' : 'does not have') + ' objects in COMPLIANT status'); references1.push('Related list [CA10__AWS_IAM_Role_Policy_Attachments__r] ' + (count_CA10__AWS_IAM_Role_Policy_Attachments__r_COMPLIANT3 > 0 ? 'has' : 'does not have') + ' objects in COMPLIANT status'); if (count_CA10__AWS_IAM_Policies__r_COMPLIANT2 > 0 && count_CA10__AWS_IAM_Role_Policy_Attachments__r_COMPLIANT3 > 0) { return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "CA10__AWS_IAM_Policies__r.has(COMPLIANT) && CA10__AWS_IAM_Role_Policy_Attachments__r.has(COMPLIANT)", currentStateMessage: "The AWS account has a support role for managing incidents with AWS Support.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } var count_CA10__AWS_IAM_Policies__r_INCOMPLIANT6 = 0; if (obj.CA10__AWS_IAM_Policies__r != null) { for (var i7 = 0; i7 < obj.CA10__AWS_IAM_Policies__r.length; i7++) { if (typeof(obj.CA10__AWS_IAM_Policies__r[i7].status) !== 'undefined') { if (obj.CA10__AWS_IAM_Policies__r[i7].status == 'INCOMPLIANT') { count_CA10__AWS_IAM_Policies__r_INCOMPLIANT6 += obj.CA10__AWS_IAM_Policies__r[i7].count; } } else { if (obj.CA10__AWS_IAM_Policies__r[i7].result.status == 'INCOMPLIANT') { count_CA10__AWS_IAM_Policies__r_INCOMPLIANT6 += 1; } } } } // condition[2], conditionIndex:[200..299] if (count_CA10__AWS_IAM_Policies__r_INCOMPLIANT6 > 0) { return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "CA10__AWS_IAM_Policies__r.has(INCOMPLIANT)", currentStateMessage: "The AWSSupportAccess IAM policy for managing incidents with AWS Support does not exist.", currentStateReferences: references1.join('\n'), remediation: "Create the AWSSupportAccess IAM policy.", runtimeError: null}; } var count_CA10__AWS_IAM_Role_Policy_Attachments__r_INCOMPLIANT8 = 0; if (obj.CA10__AWS_IAM_Role_Policy_Attachments__r != null) { for (var i9 = 0; i9 < obj.CA10__AWS_IAM_Role_Policy_Attachments__r.length; i9++) { if (typeof(obj.CA10__AWS_IAM_Role_Policy_Attachments__r[i9].status) !== 'undefined') { if (obj.CA10__AWS_IAM_Role_Policy_Attachments__r[i9].status == 'INCOMPLIANT') { count_CA10__AWS_IAM_Role_Policy_Attachments__r_INCOMPLIANT8 += obj.CA10__AWS_IAM_Role_Policy_Attachments__r[i9].count; } } else { if (obj.CA10__AWS_IAM_Role_Policy_Attachments__r[i9].result.status == 'INCOMPLIANT') { count_CA10__AWS_IAM_Role_Policy_Attachments__r_INCOMPLIANT8 += 1; } } } } // condition[3], conditionIndex:[300..399] if (count_CA10__AWS_IAM_Role_Policy_Attachments__r_INCOMPLIANT8 > 0) { return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "CA10__AWS_IAM_Role_Policy_Attachments__r.has(INCOMPLIANT)", currentStateMessage: "The AWSSupportAccess IAM policy is not attached to any IAM role.", currentStateReferences: references1.join('\n'), remediation: "Attach the AWSSupportAccess IAM policy to an IAM role dedicated to managing AWS Support incidents.", runtimeError: null}; } return {status: 'UNDETERMINED', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "There are no active IAM roles or IAM policies.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; """; CREATE TEMP FUNCTION process_CA10__AWS_IAM_Role_Policy_Attachments__r( obj STRUCT< CA10__disappearanceTime__c TIMESTAMP, CA10__role__r STRUCT< Id STRING, CA10__disappearanceTime__c TIMESTAMP >, CA10__role__c STRING, CA10__roleArn__c STRING, CA10__policy__r STRUCT< Id STRING, CA10__disappearanceTime__c TIMESTAMP >, CA10__policy__c STRING, CA10__policyArn__c STRING, CA10__account__c STRING, Id STRING >, snapshotTime TIMESTAMP ) RETURNS STRUCT DETERMINISTIC LANGUAGE js AS r""" var TextLib = new function () { this.normalize = function(arg) { return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase(); }; this.isEmpty = function(arg) { return this.normalize(arg) == ''; }; this.isNotEmpty = function(arg) { return this.normalize(arg) != ''; }; this.equal = function(left, right) { return this.normalize(left) == this.normalize(right); }; this.notEqual = function(left, right) { return this.normalize(left) != this.normalize(right); }; this.startsWith = function(arg, substring) { return this.normalize(arg).startsWith(this.normalize(substring)); }; this.endsWith = function(arg, substring) { return this.normalize(arg).endsWith(this.normalize(substring)); }; this.contains = function(arg, substring) { return this.normalize(arg).includes(this.normalize(substring)); }; this.containsAll = function(arg, substrings) { if (substrings == null || substrings.length === 0) return false; let normalizedArg = this.normalize(arg); return substrings.every(sub => normalizedArg.includes(this.normalize(sub))); }; this.containsAny = function(arg, substrings) { if (substrings == null || substrings.length === 0) return false; let normalizedArg = this.normalize(arg); return substrings.some(sub => normalizedArg.includes(this.normalize(sub))); }; }(); var references1 = []; // condition[0], conditionIndex:[0..99] references1.push('Deleted From AWS [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c); if (obj.CA10__disappearanceTime__c != null) { return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[1], conditionIndex:[100..199] function extract3() { if (!this.out) { this.out = obj.CA10__policyArn__c; } return this.out; }; references1.push('Policy ARN [obj.CA10__policyArn__c]: ' + obj.CA10__policyArn__c); if ((TextLib.isNotEmpty(obj.CA10__roleArn__c) && TextLib.isNotEmpty(obj.CA10__role__c) && obj.CA10__role__r.CA10__disappearanceTime__c == null) && (TextLib.isNotEmpty(obj.CA10__policyArn__c) && TextLib.isNotEmpty(obj.CA10__policy__c) && obj.CA10__policy__r.CA10__disappearanceTime__c == null) && TextLib.equal(extract3.call(extract3), 'arn:aws:iam::aws:policy/AWSSupportAccess')) { return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "notEmptyLookup('CA10__role__r') && notEmptyLookup('CA10__policy__r') && extract('CA10__policyArn__c') == 'arn:aws:iam::aws:policy/AWSSupportAccess'", currentStateMessage: "An IAM role is attached to the AWSSupportAccess IAM policy.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } return {status: 'INCOMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "No IAM role is attached to the AWSSupportAccess IAM policy.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; """; CREATE TEMP FUNCTION process_CA10__AWS_IAM_Policies__r( obj STRUCT< CA10__disappearanceTime__c TIMESTAMP, CA10__arn__c STRING, CA10__account__c STRING, Id STRING >, snapshotTime TIMESTAMP ) RETURNS STRUCT DETERMINISTIC LANGUAGE js AS r""" var TextLib = new function () { this.normalize = function(arg) { return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase(); }; this.isEmpty = function(arg) { return this.normalize(arg) == ''; }; this.isNotEmpty = function(arg) { return this.normalize(arg) != ''; }; this.equal = function(left, right) { return this.normalize(left) == this.normalize(right); }; this.notEqual = function(left, right) { return this.normalize(left) != this.normalize(right); }; this.startsWith = function(arg, substring) { return this.normalize(arg).startsWith(this.normalize(substring)); }; this.endsWith = function(arg, substring) { return this.normalize(arg).endsWith(this.normalize(substring)); }; this.contains = function(arg, substring) { return this.normalize(arg).includes(this.normalize(substring)); }; this.containsAll = function(arg, substrings) { if (substrings == null || substrings.length === 0) return false; let normalizedArg = this.normalize(arg); return substrings.every(sub => normalizedArg.includes(this.normalize(sub))); }; this.containsAny = function(arg, substrings) { if (substrings == null || substrings.length === 0) return false; let normalizedArg = this.normalize(arg); return substrings.some(sub => normalizedArg.includes(this.normalize(sub))); }; }(); var references1 = []; // condition[0], conditionIndex:[0..99] references1.push('Deleted From AWS [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c); if (obj.CA10__disappearanceTime__c != null) { return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[1], conditionIndex:[100..199] function fieldChecked4() { if (TextLib.isEmpty(obj.CA10__arn__c)) { throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__arn__c.isEmpty()", currentStateMessage: "Corrupted data. Policy ARN cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } return obj.CA10__arn__c; } function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; }; references1.push('ARN [obj.CA10__arn__c]: ' + obj.CA10__arn__c); try { if (TextLib.equal(extract3.call(extract3), 'arn:aws:iam::aws:policy/AWSSupportAccess')) { return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__arn__c') == 'arn:aws:iam::aws:policy/AWSSupportAccess'", currentStateMessage: "This is the AWSSupportAccess IAM policy.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } } catch (err) { if (err.cause && err.cause.status) { return err.cause; } else { throw err; } } return {status: 'INCOMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "The AWSSupportAccess IAM policy is not found.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; """; SELECT expectedResult.Id as Id, IF ( IFNULL(expectedResult.expectedResult.status, '') = IFNULL(sObject.result.status, '') AND IFNULL(expectedResult.expectedResult.conditionIndex, -1) = IFNULL(sObject.result.conditionIndex, -1) AND IFNULL(expectedResult.expectedResult.conditionText, '') = IFNULL(sObject.result.conditionText, '') AND IFNULL(expectedResult.expectedResult.runtimeError, '') = IFNULL(sObject.result.runtimeError, ''), "MATCH", "FAIL" ) as match, expectedResult.expectedResult.status as expectedStatus, sObject.result.status as actualStatus, expectedResult.expectedResult.conditionIndex as expectedConditionIndex, sObject.result.conditionIndex as actualConditionIndex, expectedResult.expectedResult.conditionText as expectedConditionText, sObject.result.conditionText as actualConditionText, expectedResult.expectedResult.runtimeError as expectedRuntimeError, sObject.result.runtimeError as actualRuntimeError FROM UNNEST(mock_ExpectedResult()) expectedResult LEFT JOIN ( SELECT `CA10__AWS_IAM_Policies__r`.arr AS CA10__AWS_IAM_Policies__r, `CA10__AWS_IAM_Role_Policy_Attachments__r`.arr AS CA10__AWS_IAM_Role_Policy_Attachments__r, sObject.Id AS Id, process_CA10__CaAwsAccount__c( STRUCT( `CA10__AWS_IAM_Policies__r`.arr AS CA10__AWS_IAM_Policies__r, `CA10__AWS_IAM_Role_Policy_Attachments__r`.arr AS CA10__AWS_IAM_Role_Policy_Attachments__r, sObject.Id AS Id ), sObject.context.snapshotTime ) as result FROM UNNEST(mock_CA10__CaAwsAccount__c()) AS sObject LEFT JOIN ( SELECT sObject.CA10__account__c, ARRAY_AGG( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10__arn__c AS CA10__arn__c, sObject.CA10__account__c AS CA10__account__c, sObject.Id AS Id, process_CA10__AWS_IAM_Policies__r( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10__arn__c AS CA10__arn__c, sObject.CA10__account__c AS CA10__account__c, sObject.Id AS Id ), sObject.context.snapshotTime ) as result ) ) AS arr FROM UNNEST(mock_CA10__CaAwsIamPolicy__c()) AS sObject GROUP BY sObject.CA10__account__c ) AS `CA10__AWS_IAM_Policies__r` ON sObject.Id = `CA10__AWS_IAM_Policies__r`.CA10__account__c LEFT JOIN ( SELECT sObject.CA10__account__c, ARRAY_AGG( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, STRUCT ( `CA10__role__r`.Id AS Id, `CA10__role__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c ) AS CA10__role__r, sObject.CA10__role__c AS CA10__role__c, sObject.CA10__roleArn__c AS CA10__roleArn__c, STRUCT ( `CA10__policy__r`.Id AS Id, `CA10__policy__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c ) AS CA10__policy__r, sObject.CA10__policy__c AS CA10__policy__c, sObject.CA10__policyArn__c AS CA10__policyArn__c, sObject.CA10__account__c AS CA10__account__c, sObject.Id AS Id, process_CA10__AWS_IAM_Role_Policy_Attachments__r( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, STRUCT ( `CA10__role__r`.Id AS Id, `CA10__role__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c ) AS CA10__role__r, sObject.CA10__role__c AS CA10__role__c, sObject.CA10__roleArn__c AS CA10__roleArn__c, STRUCT ( `CA10__policy__r`.Id AS Id, `CA10__policy__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c ) AS CA10__policy__r, sObject.CA10__policy__c AS CA10__policy__c, sObject.CA10__policyArn__c AS CA10__policyArn__c, sObject.CA10__account__c AS CA10__account__c, sObject.Id AS Id ), sObject.context.snapshotTime ) as result ) ) AS arr FROM UNNEST(mock_CA10__CaAwsIamRolePolicyAttachment__c()) AS sObject LEFT JOIN UNNEST(mock_CA10__CaAwsRole__c()) AS `CA10__role__r` ON sObject.CA10__role__c = `CA10__role__r`.Id LEFT JOIN UNNEST(mock_CA10__CaAwsIamPolicy__c()) AS `CA10__policy__r` ON sObject.CA10__policy__c = `CA10__policy__r`.Id GROUP BY sObject.CA10__account__c ) AS `CA10__AWS_IAM_Role_Policy_Attachments__r` ON sObject.Id = `CA10__AWS_IAM_Role_Policy_Attachments__r`.CA10__account__c ) sObject ON sObject.Id = expectedResult.Id;