---
policy: /ce/ca/aws/account/password-policy-number-of-passwords-to-remember-24
logic: /ce/ca/aws/account/password-policy-number-of-passwords-to-remember-24/prod.logic.yaml
executionTime: 2025-05-10T12:01:21.564825498Z
rows:
  - id: a01
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10__AWS_IAM_Password_Policies__r.has(COMPLIANT)
      actual: CA10__AWS_IAM_Password_Policies__r.has(COMPLIANT)
    runtimeError: {}
  - id: a02
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10__AWS_IAM_Password_Policies__r.has(INCOMPLIANT)
      actual: CA10__AWS_IAM_Password_Policies__r.has(INCOMPLIANT)
    runtimeError: {}
  - id: a03
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/account/password-policy-number-of-passwords-to-remember-24/policy.yaml
    md5Hash: 4AFAF14C34C75D62352CCD4DEB2D2C93
    content: |
      ---
      names:
        full: "AWS Account IAM Password Policy Number of passwords to remember is not set to 24"
        contextual: "IAM Password Policy Number of passwords to remember is not set to 24"
      description: "IAM password policies can prevent the reuse of a given password by \
        the same user. It is recommended that the password policy prevent the reuse of passwords."
      type: "COMPLIANCE_POLICY"
      categories:
        - "SECURITY"
      frameworkMappings:
        - "/frameworks/cis-aws-v5.0.0/01/08"
        - "/frameworks/cloudaware/identity-and-access-governance/credential-lifecycle-management"
        - "/frameworks/aws-fsbp-v1.0.0/iam/07"
      similarPolicies:
        internal:
          - dec-x-f7c2faac
        cloudConformity:
         # One policy for 1.8 and 1.9. Checks are combined into one policy
          - url: "https://www.trendmicro.com/cloudoneconformity-staging/knowledge-base/aws/IAM/password-policy.html"
            name: "IAM Password Policy"
  - path: /ce/ca/aws/account/password-policy-number-of-passwords-to-remember-24/prod.logic.yaml
    md5Hash: B303F7E7E5C72A0BC778CE28095A446B
    content: |-
      ---
      inputType: "CA10__CaAwsAccount__c"
      testData:
        - file: test-data.json
      conditions:
        - status: "COMPLIANT"
          currentStateMessage: "Number of passwords to remember is set to the max of 24."
          check:
            RELATED_LIST_HAS:
              relationshipName: "CA10__AWS_IAM_Password_Policies__r"
              status: "COMPLIANT"
        - status: "INCOMPLIANT"
          currentStateMessage: "Number of passwords to remember should be set to the max of 24."
          remediationMessage: "Consider setting the Number of passwords to remember to the max of 24."
          check:
            RELATED_LIST_HAS:
              relationshipName: "CA10__AWS_IAM_Password_Policies__r"
              status: "INCOMPLIANT"
      otherwise:
        status: "INCOMPLIANT"
        currentStateMessage: "AWS Account password policy does not exist."
      relatedLists:
        - relationshipName: "CA10__AWS_IAM_Password_Policies__r"
          importExtracts:
            - file: /types/CA10__CaAwsPasswordPolicy__c/object.extracts.yaml
          conditions:
            - status: "INCOMPLIANT"
              currentStateMessage: "Password policy does not have 'Number of passwords to remember' set to the max of 24"
              remediationMessage: "Set 'Number of passwords to remember' to the max of 24"
              check:
                NOT_EQUAL:
                  left:
                    EXTRACT: "CA10__passwordReusePrevention__c"
                  right:
                    NUMBER: 24.0
            - status: "COMPLIANT"
              currentStateMessage: "Password policy have 'Number of passwords to remember' set to the max of 24"
              check:
                IS_EQUAL:
                  left:
                    EXTRACT: "CA10__passwordReusePrevention__c"
                  right:
                    NUMBER: 24.0
          otherwise:
            status: "UNDETERMINED"
            currentStateMessage: "Unexpected value in the field."
  - path: /ce/ca/aws/account/password-policy-number-of-passwords-to-remember-24/test-data.json
    md5Hash: 25BB5521D4542C8238D6A3CEDA81A189
    content: |
      [
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "199",
            "conditionText": "CA10__AWS_IAM_Password_Policies__r.has(COMPLIANT)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-06-09T19:33:20Z" },
          "Id": "a01",
          "CA10__AWS_IAM_Password_Policies__r": [
            {
              "Id": "a31",
              "CA10__disappearanceTime__c": null,
              "CA10__passwordReusePrevention__c": 24,
              "CA10__account__c": "a01"
            }
          ]
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "299",
            "conditionText": "CA10__AWS_IAM_Password_Policies__r.has(INCOMPLIANT)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-06-09T19:33:20Z" },
          "Id": "a02",
          "CA10__AWS_IAM_Password_Policies__r": [
            {
              "Id": "a32",
              "CA10__disappearanceTime__c": null,
              "CA10__passwordReusePrevention__c": 20,
              "CA10__account__c": "a02"
            }
          ]
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "300",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-06-09T19:33:20Z" },
          "Id": "a03",
          "CA10__AWS_IAM_Password_Policies__r": []
        }
      ]
  - 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" : "COMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "CA10__AWS_IAM_Password_Policies__r.has(COMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "a02",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "CA10__AWS_IAM_Password_Policies__r.has(INCOMPLIANT)",
      "runtimeError" : null
    }
  }, {
    "Id" : "a03",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "300",
      "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-09T19:33:20Z")
    },
    "Id" : "a01"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-09T19:33:20Z")
    },
    "Id" : "a02"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-09T19:33:20Z")
    },
    "Id" : "a03"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsPasswordPolicy__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__passwordReusePrevention__c FLOAT64,
      CA10__account__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-06-09T19:33:20Z")
    },
    "Id" : "a31",
    "CA10__passwordReusePrevention__c" : 24,
    "CA10__account__c" : "a01"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-09T19:33:20Z")
    },
    "Id" : "a32",
    "CA10__passwordReusePrevention__c" : 20,
    "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__passwordReusePrevention__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_COMPLIANT2 = 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 == 'COMPLIANT') {
                  count_CA10__AWS_IAM_Password_Policies__r_COMPLIANT2 += 1;
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10__AWS_IAM_Password_Policies__r] ' + (count_CA10__AWS_IAM_Password_Policies__r_COMPLIANT2 > 0 ? 'has' : 'does not have') + ' objects in COMPLIANT status');
      if (count_CA10__AWS_IAM_Password_Policies__r_COMPLIANT2 > 0) {
          return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "CA10__AWS_IAM_Password_Policies__r.has(COMPLIANT)", currentStateMessage: "Number of passwords to remember is set to the max of 24.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10__AWS_IAM_Password_Policies__r_INCOMPLIANT4 = 0;
      if (obj.CA10__AWS_IAM_Password_Policies__r != null) {
          for (var i5 = 0; i5 < obj.CA10__AWS_IAM_Password_Policies__r.length; i5++) {
              if (obj.CA10__AWS_IAM_Password_Policies__r[i5].result.status == 'INCOMPLIANT') {
                  count_CA10__AWS_IAM_Password_Policies__r_INCOMPLIANT4 += 1;
              }
          }
      }
      // condition[2], conditionIndex:[200..299]
      if (count_CA10__AWS_IAM_Password_Policies__r_INCOMPLIANT4 > 0) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "CA10__AWS_IAM_Password_Policies__r.has(INCOMPLIANT)", currentStateMessage: "Number of passwords to remember should be set to the max of 24.", currentStateReferences: references1.join('\n'), remediation: "Consider setting the Number of passwords to remember to the max of 24.", runtimeError: null};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "AWS Account password policy does not exist.", 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__passwordReusePrevention__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 fieldChecked4() {
          if (IsEmptyLib.simpleIsEmpty(obj.CA10__passwordReusePrevention__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__passwordReusePrevention__c.isEmpty()", currentStateMessage: "Possibly corrupted data. Number of passwords to remember should not be empty", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__passwordReusePrevention__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Password Reuse Prevention [obj.CA10__passwordReusePrevention__c]: ' + obj.CA10__passwordReusePrevention__c);
      try {
          if (extract3.call(extract3) != 24.0) {
              return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__passwordReusePrevention__c') != number(24.0)", currentStateMessage: "Password policy does not have 'Number of passwords to remember' set to the max of 24", currentStateReferences: references1.join('\n'), remediation: "Set 'Number of passwords to remember' to the max of 24", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[2], conditionIndex:[200..299]
      function fieldChecked7() {
          if (IsEmptyLib.simpleIsEmpty(obj.CA10__passwordReusePrevention__c)) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10__passwordReusePrevention__c.isEmpty()", currentStateMessage: "Possibly corrupted data. Number of passwords to remember should not be empty", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__passwordReusePrevention__c;
      }
      function extract6() { if (!this.out) { this.out = fieldChecked7(); } return this.out; };
      try {
          if (extract6.call(extract6) == 24.0) {
              return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__passwordReusePrevention__c') == number(24.0)", currentStateMessage: "Password policy have 'Number of passwords to remember' set to the max of 24", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'UNDETERMINED', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "Unexpected value in the field.", 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__passwordReusePrevention__c AS CA10__passwordReusePrevention__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__passwordReusePrevention__c AS CA10__passwordReusePrevention__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;
