---
policy: /ce/ca/google/dns/dnssec-settings-for-cloud-dns
logic: /ce/ca/google/dns/dnssec-settings-for-cloud-dns/prod.logic.yaml
executionTime: 2025-04-24T23:46:57.437448533Z
rows:
  - id: 111
    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: 112
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__visibility__c') != 'public'
      actual: extract('CA10__visibility__c') != 'public'
    runtimeError: {}
  - id: 113
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__dnssecConfigurationState__c') == 'on'
      actual: extract('CA10__dnssecConfigurationState__c') == 'on'
    runtimeError: {}
  - id: 114
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/dns/dnssec-settings-for-cloud-dns/policy.yaml
    md5Hash: D976A200F67BB334F1EA9DF0FAE74FFD
    content: "---\nnames: \n  full: \"Google Cloud DNS Managed Zone DNSSEC is not\
      \ enabled\"\n  contextual: \"Managed Zone DNSSEC is not enabled\"\ndescription:\
      \ \"Cloud Domain Name System (DNS) is a fast, reliable and cost-effective \\\
      \n domain name system that powers millions of domains on the internet. \\\n\
      \ Domain Name System Security Extensions (DNSSEC) in Cloud DNS enables domain\
      \ owners \\ \n to take easy steps to protect their domains against DNS hijacking\
      \ and \\ \n man-in-the-middle and other attacks.\"\ntype: COMPLIANCE_POLICY\n\
      categories:\n  - \"SECURITY\"\n  - \"RELIABILITY\"\nframeworkMappings:\n  -\
      \ /frameworks/cis-gcp-v3.0.0/03/03\n  - /frameworks/cloudaware/resource-security/threat-protection\n\
      \  - /frameworks/cloudaware/resource-reliability/system-configuration\nsimilarPolicies:\n\
      \  cloudConformity:\n    - url: \"https://www.trendmicro.com/cloudoneconformity-staging/knowledge-base/gcp/CloudDNS/enable-dns-sec.html\"\
      \n      name: \"Enable DNSSEC for Google Cloud DNS Zones\"\n"
  - path: /ce/ca/google/dns/dnssec-settings-for-cloud-dns/prod.logic.yaml
    md5Hash: 26386DB4759FC893CEEC3821FBDE5D10
    content: |
      ---
      inputType: "CA10__CaGoogleDnsManagedZone__c"
      testData:
        - file: test-data.json
      importExtracts:
        - file: /types/CA10__CaGoogleDnsManagedZone__c/object.extracts.yaml
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "Only for public DNS Managed Zone"
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10__visibility__c"
              right:
                TEXT: 'public'
        - status: "COMPLIANT"
          currentStateMessage: "DNSSEC is enabled for the DNS Managed Zone."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__dnssecConfigurationState__c"
              right:
                TEXT: 'on'
      otherwise:
        status: "INCOMPLIANT"
        currentStateMessage: "DNSSEC is not enabled for the DNS Managed Zone."
        remediationMessage: "Enable DNSSEC for the DNS Managed Zone."
  - path: /types/CA10__CaGoogleDnsManagedZone__c/object.extracts.yaml
    md5Hash: DEC5B55A555645F54FDC22FF0932896B
    content: "---\nextracts:\n  - name: \"CA10__visibility__c\"\n    value: \n   \
      \   FIELD:\n        path: \"CA10__visibility__c\"\n  - name: \"CA10__dnssecConfigurationState__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__dnssecConfigurationState__c\"\
      \n  - name: \"CA10__dnssecConfigurationKeySpecs__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__dnssecConfigurationKeySpecs__c\"\n        returnType:\
      \ BYTES\n  - name: \"caJsonFrom__dnssecConfigurationKeySpecs__c\"\n    value:\
      \ \n      JSON_FROM:\n        arg: \n          EXTRACT: \"CA10__dnssecConfigurationKeySpecs__c\"\
      \n        undeterminedIf:\n          isInvalid: \"JSON is invalid.\"\n     \
      \     isEmpty: \"JSON is empty.\"\n  - name: \"caJsonFrom__dnssecConfigurationKeySpecs_keySigning_algorithm_value\"\
      \n    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__dnssecConfigurationKeySpecs__c\"\
      \n        expression: \"to_string([?keyType == 'keySigning'].algorithm)\"\n\
      \        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return a text.\"\n\
      \          resultIsEmpty: \"The JSON query did not return a value.\"\n  - name:\
      \ \"caJsonFrom__dnssecConfigurationKeySpecs_zoneSigning_algorithm_value\"\n\
      \    value: \n      JSON_QUERY_TEXT:\n        arg:\n          EXTRACT: \"caJsonFrom__dnssecConfigurationKeySpecs__c\"\
      \n        expression: \"to_string([?keyType == 'zoneSigning'].algorithm)\"\n\
      \        undeterminedIf:\n          evaluationError: \"The JSON query has failed.\"\
      \n          resultTypeMismatch: \"The JSON query did not return a text.\"\n\
      \          resultIsEmpty: \"The JSON query did not return a value.\"\n\n\n\n\
      \n\n          "
  - path: /ce/ca/google/dns/dnssec-settings-for-cloud-dns/test-data.json
    md5Hash: F836C1E0F693D4A7445DAC948BE2C434
    content: |
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-01-16T06:54:27Z" },
          "Id": "111",
          "CA10__disappearanceTime__c": "2025-01-14T19:40:37Z",
          "CA10__visibility__c": "private",
          "CA10__dnssecConfigurationState__c": ""
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "199",
            "conditionText": "extract('CA10__visibility__c') != 'public'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-01-16T06:54:27Z" },
          "Id": "112",
          "CA10__disappearanceTime__c": null,
          "CA10__visibility__c": "private",
          "CA10__dnssecConfigurationState__c": ""
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "299",
            "conditionText": "extract('CA10__dnssecConfigurationState__c') == 'on'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-01-16T06:54:27Z" },
          "Id": "113",
          "CA10__disappearanceTime__c": null,
          "CA10__visibility__c": "public",
          "CA10__dnssecConfigurationState__c": "on"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "300",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-01-16T06:54:27Z" },
          "Id": "114",
          "CA10__disappearanceTime__c": null,
          "CA10__visibility__c": "public",
          "CA10__dnssecConfigurationState__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" : "111",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "112",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__visibility__c') != 'public'",
      "runtimeError" : null
    }
  }, {
    "Id" : "113",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__dnssecConfigurationState__c') == 'on'",
      "runtimeError" : null
    }
  }, {
    "Id" : "114",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleDnsManagedZone__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__visibility__c STRING,
      CA10__dnssecConfigurationState__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-01-16T06:54:27Z")
    },
    "Id" : "111",
    "CA10__disappearanceTime__c" : new Date("2025-01-14T19:40:37Z"),
    "CA10__visibility__c" : "private",
    "CA10__dnssecConfigurationState__c" : ""
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-01-16T06:54:27Z")
    },
    "Id" : "112",
    "CA10__visibility__c" : "private",
    "CA10__dnssecConfigurationState__c" : ""
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-01-16T06:54:27Z")
    },
    "Id" : "113",
    "CA10__visibility__c" : "public",
    "CA10__dnssecConfigurationState__c" : "on"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-01-16T06:54:27Z")
    },
    "Id" : "114",
    "CA10__visibility__c" : "public",
    "CA10__dnssecConfigurationState__c" : ""
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleDnsManagedZone__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__visibility__c STRING,
          CA10__dnssecConfigurationState__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 Google [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 extract3() { if (!this.out) { this.out = obj.CA10__visibility__c; } return this.out; };
      references1.push('Visibility [obj.CA10__visibility__c]: ' + obj.CA10__visibility__c);
      if (TextLib.notEqual(extract3.call(extract3), 'public')) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__visibility__c') != 'public'", currentStateMessage: "Only for public DNS Managed Zone", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__dnssecConfigurationState__c; } return this.out; };
      references1.push('DNSSEC Configuration State [obj.CA10__dnssecConfigurationState__c]: ' + obj.CA10__dnssecConfigurationState__c);
      if (TextLib.equal(extract6.call(extract6), 'on')) {
          return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__dnssecConfigurationState__c') == 'on'", currentStateMessage: "DNSSEC is enabled for the DNS Managed Zone.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "DNSSEC is not enabled for the DNS Managed Zone.", currentStateReferences: references1.join('\n'), remediation: "Enable DNSSEC for the DNS Managed Zone.", 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__visibility__c AS CA10__visibility__c,
          sObject.CA10__dnssecConfigurationState__c AS CA10__dnssecConfigurationState__c,
          process_CA10__CaGoogleDnsManagedZone__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__visibility__c AS CA10__visibility__c,
                  sObject.CA10__dnssecConfigurationState__c AS CA10__dnssecConfigurationState__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleDnsManagedZone__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
