---
policy: /ce/ca/azure/storage/snb-protocol-version
logic: /ce/ca/azure/storage/snb-protocol-version/prod.logic.yaml
executionTime: 2025-07-21T17:38:57.24941341Z
rows:
  - id: '001'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: '002'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: '004'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: '003'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10Z1__protocolSettingsSmbVersions__c').contains('SMB3.1.1')
        && not(extract('CA10Z1__protocolSettingsSmbVersions__c').contains('SMB2.1'))
        && not(extract('CA10Z1__protocolSettingsSmbVersions__c').contains('SMB3.0'))
      actual: extract('CA10Z1__protocolSettingsSmbVersions__c').contains('SMB3.1.1')
        && not(extract('CA10Z1__protocolSettingsSmbVersions__c').contains('SMB2.1'))
        && not(extract('CA10Z1__protocolSettingsSmbVersions__c').contains('SMB3.0'))
    runtimeError: {}
usedFiles:
  - path: /ce/ca/azure/storage/snb-protocol-version/policy.yaml
    md5Hash: 4D5BF0ADDE6B5CC81D38BC07D0962224
    content: |
      ---
      names:
        full: "Azure Storage File Shares SMB Protocol Version is not set to SMB 3.1.1 or higher"
        contextual: "File Shares SMB Protocol Version is not set to SMB 3.1.1 or higher"
      description: "Ensure that SMB file shares are configured to use the latest supported SMB protocol\
        \ version. Keeping the SMB protocol updated helps mitigate risks associated with older SMB versions,\
        \ which may contain vulnerabilities and lack essential security controls."
      type: BEST_PRACTICE
      categories:
        - SECURITY
        - RELIABILITY
      frameworkMappings:
        - "/frameworks/cis-azure-v4.0.0/10/01/02"
        - "/frameworks/cloudaware/resource-security/threat-protection"
        - "/frameworks/cloudaware/resource-reliability/infrastructure-modernization"
  - path: /ce/ca/azure/storage/snb-protocol-version/prod.logic.yaml
    md5Hash: 9433E5E9F38C8CCCBB050109F3632BDC
    content: "---\ninputType: \"CA10Z1__CaAzureStorageFile__c\"\ntestData:\n  - file:\
      \ test-data.json\nimportExtracts:\n  - file: /types/CA10Z1__CaAzureStorageFile__c/object.extracts.yaml\n\
      conditions:\n  - status: \"COMPLIANT\"\n    currentStateMessage: \"SMB protocol\
      \ version is set to 'SMB3.1.1'.\"\n    check:\n      AND:\n        args:\n \
      \         - CONTAINS:\n              arg:\n                EXTRACT: \"CA10Z1__protocolSettingsSmbVersions__c\"\
      \n              search:\n                TEXT: \"SMB3.1.1\"\n          - NOT:\n\
      \              arg:\n                CONTAINS:\n                  arg:\n   \
      \                 EXTRACT: \"CA10Z1__protocolSettingsSmbVersions__c\"\n    \
      \              search:\n                    TEXT: \"SMB2.1\"\n          - NOT:\n\
      \              arg:\n                CONTAINS:\n                  arg:\n   \
      \                 EXTRACT: \"CA10Z1__protocolSettingsSmbVersions__c\"\n    \
      \              search:\n                    TEXT: \"SMB3.0\"\n# if CA10Z1__protocolSettingsSmbVersions__c\
      \ is empty,\n# then the default maximum compatibility (that includes all values)\
      \ is set\notherwise:\n  status: \"INCOMPLIANT\"\n  currentStateMessage: \"SMB\
      \ protocol version is not set to 'SMB3.1.1'.\"\n  remediationMessage: \"Set\
      \ SMB protocol version to 'SMB3.1.1'.\"\n  "
  - path: /ce/ca/azure/storage/snb-protocol-version/test-data.json
    md5Hash: 2EBFE3C91B8B5A370535E84F05DB5E79
    content: |
      [
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-07T09:01:03Z" },
          "Id": "001",
          "CA10Z1__protocolSettingsSmbVersions__c": ""
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-07T09:01:03Z" },
          "Id": "002",
          "CA10Z1__protocolSettingsSmbVersions__c": "SMB2.1"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-07T09:01:03Z" },
          "Id": "004",
          "CA10Z1__protocolSettingsSmbVersions__c": "SMB2.1; SMB3.1.1"
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "199",
            "conditionText": "extract('CA10Z1__protocolSettingsSmbVersions__c').contains('SMB3.1.1') && not(extract('CA10Z1__protocolSettingsSmbVersions__c').contains('SMB2.1')) && not(extract('CA10Z1__protocolSettingsSmbVersions__c').contains('SMB3.0'))",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-07T09:01:03Z" },
          "Id": "003",
          "CA10Z1__protocolSettingsSmbVersions__c": "SMB3.1.1"
        }
      ]
  - path: /types/CA10Z1__CaAzureStorageFile__c/object.extracts.yaml
    md5Hash: 710D57682B15A41C11105284C265F338
    content: "---\nextracts:\n# Nullable. Text field. Valid values are AES-128-CCM,\
      \ AES-128-GCM, AES-256-GCM. Should be passed as a string with delimiter ';'\n\
      \  - name: \"CA10Z1__protocolSettingsSmbChannelEncrypt__c\"\n    value: \n \
      \     FIELD:\n        path: \"CA10Z1__protocolSettingsSmbChannelEncrypt__c\"\
      \n# Nullable, when Null, then the default maximum compatibility is set. \n#\
      \ Text field. Valid values are SMB2.1, SMB3.0, SMB3.1.1. Should be passed as\
      \ a string with delimiter ';'.\n  - name: \"CA10Z1__protocolSettingsSmbVersions__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10Z1__protocolSettingsSmbVersions__c\"\
      \n# Nullable. Text field.\n  - name: \"CA10Z1__shareDeleteRetentionPolicyStatus__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10Z1__shareDeleteRetentionPolicyStatus__c\"\
      \n# Nullable. Number field.\n  - name: \"CA10Z1__shareDeleteRetentionPolicyDays__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10Z1__shareDeleteRetentionPolicyDays__c\"\
      \        \n\n\n\n\n\n        \n\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" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "002",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "004",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "003",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10Z1__protocolSettingsSmbVersions__c').contains('SMB3.1.1') && not(extract('CA10Z1__protocolSettingsSmbVersions__c').contains('SMB2.1')) && not(extract('CA10Z1__protocolSettingsSmbVersions__c').contains('SMB3.0'))",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10Z1__CaAzureStorageFile__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10Z1__protocolSettingsSmbVersions__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-07-07T09:01:03Z")
    },
    "Id" : "001",
    "CA10Z1__protocolSettingsSmbVersions__c" : ""
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-07T09:01:03Z")
    },
    "Id" : "002",
    "CA10Z1__protocolSettingsSmbVersions__c" : "SMB2.1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-07T09:01:03Z")
    },
    "Id" : "004",
    "CA10Z1__protocolSettingsSmbVersions__c" : "SMB2.1; SMB3.1.1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-07T09:01:03Z")
    },
    "Id" : "003",
    "CA10Z1__protocolSettingsSmbVersions__c" : "SMB3.1.1"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10Z1__CaAzureStorageFile__c(
      obj STRUCT<
          Id STRING,
          CA10Z1__protocolSettingsSmbVersions__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]
      if (false) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared()", 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__protocolSettingsSmbVersions__c; } return this.out; };
      references1.push('Protocol Settings: SMB Versions [obj.CA10Z1__protocolSettingsSmbVersions__c]: ' + obj.CA10Z1__protocolSettingsSmbVersions__c);
      if (TextLib.contains(extract3.call(extract3), 'SMB3.1.1') && !TextLib.contains(extract3.call(extract3), 'SMB2.1') && !TextLib.contains(extract3.call(extract3), 'SMB3.0')) {
          return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "extract('CA10Z1__protocolSettingsSmbVersions__c').contains('SMB3.1.1') && not(extract('CA10Z1__protocolSettingsSmbVersions__c').contains('SMB2.1')) && not(extract('CA10Z1__protocolSettingsSmbVersions__c').contains('SMB3.0'))", currentStateMessage: "SMB protocol version is set to 'SMB3.1.1'.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "SMB protocol version is not set to 'SMB3.1.1'.", currentStateReferences: references1.join('\n'), remediation: "Set SMB protocol version to 'SMB3.1.1'.", 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__protocolSettingsSmbVersions__c AS CA10Z1__protocolSettingsSmbVersions__c,
          process_CA10Z1__CaAzureStorageFile__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10Z1__protocolSettingsSmbVersions__c AS CA10Z1__protocolSettingsSmbVersions__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10Z1__CaAzureStorageFile__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
