---
policy: /ce/ca/google/load-balancing/load-balancer-logging
logic: /ce/ca/google/load-balancing/load-balancer-logging/prod.logic.yaml
executionTime: 2025-04-24T23:47:06.042604968Z
rows:
  - id: a7xVU1
    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: a7x7V2
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__logConfigState__c') == 'Enabled' && extract('CA10__logConfigSampleRate__c').isNotEmpty()
      actual: extract('CA10__logConfigState__c') == 'Enabled' && extract('CA10__logConfigSampleRate__c').isNotEmpty()
    runtimeError: {}
  - id: a7x7V3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: a7x7V32
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/load-balancing/load-balancer-logging/policy.yaml
    md5Hash: D402E514E82CBE6DE1A959F103EEE482
    content: "---\nnames: \n  full: \"Google HTTP(S) Load Balancer Logging is not\
      \ enabled\"\n  contextual: \"HTTP(S) Load Balancer Logging is not enabled\"\n\
      description: \"Logging enabled on a HTTPS Load Balancer will show all network\
      \ traffic and its destination.\"\ntype: COMPLIANCE_POLICY\ncategories:\n  -\
      \ \"SECURITY\"\nframeworkMappings:\n  - /frameworks/cis-gcp-v3.0.0/02/16\n \
      \ - /frameworks/cloudaware/logging-and-monitoring/logging-and-monitoring-configuration\n\
      similarPolicies:\n  cloudConformity:\n    - url: \"https://www.trendmicro.com/cloudoneconformity-staging/knowledge-base/gcp/CloudLoadBalancing/https-load-balancer-logging-enabled.html\"\
      \n      name: \"Enable Logging for HTTP(S) Load Balancers\"\n"
  - path: /ce/ca/google/load-balancing/load-balancer-logging/prod.logic.yaml
    md5Hash: 81731FB85B337C817CC6BE2BF98D17A1
    content: |-
      ---

      inputType: "CA10__CaGoogleGceBackendService__c"
      testData:
        - file: test-data.json
      importExtracts:
        - file: /types/CA10__CaGoogleGceBackendService__c/object.extracts.yaml
      conditions:
        - status: "COMPLIANT"
          currentStateMessage: "Logging is enabled for the HTTP(S) Load Balancer."
          check:
            AND:
              args:
                - IS_EQUAL:
                    left:
                      EXTRACT: "CA10__logConfigState__c"
                    right:
                      TEXT: "Enabled"
                - NOT_EMPTY:
                    arg:
                      EXTRACT: "CA10__logConfigSampleRate__c"
      otherwise:
        status: "INCOMPLIANT"
        currentStateMessage: "Logging isn't enabled for the HTTP(S) Load Balancer or sample rate isn't set."
        remediationMessage: "Enable logging for the HTTP(S) Load Balancer."
  - path: /types/CA10__CaGoogleGceBackendService__c/object.extracts.yaml
    md5Hash: CE356777514CFA68200FC0F3D36CA296
    content: "---\nextracts:\n  - name: \"CA10__logConfigState__c\"\n    value: \n\
      \      FIELD:\n        path: \"CA10__logConfigState__c\"\n  - name: \"CA10__logConfigSampleRate__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10__logConfigSampleRate__c\""
  - path: /ce/ca/google/load-balancing/load-balancer-logging/test-data.json
    md5Hash: 8230B8A909270152F761F696D8EF2BF5
    content: |
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-11-27T19:20:52Z" },
          "Id": "a7xVU1",
          "CA10__disappearanceTime__c": "2024-11-27T16:13:30Z",
          "CA10__logConfigState__c": "Enabled",
          "CA10__logConfigSampleRate__c": 1
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "199",
            "conditionText": "extract('CA10__logConfigState__c') == 'Enabled' && extract('CA10__logConfigSampleRate__c').isNotEmpty()",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-11-27T19:20:52Z" },
          "Id": "a7x7V2",
          "CA10__disappearanceTime__c": null,
          "CA10__logConfigState__c": "Enabled",
          "CA10__logConfigSampleRate__c": 1
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-11-27T19:20:52Z" },
          "Id": "a7x7V3",
          "CA10__disappearanceTime__c": null,
          "CA10__logConfigState__c": "Disabled",
          "CA10__logConfigSampleRate__c": null
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-11-27T19:20:52Z" },
          "Id": "a7x7V32",
          "CA10__disappearanceTime__c": null,
          "CA10__logConfigState__c": "Enabled",
          "CA10__logConfigSampleRate__c": null
        }
      ]
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" : "a7xVU1",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "a7x7V2",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__logConfigState__c') == 'Enabled' && extract('CA10__logConfigSampleRate__c').isNotEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "a7x7V3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "a7x7V32",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleGceBackendService__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__logConfigState__c STRING,
      CA10__logConfigSampleRate__c FLOAT64,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-11-27T19:20:52Z")
    },
    "Id" : "a7xVU1",
    "CA10__disappearanceTime__c" : new Date("2024-11-27T16:13:30Z"),
    "CA10__logConfigState__c" : "Enabled",
    "CA10__logConfigSampleRate__c" : 1
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-27T19:20:52Z")
    },
    "Id" : "a7x7V2",
    "CA10__logConfigState__c" : "Enabled",
    "CA10__logConfigSampleRate__c" : 1
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-27T19:20:52Z")
    },
    "Id" : "a7x7V3",
    "CA10__logConfigState__c" : "Disabled",
    "CA10__logConfigSampleRate__c" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-11-27T19:20:52Z")
    },
    "Id" : "a7x7V32",
    "CA10__logConfigState__c" : "Enabled",
    "CA10__logConfigSampleRate__c" : null
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleGceBackendService__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__logConfigState__c STRING,
          CA10__logConfigSampleRate__c FLOAT64
      >,
      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 IsEmptyLib = new function () {
          this.simpleIsEmpty = function(arg) {
              return arg == null;
          };
          this.simpleIsNotEmpty = function(arg) {
              return arg != null;
          };
      }();
      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__logConfigState__c; } return this.out; };
      function extract6() { if (!this.out) { this.out = obj.CA10__logConfigSampleRate__c; } return this.out; };
      references1.push('Log Config: State [obj.CA10__logConfigState__c]: ' + obj.CA10__logConfigState__c);
      references1.push('Log Config: Sample Rate [obj.CA10__logConfigSampleRate__c]: ' + obj.CA10__logConfigSampleRate__c);
      if (TextLib.equal(extract3.call(extract3), 'Enabled') && IsEmptyLib.simpleIsNotEmpty(extract6.call(extract6))) {
          return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__logConfigState__c') == 'Enabled' && extract('CA10__logConfigSampleRate__c').isNotEmpty()", currentStateMessage: "Logging is enabled for the HTTP(S) Load Balancer.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "Logging isn't enabled for the HTTP(S) Load Balancer or sample rate isn't set.", currentStateReferences: references1.join('\n'), remediation: "Enable logging for the HTTP(S) Load Balancer.", 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__logConfigState__c AS CA10__logConfigState__c,
          sObject.CA10__logConfigSampleRate__c AS CA10__logConfigSampleRate__c,
          process_CA10__CaGoogleGceBackendService__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__logConfigState__c AS CA10__logConfigState__c,
                  sObject.CA10__logConfigSampleRate__c AS CA10__logConfigSampleRate__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleGceBackendService__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
