---
policy: /ce/ca/azure/subscription/custom-subscription-administrator-roles-exist
logic: /ce/ca/azure/subscription/custom-subscription-administrator-roles-exist/prod.logic.yaml
executionTime: 2025-04-24T23:46:14.722850431Z
rows:
  - id: test1
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10__Azure_Authorization_Role_Definitions__r.has(INCOMPLIANT)
      actual: CA10__Azure_Authorization_Role_Definitions__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/azure/subscription/custom-subscription-administrator-roles-exist/policy.yaml
    md5Hash: 513C8C5836BF33FDFCBA20DB5FD40742
    content: |
      ---
      names:
        full: Azure Subscription Custom Subscription Administrator Roles exist
        contextual: Custom Subscription Administrator Roles exist
      description: The principle of least privilege should be followed and only necessary
        privileges should be assigned instead of allowing full administrative access.
      type: COMPLIANCE_POLICY
      categories:
        - SECURITY
      frameworkMappings:
        - "/frameworks/cis-azure-v2.1.0/01/22"
        - "/frameworks/cis-azure-v3.0.0/02/23"
        - "/frameworks/cloudaware/identity-and-access-governance/rbac-management"
      similarPolicies:
        cloudConformity:
          - url: https://www.trendmicro.com/cloudoneconformity/knowledge-base/azure/AccessControl/no-custom-subscription-admin.html
            name: Subscription Administrator Custom Role
  - path: /ce/ca/azure/subscription/custom-subscription-administrator-roles-exist/prod.logic.yaml
    md5Hash: 73DFCC88B98DBCD02F77722E23EC9D31
    content: "---\ninputType: \"CA10__CaAzureAccount__c\"\ntestData:\n  - file: \"\
      test-data.json\"\nconditions:\n  - status: \"INCOMPLIANT\"\n    currentStateMessage:\
      \ \"This subscription has a custom role with owner permissions\\ \n     \\ and\
      \ assignable scope is set to subscription.\"\n    remediationMessage: \"Consider\
      \ removing the custom role.\"\n    check:\n      RELATED_LIST_HAS:\n       \
      \ relationshipName: \"CA10__Azure_Authorization_Role_Definitions__r\"\n    \
      \    status: \"INCOMPLIANT\"\notherwise:\n  status: \"COMPLIANT\"\n  currentStateMessage:\
      \ \"This subscription doesn't have a custom role with owner permissions.\"\n\
      relatedLists:\n  - relationshipName: \"CA10__Azure_Authorization_Role_Definitions__r\"\
      \n    importExtracts:\n      - file: \"/types/CA10__CaAzureAuthorizationRole__c/object.extracts.yaml\"\
      \n    conditions:\n      - status: \"INAPPLICABLE\"\n        currentStateMessage:\
      \ \"This is not a Custom role.\"\n        check:\n          NOT_EQUAL:\n   \
      \         left:\n              EXTRACT: \"CA10__roleType__c\"\n            right:\n\
      \              TEXT: \"CustomRole\"\n      - status: \"INAPPLICABLE\"\n    \
      \    currentStateMessage: \"Permissions do not have * actions.\"\n        check:\n\
      # Returns true if permissions' actions have \"*\" action\n          IS_EQUAL:\n\
      \            left:\n              JSON_QUERY_BOOLEAN:\n                arg:\n\
      \                  JSON_FROM:\n                    arg: \n                 \
      \     EXTRACT: \"CA10__permissionsJson__c\"\n                    undeterminedIf:\n\
      \                      isInvalid: \"The provided Permissions JSON is invalid.\"\
      \n                expression: \"contains([*].actions[], '*')\"\n           \
      \     undeterminedIf:\n                  evaluationError: \"JSON query boolean\
      \ has failed.\"\n                  resultTypeMismatch: \"JSON query did not\
      \ return boolean type.\"\n            right:\n              BOOLEAN: false\n\
      \      - status: \"INCOMPLIANT\"\n        currentStateMessage: \"This custom\
      \ role has owner permissions and subscription scopes.\"\n        remediationMessage:\
      \ \"Consider removing this role.\"\n        check:\n# JSON_QUERY_NUMBER returns\
      \ the number of scopes that fall into the filter:\n# the scope start with '/subscriptions/'\
      \ and does not contain 'resourceGroups'\n          GREATER_THAN:\n         \
      \   left:\n              JSON_QUERY_NUMBER:\n                arg:\n        \
      \          JSON_FROM:\n                    arg: \n                      EXTRACT:\
      \ \"CA10__assignableScopesJson__c\"\n                    undeterminedIf:\n \
      \                     isInvalid: \"The provided Assignable Scopes JSON is invalid.\"\
      \n                expression: \"length([?starts_with(@, '/subscriptions/') &&\
      \ !contains(@, 'resourceGroups')])\"\n                undeterminedIf:\n    \
      \              evaluationError: \"JSON query number has failed.\"\n        \
      \          resultTypeMismatch: \"JSON query did not return number type.\"\n\
      \            right: \n              NUMBER: 0.0\n    otherwise:\n      status:\
      \ \"INAPPLICABLE\"\n      currentStateMessage: \"A role has owner permissions\
      \ without subscription scopes.\""
  - path: /ce/ca/azure/subscription/custom-subscription-administrator-roles-exist/test-data.json
    md5Hash: 765AF2CAA1D3B3A38E0FC73D056B3314
    content: |-
      [
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "CA10__Azure_Authorization_Role_Definitions__r.has(INCOMPLIANT)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-09T19:33:20Z"
              },
              "Id": "test1",
              "CA10__Azure_Authorization_Role_Definitions__r": [
                  {
                      "Id": "test1_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__roleType__c": "CustomRole",
                      "CA10__permissionsJson__c": "[{\"actions\":[\"*\", \"Microsoft.Resources/subscriptions/resourceGroups/read\"],\"notActions\":[],\"dataActions\":[],\"notDataActions\":[]}]",
                      "CA10__assignableScopesJson__c": "[\"/subscriptions/subscriptionId\"]",
                      "CA10__subscription__c": "test1",
                      "CA10__subscription__r": {
                          "Id": "test1",
                          "CA10__subscriptionId__c": "subscriptionId"
                      }
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "200",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-09T19:33:20Z"
              },
              "Id": "test2",
              "CA10__Azure_Authorization_Role_Definitions__r": [
                  {
                      "Id": "test2_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__roleType__c": "BuiltInRole",
                      "CA10__permissionsJson__c": "[{\"actions\":[\"*\"],\"notActions\":[],\"dataActions\":[],\"notDataActions\":[]}]",
                      "CA10__assignableScopesJson__c": "[\"/subscriptions/subscriptionId\"]",
                      "CA10__subscription__c": "test2",
                      "CA10__subscription__r": {
                          "Id": "test2",
                          "CA10__subscriptionId__c": "subscriptionId"
                      }
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "200",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-09T19:33:20Z"
              },
              "Id": "test3",
              "CA10__Azure_Authorization_Role_Definitions__r": [
                  {
                      "Id": "test3_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__roleType__c": "CustomRole",
                      "CA10__permissionsJson__c": "[{\"actions\":[\"Microsoft.Resources/subscriptions/resourceGroups/read\"],\"notActions\":[],\"dataActions\":[],\"notDataActions\":[]}]",
                      "CA10__assignableScopesJson__c": "[\"/subscriptions/subscriptionId\"]",
                      "CA10__subscription__c": "test3",
                      "CA10__subscription__r": {
                          "Id": "test3",
                          "CA10__subscriptionId__c": "subscriptionId"
                      }
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "200",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-09T19:33:20Z"
              },
              "Id": "test4",
              "CA10__Azure_Authorization_Role_Definitions__r": [
                  {
                      "Id": "test4_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__roleType__c": "CustomRole",
                      "CA10__permissionsJson__c": "[{\"actions\":[\"*\"],\"notActions\":[],\"dataActions\":[],\"notDataActions\":[]}]",
                      "CA10__assignableScopesJson__c": "[\"/\"]",
                      "CA10__subscription__c": "test4",
                      "CA10__subscription__r": {
                          "Id": "test4",
                          "CA10__subscriptionId__c": "subscriptionId"
                      }
                  }
              ]
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "200",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-09T19:33:20Z"
              },
              "Id": "test5",
              "CA10__Azure_Authorization_Role_Definitions__r": [
                  {
                      "Id": "test5_1",
                      "CA10__disappearanceTime__c": null,
                      "CA10__roleType__c": "CustomRole",
                      "CA10__permissionsJson__c": "{",
                      "CA10__assignableScopesJson__c": "[\"/\"]",
                      "CA10__subscription__c": "test5",
                      "CA10__subscription__r": {
                          "Id": "test5",
                          "CA10__subscriptionId__c": "subscriptionId"
                      }
                  }
              ]
          }
      ]
  - path: /types/CA10__CaAzureAuthorizationRole__c/object.extracts.yaml
    md5Hash: 4CDB79E4A44CCA84E7046E7B9C7C8873
    content: "---\nextracts:\n# Values: BuiltInRole, CustomRole. Not Nullable. Can't\
      \ have no access, retrieved via Microsoft.Authorization/roleDefinitions\n  -\
      \ name: \"CA10__roleType__c\"\n    value: \n      FIELD:\n        path: \"CA10__roleType__c\"\
      \n        undeterminedIf:\n          isEmpty: \"Corrupted data. Role Type cannot\
      \ be empty.\"\n# Not Nullable. Can't have no access, retrieved via Microsoft.Authorization/roleDefinitions\n\
      \  - name: \"CA10__permissionsJson__c\"\n    value: \n      FIELD:\n       \
      \ path: \"CA10__permissionsJson__c\"\n        undeterminedIf:\n          isEmpty:\
      \ \"Corrupted data. Permissions JSON cannot be empty.\"\n# Not Nullable. Can't\
      \ have no access, retrieved via Microsoft.Authorization/roleDefinitions\n  -\
      \ name: \"CA10__assignableScopesJson__c\"\n    value: \n      FIELD:\n     \
      \   path: \"CA10__assignableScopesJson__c\"\n        undeterminedIf:\n     \
      \       isEmpty: \"Corrupted data. Assignable Scopes JSON cannot 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" : "test1",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10__Azure_Authorization_Role_Definitions__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAzureAccount__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-06-09T19:33:20Z")
    },
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-09T19:33:20Z")
    },
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-09T19:33:20Z")
    },
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-09T19:33:20Z")
    },
    "Id" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-09T19:33:20Z")
    },
    "Id" : "test5"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAzureAuthorizationRole__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__roleType__c STRING,
      CA10__permissionsJson__c STRING,
      CA10__assignableScopesJson__c STRING,
      CA10__subscription__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-06-09T19:33:20Z")
    },
    "Id" : "test1_1",
    "CA10__roleType__c" : "CustomRole",
    "CA10__permissionsJson__c" : "[{\"actions\":[\"*\", \"Microsoft.Resources/subscriptions/resourceGroups/read\"],\"notActions\":[],\"dataActions\":[],\"notDataActions\":[]}]",
    "CA10__assignableScopesJson__c" : "[\"/subscriptions/subscriptionId\"]",
    "CA10__subscription__c" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-09T19:33:20Z")
    },
    "Id" : "test2_1",
    "CA10__roleType__c" : "BuiltInRole",
    "CA10__permissionsJson__c" : "[{\"actions\":[\"*\"],\"notActions\":[],\"dataActions\":[],\"notDataActions\":[]}]",
    "CA10__assignableScopesJson__c" : "[\"/subscriptions/subscriptionId\"]",
    "CA10__subscription__c" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-09T19:33:20Z")
    },
    "Id" : "test3_1",
    "CA10__roleType__c" : "CustomRole",
    "CA10__permissionsJson__c" : "[{\"actions\":[\"Microsoft.Resources/subscriptions/resourceGroups/read\"],\"notActions\":[],\"dataActions\":[],\"notDataActions\":[]}]",
    "CA10__assignableScopesJson__c" : "[\"/subscriptions/subscriptionId\"]",
    "CA10__subscription__c" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-09T19:33:20Z")
    },
    "Id" : "test4_1",
    "CA10__roleType__c" : "CustomRole",
    "CA10__permissionsJson__c" : "[{\"actions\":[\"*\"],\"notActions\":[],\"dataActions\":[],\"notDataActions\":[]}]",
    "CA10__assignableScopesJson__c" : "[\"/\"]",
    "CA10__subscription__c" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-09T19:33:20Z")
    },
    "Id" : "test5_1",
    "CA10__roleType__c" : "CustomRole",
    "CA10__permissionsJson__c" : "{",
    "CA10__assignableScopesJson__c" : "[\"/\"]",
    "CA10__subscription__c" : "test5"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAzureAccount__c(
      obj STRUCT<
          Id STRING,
          CA10__Azure_Authorization_Role_Definitions__r ARRAY<STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__roleType__c STRING,
              CA10__permissionsJson__c STRING,
              CA10__assignableScopesJson__c STRING,
              CA10__subscription__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]
      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__Azure_Authorization_Role_Definitions__r_INCOMPLIANT2 = 0;
      if (obj.CA10__Azure_Authorization_Role_Definitions__r != null) {
          for (var i3 = 0; i3 < obj.CA10__Azure_Authorization_Role_Definitions__r.length; i3++) {
              if (obj.CA10__Azure_Authorization_Role_Definitions__r[i3].result.status == 'INCOMPLIANT') {
                  count_CA10__Azure_Authorization_Role_Definitions__r_INCOMPLIANT2 += 1;
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10__Azure_Authorization_Role_Definitions__r] ' + (count_CA10__Azure_Authorization_Role_Definitions__r_INCOMPLIANT2 > 0 ? 'has' : 'does not have') + ' objects in INCOMPLIANT status');
      if (count_CA10__Azure_Authorization_Role_Definitions__r_INCOMPLIANT2 > 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "CA10__Azure_Authorization_Role_Definitions__r.has(INCOMPLIANT)", currentStateMessage: "This subscription has a custom role with owner permissions   and assignable scope is set to subscription.", currentStateReferences: references1.join('\n'), remediation: "Consider removing the custom role.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "This subscription doesn't have a custom role with owner permissions.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__Azure_Authorization_Role_Definitions__r(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__roleType__c STRING,
          CA10__permissionsJson__c STRING,
          CA10__assignableScopesJson__c STRING,
          CA10__subscription__c STRING
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  OPTIONS (library=['gs://compliance-platform-public/jmespath.min.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));
          };
      }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From Azure [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__roleType__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__roleType__c.isEmpty()", currentStateMessage: "Corrupted data. Role Type cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__roleType__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Role Type [obj.CA10__roleType__c]: ' + obj.CA10__roleType__c);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'CustomRole')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__roleType__c') != 'CustomRole'", currentStateMessage: "This is not a Custom role.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[2], conditionIndex:[200..299]
      function jsonQueryChecked5() {
          var input = jsonChecked6();
          var out;
          try {
              out = jmespath.search(input, 'contains([*].actions[], \'*\')');
          if (out != null && typeof out != 'boolean') {
              throw new Error("UNDETERMINED condition:203", {cause: {status: 'UNDETERMINED', conditionIndex: 203, conditionText: "extract('CA10__permissionsJson__c').asJson().jsonQueryText('contains([*].actions[], \\'*\\')').isResultTypeMismatch()", currentStateMessage: "JSON query did not return boolean type.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          } catch (e) {
              throw new Error("UNDETERMINED condition:204", {cause: {status: 'UNDETERMINED', conditionIndex: 204, conditionText: "extract('CA10__permissionsJson__c').asJson().jsonQueryText('contains([*].actions[], \\'*\\')').isEvaluationFailed()", currentStateMessage: "JSON query boolean has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function jsonChecked6() {
          var input = extract8.call(extract8);
          input = TextLib.isEmpty(input) ? null : input;
          var out;
          try {
              out = JSON.parse(input);
          } catch (e) {
              throw new Error("UNDETERMINED condition:202", {cause: {status: 'UNDETERMINED', conditionIndex: 202, conditionText: "extract('CA10__permissionsJson__c').asJson().isInvalid()", currentStateMessage: "The provided Permissions JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function fieldChecked9() {
          if ((obj.CA10__permissionsJson__c == null || obj.CA10__permissionsJson__c == '')) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10__permissionsJson__c.isEmpty()", currentStateMessage: "Corrupted data. Permissions JSON cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__permissionsJson__c;
      }
      function extract8() { if (!this.out) { this.out = fieldChecked9(); } return this.out; };
      references1.push('Permissions JSON [obj.CA10__permissionsJson__c]: ' + obj.CA10__permissionsJson__c);
      try {
          if (jsonQueryChecked5() == false) {
              return {status: 'INAPPLICABLE', conditionIndex: 299, conditionText: "extract('CA10__permissionsJson__c').asJson().jsonQueryText('contains([*].actions[], \\'*\\')') == false", currentStateMessage: "Permissions do not have * actions.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[3], conditionIndex:[300..399]
      function comparison11() {
          var comparisonLeft18 = jsonQueryChecked12();
          return comparisonLeft18 != null && 0.0 != null && comparisonLeft18 > 0.0;
      }
      function jsonQueryChecked12() {
          var input = jsonChecked13();
          var out;
          try {
              out = jmespath.search(input, 'length([?starts_with(@, \'/subscriptions/\') && !contains(@, \'resourceGroups\')])');
          if (out != null && typeof out != 'number') {
              throw new Error("UNDETERMINED condition:303", {cause: {status: 'UNDETERMINED', conditionIndex: 303, conditionText: "extract('CA10__assignableScopesJson__c').asJson().jsonQueryText('length([?starts_with(@, \\'/subscriptions/\\') && !contains(@, \\'resourceGroups\\')])').isResultTypeMismatch()", currentStateMessage: "JSON query did not return number type.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          } catch (e) {
              throw new Error("UNDETERMINED condition:304", {cause: {status: 'UNDETERMINED', conditionIndex: 304, conditionText: "extract('CA10__assignableScopesJson__c').asJson().jsonQueryText('length([?starts_with(@, \\'/subscriptions/\\') && !contains(@, \\'resourceGroups\\')])').isEvaluationFailed()", currentStateMessage: "JSON query number has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function jsonChecked13() {
          var input = extract15.call(extract15);
          input = TextLib.isEmpty(input) ? null : input;
          var out;
          try {
              out = JSON.parse(input);
          } catch (e) {
              throw new Error("UNDETERMINED condition:302", {cause: {status: 'UNDETERMINED', conditionIndex: 302, conditionText: "extract('CA10__assignableScopesJson__c').asJson().isInvalid()", currentStateMessage: "The provided Assignable Scopes JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function fieldChecked16() {
          if ((obj.CA10__assignableScopesJson__c == null || obj.CA10__assignableScopesJson__c == '')) {
              throw new Error("UNDETERMINED condition:301", {cause: {status: 'UNDETERMINED', conditionIndex: 301, conditionText: "CA10__assignableScopesJson__c.isEmpty()", currentStateMessage: "Corrupted data. Assignable Scopes JSON cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__assignableScopesJson__c;
      }
      function extract15() { if (!this.out) { this.out = fieldChecked16(); } return this.out; };
      references1.push('Assignable Scopes JSON [obj.CA10__assignableScopesJson__c]: ' + obj.CA10__assignableScopesJson__c);
      try {
          if (comparison11()) {
              return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "extract('CA10__assignableScopesJson__c').asJson().jsonQueryText('length([?starts_with(@, \\'/subscriptions/\\') && !contains(@, \\'resourceGroups\\')])') > number(0.0)", currentStateMessage: "This custom role has owner permissions and subscription scopes.", currentStateReferences: references1.join('\n'), remediation: "Consider removing this role.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'INAPPLICABLE', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "A role has owner permissions without subscription scopes.", 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__Azure_Authorization_Role_Definitions__r`.arr AS CA10__Azure_Authorization_Role_Definitions__r,
          process_CA10__CaAzureAccount__c(
              STRUCT(
                  sObject.Id AS Id,
                  `CA10__Azure_Authorization_Role_Definitions__r`.arr AS CA10__Azure_Authorization_Role_Definitions__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAzureAccount__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__subscription__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__roleType__c AS CA10__roleType__c,
                      sObject.CA10__permissionsJson__c AS CA10__permissionsJson__c,
                      sObject.CA10__assignableScopesJson__c AS CA10__assignableScopesJson__c,
                      sObject.CA10__subscription__c AS CA10__subscription__c,
                      process_CA10__Azure_Authorization_Role_Definitions__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__roleType__c AS CA10__roleType__c,
                              sObject.CA10__permissionsJson__c AS CA10__permissionsJson__c,
                              sObject.CA10__assignableScopesJson__c AS CA10__assignableScopesJson__c,
                              sObject.CA10__subscription__c AS CA10__subscription__c
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAzureAuthorizationRole__c()) AS sObject
          GROUP BY sObject.CA10__subscription__c
      ) AS `CA10__Azure_Authorization_Role_Definitions__r`
          ON sObject.Id = `CA10__Azure_Authorization_Role_Definitions__r`.CA10__subscription__c
  ) sObject ON sObject.Id = expectedResult.Id;
