---
policy: /ce/ca/google/iam/kms-project-has-owner
logic: /ce/ca/google/iam/kms-project-has-owner/prod.logic.yaml
executionTime: 2025-10-25T12:02:46.724522773Z
generationMs: 116
executionMs: 835
rows:
  - id: '001'
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10__Google_CloudKSM_Crypto_Keys__r.hasNo(INCOMPLIANT)
      actual: CA10__Google_CloudKSM_Crypto_Keys__r.hasNo(INCOMPLIANT)
    runtimeError: {}
  - id: '002'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: '003'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10__Google_IAM_Policy_Bindings__r.has(INCOMPLIANT) && CA10__Google_CloudKSM_Crypto_Keys__r.has(INCOMPLIANT)
      actual: CA10__Google_IAM_Policy_Bindings__r.has(INCOMPLIANT) && CA10__Google_CloudKSM_Crypto_Keys__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: '004'
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10__Google_CloudKSM_Crypto_Keys__r.hasNo(INCOMPLIANT)
      actual: CA10__Google_CloudKSM_Crypto_Keys__r.hasNo(INCOMPLIANT)
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/iam/kms-project-has-owner/policy.yaml
    md5Hash: 3AC2681DB05903381D6B59AC31C3A47C
    content: "---\nnames: \n  full: \"Google Project with KMS keys has a principal\
      \ with Owner role\"\n  contextual: \"Project with KMS keys has a principal with\
      \ Owner role\"\ndescription: \"Ensure that projects containing cryptographic\
      \ keys do not grant the\\\n  \\ primitive Owner role to any principal, in order\
      \ to enforce the principle of\\\n  \\ least privilege and separation of duties.\
      \ Assigning the Owner role provides\\\n  \\ unrestricted access to all resources\
      \ within the project, including the ability\\\n  \\ to manage and use sensitive\
      \ cryptographic keys, which creates a significant\\\n  \\ security risk.\"\n\
      type: COMPLIANCE_POLICY\ncategories:\n  - \"SECURITY\"\nframeworkMappings:\n\
      \  - \"/frameworks/nist-sp-800-53-r4/ac/06\"\n  - \"/frameworks/nist-sp-800-53-r4/sc/12\"\
      \n  - \"/frameworks/nist-sp-800-53-r5/ac/03\"\n  - \"/frameworks/nist-sp-800-53-r5/ac/05\"\
      \n  - \"/frameworks/nist-sp-800-53-r5/ac/06\"\n  - \"/frameworks/nist-sp-800-53-r5/mp/02\"\
      \n  - \"/frameworks/pci-dss-v3.2.1/03/05\"\n  - \"/frameworks/pci-dss-v4.0/01/03/01\"\
      \n  - \"/frameworks/iso-iec-27001-2013/10/01/02\"\n  - \"/frameworks/iso-iec-27001-2013/09/02/03\"\
      \n  - \"/frameworks/iso-iec-27001-2022/05/10\"\n  - \"/frameworks/iso-iec-27001-2022/05/15\"\
      \n  - \"/frameworks/iso-iec-27001-2022/08/03\"\n  - \"/frameworks/iso-iec-27001-2022/08/04\"\
      \n  - \"/frameworks/soc-2/cc5/02/03\"\n  - \"/frameworks/soc-2/cc6/01/03\"\n\
      \  - \"/frameworks/soc-2/cc6/01/07\"\n  - \"/frameworks/cloudaware/identity-and-access-governance/user-account-management\"\
      \n"
  - path: /ce/ca/google/iam/kms-project-has-owner/prod.logic.yaml
    md5Hash: 3E04A5C3B9F5EDC6E69ED24234BA0293
    content: "---\ninputType: \"CA10__CaGoogleProject__c\"\ntestData:\n  - file: test-data.json\n\
      importExtracts:\n  - file: /types/CA10__CaGoogleProject__c/object.extracts.yaml\n\
      conditions:\n  - status: \"INAPPLICABLE\"\n    currentStateMessage: \"This project\
      \ does not contain any KMS keys.\"\n    check:\n      RELATED_LIST_HAS_NO:\n\
      \        status: \"INCOMPLIANT\"\n        relationshipName: \"CA10__Google_CloudKSM_Crypto_Keys__r\"\
      \n  - status: \"INCOMPLIANT\"\n    currentStateMessage: \"The project contains\
      \ cryptographic keys and has a principal with Owner permissions.\"\n    remediationMessage:\
      \ \"Assign more granular predefined or custom roles instead.\"\n    check:\n\
      \      AND:\n        args:\n          - RELATED_LIST_HAS:\n              status:\
      \ \"INCOMPLIANT\"\n              relationshipName: \"CA10__Google_IAM_Policy_Bindings__r\"\
      \n          - RELATED_LIST_HAS:\n              status: \"INCOMPLIANT\"\n   \
      \           relationshipName: \"CA10__Google_CloudKSM_Crypto_Keys__r\"\notherwise:\n\
      \  status: \"COMPLIANT\"\n  currentStateMessage: \"The project either does not\
      \ have any principals with the Owner role.\"\nrelatedLists:\n  - relationshipName:\
      \ \"CA10__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\
      \      - \"caGoogleIamPolicyBindingProject\"\n    conditions: \n       - status:\
      \ \"COMPLIANT\"\n         currentStateMessage: \"Binding without a role.\"\n\
      \         check:\n           IS_EMPTY_LOOKUP: \"CA10__iamRole__r\"\n       -\
      \ status: \"INCOMPLIANT\"\n         currentStateMessage: \"This principal is\
      \ assigned the Owner role at the project level.\"\n         remediationMessage:\
      \ \"Remove the binding.\"\n         check: \n           IS_EQUAL:\n        \
      \    left:\n              EXTRACT: \"CA10__iamRole__r.CA10__roleName__c\"\n\
      \            right:\n              TEXT: \"roles/owner\"\n    otherwise:\n \
      \     status: \"COMPLIANT\"\n      currentStateMessage: \"Other IAM Role Bindings.\"\
      \n  - relationshipName: \"CA10__Google_CloudKSM_Crypto_Keys__r\"\n    importExtracts:\n\
      \      - file: \"/types/CA10__CaGoogleCloudKmsCryptoKey__c/object.extracts.yaml\"\
      \n    conditions: []\n    otherwise:\n      status: \"INCOMPLIANT\"\n      currentStateMessage:\
      \ \"The Project with KMS Crypto Key.\"\n"
  - path: /ce/ca/google/iam/kms-project-has-owner/test-data.json
    md5Hash: 6B7DCEE33B5F0D17B8749CF562B0E87E
    content: |-
      [
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "199",
            "conditionText": "CA10__Google_CloudKSM_Crypto_Keys__r.hasNo(INCOMPLIANT)",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2025-10-06T13:24:21Z"
          },
          "Id": "001",
          "CA10__Google_IAM_Policy_Bindings__r": [],
          "CA10__Google_CloudKSM_Crypto_Keys__r": []
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "300",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2025-10-06T13:24:21Z"
          },
          "Id": "002",
          "CA10__Google_IAM_Policy_Bindings__r": [],
          "CA10__Google_CloudKSM_Crypto_Keys__r": [
            {
              "CA10__disappearanceTime__c": null,
              "CA10__project__c": "002",
              "Id": "cck001"
            }
          ]
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "299",
            "conditionText": "CA10__Google_IAM_Policy_Bindings__r.has(INCOMPLIANT) && CA10__Google_CloudKSM_Crypto_Keys__r.has(INCOMPLIANT)",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2025-10-06T13:24:21Z"
          },
          "Id": "003",
          "CA10__Google_IAM_Policy_Bindings__r": [
            {
              "Id": "a9002",
              "RecordTypeId": "RecordTypeId1",
              "CA10__disappearanceTime__c": null,
              "CA10__iamRole__c": "r002",
              "CA10__iamCuratedRoleId__c": "roles/owner",
              "CA10__project__c": "003",
              "RecordType": {
                "DeveloperName": "caGoogleIamPolicyBindingProject",
                "Id": "RecordTypeId1"
              },
              "CA10__iamRole__r": {
                "Id": "r002",
                "CA10__disappearanceTime__c": null,
                "CA10__roleName__c": "roles/owner"
              }
            }
          ],
          "CA10__Google_CloudKSM_Crypto_Keys__r": [
            {
              "CA10__disappearanceTime__c": null,
              "CA10__project__c": "003",
              "Id": "cck002"
            }
          ]
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "199",
            "conditionText": "CA10__Google_CloudKSM_Crypto_Keys__r.hasNo(INCOMPLIANT)",
            "runtimeError": null
          },
          "context": {
            "snapshotTime": "2025-10-06T13:24:21Z"
          },
          "Id": "004",
          "CA10__Google_IAM_Policy_Bindings__r": [
            {
              "Id": "a9004",
              "RecordTypeId": "RecordTypeId1",
              "CA10__disappearanceTime__c": null,
              "CA10__iamRole__c": "r004",
              "CA10__iamCuratedRoleId__c": "roles/owner",
              "CA10__project__c": "004",
              "RecordType": {
                "DeveloperName": "caGoogleIamPolicyBindingProject",
                "Id": "RecordTypeId1"
              },
              "CA10__iamRole__r": {
                "Id": "r004",
                "CA10__disappearanceTime__c": null,
                "CA10__roleName__c": "roles/owner"
              }
            }
          ],
          "CA10__Google_CloudKSM_Crypto_Keys__r": []
        }
      ]
  - path: /types/CA10__CaGoogleCloudKmsCryptoKey__c/object.extracts.yaml
    md5Hash: FBA6F55EDAD759EA3CCFC1311CEB0AAB
    content: "---\nextracts:\n  - name: \"Name\"\n    value: \n      FIELD:\n    \
      \    path: \"Name\"\n        undeterminedIf:\n          isEmpty: \"Name should\
      \ not be empty\"\n  - name: \"CA10__rotationPeriod__c\"\n    value: \n     \
      \ FIELD:\n        path: \"CA10__rotationPeriod__c\"\n        undeterminedIf:\n\
      \          isEmpty: \"Empty rotation period\"\n  - name: \"rotationDuration\"\
      \n    value:\n      DURATION_FROM:\n        arg:\n          EXTRACT: \"CA10__rotationPeriod__c\"\
      \n        format: GCP\n  - name: \"CA10__nextRotationTime__c\"\n    value: \n\
      \      FIELD:\n        path: \"CA10__nextRotationTime__c\"\n        undeterminedIf:\n\
      \          isEmpty: \"Empty value of next rotation time\"\n\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"
  - path: /types/CA10__CaGoogleProject__c/object.extracts.yaml
    md5Hash: 8EB422663BF4493D44ABA5FEC0FB9AD4
    content: "---\nextracts:\n  - name: \"CA10__projectId__c\"\n    value: \n    \
      \   FIELD:\n         path: \"CA10__projectId__c\"\n         undeterminedIf:\n\
      \          isEmpty: \"Corrupted data. Project ID cannot be empty.\"\n  - name:\
      \ \"CA10__enabledServices__c\"\n    value: \n      FIELD:\n        path: \"\
      CA10__enabledServices__c\""
  - 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"
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" : "001",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "CA10__Google_CloudKSM_Crypto_Keys__r.hasNo(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "002",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "003",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "CA10__Google_IAM_Policy_Bindings__r.has(INCOMPLIANT) && CA10__Google_CloudKSM_Crypto_Keys__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "004",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "CA10__Google_CloudKSM_Crypto_Keys__r.hasNo(INCOMPLIANT)",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleProject__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-10-06T13:24:21Z")
    },
    "Id" : "001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-06T13:24:21Z")
    },
    "Id" : "002"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-06T13:24:21Z")
    },
    "Id" : "003"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-06T13:24:21Z")
    },
    "Id" : "004"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleIamPolicyBinding__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__iamRole__c STRING,
      CA10__iamCuratedRoleId__c STRING,
      CA10__project__c STRING,
      Id STRING,
      RecordTypeId STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-10-06T13:24:21Z")
    },
    "CA10__iamRole__c" : "r002",
    "CA10__iamCuratedRoleId__c" : "roles/owner",
    "CA10__project__c" : "003",
    "Id" : "a9002",
    "RecordTypeId" : "RecordTypeId1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-06T13:24:21Z")
    },
    "CA10__iamRole__c" : "r004",
    "CA10__iamCuratedRoleId__c" : "roles/owner",
    "CA10__project__c" : "004",
    "Id" : "a9004",
    "RecordTypeId" : "RecordTypeId1"
  } ];
  """;

  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-10-06T13:24:21Z")
    },
    "DeveloperName" : "caGoogleIamPolicyBindingProject",
    "Id" : "RecordTypeId1"
  } ];
  """;

  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-10-06T13:24:21Z")
    },
    "Id" : "r002",
    "CA10__roleName__c" : "roles/owner"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-06T13:24:21Z")
    },
    "Id" : "r004",
    "CA10__roleName__c" : "roles/owner"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleCloudKmsCryptoKey__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__project__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-10-06T13:24:21Z")
    },
    "CA10__project__c" : "002",
    "Id" : "cck001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-06T13:24:21Z")
    },
    "CA10__project__c" : "003",
    "Id" : "cck002"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleProject__c(
      obj STRUCT<
          Id STRING,
          CA10__Google_IAM_Policy_Bindings__r ARRAY<STRUCT<
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__iamRole__c STRING,
              CA10__iamCuratedRoleId__c STRING,
              CA10__project__c STRING,
              Id STRING,
              RecordTypeId 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>
          >>,
          CA10__Google_CloudKSM_Crypto_Keys__r ARRAY<STRUCT<
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__project__c STRING,
              Id 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]
      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__Google_CloudKSM_Crypto_Keys__r_INCOMPLIANT2 = 0;
      if (obj.CA10__Google_CloudKSM_Crypto_Keys__r != null) {
          for (var i3 = 0; i3 < obj.CA10__Google_CloudKSM_Crypto_Keys__r.length; i3++) {
              if (typeof(obj.CA10__Google_CloudKSM_Crypto_Keys__r[i3].status) !== 'undefined') {
                  if (obj.CA10__Google_CloudKSM_Crypto_Keys__r[i3].status == 'INCOMPLIANT') {
                      count_CA10__Google_CloudKSM_Crypto_Keys__r_INCOMPLIANT2 += obj.CA10__Google_CloudKSM_Crypto_Keys__r[i3].count;
                  }
              } else  {
                  if (obj.CA10__Google_CloudKSM_Crypto_Keys__r[i3].result.status == 'INCOMPLIANT') {
                      count_CA10__Google_CloudKSM_Crypto_Keys__r_INCOMPLIANT2 += 1;
                  }
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10__Google_CloudKSM_Crypto_Keys__r] ' + (count_CA10__Google_CloudKSM_Crypto_Keys__r_INCOMPLIANT2 == 0 ? 'does not have' : 'has') + ' objects in INCOMPLIANT status');
      if (count_CA10__Google_CloudKSM_Crypto_Keys__r_INCOMPLIANT2 == 0) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "CA10__Google_CloudKSM_Crypto_Keys__r.hasNo(INCOMPLIANT)", currentStateMessage: "This project does not contain any KMS keys.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10__Google_IAM_Policy_Bindings__r_INCOMPLIANT4 = 0;
      if (obj.CA10__Google_IAM_Policy_Bindings__r != null) {
          for (var i5 = 0; i5 < obj.CA10__Google_IAM_Policy_Bindings__r.length; i5++) {
              if (typeof(obj.CA10__Google_IAM_Policy_Bindings__r[i5].status) !== 'undefined') {
                  if (obj.CA10__Google_IAM_Policy_Bindings__r[i5].status == 'INCOMPLIANT') {
                      count_CA10__Google_IAM_Policy_Bindings__r_INCOMPLIANT4 += obj.CA10__Google_IAM_Policy_Bindings__r[i5].count;
                  }
              } else  {
                  if (obj.CA10__Google_IAM_Policy_Bindings__r[i5].result.status == 'INCOMPLIANT') {
                      count_CA10__Google_IAM_Policy_Bindings__r_INCOMPLIANT4 += 1;
                  }
              }
          }
      }
      var count_CA10__Google_CloudKSM_Crypto_Keys__r_INCOMPLIANT2 = 0;
      if (obj.CA10__Google_CloudKSM_Crypto_Keys__r != null) {
          for (var i6 = 0; i6 < obj.CA10__Google_CloudKSM_Crypto_Keys__r.length; i6++) {
              if (typeof(obj.CA10__Google_CloudKSM_Crypto_Keys__r[i6].status) !== 'undefined') {
                  if (obj.CA10__Google_CloudKSM_Crypto_Keys__r[i6].status == 'INCOMPLIANT') {
                      count_CA10__Google_CloudKSM_Crypto_Keys__r_INCOMPLIANT2 += obj.CA10__Google_CloudKSM_Crypto_Keys__r[i6].count;
                  }
              } else  {
                  if (obj.CA10__Google_CloudKSM_Crypto_Keys__r[i6].result.status == 'INCOMPLIANT') {
                      count_CA10__Google_CloudKSM_Crypto_Keys__r_INCOMPLIANT2 += 1;
                  }
              }
          }
      }
      // condition[2], conditionIndex:[200..299]
      references1.push('Related list [CA10__Google_IAM_Policy_Bindings__r] ' + (count_CA10__Google_IAM_Policy_Bindings__r_INCOMPLIANT4 > 0 ? 'has' : 'does not have') + ' objects in INCOMPLIANT status');
      if (count_CA10__Google_IAM_Policy_Bindings__r_INCOMPLIANT4 > 0 && count_CA10__Google_CloudKSM_Crypto_Keys__r_INCOMPLIANT2 > 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "CA10__Google_IAM_Policy_Bindings__r.has(INCOMPLIANT) && CA10__Google_CloudKSM_Crypto_Keys__r.has(INCOMPLIANT)", currentStateMessage: "The project contains cryptographic keys and has a principal with Owner permissions.", currentStateReferences: references1.join('\n'), remediation: "Assign more granular predefined or custom roles instead.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "The project either does not have any principals with the Owner role.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__Google_IAM_Policy_Bindings__r(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__iamRole__c STRING,
          CA10__iamCuratedRoleId__c STRING,
          CA10__project__c STRING,
          Id STRING,
          RecordTypeId 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 BytesLib = new function () {
      this.normalize = function(arg) {
          return arg == null ? '' : arg;
      };
      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 CollectionLib = new function () {
      this.parse = function(arg, separator, skipEmpty, skipDuplicates, sort, normalize) {
          if (arg == null) return [];
          let parts = arg.split(separator);
          return this.fromArray(parts, skipEmpty, skipDuplicates, sort, normalize);
      };
      this.fromArray = function(arr, skipEmpty, skipDuplicates, sort, normalize) {
          if (arr == null) return [];
          let result = [];
          let seen = new Set();
          arr.forEach(el => {
              let normalized = normalize ? TextLib.normalize(el) : BytesLib.normalize(el);
              if (!skipEmpty || (normalize ? TextLib.isNotEmpty(el) : BytesLib.isNotEmpty(el))) {
                  if (!skipDuplicates || !seen.has(normalized)) {
                      if (skipDuplicates) seen.add(normalized);
                      result.push(normalized);
                  }
              }
          });
          if (sort) result.sort();
          return result;
      };
      this.equal = function(left, right) {
          left = left == null ? [] : left;
          right = right == null ? [] : right;
          if (left.length !== right.length) return false;
          for (let i = 0; i < left.length; i++) {
              if (left[i] !== right[i]) return false;
          }
          return true;
      };
      this.notEqual = function(left, right) {
          return !this.equal(left, right);
      };
      this.size = function(collection) {
          return collection == null ? 0 : collection.length;
      };
      this.startsWith = function(collection, search, normalize) {
          if (collection == null || collection.length === 0) return false;
          let normalizedSearch = normalize ? TextLib.normalize(search) : BytesLib.normalize(search);
          return collection[0] === normalizedSearch;
      };
      this.endsWith = function(collection, search, normalize) {
          if (collection == null || collection.length === 0) return false;
          let normalizedSearch = normalize ? TextLib.normalize(search) : BytesLib.normalize(search);
          return collection[collection.length - 1] === normalizedSearch;
      };
      this.contains = function(collection, search, normalize) {
          if (collection == null || collection.length === 0) return false;
          return collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search));
      };
      this.containsAll = function(collection, searchArray, normalize) {
          if (collection == null || collection.length === 0 || searchArray == null || searchArray.length === 0) return false;
          return searchArray.every(search => collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search)));
      };
      this.containsAny = function(collection, searchArray, normalize) {
          if (collection == null || collection.length === 0 || searchArray == null || searchArray.length === 0) return false;
          return searchArray.some(search => collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search)));
      };
  }();
  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 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(['caGoogleIamPolicyBindingProject'], true, true, true, true), obj.RecordType.DeveloperName, true)) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "not(setOfText(['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: "Binding without a role.", 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/owner')) {
              return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "extract('CA10__iamRole__r.CA10__roleName__c') == 'roles/owner'", currentStateMessage: "This principal is assigned the Owner role at the project level.", currentStateReferences: references1.join('\n'), remediation: "Remove the binding.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'COMPLIANT', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "Other IAM Role Bindings.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__Google_CloudKSM_Crypto_Keys__r(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__project__c STRING,
          Id 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 [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};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 100, conditionText: "otherwise", currentStateMessage: "The Project with KMS Crypto Key.", 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,
          `CA10__Google_IAM_Policy_Bindings__r`.arr AS CA10__Google_IAM_Policy_Bindings__r,
          `CA10__Google_CloudKSM_Crypto_Keys__r`.arr AS CA10__Google_CloudKSM_Crypto_Keys__r,
          process_CA10__CaGoogleProject__c(
              STRUCT(
                  sObject.Id AS Id,
                  `CA10__Google_IAM_Policy_Bindings__r`.arr AS CA10__Google_IAM_Policy_Bindings__r,
                  `CA10__Google_CloudKSM_Crypto_Keys__r`.arr AS CA10__Google_CloudKSM_Crypto_Keys__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleProject__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__project__c,
              ARRAY_AGG(
                  STRUCT(
                      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.CA10__project__c AS CA10__project__c,
                      sObject.Id AS Id,
                      sObject.RecordTypeId AS RecordTypeId,
                      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_CA10__Google_IAM_Policy_Bindings__r(
                          STRUCT(
                              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.CA10__project__c AS CA10__project__c,
                              sObject.Id AS Id,
                              sObject.RecordTypeId AS RecordTypeId,
                              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.CA10__project__c
      ) AS `CA10__Google_IAM_Policy_Bindings__r`
          ON sObject.Id = `CA10__Google_IAM_Policy_Bindings__r`.CA10__project__c
      LEFT JOIN (
          SELECT
              sObject.CA10__project__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__project__c AS CA10__project__c,
                      sObject.Id AS Id,
                      process_CA10__Google_CloudKSM_Crypto_Keys__r(
                          STRUCT(
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__project__c AS CA10__project__c,
                              sObject.Id AS Id
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaGoogleCloudKmsCryptoKey__c()) AS sObject
          GROUP BY sObject.CA10__project__c
      ) AS `CA10__Google_CloudKSM_Crypto_Keys__r`
          ON sObject.Id = `CA10__Google_CloudKSM_Crypto_Keys__r`.CA10__project__c
  ) sObject ON sObject.Id = expectedResult.Id;
