---
policy: /ce/ca/google/iam/kms-related-roles-to-users
logic: /ce/ca/google/iam/kms-related-roles-to-users/prod.logic.yaml
executionTime: 2025-04-24T23:47:01.353215604Z
rows:
  - id: INCO001
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10G1__Google_IAM_Policy_Bindings__r.has(INCOMPLIANT)
      actual: CA10G1__Google_IAM_Policy_Bindings__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: CO001
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: aUNVI001
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: not(CA10G1__Google_IAM_Policy_Bindings__r.has(INAPPLICABLE))
      actual: not(CA10G1__Google_IAM_Policy_Bindings__r.has(INAPPLICABLE))
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/iam/kms-related-roles-to-users/policy.yaml
    md5Hash: AE40BF84A03BF1B4FF2185420CEAC8F9
    content: "---\nnames: \n  full: \"Google IAM Roles related to KMS are not assigned\
      \ to separate users\"\n  contextual: \"Roles related to KMS are not assigned\
      \ to separate users\"\ndescription: \"It is recommended that the principle of\
      \ 'Separation of Duties' is enforced while assigning KMS related roles to users.\"\
      \ntype: COMPLIANCE_POLICY\ncategories:\n  - \"SECURITY\"\nframeworkMappings:\n\
      \  - /frameworks/cis-gcp-v3.0.0/01/11\n  - /frameworks/cloudaware/identity-and-access-governance/rbac-management\n\
      similarPolicies:\n  cloudConformity:\n    - url: \"https://www.trendmicro.com/cloudoneconformity-staging/knowledge-base/gcp/CloudIAM/enforce-separation-of-duties-for-kms-related-roles.html\"\
      \n      name: \"Enforce Separation of Duties for KMS-Related Roles\"\n "
  - path: /ce/ca/google/iam/kms-related-roles-to-users/prod.logic.yaml
    md5Hash: B508D4F92E36DE62F7469054BB464749
    content: "---\ninputType: \"CA10G1__CaGoogleUser__c\"\ntestData:\n  - file: test-data.json\n\
      conditions:\n  - status: \"INAPPLICABLE\"\n    currentStateMessage: \"Only for\
      \ Cloud KMS Admin Users\"\n    check:\n      NOT:\n        arg:\n          RELATED_LIST_HAS:\n\
      \            status: \"INAPPLICABLE\"\n            relationshipName: \"CA10G1__Google_IAM_Policy_Bindings__r\"\
      \n  - status: \"INCOMPLIANT\"\n    currentStateMessage: \"User has 'Cloud KMS\
      \ Admin' and Cloud KMS CryptoKey Encrypter or Decrypter roles assigned at the\
      \ same time.\"\n    remediationMessage: \"Remove an extra role from the user.\"\
      \n    check:\n      RELATED_LIST_HAS:\n        status: \"INCOMPLIANT\"\n   \
      \     relationshipName: \"CA10G1__Google_IAM_Policy_Bindings__r\"\notherwise:\n\
      \  status: \"COMPLIANT\"\n  currentStateMessage: \"The principle of 'Separation\
      \ of Duties' is enforced.\"\nrelatedLists:\n  - relationshipName: \"CA10G1__Google_IAM_Policy_Bindings__r\"\
      \n    importExtracts:\n      - file: \"/types/CA10__CaGoogleIamPolicyBinding__c/object.extracts.yaml\"\
      \n      - file: /types/CA10__CaGoogleIamRole__c/object.extracts.yaml\n    recordTypes:\n\
      \      - \"caGoogleIamPolicyBindingOrganization\"\n      - \"caGoogleIamPolicyBindingFolder\"\
      \n      - \"caGoogleIamPolicyBindingProject\"\n    conditions: \n      - status:\
      \ \"COMPLIANT\"\n        currentStateMessage: \"Empty policy binding\"\n   \
      \     check:\n          IS_EMPTY_LOOKUP: \"CA10__iamRole__r\"\n      - status:\
      \ \"INAPPLICABLE\"\n        currentStateMessage: \"User has a KMS Admin role\
      \ assigned\"\n        check:\n          IS_EQUAL:\n            left:\n     \
      \         EXTRACT: \"CA10__iamRole__r.CA10__roleName__c\"\n            right:\n\
      \              TEXT: \"roles/cloudkms.admin\" \n      - status: \"INCOMPLIANT\"\
      \n        currentStateMessage: \"User has a KMS related role assigned\"\n  \
      \      check: \n          OR:\n            args:\n              - IS_EQUAL:\n\
      \                  left:\n                    EXTRACT: \"CA10__iamRole__r.CA10__roleName__c\"\
      \n                  right:\n                    TEXT: \"roles/cloudkms.cryptoKeyEncrypterDecrypter\"\
      \n              - IS_EQUAL:\n                  left:\n                    EXTRACT:\
      \ \"CA10__iamRole__r.CA10__roleName__c\"\n                  right:\n       \
      \             TEXT: \"roles/cloudkms.cryptoKeyEncrypter\"\n              - IS_EQUAL:\n\
      \                  left:\n                    EXTRACT: \"CA10__iamRole__r.CA10__roleName__c\"\
      \n                  right:\n                    TEXT: \"roles/cloudkms.cryptoKeyDecrypter\"\
      \n    otherwise:\n      status: \"COMPLIANT\"\n      currentStateMessage: \"\
      User doesn't have a KMS related role assigned\"\n\n"
  - path: /ce/ca/google/iam/kms-related-roles-to-users/test-data.json
    md5Hash: C48A1F22E160DD43A7A187B3CC2019AF
    content: |
      [
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "299",
            "conditionText": "CA10G1__Google_IAM_Policy_Bindings__r.has(INCOMPLIANT)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-02-18T02:05:16Z" },
          "Id": "INCO001",
          "CA10G1__disappearanceTime__c": null,
          "CA10G1__Google_IAM_Policy_Bindings__r": [
            {
              "Id": "aAI7111",
              "RecordTypeId": "0120e0000001HBtAAM",
              "CA10__disappearanceTime__c": null,
              "CA10__iamRole__c": "aAJ011",
              "CA10__iamCuratedRoleId__c": "roles/iam.securityReviewer",
              "CA10G1__googleUser__c": "INCO001",
              "RecordType": {
                "DeveloperName": "caGoogleIamPolicyBindingOrganization",
                "Id": "0120e0000001HBtAAM"
              },
              "CA10__iamRole__r": {
                "Id": "aAJ011",
                "CA10__disappearanceTime__c": null,
                "CA10__roleName__c": "roles/cloudkms.admin"
              }
            },
            {
              "Id": "aAIV111",
              "RecordTypeId": "0120e0000001HBuAAM",
              "CA10__disappearanceTime__c": null,
              "CA10__iamRole__c": "aAJ0e22",
              "CA10__iamCuratedRoleId__c": "roles/iam.serviceAccountUser",
              "CA10G1__googleUser__c": "INCO001",
              "RecordType": {
                "DeveloperName": "caGoogleIamPolicyBindingProject",
                "Id": "0120e0000001HBuAAM"
              },
              "CA10__iamRole__r": {
                "Id": "aAJ0e22",
                "CA10__disappearanceTime__c": null,
                "CA10__roleName__c": "roles/cloudkms.cryptoKeyEncrypter"
              }
            },
            {
              "Id": "aAIVU111",
              "RecordTypeId": "0120e0000001HBuAAM",
              "CA10__disappearanceTime__c": null,
              "CA10__iamRole__c": "aAJ0e33",
              "CA10__iamCuratedRoleId__c": "roles/iam.serviceAccountAdmin",
              "CA10G1__googleUser__c": "INCO001",
              "RecordType": {
                "DeveloperName": "caGoogleIamPolicyBindingProject",
                "Id": "0120e0000001HBuAAM"
              },
              "CA10__iamRole__r": {
                "Id": "aAJ0e33",
                "CA10__disappearanceTime__c": null,
                "CA10__roleName__c": "roles/iam.serviceAccountAdmin"
              }
            }
          ]
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "300",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-02-18T02:05:16Z" },
          "Id": "CO001",
          "CA10G1__disappearanceTime__c": null,
          "CA10G1__Google_IAM_Policy_Bindings__r": [
            {
              "Id": "aAIVU44",
              "RecordTypeId": "0120e0000001HBuAAM",
              "CA10__disappearanceTime__c": null,
              "CA10__iamRole__c": "aAJ0e43",
              "CA10__iamCuratedRoleId__c": "roles/iam.serviceAccountAdmin",
              "CA10G1__googleUser__c": "CO001",
              "RecordType": {
                "DeveloperName": "caGoogleIamPolicyBindingProject",
                "Id": "0120e0000001HBuAAM"
              },
              "CA10__iamRole__r": {
                "Id": "aAJ0e43",
                "CA10__disappearanceTime__c": null,
                "CA10__roleName__c": "roles/cloudkms.admin"
              }
            },
            {
              "Id": "aAIVU55",
              "RecordTypeId": "0120e0000001HBuAAM",
              "CA10__disappearanceTime__c": null,
              "CA10__iamRole__c": "aAJ0e055",
              "CA10__iamCuratedRoleId__c": "roles/owner",
              "CA10G1__googleUser__c": "CO001",
              "RecordType": {
                "DeveloperName": "caGoogleIamPolicyBindingProject",
                "Id": "0120e0000001HBuAAM"
              },
              "CA10__iamRole__r": {
                "Id": "aAJ0e055",
                "CA10__disappearanceTime__c": null,
                "CA10__roleName__c": "roles/owner"
              }
            }
          ]
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "199",
            "conditionText": "not(CA10G1__Google_IAM_Policy_Bindings__r.has(INAPPLICABLE))",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-02-19T01:59:27Z" },
          "Id": "aUNVI001",
          "CA10G1__disappearanceTime__c": null,
          "CA10G1__Google_IAM_Policy_Bindings__r": [
            {
              "Id": "aAI7V000002R3WhWAK",
              "RecordTypeId": "0120e0000001HBtAAM",
              "CA10__disappearanceTime__c": null,
              "CA10__iamRole__c": "aAJ0e000000H8MyGAK",
              "CA10__iamCuratedRoleId__c": "roles/cloudkms.cryptoKeyEncrypter",
              "CA10G1__googleUser__c": "aUNVI001",
              "RecordType": {
                "DeveloperName": "caGoogleIamPolicyBindingOrganization",
                "Id": "0120e0000001HBtAAM"
              },
              "CA10__iamRole__r": {
                "Id": "aAJ0e000000H8MyGAK",
                "CA10__disappearanceTime__c": null,
                "CA10__roleName__c": "roles/cloudkms.cryptoKeyEncrypter"
              }
            },
            {
              "Id": "aAIVU0000001wI74AI",
              "RecordTypeId": "0120e0000001HBuAAM",
              "CA10__disappearanceTime__c": null,
              "CA10__iamRole__c": "aAJ0e000000H8N3GAK",
              "CA10__iamCuratedRoleId__c": "roles/cloudkms.cryptoKeyDecrypter",
              "CA10G1__googleUser__c": "aUNVI001",
              "RecordType": {
                "DeveloperName": "caGoogleIamPolicyBindingProject",
                "Id": "0120e0000001HBuAAM"
              },
              "CA10__iamRole__r": {
                "Id": "aAJ0e000000H8N3GAK",
                "CA10__disappearanceTime__c": null,
                "CA10__roleName__c": "roles/cloudkms.cryptoKeyDecrypter"
              }
            }
          ]
        }
      ]
  - path: /types/CA10__CaGoogleIamPolicyBinding__c/object.extracts.yaml
    md5Hash: DA65DB880E2440923287921FF4E70B30
    content: "---\nextracts:\n  - name: \"Name\"\n    value: \n      FIELD:\n    \
      \    path: \"Name\"\n        undeterminedIf:\n          isEmpty:  \"Name should\
      \ not be empty\"\n  - name: \"CA10__membersAllUsers__c\"\n    value: \n    \
      \  FIELD:\n        path: \"CA10__membersAllUsers__c\"\n        undeterminedIf:\n\
      \          isEmpty:  \"Field should not be empty\"\n  - name: \"CA10__membersAllAuthenticatedUsers__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__membersAllAuthenticatedUsers__c\"\
      \n        undeterminedIf:\n          isEmpty:  \"Field should not be empty\"\
      \n"
  - path: /types/CA10__CaGoogleIamRole__c/object.extracts.yaml
    md5Hash: 545CD4D347F041DCDD9980D122D63882
    content: "---\nextracts:\n  - name: \"Name\"\n    value: \n      FIELD:\n    \
      \    path: \"Name\"\n        undeterminedIf:\n          isEmpty: \"Name should\
      \ not be empty\"\n  - name: \"CA10__roleName__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__roleName__c\"\n        undeterminedIf:\n          isEmpty:\
      \  \"Name should not be empty\"\n"
script: |-
  CREATE TEMP FUNCTION mock_ExpectedResult()
  RETURNS ARRAY<STRUCT<
          Id STRING,
          expectedResult STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, runtimeError STRING>
      >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "Id" : "INCO001",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "CA10G1__Google_IAM_Policy_Bindings__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "CO001",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "aUNVI001",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "not(CA10G1__Google_IAM_Policy_Bindings__r.has(INAPPLICABLE))",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10G1__CaGoogleUser__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10G1__disappearanceTime__c TIMESTAMP,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-02-18T02:05:16Z")
    },
    "Id" : "INCO001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-02-18T02:05:16Z")
    },
    "Id" : "CO001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-02-19T01:59:27Z")
    },
    "Id" : "aUNVI001"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleIamPolicyBinding__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      RecordTypeId STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__iamRole__c STRING,
      CA10__iamCuratedRoleId__c STRING,
      CA10G1__googleUser__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-02-18T02:05:16Z")
    },
    "Id" : "aAI7111",
    "RecordTypeId" : "0120e0000001HBtAAM",
    "CA10__iamRole__c" : "aAJ011",
    "CA10__iamCuratedRoleId__c" : "roles/iam.securityReviewer",
    "CA10G1__googleUser__c" : "INCO001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-02-18T02:05:16Z")
    },
    "Id" : "aAIV111",
    "RecordTypeId" : "0120e0000001HBuAAM",
    "CA10__iamRole__c" : "aAJ0e22",
    "CA10__iamCuratedRoleId__c" : "roles/iam.serviceAccountUser",
    "CA10G1__googleUser__c" : "INCO001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-02-18T02:05:16Z")
    },
    "Id" : "aAIVU111",
    "RecordTypeId" : "0120e0000001HBuAAM",
    "CA10__iamRole__c" : "aAJ0e33",
    "CA10__iamCuratedRoleId__c" : "roles/iam.serviceAccountAdmin",
    "CA10G1__googleUser__c" : "INCO001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-02-18T02:05:16Z")
    },
    "Id" : "aAIVU44",
    "RecordTypeId" : "0120e0000001HBuAAM",
    "CA10__iamRole__c" : "aAJ0e43",
    "CA10__iamCuratedRoleId__c" : "roles/iam.serviceAccountAdmin",
    "CA10G1__googleUser__c" : "CO001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-02-18T02:05:16Z")
    },
    "Id" : "aAIVU55",
    "RecordTypeId" : "0120e0000001HBuAAM",
    "CA10__iamRole__c" : "aAJ0e055",
    "CA10__iamCuratedRoleId__c" : "roles/owner",
    "CA10G1__googleUser__c" : "CO001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-02-19T01:59:27Z")
    },
    "Id" : "aAI7V000002R3WhWAK",
    "RecordTypeId" : "0120e0000001HBtAAM",
    "CA10__iamRole__c" : "aAJ0e000000H8MyGAK",
    "CA10__iamCuratedRoleId__c" : "roles/cloudkms.cryptoKeyEncrypter",
    "CA10G1__googleUser__c" : "aUNVI001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-02-19T01:59:27Z")
    },
    "Id" : "aAIVU0000001wI74AI",
    "RecordTypeId" : "0120e0000001HBuAAM",
    "CA10__iamRole__c" : "aAJ0e000000H8N3GAK",
    "CA10__iamCuratedRoleId__c" : "roles/cloudkms.cryptoKeyDecrypter",
    "CA10G1__googleUser__c" : "aUNVI001"
  } ];
  """;

  CREATE TEMP FUNCTION mock_RecordType()
  RETURNS ARRAY<STRUCT<
      DeveloperName STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-02-19T01:59:27Z")
    },
    "DeveloperName" : "caGoogleIamPolicyBindingOrganization",
    "Id" : "0120e0000001HBtAAM"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-02-19T01:59:27Z")
    },
    "DeveloperName" : "caGoogleIamPolicyBindingProject",
    "Id" : "0120e0000001HBuAAM"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleIamRole__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__roleName__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-02-18T02:05:16Z")
    },
    "Id" : "aAJ011",
    "CA10__roleName__c" : "roles/cloudkms.admin"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-02-18T02:05:16Z")
    },
    "Id" : "aAJ0e22",
    "CA10__roleName__c" : "roles/cloudkms.cryptoKeyEncrypter"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-02-18T02:05:16Z")
    },
    "Id" : "aAJ0e33",
    "CA10__roleName__c" : "roles/iam.serviceAccountAdmin"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-02-18T02:05:16Z")
    },
    "Id" : "aAJ0e43",
    "CA10__roleName__c" : "roles/cloudkms.admin"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-02-18T02:05:16Z")
    },
    "Id" : "aAJ0e055",
    "CA10__roleName__c" : "roles/owner"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-02-19T01:59:27Z")
    },
    "Id" : "aAJ0e000000H8MyGAK",
    "CA10__roleName__c" : "roles/cloudkms.cryptoKeyEncrypter"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-02-19T01:59:27Z")
    },
    "Id" : "aAJ0e000000H8N3GAK",
    "CA10__roleName__c" : "roles/cloudkms.cryptoKeyDecrypter"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10G1__CaGoogleUser__c(
      obj STRUCT<
          Id STRING,
          CA10G1__disappearanceTime__c TIMESTAMP,
          CA10G1__Google_IAM_Policy_Bindings__r ARRAY<STRUCT<
              Id STRING,
              RecordTypeId STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__iamRole__c STRING,
              CA10__iamCuratedRoleId__c STRING,
              CA10G1__googleUser__c STRING,
              RecordType STRUCT<
                  DeveloperName STRING,
                  Id STRING
              >,
              CA10__iamRole__r STRUCT<
                  Id STRING,
                  CA10__disappearanceTime__c TIMESTAMP,
                  CA10__roleName__c STRING
              >,
              result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
          >>
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From Google [CA10G1__disappearanceTime__c]: ' + obj.CA10G1__disappearanceTime__c);
      if (obj.CA10G1__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10G1__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10G1__Google_IAM_Policy_Bindings__r_INAPPLICABLE2 = 0;
      if (obj.CA10G1__Google_IAM_Policy_Bindings__r != null) {
          for (var i3 = 0; i3 < obj.CA10G1__Google_IAM_Policy_Bindings__r.length; i3++) {
              if (obj.CA10G1__Google_IAM_Policy_Bindings__r[i3].result.status == 'INAPPLICABLE') {
                  count_CA10G1__Google_IAM_Policy_Bindings__r_INAPPLICABLE2 += 1;
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10G1__Google_IAM_Policy_Bindings__r] ' + (count_CA10G1__Google_IAM_Policy_Bindings__r_INAPPLICABLE2 > 0 ? 'has' : 'does not have') + ' objects in INAPPLICABLE status');
      if (!count_CA10G1__Google_IAM_Policy_Bindings__r_INAPPLICABLE2 > 0) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "not(CA10G1__Google_IAM_Policy_Bindings__r.has(INAPPLICABLE))", currentStateMessage: "Only for Cloud KMS Admin Users", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10G1__Google_IAM_Policy_Bindings__r_INCOMPLIANT4 = 0;
      if (obj.CA10G1__Google_IAM_Policy_Bindings__r != null) {
          for (var i5 = 0; i5 < obj.CA10G1__Google_IAM_Policy_Bindings__r.length; i5++) {
              if (obj.CA10G1__Google_IAM_Policy_Bindings__r[i5].result.status == 'INCOMPLIANT') {
                  count_CA10G1__Google_IAM_Policy_Bindings__r_INCOMPLIANT4 += 1;
              }
          }
      }
      // condition[2], conditionIndex:[200..299]
      if (count_CA10G1__Google_IAM_Policy_Bindings__r_INCOMPLIANT4 > 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "CA10G1__Google_IAM_Policy_Bindings__r.has(INCOMPLIANT)", currentStateMessage: "User has 'Cloud KMS Admin' and Cloud KMS CryptoKey Encrypter or Decrypter roles assigned at the same time.", currentStateReferences: references1.join('\n'), remediation: "Remove an extra role from the user.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "The principle of 'Separation of Duties' is enforced.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10G1__Google_IAM_Policy_Bindings__r(
      obj STRUCT<
          Id STRING,
          RecordTypeId STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__iamRole__c STRING,
          CA10__iamCuratedRoleId__c STRING,
          CA10G1__googleUser__c STRING,
          RecordType STRUCT<
              DeveloperName STRING,
              Id STRING
          >,
          CA10__iamRole__r STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__roleName__c STRING
          >
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
      var CollectionLib = new function () {
          this.parse = function(arg, separator) {
              let out = new Set();
              if (arg == null) {
                  return out;
              }
              arg.split(separator).forEach(el => {if (TextLib.isNotEmpty(el)) {out.add(TextLib.normalize(el))}});
              return out;
          };
          this.fromArray = function(arr) {
              let out = new Set();
              if (arr == null) {
                  return out;
              }
              arr.forEach(el => {if (TextLib.isNotEmpty(el)) {out.add(TextLib.normalize(el))}});
              return out;
          };
          this.equal = function(left, right) {
              left = left == null ? new Set() : left;
              right = right == null ? new Set() : right;
              return left.size === right.size && new Set([...left, ...right]).size === left.size;
          };
          this.notEqual = function(left, right) {
              left = left == null ? new Set() : left;
              right = right == null ? new Set() : right;
              return left.size !== right.size || new Set([...left, ...right]).size !== left.size;
          };
          this.contains = function(collection, search) {
              if (collection == null || TextLib.isEmpty(search)) {
                  return false;
              }
              return collection.has(TextLib.normalize(search));
          };
          this.size = function(collection) {
              return collection == null ? 0 : collection.size;
          };
      }();
      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));
          };
      }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From Google [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]
      references1.push('Record Type Name [obj.RecordType.DeveloperName]: ' + obj.RecordType.DeveloperName);
      if (!CollectionLib.contains(CollectionLib.fromArray(['caGoogleIamPolicyBindingOrganization', 'caGoogleIamPolicyBindingFolder', 'caGoogleIamPolicyBindingProject']), obj.RecordType.DeveloperName)) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "not(['caGoogleIamPolicyBindingOrganization', 'caGoogleIamPolicyBindingFolder', 'caGoogleIamPolicyBindingProject'].contains(RecordType.DeveloperName))", currentStateMessage: "Object record type is not applicable", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      if (TextLib.isEmpty(obj.CA10__iamCuratedRoleId__c) || TextLib.isEmpty(obj.CA10__iamRole__c) || obj.CA10__iamRole__r.CA10__disappearanceTime__c != null) {
          return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "isEmptyLookup('CA10__iamRole__r')", currentStateMessage: "Empty policy binding", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function extractChecked3() {
          if (TextLib.isEmpty(obj.CA10__iamCuratedRoleId__c)) {
              throw new Error("UNDETERMINED condition:301", {cause: {status: 'UNDETERMINED', conditionIndex: 301, conditionText: "extractCheck(obj.CA10__iamCuratedRoleId__c)", currentStateMessage: "Related object via CA10__iamCuratedRoleId__c has empty ID", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (TextLib.isEmpty(obj.CA10__iamRole__c)) {
              throw new Error("UNDETERMINED condition:302", {cause: {status: 'UNDETERMINED', conditionIndex: 302, conditionText: "extractCheck(obj.CA10__iamRole__c)", currentStateMessage: "Related object via CA10__iamRole__c is not present", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (obj.CA10__iamRole__r.CA10__disappearanceTime__c != null) {
              throw new Error("UNDETERMINED condition:303", {cause: {status: 'UNDETERMINED', conditionIndex: 303, conditionText: "extractCheck(obj.CA10__iamRole__r.CA10__disappearanceTime__c)", currentStateMessage: "Related object via CA10__iamRole__c is present, but deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return extract4.call(extract4);
      }
      function fieldChecked5() {
          if (TextLib.isEmpty(obj.CA10__iamRole__r.CA10__roleName__c)) {
              throw new Error("UNDETERMINED condition:304", {cause: {status: 'UNDETERMINED', conditionIndex: 304, conditionText: "CA10__roleName__c.isEmpty()", currentStateMessage: "Name should not be empty", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__iamRole__r.CA10__roleName__c;
      }
      function extract4() { if (!this.out) { this.out = fieldChecked5(); } return this.out; };
      references1.push('Role Name [obj.CA10__iamRole__r.CA10__roleName__c]: ' + obj.CA10__iamRole__r.CA10__roleName__c);
      try {
          if (TextLib.equal(extractChecked3(), 'roles/cloudkms.admin')) {
              return {status: 'INAPPLICABLE', conditionIndex: 399, conditionText: "extract('CA10__iamRole__r.CA10__roleName__c') == 'roles/cloudkms.admin'", currentStateMessage: "User has a KMS Admin role assigned", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[4], conditionIndex:[400..499]
      function extractChecked6() {
          if (TextLib.isEmpty(obj.CA10__iamCuratedRoleId__c)) {
              throw new Error("UNDETERMINED condition:401", {cause: {status: 'UNDETERMINED', conditionIndex: 401, conditionText: "extractCheck(obj.CA10__iamCuratedRoleId__c)", currentStateMessage: "Related object via CA10__iamCuratedRoleId__c has empty ID", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (TextLib.isEmpty(obj.CA10__iamRole__c)) {
              throw new Error("UNDETERMINED condition:402", {cause: {status: 'UNDETERMINED', conditionIndex: 402, conditionText: "extractCheck(obj.CA10__iamRole__c)", currentStateMessage: "Related object via CA10__iamRole__c is not present", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (obj.CA10__iamRole__r.CA10__disappearanceTime__c != null) {
              throw new Error("UNDETERMINED condition:403", {cause: {status: 'UNDETERMINED', conditionIndex: 403, conditionText: "extractCheck(obj.CA10__iamRole__r.CA10__disappearanceTime__c)", currentStateMessage: "Related object via CA10__iamRole__c is present, but deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return extract7.call(extract7);
      }
      function fieldChecked8() {
          if (TextLib.isEmpty(obj.CA10__iamRole__r.CA10__roleName__c)) {
              throw new Error("UNDETERMINED condition:404", {cause: {status: 'UNDETERMINED', conditionIndex: 404, conditionText: "CA10__roleName__c.isEmpty()", currentStateMessage: "Name should not be empty", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__iamRole__r.CA10__roleName__c;
      }
      function extract7() { if (!this.out) { this.out = fieldChecked8(); } return this.out; };
      function extractChecked9() {
          if (TextLib.isEmpty(obj.CA10__iamCuratedRoleId__c)) {
              throw new Error("UNDETERMINED condition:405", {cause: {status: 'UNDETERMINED', conditionIndex: 405, conditionText: "extractCheck(obj.CA10__iamCuratedRoleId__c)", currentStateMessage: "Related object via CA10__iamCuratedRoleId__c has empty ID", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (TextLib.isEmpty(obj.CA10__iamRole__c)) {
              throw new Error("UNDETERMINED condition:406", {cause: {status: 'UNDETERMINED', conditionIndex: 406, conditionText: "extractCheck(obj.CA10__iamRole__c)", currentStateMessage: "Related object via CA10__iamRole__c is not present", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (obj.CA10__iamRole__r.CA10__disappearanceTime__c != null) {
              throw new Error("UNDETERMINED condition:407", {cause: {status: 'UNDETERMINED', conditionIndex: 407, conditionText: "extractCheck(obj.CA10__iamRole__r.CA10__disappearanceTime__c)", currentStateMessage: "Related object via CA10__iamRole__c is present, but deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return extract7.call(extract7);
      }
      function extractChecked10() {
          if (TextLib.isEmpty(obj.CA10__iamCuratedRoleId__c)) {
              throw new Error("UNDETERMINED condition:408", {cause: {status: 'UNDETERMINED', conditionIndex: 408, conditionText: "extractCheck(obj.CA10__iamCuratedRoleId__c)", currentStateMessage: "Related object via CA10__iamCuratedRoleId__c has empty ID", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (TextLib.isEmpty(obj.CA10__iamRole__c)) {
              throw new Error("UNDETERMINED condition:409", {cause: {status: 'UNDETERMINED', conditionIndex: 409, conditionText: "extractCheck(obj.CA10__iamRole__c)", currentStateMessage: "Related object via CA10__iamRole__c is not present", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (obj.CA10__iamRole__r.CA10__disappearanceTime__c != null) {
              throw new Error("UNDETERMINED condition:410", {cause: {status: 'UNDETERMINED', conditionIndex: 410, conditionText: "extractCheck(obj.CA10__iamRole__r.CA10__disappearanceTime__c)", currentStateMessage: "Related object via CA10__iamRole__c is present, but deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return extract7.call(extract7);
      }
      try {
          if (TextLib.equal(extractChecked6(), 'roles/cloudkms.cryptoKeyEncrypterDecrypter') || TextLib.equal(extractChecked9(), 'roles/cloudkms.cryptoKeyEncrypter') || TextLib.equal(extractChecked10(), 'roles/cloudkms.cryptoKeyDecrypter')) {
              return {status: 'INCOMPLIANT', conditionIndex: 499, conditionText: "extract('CA10__iamRole__r.CA10__roleName__c') == 'roles/cloudkms.cryptoKeyEncrypterDecrypter' || extract('CA10__iamRole__r.CA10__roleName__c') == 'roles/cloudkms.cryptoKeyEncrypter' || extract('CA10__iamRole__r.CA10__roleName__c') == 'roles/cloudkms.cryptoKeyDecrypter'", currentStateMessage: "User has a KMS related role assigned", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'COMPLIANT', conditionIndex: 500, conditionText: "otherwise", currentStateMessage: "User doesn't have a KMS related role assigned", 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
          sObject.Id AS Id,
          sObject.CA10G1__disappearanceTime__c AS CA10G1__disappearanceTime__c,
          `CA10G1__Google_IAM_Policy_Bindings__r`.arr AS CA10G1__Google_IAM_Policy_Bindings__r,
          process_CA10G1__CaGoogleUser__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10G1__disappearanceTime__c AS CA10G1__disappearanceTime__c,
                  `CA10G1__Google_IAM_Policy_Bindings__r`.arr AS CA10G1__Google_IAM_Policy_Bindings__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10G1__CaGoogleUser__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10G1__googleUser__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.RecordTypeId AS RecordTypeId,
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__iamRole__c AS CA10__iamRole__c,
                      sObject.CA10__iamCuratedRoleId__c AS CA10__iamCuratedRoleId__c,
                      sObject.CA10G1__googleUser__c AS CA10G1__googleUser__c,
                      STRUCT (
                          `RecordType`.DeveloperName AS DeveloperName,
                          `RecordType`.Id AS Id
                      ) AS RecordType,
                      STRUCT (
                          `CA10__iamRole__r`.Id AS Id,
                          `CA10__iamRole__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                          `CA10__iamRole__r`.CA10__roleName__c AS CA10__roleName__c
                      ) AS CA10__iamRole__r,
                      process_CA10G1__Google_IAM_Policy_Bindings__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.RecordTypeId AS RecordTypeId,
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__iamRole__c AS CA10__iamRole__c,
                              sObject.CA10__iamCuratedRoleId__c AS CA10__iamCuratedRoleId__c,
                              sObject.CA10G1__googleUser__c AS CA10G1__googleUser__c,
                              STRUCT (
                                  `RecordType`.DeveloperName AS DeveloperName,
                                  `RecordType`.Id AS Id
                              ) AS RecordType,
                              STRUCT (
                                  `CA10__iamRole__r`.Id AS Id,
                                  `CA10__iamRole__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                                  `CA10__iamRole__r`.CA10__roleName__c AS CA10__roleName__c
                              ) AS CA10__iamRole__r
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaGoogleIamPolicyBinding__c()) AS sObject
          LEFT JOIN UNNEST(mock_RecordType()) AS `RecordType`
              ON sObject.RecordTypeId = `RecordType`.Id
          LEFT JOIN UNNEST(mock_CA10__CaGoogleIamRole__c()) AS `CA10__iamRole__r`
              ON sObject.CA10__iamRole__c = `CA10__iamRole__r`.Id
          GROUP BY sObject.CA10G1__googleUser__c
      ) AS `CA10G1__Google_IAM_Policy_Bindings__r`
          ON sObject.Id = `CA10G1__Google_IAM_Policy_Bindings__r`.CA10G1__googleUser__c
  ) sObject ON sObject.Id = expectedResult.Id;
