---
policy: /ce/ca/azure/key-vault/soft-delete-and-purge-protection
logic: /ce/ca/azure/key-vault/soft-delete-and-purge-protection/prod.logic.yaml
executionTime: 2025-04-24T23:45:28.44441108Z
rows:
  - id: test1
    match: true
    status:
      expected: DISAPPEARED
      actual: DISAPPEARED
    conditionIndex:
      expected: 99
      actual: 99
    conditionText:
      expected: isDisappeared(CA10__disappearanceTime__c)
      actual: isDisappeared(CA10__disappearanceTime__c)
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__softDelete__c') == 'Disabled'
      actual: extract('CA10__softDelete__c') == 'Disabled'
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__purgeProtection__c') != 'Enabled'
      actual: extract('CA10__purgeProtection__c') != 'Enabled'
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: extract('CA10__purgeProtection__c') == 'Enabled' && extract('CA10__softDelete__c')
        == 'Enabled'
      actual: extract('CA10__purgeProtection__c') == 'Enabled' && extract('CA10__softDelete__c')
        == 'Enabled'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/azure/key-vault/soft-delete-and-purge-protection/policy.yaml
    md5Hash: 116BE035C201EA3629BEA61BC50A7305
    content: |
      ---
      names:
        full: Azure Key Vault Soft Delete and Purge Protection functions are not enabled
        contextual: Soft Delete and Purge Protection functions are not enabled
      description: "It is recommended the Key Vault be made recoverable by enabling the\
        \ 'Do Not Purge' and 'Soft Delete' functions. This is in order to prevent loss of\
        \ encrypted data,   including storage accounts, SQL databases, and/or dependent\
        \ services provided by Key Vault objects (Keys, Secrets, Certificates) etc."
      type: COMPLIANCE_POLICY
      categories:
        - SECURITY
      frameworkMappings:
        - "/frameworks/cis-azure-v2.1.0/08/05"
        - "/frameworks/cis-azure-v3.0.0/03/03/05"
        - "/frameworks/cloudaware/resource-security/data-protection-and-recovery"
      similarPolicies:
        internal:
          - dec-x-0be4dfe5
        cloudConformity:
          - url: https://www.trendmicro.com/cloudoneconformity/knowledge-base/azure/KeyVault/enable-key-vault-recoverability.html
            name: Enable Key Vault Recoverability
  - path: /ce/ca/azure/key-vault/soft-delete-and-purge-protection/prod.logic.yaml
    md5Hash: 9A06E6BB38871CF56693C5F40E3AE4D3
    content: |
      ---
      inputType: "CA10__CaAzureKeyVault__c"
      importExtracts:
        - file: "/types/CA10__CaAzureKeyVault__c/object.extracts.yaml"
      testData:
        - file: "test-data.json"
      conditions:
        - status: "INCOMPLIANT"
          currentStateMessage: "The Soft Delete is disabled. The Purge Protection is effective only if Soft Delete is also enabled."
          remediationMessage: "Consider enabling Soft Delete and Purge Protection functions."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__softDelete__c"
              right:
                TEXT: "Disabled"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Purge Protection is disabled."
          remediationMessage: "Consider enabling Purge Protection function."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10__purgeProtection__c"
              right:
                TEXT: "Enabled"
        - status: "COMPLIANT"
          currentStateMessage: "The Soft Delete and Purge Protection functions are enabled."
          check:
            AND:
              args:
                - IS_EQUAL:
                    left:
                      EXTRACT: "CA10__purgeProtection__c"
                    right:
                      TEXT: "Enabled"
                - IS_EQUAL:
                    left:
                      EXTRACT: "CA10__softDelete__c"
                    right:
                      TEXT: "Enabled"
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unexpected values in the fields."
  - path: /ce/ca/azure/key-vault/soft-delete-and-purge-protection/test-data.json
    md5Hash: 9CD8B266A0A3A9974D607D6182786FD7
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-27T20:33:04Z"
              },
              "Id": "test1",
              "CA10__disappearanceTime__c": "2024-06-27T20:33:04Z",
              "CA10__softDelete__c": "Enabled",
              "CA10__purgeProtection__c": "Enabled"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__softDelete__c') == 'Disabled'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-27T20:33:04Z"
              },
              "Id": "test2",
              "CA10__disappearanceTime__c": null,
              "CA10__softDelete__c": "Disabled",
              "CA10__purgeProtection__c": ""
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10__purgeProtection__c') != 'Enabled'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-27T20:33:04Z"
              },
              "Id": "test3",
              "CA10__disappearanceTime__c": null,
              "CA10__softDelete__c": "Enabled",
              "CA10__purgeProtection__c": ""
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "extract('CA10__purgeProtection__c') == 'Enabled' && extract('CA10__softDelete__c') == 'Enabled'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-06-27T20:33:04Z"
              },
              "Id": "test4",
              "CA10__disappearanceTime__c": null,
              "CA10__softDelete__c": "Enabled",
              "CA10__purgeProtection__c": "Enabled"
          }
      ]
  - path: /types/CA10__CaAzureKeyVault__c/object.extracts.yaml
    md5Hash: 6C8158AF4E8A90E532020A68611A20C7
    content: "---\nextracts:\n# Values: Enabled, Disabled. Not Nullable. Can't have\
      \ no access, retrieved via Microsoft.KeyVault/vaults\n  - name: \"CA10__rbacAuthorization__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__rbacAuthorization__c\"\n\
      \        undeterminedIf:\n          isEmpty: \"Corrupted data. Key Vault RBAC\
      \ Authorization cannot be empty.\"\n# Values: Enabled, null. Nullable. Can't\
      \ have no access, retrieved via Microsoft.KeyVault/vaults\n  - name: \"CA10__purgeProtection__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__purgeProtection__c\"\n# Values:\
      \ Enabled, Disabled. Not Nullable. Can't have no access, retrieved via Microsoft.KeyVault/vaults\n\
      \  - name: \"CA10__softDelete__c\"\n    value: \n      FIELD:\n        path:\
      \ \"CA10__softDelete__c\"\n        undeterminedIf:\n          isEmpty: \"Corrupted\
      \ data. Soft Delete function 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" : "test1",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__softDelete__c') == 'Disabled'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__purgeProtection__c') != 'Enabled'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "extract('CA10__purgeProtection__c') == 'Enabled' && extract('CA10__softDelete__c') == 'Enabled'",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAzureKeyVault__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__softDelete__c STRING,
      CA10__purgeProtection__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-06-27T20:33:04Z")
    },
    "Id" : "test1",
    "CA10__disappearanceTime__c" : new Date("2024-06-27T20:33:04Z"),
    "CA10__softDelete__c" : "Enabled",
    "CA10__purgeProtection__c" : "Enabled"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-27T20:33:04Z")
    },
    "Id" : "test2",
    "CA10__softDelete__c" : "Disabled",
    "CA10__purgeProtection__c" : ""
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-27T20:33:04Z")
    },
    "Id" : "test3",
    "CA10__softDelete__c" : "Enabled",
    "CA10__purgeProtection__c" : ""
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-06-27T20:33:04Z")
    },
    "Id" : "test4",
    "CA10__softDelete__c" : "Enabled",
    "CA10__purgeProtection__c" : "Enabled"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAzureKeyVault__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__softDelete__c STRING,
          CA10__purgeProtection__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 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));
          };
      }();
      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.CA10__softDelete__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__softDelete__c.isEmpty()", currentStateMessage: "Corrupted data. Soft Delete function cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__softDelete__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Soft Delete [obj.CA10__softDelete__c]: ' + obj.CA10__softDelete__c);
      try {
          if (TextLib.equal(extract3.call(extract3), 'Disabled')) {
              return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__softDelete__c') == 'Disabled'", currentStateMessage: "The Soft Delete is disabled. The Purge Protection is effective only if Soft Delete is also enabled.", currentStateReferences: references1.join('\n'), remediation: "Consider enabling Soft Delete and Purge Protection functions.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__purgeProtection__c; } return this.out; };
      references1.push('Purge Protection [obj.CA10__purgeProtection__c]: ' + obj.CA10__purgeProtection__c);
      if (TextLib.notEqual(extract6.call(extract6), 'Enabled')) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__purgeProtection__c') != 'Enabled'", currentStateMessage: "The Purge Protection is disabled.", currentStateReferences: references1.join('\n'), remediation: "Consider enabling Purge Protection function.", runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function extract9() { if (!this.out) { this.out = obj.CA10__purgeProtection__c; } return this.out; };
      function fieldChecked13() {
          if (TextLib.isEmpty(obj.CA10__softDelete__c)) {
              throw new Error("UNDETERMINED condition:301", {cause: {status: 'UNDETERMINED', conditionIndex: 301, conditionText: "CA10__softDelete__c.isEmpty()", currentStateMessage: "Corrupted data. Soft Delete function cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__softDelete__c;
      }
      function extract12() { if (!this.out) { this.out = fieldChecked13(); } return this.out; };
      try {
          if (TextLib.equal(extract9.call(extract9), 'Enabled') && TextLib.equal(extract12.call(extract12), 'Enabled')) {
              return {status: 'COMPLIANT', conditionIndex: 399, conditionText: "extract('CA10__purgeProtection__c') == 'Enabled' && extract('CA10__softDelete__c') == 'Enabled'", currentStateMessage: "The Soft Delete and Purge Protection functions are enabled.", 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: 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.Id AS Id,
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__softDelete__c AS CA10__softDelete__c,
          sObject.CA10__purgeProtection__c AS CA10__purgeProtection__c,
          process_CA10__CaAzureKeyVault__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__softDelete__c AS CA10__softDelete__c,
                  sObject.CA10__purgeProtection__c AS CA10__purgeProtection__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAzureKeyVault__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
