---
policy: /ce/ca/aws/secrets-manager/secret-automatic-rotation
logic: /ce/ca/aws/secrets-manager/secret-automatic-rotation/prod.logic.yaml
executionTime: 2025-10-25T12:02:02.444994852Z
generationMs: 53
executionMs: 823
rows:
  - id: test1
    match: true
    status:
      expected: DISAPPEARED
      actual: DISAPPEARED
    conditionIndex:
      expected: 99
      actual: 99
    conditionText:
      expected: isDisappeared(CA10A1__disappearanceTime__c)
      actual: isDisappeared(CA10A1__disappearanceTime__c)
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10A1__deletedDate__c').isNotEmpty()
      actual: extract('CA10A1__deletedDate__c').isNotEmpty()
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: extract('CA10A1__rotationEnabled__c') == true
      actual: extract('CA10A1__rotationEnabled__c') == true
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10A1__rotationEnabled__c') == false
      actual: extract('CA10A1__rotationEnabled__c') == false
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/secrets-manager/secret-automatic-rotation/policy.yaml
    md5Hash: 3673698FC013CAE752B5052631076649
    content: "---\nnames:\n  full: \"AWS Secrets Manager Secret Automatic Rotation\
      \ is not enabled\"\n  contextual: \"Secret Automatic Rotation is not enabled\"\
      \ndescription: >\n  Ensure that secrets stored in AWS Secrets Manager are configured\
      \ for automatic \n  rotation to minimize the risk associated with long-lived\
      \ credentials\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n  - \"SECURITY\"\n\
      frameworkMappings:\n  - \"/frameworks/cloudaware/secret-and-certificate-governance/expiration-management\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/secrets-manager/01\"\n  - \"/frameworks/aws-well-architected/sec/02/03\"\
      \nsimilarPolicies:\n  awsSecurityHub:\n    - name: \"[SecretsManager.1] Secrets\
      \ Manager secrets should have automatic rotation enabled\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/secretsmanager-controls.html#secretsmanager-1\""
  - path: /ce/ca/aws/secrets-manager/secret-automatic-rotation/prod.logic.yaml
    md5Hash: 5D33977AC8186FDC3CB312E64D5E56D8
    content: "---\ninputType: \"CA10A1__CaAwsSecretsManagerSecret__c\"\ntestData:\n\
      \  - file: \"test-data.json\"\nimportExtracts:\n  - file: \"/types/CA10A1__CaAwsSecretsManagerSecret__c/object.extracts.yaml\"\
      \nconditions:\n  - status: \"INAPPLICABLE\"\n    currentStateMessage: \"This\
      \ secret is active.\"\n    check:\n      NOT_EMPTY:\n        arg:\n        \
      \  EXTRACT: \"CA10A1__deletedDate__c\"\n  - status: \"INCOMPLIANT\"\n    currentStateMessage:\
      \ \"Automatic rotation is not enabled for this Secret.\"\n    remediationMessage:\
      \ \"Enable automatic rotation for the secret to reduce the risk of long-lived\
      \ credentials being compromised.\"    \n    check:\n      IS_EQUAL:\n      \
      \  left:\n          EXTRACT: \"CA10A1__rotationEnabled__c\"\n        right:\n\
      \          BOOLEAN: false\n  - status: \"COMPLIANT\"\n    currentStateMessage:\
      \ \"Automatic rotation is enabled for this Secret.\"\n    check:\n      IS_EQUAL:\n\
      \        left:\n          EXTRACT: \"CA10A1__rotationEnabled__c\"\n        right:\n\
      \          BOOLEAN: true\notherwise:\n  status: \"UNDETERMINED\"\n  currentStateMessage:\
      \ \"Unexpected values in the fields.\"\n"
  - path: /ce/ca/aws/secrets-manager/secret-automatic-rotation/test-data.json
    md5Hash: 257226E972292860D961B63294E5CEFC
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10A1__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-23T14:48:06Z"
              },
              "CA10A1__disappearanceTime__c": "2025-10-16T20:08:56Z",
              "CA10A1__deletedDate__c": null,
              "CA10A1__rotationEnabled__c": false,
              "Id": "test1"
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10A1__deletedDate__c').isNotEmpty()",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-23T14:48:06Z"
              },
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__deletedDate__c": "2025-10-23T14:48:06Z",
              "CA10A1__rotationEnabled__c": true,
              "Id": "test2"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "extract('CA10A1__rotationEnabled__c') == true",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-23T14:48:06Z"
              },
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__deletedDate__c": null,
              "CA10A1__rotationEnabled__c": true,
              "Id": "test3"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10A1__rotationEnabled__c') == false",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-23T14:48:06Z"
              },
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__deletedDate__c": null,
              "CA10A1__rotationEnabled__c": false,
              "Id": "test4"
          }
      ]
  - path: /types/CA10A1__CaAwsSecretsManagerSecret__c/object.extracts.yaml
    md5Hash: 57E703908B8097ACBC5E66064F855C93
    content: "---\nextracts:\n# Nullable. Can't have no access, retrieved via secretsmanager:ListSecrets\n\
      \  - name: CA10A1__deletedDate__c\n    value:\n      FIELD: \n        path:\
      \ CA10A1__deletedDate__c\n# Checkbox. Can't have no access, retrieved via secretsmanager:ListSecrets\n\
      \  - name: CA10A1__rotationEnabled__c\n    value:\n      FIELD: \n        path:\
      \ CA10A1__rotationEnabled__c"
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" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10A1__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10A1__deletedDate__c').isNotEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "extract('CA10A1__rotationEnabled__c') == true",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10A1__rotationEnabled__c') == false",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10A1__CaAwsSecretsManagerSecret__c()
  RETURNS ARRAY<STRUCT<
      CA10A1__disappearanceTime__c TIMESTAMP,
      CA10A1__deletedDate__c TIMESTAMP,
      CA10A1__rotationEnabled__c BOOLEAN,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-10-23T14:48:06Z")
    },
    "CA10A1__disappearanceTime__c" : new Date("2025-10-16T20:08:56Z"),
    "CA10A1__rotationEnabled__c" : false,
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-23T14:48:06Z")
    },
    "CA10A1__deletedDate__c" : new Date("2025-10-23T14:48:06Z"),
    "CA10A1__rotationEnabled__c" : true,
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-23T14:48:06Z")
    },
    "CA10A1__rotationEnabled__c" : true,
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-23T14:48:06Z")
    },
    "CA10A1__rotationEnabled__c" : false,
    "Id" : "test4"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10A1__CaAwsSecretsManagerSecret__c(
      obj STRUCT<
          CA10A1__disappearanceTime__c TIMESTAMP,
          CA10A1__deletedDate__c TIMESTAMP,
          CA10A1__rotationEnabled__c BOOLEAN,
          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 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 [CA10A1__disappearanceTime__c]: ' + obj.CA10A1__disappearanceTime__c);
      if (obj.CA10A1__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10A1__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.CA10A1__deletedDate__c; } return this.out; };
      references1.push('Deleted Date [obj.CA10A1__deletedDate__c]: ' + obj.CA10A1__deletedDate__c);
      if (IsEmptyLib.simpleIsNotEmpty(extract3.call(extract3))) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10A1__deletedDate__c').isNotEmpty()", currentStateMessage: "This secret is active.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10A1__rotationEnabled__c; } return this.out; };
      references1.push('Rotation Enabled [obj.CA10A1__rotationEnabled__c]: ' + obj.CA10A1__rotationEnabled__c);
      if (extract6.call(extract6) == false) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10A1__rotationEnabled__c') == false", currentStateMessage: "Automatic rotation is not enabled for this Secret.", currentStateReferences: references1.join('\n'), remediation: "Enable automatic rotation for the secret to reduce the risk of long-lived credentials being compromised.", runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function extract9() { if (!this.out) { this.out = obj.CA10A1__rotationEnabled__c; } return this.out; };
      if (extract9.call(extract9) == true) {
          return {status: 'COMPLIANT', conditionIndex: 399, conditionText: "extract('CA10A1__rotationEnabled__c') == true", currentStateMessage: "Automatic rotation is enabled for this Secret.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "Unexpected values in the fields.", 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.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
          sObject.CA10A1__deletedDate__c AS CA10A1__deletedDate__c,
          sObject.CA10A1__rotationEnabled__c AS CA10A1__rotationEnabled__c,
          sObject.Id AS Id,
          process_CA10A1__CaAwsSecretsManagerSecret__c(
              STRUCT(
                  sObject.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
                  sObject.CA10A1__deletedDate__c AS CA10A1__deletedDate__c,
                  sObject.CA10A1__rotationEnabled__c AS CA10A1__rotationEnabled__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10A1__CaAwsSecretsManagerSecret__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
