---
policy: /ce/ca/aws/account/password-policy-minimum-password-length-14
logic: /ce/ca/aws/account/password-policy-minimum-password-length-14/prod.logic.yaml
executionTime: 2025-04-24T23:44:12.333673462Z
rows:
  - id: a01
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10__AWS_IAM_Password_Policies__r.has(INCOMPLIANT)
      actual: CA10__AWS_IAM_Password_Policies__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: a02
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/account/password-policy-minimum-password-length-14/policy.yaml
    md5Hash: 1B6C00798A3598F8784D381EEC59BB9C
    content: |
      ---
      names:
        full: "AWS Account IAM Password Policy minimum password length is 14 characters or less"
        contextual: "IAM Password Policy minimum password length is 14 characters or less"
      description: "Password policies are, in part, used to enforce password complexity requirements. \
        IAM password policies can be used to ensure password are at least a given length. \
        It is recommended that the password policy require a minimum password length 14."
      type: "COMPLIANCE_POLICY"
      categories:
        - "SECURITY"
      frameworkMappings:
        - "/frameworks/cis-aws-v5.0.0/01/07"
        - "/frameworks/cloudaware/identity-and-access-governance/credential-lifecycle-management"
        - "/frameworks/aws-fsbp-v1.0.0/iam/07"
      similarPolicies:
        cloudConformity:
        # One policy for 1.8 and 1.9. Checks are combined into one policy
          - url: "https://www.trendmicro.com/cloudoneconformity/knowledge-base/aws/IAM/password-policy.html"
            name: "IAM Password Policy"
  - path: /ce/ca/aws/account/password-policy-minimum-password-length-14/prod.logic.yaml
    md5Hash: 680D18537B0347A93DDED206939EAEF2
    content: |
      ---
      inputType: "CA10__CaAwsAccount__c"
      testData:
        - file: test-data.json
      conditions:
        - status: "INCOMPLIANT"
          currentStateMessage: "Account does not have a password policy that requires passwords\
            \ of 14 characters long or longer."
          remediationMessage: "Create or update password policy to require password of 14\
            \ characters or longer."
          check:
            RELATED_LIST_HAS:
              relationshipName: "CA10__AWS_IAM_Password_Policies__r"
              status: "INCOMPLIANT"
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: "Account has password policy that requires passwords of 14\
          \ characters or longer."
      relatedLists:
        - relationshipName: "CA10__AWS_IAM_Password_Policies__r"
          importExtracts:
            - file: /types/CA10__CaAwsPasswordPolicy__c/object.extracts.yaml
          conditions:
            - status: "INCOMPLIANT"
              currentStateMessage: "Password policy requires less than 14 characters long\
                \ password."
              remediationMessage: "Increase password length requirement to 14 characters\
                \ or longer."
              check:
                LESS_THAN:
                  left:
                    EXTRACT: "CA10__minimumPasswordLength__c"
                  right:
                    NUMBER: 14.0
          otherwise:
            status: "COMPLIANT"
            currentStateMessage: "Password policy requires passwords 14 characters long\
              \ or longer."
  - path: /ce/ca/aws/account/password-policy-minimum-password-length-14/test-data.json
    md5Hash: 37170936C607F153D212CA42DD9533AF
    content: |
      [
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "199",
            "conditionText": "CA10__AWS_IAM_Password_Policies__r.has(INCOMPLIANT)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-06-18T05:52:54Z" },
          "Id": "a01",
          "CA10__AWS_IAM_Password_Policies__r": [
            {
              "Id": "a31",
              "CA10__disappearanceTime__c": null,
              "CA10__minimumPasswordLength__c": 8,
              "CA10__account__c": "a01"
            }
          ]
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-06-18T05:52:54Z" },
          "Id": "a02",
          "CA10__AWS_IAM_Password_Policies__r": [
            {
              "Id": "a32",
              "CA10__disappearanceTime__c": null,
              "CA10__minimumPasswordLength__c": 14,
              "CA10__account__c": "a02"
            }
          ]
        }
      ]
  - path: /types/CA10__CaAwsPasswordPolicy__c/object.extracts.yaml
    md5Hash: 2C1D97EF4F574F9BE1A9C1EB7CAE6A9C
    content: "---\nextracts:\n  - name: CA10__minimumPasswordLength__c\n    # Should\
      \ not be null if the policy itself exists? Needs additional research\n    #TODO:\
      \ research if CA10__minimumPasswordLength__c can be null\n    value:\n     \
      \ FIELD: \n        path: CA10__minimumPasswordLength__c\n        undeterminedIf:\n\
      \          isEmpty: Possibly corrupted data. Minimum password length should\
      \ not be empty\n  - name: CA10__passwordReusePrevention__c\n    value: \n  \
      \    FIELD:\n        path: CA10__passwordReusePrevention__c\n        undeterminedIf:\n\
      \          isEmpty:  Possibly corrupted data. Number of passwords to remember\
      \ should not be empty"
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" : "a01",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10__AWS_IAM_Password_Policies__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "a02",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsAccount__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-06-18T05:52:54Z")
    },
    "Id" : "a01"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-18T05:52:54Z")
    },
    "Id" : "a02"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsPasswordPolicy__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__minimumPasswordLength__c FLOAT64,
      CA10__account__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-06-18T05:52:54Z")
    },
    "Id" : "a31",
    "CA10__minimumPasswordLength__c" : 8,
    "CA10__account__c" : "a01"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-18T05:52:54Z")
    },
    "Id" : "a32",
    "CA10__minimumPasswordLength__c" : 14,
    "CA10__account__c" : "a02"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsAccount__c(
      obj STRUCT<
          Id STRING,
          CA10__AWS_IAM_Password_Policies__r ARRAY<STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__minimumPasswordLength__c FLOAT64,
              CA10__account__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__AWS_IAM_Password_Policies__r_INCOMPLIANT2 = 0;
      if (obj.CA10__AWS_IAM_Password_Policies__r != null) {
          for (var i3 = 0; i3 < obj.CA10__AWS_IAM_Password_Policies__r.length; i3++) {
              if (obj.CA10__AWS_IAM_Password_Policies__r[i3].result.status == 'INCOMPLIANT') {
                  count_CA10__AWS_IAM_Password_Policies__r_INCOMPLIANT2 += 1;
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10__AWS_IAM_Password_Policies__r] ' + (count_CA10__AWS_IAM_Password_Policies__r_INCOMPLIANT2 > 0 ? 'has' : 'does not have') + ' objects in INCOMPLIANT status');
      if (count_CA10__AWS_IAM_Password_Policies__r_INCOMPLIANT2 > 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "CA10__AWS_IAM_Password_Policies__r.has(INCOMPLIANT)", currentStateMessage: "Account does not have a password policy that requires passwords of 14 characters long or longer.", currentStateReferences: references1.join('\n'), remediation: "Create or update password policy to require password of 14 characters or longer.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "Account has password policy that requires passwords of 14 characters or longer.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__AWS_IAM_Password_Policies__r(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__minimumPasswordLength__c FLOAT64,
          CA10__account__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 IsEmptyLib = new function () {
          this.simpleIsEmpty = function(arg) {
              return arg == null;
          };
          this.simpleIsNotEmpty = function(arg) {
              return arg != null;
          };
      }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      function fieldChecked5() {
          if (IsEmptyLib.simpleIsEmpty(obj.CA10__minimumPasswordLength__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__minimumPasswordLength__c.isEmpty()", currentStateMessage: "Possibly corrupted data. Minimum password length should not be empty", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__minimumPasswordLength__c;
      }
      function extract4() { if (!this.out) { this.out = fieldChecked5(); } return this.out; };
      references1.push('Minimum Password Length [obj.CA10__minimumPasswordLength__c]: ' + obj.CA10__minimumPasswordLength__c);
      try {
          if (extract4.call(extract4) != null && 14.0 != null && extract4.call(extract4) < 14.0) {
              return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__minimumPasswordLength__c') < number(14.0)", currentStateMessage: "Password policy requires less than 14 characters long password.", currentStateReferences: references1.join('\n'), remediation: "Increase password length requirement to 14 characters or longer.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "Password policy requires passwords 14 characters long or longer.", 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__AWS_IAM_Password_Policies__r`.arr AS CA10__AWS_IAM_Password_Policies__r,
          process_CA10__CaAwsAccount__c(
              STRUCT(
                  sObject.Id AS Id,
                  `CA10__AWS_IAM_Password_Policies__r`.arr AS CA10__AWS_IAM_Password_Policies__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsAccount__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__account__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.Id AS Id,
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__minimumPasswordLength__c AS CA10__minimumPasswordLength__c,
                      sObject.CA10__account__c AS CA10__account__c,
                      process_CA10__AWS_IAM_Password_Policies__r(
                          STRUCT(
                              sObject.Id AS Id,
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__minimumPasswordLength__c AS CA10__minimumPasswordLength__c,
                              sObject.CA10__account__c AS CA10__account__c
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAwsPasswordPolicy__c()) AS sObject
          GROUP BY sObject.CA10__account__c
      ) AS `CA10__AWS_IAM_Password_Policies__r`
          ON sObject.Id = `CA10__AWS_IAM_Password_Policies__r`.CA10__account__c
  ) sObject ON sObject.Id = expectedResult.Id;
