---
policy: /ce/ca/azure/subscription/user-access-administrator-role
logic: /ce/ca/azure/subscription/user-access-administrator-role/prod.logic.yaml
executionTime: 2025-07-21T17:39:41.182083122Z
rows:
  - id: a001
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('Name') != 'User Access Administrator'
      actual: extract('Name') != 'User Access Administrator'
    runtimeError: {}
  - id: a002
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10__Azure_Authorization_Role_Assignments__r.has(INCOMPLIANT)
      actual: CA10__Azure_Authorization_Role_Assignments__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: a003
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/azure/subscription/user-access-administrator-role/policy.yaml
    md5Hash: 2F103BB5C873201AFF78F51D720EB397
    content: |
      ---
      names:
        full: Azure User Access Administrator Role has assignments
        contextual: Use of the 'User Access Administrator' role is not restricted
      description: "The User Access Administrator role grants the ability to view all resources and manage\
        \ access assignments at any subscription or management group level within the tenant.\
        \ Due to its broad privileges, this role should be assigned only for the\
        \ duration of the necessary changes at the root scope and then removed immediately.\
        \ For ongoing operations, define and use custom roles that grant only the minimum permissions required."
      type: COMPLIANCE_POLICY
      categories:
        - SECURITY
      frameworkMappings:
        - "/frameworks/cis-azure-v4.0.0/06/03/03"
        - "/frameworks/cloudaware/identity-and-access-governance/rbac-management"
  - path: /ce/ca/azure/subscription/user-access-administrator-role/prod.logic.yaml
    md5Hash: 78D923A7DCEADB595C74FC0CDB7007CB
    content: "---\ninputType: \"CA10__CaAzureAuthorizationRole__c\"\ntestData:\n \
      \ - file: \"test-data.json\"\nimportExtracts:\n  - file: \"/types/CA10__CaAzureAuthorizationRole__c/object.extracts.yaml\"\
      \nconditions:\n  - status: \"INAPPLICABLE\"\n    currentStateMessage: \"The\
      \ policy applies only to the 'User Access Administrator' role.\"\n    check:\n\
      \      NOT_EQUAL:\n        left:\n          EXTRACT: \"Name\"\n        right:\n\
      \          TEXT: \"User Access Administrator\"\n  - status: \"INCOMPLIANT\"\n\
      \    currentStateMessage: \"User Access Administrator role is assigned.\"\n\
      \    remediationMessage: \"Remove all role assignments.\"\n    check:\n    \
      \  RELATED_LIST_HAS:\n        relationshipName: \"CA10__Azure_Authorization_Role_Assignments__r\"\
      \n        status: \"INCOMPLIANT\"\notherwise:\n  status: \"COMPLIANT\"\n  currentStateMessage:\
      \ \"User Access Administrator role is not assigned.\"\nrelatedLists:\n  - relationshipName:\
      \ \"CA10__Azure_Authorization_Role_Assignments__r\"\n    conditions: []\n  \
      \  otherwise: \n      status: \"INCOMPLIANT\"\n      currentStateMessage: \"\
      Authorization Role Assignment exists.\"\n"
  - path: /ce/ca/azure/subscription/user-access-administrator-role/test-data.json
    md5Hash: 76A3858C710A21747BAEF25F48A59F4C
    content: |
      [
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "199",
            "conditionText": "extract('Name') != 'User Access Administrator'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-01T17:36:53Z" },
          "Id": "a001",
          "CA10__disappearanceTime__c": null,
          "Name": "Microsoft.Kubernetes connected cluster role",
          "CA10__Azure_Authorization_Role_Assignments__r": []
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "299",
            "conditionText": "CA10__Azure_Authorization_Role_Assignments__r.has(INCOMPLIANT)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-01T17:36:53Z" },
          "Id": "a002",
          "CA10__disappearanceTime__c": null,
          "Name": "User Access Administrator",
          "CA10__Azure_Authorization_Role_Assignments__r": [
            {
              "Id": "111",
              "CA10__disappearanceTime__c": null,
              "CA10__role__c": "a002"
            }
          ]
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "300",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-01T17:36:53Z" },
          "Id": "a003",
          "CA10__disappearanceTime__c": null,
          "Name": "User Access Administrator",
          "CA10__Azure_Authorization_Role_Assignments__r": []
        }
      ]
  - path: /types/CA10__CaAzureAuthorizationRole__c/object.extracts.yaml
    md5Hash: 650620E870B163F79D5A42D138E2697E
    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# Not Nullable. \n  - name: \"Name\"\n    value:\n      FIELD:\n        path:\
      \ \"Name\"\n        undeterminedIf:\n          isEmpty: \"Corrupted data. Role\
      \ Name 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" : "a001",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('Name') != 'User Access Administrator'",
      "runtimeError" : null
    }
  }, {
    "Id" : "a002",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "CA10__Azure_Authorization_Role_Assignments__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "a003",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAzureAuthorizationRole__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      Name STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-07-01T17:36:53Z")
    },
    "Id" : "a001",
    "Name" : "Microsoft.Kubernetes connected cluster role"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-01T17:36:53Z")
    },
    "Id" : "a002",
    "Name" : "User Access Administrator"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-01T17:36:53Z")
    },
    "Id" : "a003",
    "Name" : "User Access Administrator"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAzureAuthorizationRoleAssignment__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__role__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-07-01T17:36:53Z")
    },
    "Id" : "111",
    "CA10__role__c" : "a002"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAzureAuthorizationRole__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          Name STRING,
          CA10__Azure_Authorization_Role_Assignments__r ARRAY<STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__role__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 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 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.Name)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "Name.isEmpty()", currentStateMessage: "Corrupted data. Role Name cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.Name;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Role Name [obj.Name]: ' + obj.Name);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'User Access Administrator')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('Name') != 'User Access Administrator'", currentStateMessage: "The policy applies only to the 'User Access Administrator' role.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      var count_CA10__Azure_Authorization_Role_Assignments__r_INCOMPLIANT5 = 0;
      if (obj.CA10__Azure_Authorization_Role_Assignments__r != null) {
          for (var i6 = 0; i6 < obj.CA10__Azure_Authorization_Role_Assignments__r.length; i6++) {
              if (obj.CA10__Azure_Authorization_Role_Assignments__r[i6].result.status == 'INCOMPLIANT') {
                  count_CA10__Azure_Authorization_Role_Assignments__r_INCOMPLIANT5 += 1;
              }
          }
      }
      // condition[2], conditionIndex:[200..299]
      references1.push('Related list [CA10__Azure_Authorization_Role_Assignments__r] ' + (count_CA10__Azure_Authorization_Role_Assignments__r_INCOMPLIANT5 > 0 ? 'has' : 'does not have') + ' objects in INCOMPLIANT status');
      if (count_CA10__Azure_Authorization_Role_Assignments__r_INCOMPLIANT5 > 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "CA10__Azure_Authorization_Role_Assignments__r.has(INCOMPLIANT)", currentStateMessage: "User Access Administrator role is assigned.", currentStateReferences: references1.join('\n'), remediation: "Remove all role assignments.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "User Access Administrator role is not assigned.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__Azure_Authorization_Role_Assignments__r(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__role__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 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};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 100, conditionText: "otherwise", currentStateMessage: "Authorization Role Assignment exists.", 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.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.Name AS Name,
          `CA10__Azure_Authorization_Role_Assignments__r`.arr AS CA10__Azure_Authorization_Role_Assignments__r,
          process_CA10__CaAzureAuthorizationRole__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.Name AS Name,
                  `CA10__Azure_Authorization_Role_Assignments__r`.arr AS CA10__Azure_Authorization_Role_Assignments__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAzureAuthorizationRole__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__role__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__role__c AS CA10__role__c,
                      process_CA10__Azure_Authorization_Role_Assignments__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__role__c AS CA10__role__c
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAzureAuthorizationRoleAssignment__c()) AS sObject
          GROUP BY sObject.CA10__role__c
      ) AS `CA10__Azure_Authorization_Role_Assignments__r`
          ON sObject.Id = `CA10__Azure_Authorization_Role_Assignments__r`.CA10__role__c
  ) sObject ON sObject.Id = expectedResult.Id;
