---
policy: /ce/ca/azure/databricks/customer-managed-keys
logic: /ce/ca/azure/databricks/customer-managed-keys/prod.logic.yaml
executionTime: 2025-07-21T17:37:22.098123059Z
rows:
  - id: '001'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10Z1__encryptionManagedDisksKeySource__c').isEmpty()
      actual: extract('CA10Z1__encryptionManagedDisksKeySource__c').isEmpty()
    runtimeError: {}
  - id: '002'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10Z1__encryptionManagedDisksKeySource__c') != 'Microsoft.Keyvault'
      actual: extract('CA10Z1__encryptionManagedDisksKeySource__c') != 'Microsoft.Keyvault'
    runtimeError: {}
  - id: '003'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: extract('CA10Z1__encryptionManagedDisksKeySource__c') == 'Microsoft.Keyvault'
      actual: extract('CA10Z1__encryptionManagedDisksKeySource__c') == 'Microsoft.Keyvault'
    runtimeError: {}
  - id: '004'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: extract('CA10Z1__encryptionManagedDisksKeySource__c') == 'Microsoft.Keyvault'
      actual: extract('CA10Z1__encryptionManagedDisksKeySource__c') == 'Microsoft.Keyvault'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/azure/databricks/customer-managed-keys/policy.yaml
    md5Hash: 2E9F0E8390FADD7A6A6F25FCE7C7AE7C
    content: "---\nnames:\n  full: Azure Databricks Workspace is not encrypted using\
      \ customer-managed key (CMK)\n  contextual: Workspace is not encrypted using\
      \ customer-managed key (CMK)\ndescription: \"Ensure that Azure Databricks Workspaces\
      \ are encrypted with a customer-managed key.\\ \n  \\ By default, data at rest\
      \ is encrypted using Microsoft-managed keys.\\\n  \\ Azure Databricks encrypts\
      \ data in transit using TLS 1.2+ to secure API, workspace,\\\n  \\ and cluster\
      \ communications.\"\ntype: COMPLIANCE_POLICY\ncategories:\n  - SECURITY\nframeworkMappings:\n\
      \  - \"/frameworks/cis-azure-v4.0.0/03/01/08\"\n  - \"/frameworks/cloudaware/resource-security/data-encryption\"\
      \n"
  - path: /ce/ca/azure/databricks/customer-managed-keys/prod.logic.yaml
    md5Hash: 1297FF67DC45519644A1B60FDD084573
    content: |
      ---
      inputType: "CA10Z1__CaAzureDatabricksWorkspace__c"
      testData:
        - file: "test-data.json"
      importExtracts:
        - file: "/types/CA10Z1__CaAzureDatabricksWorkspace__c/object.extracts.yaml"
      conditions:
        - status: "INCOMPLIANT"
          currentStateMessage: "The Databricks Workspace is not encrypted with a customer-managed key."
          remediationMessage: "Encrypt the Databricks Workspace with a customer-managed key."
          check:
            IS_EMPTY:
              arg:
                EXTRACT: "CA10Z1__encryptionManagedDisksKeySource__c"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Databricks Workspace is encrypted with a Microsoft-managed key."
          remediationMessage: "Encrypt the Databricks Workspace with a customer-managed key."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10Z1__encryptionManagedDisksKeySource__c"
              right:
                TEXT: "Microsoft.Keyvault"
        - status: "COMPLIANT"
          currentStateMessage: "The Databricks Workspace is encrypted with a customer-managed key."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10Z1__encryptionManagedDisksKeySource__c"
              right:
                TEXT: "Microsoft.Keyvault"
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unexpected value in the field."
  - path: /ce/ca/azure/databricks/customer-managed-keys/test-data.json
    md5Hash: C380A82BEBF0876E6772B1A06E613241
    content: |
      [
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "199",
            "conditionText": "extract('CA10Z1__encryptionManagedDisksKeySource__c').isEmpty()",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-10T21:40:21Z" },
          "Id": "001",
          "CA10Z1__disappearanceTime__c": null,
          "CA10Z1__encryptionManagedDisksKeySource__c": ""
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "299",
            "conditionText": "extract('CA10Z1__encryptionManagedDisksKeySource__c') != 'Microsoft.Keyvault'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-10T21:40:21Z" },
          "Id": "002",
          "CA10Z1__disappearanceTime__c": null,
          "CA10Z1__encryptionManagedDisksKeySource__c": "anykey"
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "399",
            "conditionText": "extract('CA10Z1__encryptionManagedDisksKeySource__c') == 'Microsoft.Keyvault'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-10T21:40:21Z" },
          "Id": "003",
          "CA10Z1__disappearanceTime__c": null,
          "CA10Z1__encryptionManagedDisksKeySource__c": "Microsoft.Keyvault"
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "399",
            "conditionText": "extract('CA10Z1__encryptionManagedDisksKeySource__c') == 'Microsoft.Keyvault'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-10T21:40:21Z" },
          "Id": "004",
          "CA10Z1__disappearanceTime__c": null,
          "CA10Z1__encryptionManagedDisksKeySource__c": "microsoft.keyvault"
        }
      ]
  - path: /types/CA10Z1__CaAzureDatabricksWorkspace__c/object.extracts.yaml
    md5Hash: 386013C014351948A2036C32C9D43AB2
    content: "---\n# Nullable. The encryption keySource (provider). Possible values\
      \ (case-insensitive):  Microsoft.Keyvault\nextracts:\n  - name: \"CA10Z1__encryptionManagedDisksKeySource__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10Z1__encryptionManagedDisksKeySource__c\"\
      \n  - name: \"CA10Z1__parametersJson__c\"\n    value:\n      FIELD:\n      \
      \  path: \"CA10Z1__parametersJson__c\"\n        returnType: BYTES\n  - name:\
      \ \"caJsonFrom__parametersJson__c\"\n    value:\n      JSON_FROM:\n        arg:\n\
      \          EXTRACT: \"CA10Z1__parametersJson__c\"\n        undeterminedIf:\n\
      \          isInvalid: \"DatabricsWorkspace parameters JSON is invalid\"\n\n\
      \  - name: \"caJsonText__parametersJsonCustomVirtualNetworkValue__c\"\n    value:\
      \ \n      JSON_QUERY_TEXT:\n        arg: \n          EXTRACT: \"caJsonFrom__parametersJson__c\"\
      \n        expression: \"customVirtualNetworkId.value\"\n        undeterminedIf:\
      \ \n          evaluationError: \"The JSON query has failed.\"\n          resultTypeMismatch:\
      \ \"The JSON query did not return a boolean.\"\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" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10Z1__encryptionManagedDisksKeySource__c').isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "002",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10Z1__encryptionManagedDisksKeySource__c') != 'Microsoft.Keyvault'",
      "runtimeError" : null
    }
  }, {
    "Id" : "003",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "extract('CA10Z1__encryptionManagedDisksKeySource__c') == 'Microsoft.Keyvault'",
      "runtimeError" : null
    }
  }, {
    "Id" : "004",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "extract('CA10Z1__encryptionManagedDisksKeySource__c') == 'Microsoft.Keyvault'",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10Z1__CaAzureDatabricksWorkspace__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10Z1__disappearanceTime__c TIMESTAMP,
      CA10Z1__encryptionManagedDisksKeySource__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-07-10T21:40:21Z")
    },
    "Id" : "001",
    "CA10Z1__encryptionManagedDisksKeySource__c" : ""
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-10T21:40:21Z")
    },
    "Id" : "002",
    "CA10Z1__encryptionManagedDisksKeySource__c" : "anykey"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-10T21:40:21Z")
    },
    "Id" : "003",
    "CA10Z1__encryptionManagedDisksKeySource__c" : "Microsoft.Keyvault"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-10T21:40:21Z")
    },
    "Id" : "004",
    "CA10Z1__encryptionManagedDisksKeySource__c" : "microsoft.keyvault"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10Z1__CaAzureDatabricksWorkspace__c(
      obj STRUCT<
          Id STRING,
          CA10Z1__disappearanceTime__c TIMESTAMP,
          CA10Z1__encryptionManagedDisksKeySource__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));
          };
          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 references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From Azure [CA10Z1__disappearanceTime__c]: ' + obj.CA10Z1__disappearanceTime__c);
      if (obj.CA10Z1__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10Z1__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.CA10Z1__encryptionManagedDisksKeySource__c; } return this.out; };
      references1.push('Encryption: Managed Disks Key Source [obj.CA10Z1__encryptionManagedDisksKeySource__c]: ' + obj.CA10Z1__encryptionManagedDisksKeySource__c);
      if (TextLib.isEmpty(extract3.call(extract3))) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10Z1__encryptionManagedDisksKeySource__c').isEmpty()", currentStateMessage: "The Databricks Workspace is not encrypted with a customer-managed key.", currentStateReferences: references1.join('\n'), remediation: "Encrypt the Databricks Workspace with a customer-managed key.", runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10Z1__encryptionManagedDisksKeySource__c; } return this.out; };
      if (TextLib.notEqual(extract6.call(extract6), 'Microsoft.Keyvault')) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10Z1__encryptionManagedDisksKeySource__c') != 'Microsoft.Keyvault'", currentStateMessage: "The Databricks Workspace is encrypted with a Microsoft-managed key.", currentStateReferences: references1.join('\n'), remediation: "Encrypt the Databricks Workspace with a customer-managed key.", runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function extract9() { if (!this.out) { this.out = obj.CA10Z1__encryptionManagedDisksKeySource__c; } return this.out; };
      if (TextLib.equal(extract9.call(extract9), 'Microsoft.Keyvault')) {
          return {status: 'COMPLIANT', conditionIndex: 399, conditionText: "extract('CA10Z1__encryptionManagedDisksKeySource__c') == 'Microsoft.Keyvault'", currentStateMessage: "The Databricks Workspace is encrypted with a customer-managed key.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 400, 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,
          sObject.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c,
          sObject.CA10Z1__encryptionManagedDisksKeySource__c AS CA10Z1__encryptionManagedDisksKeySource__c,
          process_CA10Z1__CaAzureDatabricksWorkspace__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c,
                  sObject.CA10Z1__encryptionManagedDisksKeySource__c AS CA10Z1__encryptionManagedDisksKeySource__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10Z1__CaAzureDatabricksWorkspace__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
