---
policy: /ce/ca/snowflake/user/mfa-is-not-enabled
logic: /ce/ca/snowflake/user/mfa-is-not-enabled/prod.logic.yaml
executionTime: 2025-05-10T12:06:07.059205335Z
rows:
  - id: test1
    match: true
    status:
      expected: DISAPPEARED
      actual: DISAPPEARED
    conditionIndex:
      expected: 99
      actual: 99
    conditionText:
      expected: isDisappeared(CA10SN__disappearanceTime__c)
      actual: isDisappeared(CA10SN__disappearanceTime__c)
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10SN__hasPassword__c') != 'true'
      actual: extract('CA10SN__hasPassword__c') != 'true'
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10SN__extAuthnDuo__c') != 'true'
      actual: extract('CA10SN__extAuthnDuo__c') != 'true'
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/snowflake/user/mfa-is-not-enabled/policy.yaml
    md5Hash: 1D89EAFC26F2E5DDBBE1AABD78B555BF
    content: "names:\n  full: \"Snowflake User MFA is not enabled\"\n  contextual:\
      \ \"MFA is not enabled\"\ndescription: >\n  Ensure that Multi-Factor Authentication\
      \ (MFA) is enabled for Snowflake\n  Users to provide an additional layer of\
      \ security. MFA support is provided as \n  an integrated Snowflake feature,\
      \ powered by the Duo Security service, which \n  is managed completely by Snowflake.\n\
      type: \"COMPLIANCE_POLICY\"\ncategories:\n  - \"SECURITY\"\nframeworkMappings:\n\
      \  - \"/frameworks/cloudaware/identity-and-access-governance/mfa-implementation\""
  - path: /ce/ca/snowflake/user/mfa-is-not-enabled/prod.logic.yaml
    md5Hash: 1E4ADC93B2BBCBDC77A7F575B559F3AC
    content: "---\ninputType: \"CA10SN__CaSnowflakeUser__c\"\ntestData:\n  - file:\
      \ \"test-data.json\"\nimportExtracts:\n  - file: \"/types/CA10SN__CaSnowflakeUser__c/object.extracts.yaml\"\
      \nconditions:\n  - status: \"INAPPLICABLE\"\n    currentStateMessage: \"The\
      \ User does not use password authentication.\"\n    check:\n      NOT_EQUAL:\n\
      \        left:\n          EXTRACT: \"CA10SN__hasPassword__c\" \n        right:\n\
      \          TEXT: \"true\" \n  - status: \"INCOMPLIANT\"\n    currentStateMessage:\
      \ \"MFA is not enabled for this user.\"\n    remediationMessage: \"Enable MFA\
      \ for this user.\"\n    check:\n      NOT_EQUAL:\n        left:\n          EXTRACT:\
      \ \"CA10SN__extAuthnDuo__c\" \n        right:\n          TEXT: \"true\"\notherwise:\n\
      \  status: \"COMPLIANT\"\n  currentStateMessage: \"The user has MFA enabled.\""
  - path: /types/CA10SN__CaSnowflakeUser__c/object.extracts.yaml
    md5Hash: C6EB37BF1FD385E8938A301910EC1C1E
    content: "---\nextracts:\n  - name: \"CA10SN__passwordLastSetTime__c\"\n    value:\
      \ \n      FIELD:\n        path: \"CA10SN__passwordLastSetTime__c\"\n  - name:\
      \ \"CA10SN__hasPassword__c\"\n    value: \n      FIELD:\n        path: \"CA10SN__hasPassword__c\"\
      \n  - name: \"CA10SN__extAuthnDuo__c\"\n    value: \n      FIELD:\n        path:\
      \ \"CA10SN__extAuthnDuo__c\"\n  - name: \"CA10SN__defaultRoleName__c\"\n   \
      \ value: \n      FIELD:\n        path: \"CA10SN__defaultRoleName__c\""
  - path: /ce/ca/snowflake/user/mfa-is-not-enabled/test-data.json
    md5Hash: 22E68A5A855EF12F0CF473CA0DFCB828
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10SN__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-11-20T20:12:30Z"
              },
              "Id": "test1",
              "CA10SN__disappearanceTime__c": "2024-11-20T17:14:43Z",
              "CA10SN__hasPassword__c": "true",
              "CA10SN__extAuthnDuo__c": "false"
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10SN__hasPassword__c') != 'true'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-11-20T20:12:30Z"
              },
              "Id": "test2",
              "CA10SN__disappearanceTime__c": null,
              "CA10SN__hasPassword__c": "false",
              "CA10SN__extAuthnDuo__c": "false"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10SN__extAuthnDuo__c') != 'true'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-11-20T20:12:30Z"
              },
              "Id": "test3",
              "CA10SN__disappearanceTime__c": null,
              "CA10SN__hasPassword__c": "true",
              "CA10SN__extAuthnDuo__c": "false"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "300",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-11-20T20:12:30Z"
              },
              "Id": "test4",
              "CA10SN__disappearanceTime__c": null,
              "CA10SN__hasPassword__c": "true",
              "CA10SN__extAuthnDuo__c": "true"
          }
      ]
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(CA10SN__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10SN__hasPassword__c') != 'true'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10SN__extAuthnDuo__c') != 'true'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10SN__CaSnowflakeUser__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10SN__disappearanceTime__c TIMESTAMP,
      CA10SN__hasPassword__c STRING,
      CA10SN__extAuthnDuo__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-11-20T20:12:30Z")
    },
    "Id" : "test1",
    "CA10SN__disappearanceTime__c" : new Date("2024-11-20T17:14:43Z"),
    "CA10SN__hasPassword__c" : "true",
    "CA10SN__extAuthnDuo__c" : "false"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-20T20:12:30Z")
    },
    "Id" : "test2",
    "CA10SN__hasPassword__c" : "false",
    "CA10SN__extAuthnDuo__c" : "false"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-20T20:12:30Z")
    },
    "Id" : "test3",
    "CA10SN__hasPassword__c" : "true",
    "CA10SN__extAuthnDuo__c" : "false"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-20T20:12:30Z")
    },
    "Id" : "test4",
    "CA10SN__hasPassword__c" : "true",
    "CA10SN__extAuthnDuo__c" : "true"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10SN__CaSnowflakeUser__c(
      obj STRUCT<
          Id STRING,
          CA10SN__disappearanceTime__c TIMESTAMP,
          CA10SN__hasPassword__c STRING,
          CA10SN__extAuthnDuo__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 Snowflake [CA10SN__disappearanceTime__c]: ' + obj.CA10SN__disappearanceTime__c);
      if (obj.CA10SN__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10SN__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.CA10SN__hasPassword__c; } return this.out; };
      references1.push('Has Password [obj.CA10SN__hasPassword__c]: ' + obj.CA10SN__hasPassword__c);
      if (TextLib.notEqual(extract3.call(extract3), 'true')) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10SN__hasPassword__c') != 'true'", currentStateMessage: "The User does not use password authentication.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10SN__extAuthnDuo__c; } return this.out; };
      references1.push('Duo Security Is Enabled [obj.CA10SN__extAuthnDuo__c]: ' + obj.CA10SN__extAuthnDuo__c);
      if (TextLib.notEqual(extract6.call(extract6), 'true')) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10SN__extAuthnDuo__c') != 'true'", currentStateMessage: "MFA is not enabled for this user.", currentStateReferences: references1.join('\n'), remediation: "Enable MFA for this user.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "The user has MFA enabled.", 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.CA10SN__disappearanceTime__c AS CA10SN__disappearanceTime__c,
          sObject.CA10SN__hasPassword__c AS CA10SN__hasPassword__c,
          sObject.CA10SN__extAuthnDuo__c AS CA10SN__extAuthnDuo__c,
          process_CA10SN__CaSnowflakeUser__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10SN__disappearanceTime__c AS CA10SN__disappearanceTime__c,
                  sObject.CA10SN__hasPassword__c AS CA10SN__hasPassword__c,
                  sObject.CA10SN__extAuthnDuo__c AS CA10SN__extAuthnDuo__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10SN__CaSnowflakeUser__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
