---
policy: /ce/ca/aws/iam/ssh-public-keys-are-not-rotated-every-90-days
logic: /ce/ca/aws/iam/ssh-public-keys-are-not-rotated-every-90-days/prod.logic.yaml
executionTime: 2025-12-27T12:02:03.049889945Z
generationMs: 48
executionMs: 653
rows:
  - id: '001'
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__status__c') != 'Active'
      actual: extract('CA10__status__c') != 'Active'
    runtimeError: {}
  - id: '003'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__uploadDate__c').beyondLastDays(90)
      actual: extract('CA10__uploadDate__c').beyondLastDays(90)
    runtimeError: {}
  - id: '004'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/iam/ssh-public-keys-are-not-rotated-every-90-days/policy.yaml
    md5Hash: A9BEE90D24A0FC122247EC77F79C43A7
    content: "---\nnames:\n  full: AWS IAM SSH Public Key are not rotated every 90\
      \ days or less\n  contextual: SSH Public Key are not rotated every 90 days or\
      \ less\ndescription: >\n  Ensure that SSH public keys used for AWS CodeCommit\
      \ are rotated every 90 days. \n  Regular rotation of credentials reduces the\
      \ risk associated with potentially \n  compromised or long-lived keys.\ntype:\
      \ COMPLIANCE_POLICY\ncategories:\n  - SECURITY\nframeworkMappings:\n  - \"/frameworks/cloudaware/identity-and-access-governance/credential-lifecycle-management\"\
      \n  - \"/frameworks/aws-well-architected/sec/02/02\"\nsimilarPolicies:\n  cloudConformity:\n\
      \    - url: https://www.trendmicro.com/cloudoneconformity/knowledge-base/aws/IAM/ssh-public-keys-rotated-90-days.html\n\
      \      name: SSH Public Keys Rotated 90 Days\n"
  - path: /ce/ca/aws/iam/ssh-public-keys-are-not-rotated-every-90-days/prod.logic.yaml
    md5Hash: BBF604EE150BFCABA934C5D5B1ACDF45
    content: |-
      ---
      inputType: "CA10__CaAwsIamSshPublicKey__c"
      testData:
        - file: test-data.json
      importExtracts:
        - file: /types/CA10__CaAwsIamSshPublicKey__c/object.extracts.yaml
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "The SSH public key is currently Inactive."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10__status__c"
              right:
                TEXT: "Active"
        - status: INCOMPLIANT
          currentStateMessage: "The SSH public key is active but was uploaded more than 90 days ago."
          remediationMessage: "Rotate the SSH public key by uploading a new one and deleting the old one."
          check:
            IS_BEYOND_LAST_DAYS:
              offsetDays: 90
              arg:
                EXTRACT: "CA10__uploadDate__c"
      otherwise:
        status: COMPLIANT
        currentStateMessage: "The SSH public key is active and has been rotated within the last 90 days."
  - path: /ce/ca/aws/iam/ssh-public-keys-are-not-rotated-every-90-days/test-data.json
    md5Hash: 6ABDC8F1FDBF23FE83825A43A6A3A723
    content: |
      [
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "199",
            "conditionText": "extract('CA10__status__c') != 'Active'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-12-09T07:11:01Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "Inactive",
          "CA10__uploadDate__c": "2020-05-09T02:09:35Z",
          "Id": "001"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "299",
            "conditionText": "extract('CA10__uploadDate__c').beyondLastDays(90)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-12-09T07:11:01Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "Active",
          "CA10__uploadDate__c": "2020-05-09T02:09:35Z",
          "Id": "003"
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "300",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-12-09T07:11:01Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "Active",
          "CA10__uploadDate__c": "2025-11-11T02:09:35Z",
          "Id": "004"
        }
      ]
  - path: /types/CA10__CaAwsIamSshPublicKey__c/object.extracts.yaml
    md5Hash: 484B2472B77AA746367697E1C8DF1B3B
    content: "---\nextracts:\n# Date/Time\n- name: CA10__uploadDate__c\n  value: \n\
      \    FIELD:\n      path: CA10__uploadDate__c\n# Date/Time\n- name: CA10__status__c\n\
      \  value: \n    FIELD:\n      path: CA10__status__c\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" : "extract('CA10__status__c') != 'Active'",
      "runtimeError" : null
    }
  }, {
    "Id" : "003",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__uploadDate__c').beyondLastDays(90)",
      "runtimeError" : null
    }
  }, {
    "Id" : "004",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsIamSshPublicKey__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__status__c STRING,
      CA10__uploadDate__c TIMESTAMP,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-12-09T07:11:01Z")
    },
    "CA10__status__c" : "Inactive",
    "CA10__uploadDate__c" : new Date("2020-05-09T02:09:35Z"),
    "Id" : "001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-12-09T07:11:01Z")
    },
    "CA10__status__c" : "Active",
    "CA10__uploadDate__c" : new Date("2020-05-09T02:09:35Z"),
    "Id" : "003"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-12-09T07:11:01Z")
    },
    "CA10__status__c" : "Active",
    "CA10__uploadDate__c" : new Date("2025-11-11T02:09:35Z"),
    "Id" : "004"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsIamSshPublicKey__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__status__c STRING,
          CA10__uploadDate__c TIMESTAMP,
          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 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 todayMinus90Day = new Date(snapshotTime.toISOString().substr(0,10)+'T00:00:00.000Z').getTime() + (-90 * 86400000);
      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 extract3() { if (!this.out) { this.out = obj.CA10__status__c; } return this.out; };
      references1.push('Status [obj.CA10__status__c]: ' + obj.CA10__status__c);
      if (TextLib.notEqual(extract3.call(extract3), 'Active')) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__status__c') != 'Active'", currentStateMessage: "The SSH public key is currently Inactive.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__uploadDate__c; } return this.out; };
      references1.push('Upload Date [obj.CA10__uploadDate__c]: ' + obj.CA10__uploadDate__c);
      if (extract6.call(extract6) != null && extract6.call(extract6).getTime() < todayMinus90Day) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__uploadDate__c').beyondLastDays(90)", currentStateMessage: "The SSH public key is active but was uploaded more than 90 days ago.", currentStateReferences: references1.join('\n'), remediation: "Rotate the SSH public key by uploading a new one and deleting the old one.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "The SSH public key is active and has been rotated within the last 90 days.", 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.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__status__c AS CA10__status__c,
          sObject.CA10__uploadDate__c AS CA10__uploadDate__c,
          sObject.Id AS Id,
          process_CA10__CaAwsIamSshPublicKey__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__status__c AS CA10__status__c,
                  sObject.CA10__uploadDate__c AS CA10__uploadDate__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsIamSshPublicKey__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
