---
policy: /ce/ca/google/big-query/dataset-anonymously-or-publicly-accessible
logic: /ce/ca/google/big-query/dataset-anonymously-or-publicly-accessible/prod.logic.yaml
executionTime: 2025-05-10T12:05:04.26756282Z
rows:
  - id: a7fD9
    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: a7fD99
    match: true
    status:
      expected: UNDETERMINED
      actual: UNDETERMINED
    conditionIndex:
      expected: 101
      actual: 101
    conditionText:
      expected: CA10__access__c.isEmpty()
      actual: CA10__access__c.isEmpty()
    runtimeError: {}
  - id: a7f4P9
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__access__c').contains('allUsers') || extract('CA10__access__c').contains('allAuthenticatedUsers')
      actual: extract('CA10__access__c').contains('allUsers') || extract('CA10__access__c').contains('allAuthenticatedUsers')
    runtimeError: {}
  - id: a7f4P99
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/big-query/dataset-anonymously-or-publicly-accessible/policy.yaml
    md5Hash: 8692AAC69D3694CAD9396EE3E0879E28
    content: "---\nnames: \n  full: \"Google BigQuery Dataset is anonymously or publicly\
      \ accessible\"\n  contextual: \"Dataset is anonymously or publicly accessible\"\
      \ndescription: \"It is recommended that the IAM policy on BigQuery datasets\
      \ does not allow anonymous \\ \n and/or public access.\"\ntype: COMPLIANCE_POLICY\n\
      categories:\n  - \"SECURITY\"\nframeworkMappings:\n  - /frameworks/cis-gcp-v3.0.0/07/01\n\
      \  - /frameworks/cloudaware/resource-security/public-and-anonymous-access\n\
      similarPolicies:\n  cloudConformity:\n    - url: \"https://www.trendmicro.com/cloudoneconformity/knowledge-base/gcp/BigQuery/publicly-accessible-big-query-datasets.html\"\
      \n      name: \"Check for Publicly Accessible BigQuery Datasets\"\n"
  - path: /ce/ca/google/big-query/dataset-anonymously-or-publicly-accessible/prod.logic.yaml
    md5Hash: 8E9532455C5E1CF270BF6AF555A6AEF4
    content: |
      ---

      inputType: "CA10__CaGoogleBigQueryDataset__c"
      testData:
        - file: test-data.json
      importExtracts:
        - file: /types/CA10__CaGoogleBigQueryDataset__c/object.extracts.yaml
      conditions:
        - status: "INCOMPLIANT"
          currentStateMessage: "IAM policy on BigQuery dataset allows anonymous and/or public access."
          remediationMessage: "Update the dataset information to remove all roles containing 'allUsers' or 'allAuthenticatedUsers'."
          check:
            OR:
              args:
                - CONTAINS:
                    arg:
                      EXTRACT: "CA10__access__c"
                    substring:
                      TEXT: "allUsers"
                - CONTAINS:
                    arg:
                      EXTRACT: "CA10__access__c"
                    substring:
                      TEXT: "allAuthenticatedUsers"
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: "IAM policy on BigQuery dataset does not allow anonymous and/or public access."
  - path: /types/CA10__CaGoogleBigQueryDataset__c/object.extracts.yaml
    md5Hash: B8DC026BE7E9C3A134486F67E1661FE7
    content: "---\nextracts:\n  - name: \"CA10__access__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__access__c\"\n        undeterminedIf:\n          isEmpty:\
      \  \"Access field should not be empty\"\n  - name: \"CA10__kmsKeyName__c\"\n\
      \    value: \n      FIELD:\n        path: \"CA10__kmsKeyName__c\""
  - path: /ce/ca/google/big-query/dataset-anonymously-or-publicly-accessible/test-data.json
    md5Hash: EA05CC604327B77F90D479F878D80840
    content: |
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-05T21:37:59Z" },
          "Id": "a7fD9",
          "CA10__disappearanceTime__c": "2023-12-03T17:06:36Z",
          "CA10__access__c": "[{\"role\":\"OWNER\",\"userByEmail\":\"nietest@test.com\"}]"
        },
        {
          "expectedResult": {
            "status": "UNDETERMINED",
            "conditionIndex": "101",
            "conditionText": "CA10__access__c.isEmpty()",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-05T21:37:59Z" },
          "Id": "a7fD99",
          "CA10__disappearanceTime__c": null,
          "CA10__access__c": ""
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "199",
            "conditionText": "extract('CA10__access__c').contains('allUsers') || extract('CA10__access__c').contains('allAuthenticatedUsers')",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-05T21:37:59Z" },
          "Id": "a7f4P9",
          "CA10__disappearanceTime__c": null,
          "CA10__access__c": "[{\"role\":\"OWNER\",\"user\":\"allUsers\"}]"
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-05T21:37:59Z" },
          "Id": "a7f4P99",
          "CA10__disappearanceTime__c": null,
          "CA10__access__c": "[{\"role\":\"OWNER\",\"userByEmail\":\"schtest@test.com\"}]"
        }
      ]
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" : "a7fD9",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "a7fD99",
    "expectedResult" : {
      "status" : "UNDETERMINED",
      "conditionIndex" : "101",
      "conditionText" : "CA10__access__c.isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "a7f4P9",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__access__c').contains('allUsers') || extract('CA10__access__c').contains('allAuthenticatedUsers')",
      "runtimeError" : null
    }
  }, {
    "Id" : "a7f4P99",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleBigQueryDataset__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__access__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-09-05T21:37:59Z")
    },
    "Id" : "a7fD9",
    "CA10__disappearanceTime__c" : new Date("2023-12-03T17:06:36Z"),
    "CA10__access__c" : "[{\"role\":\"OWNER\",\"userByEmail\":\"nietest@test.com\"}]"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-05T21:37:59Z")
    },
    "Id" : "a7fD99",
    "CA10__access__c" : ""
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-05T21:37:59Z")
    },
    "Id" : "a7f4P9",
    "CA10__access__c" : "[{\"role\":\"OWNER\",\"user\":\"allUsers\"}]"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-05T21:37:59Z")
    },
    "Id" : "a7f4P99",
    "CA10__access__c" : "[{\"role\":\"OWNER\",\"userByEmail\":\"schtest@test.com\"}]"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleBigQueryDataset__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__access__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 fieldChecked4() {
          if (TextLib.isEmpty(obj.CA10__access__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__access__c.isEmpty()", currentStateMessage: "Access field should not be empty", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__access__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Access [obj.CA10__access__c]: ' + obj.CA10__access__c);
      try {
          if (TextLib.contains(extract3.call(extract3), 'allUsers') || TextLib.contains(extract3.call(extract3), 'allAuthenticatedUsers')) {
              return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__access__c').contains('allUsers') || extract('CA10__access__c').contains('allAuthenticatedUsers')", currentStateMessage: "IAM policy on BigQuery dataset allows anonymous and/or public access.", currentStateReferences: references1.join('\n'), remediation: "Update the dataset information to remove all roles containing 'allUsers' or 'allAuthenticatedUsers'.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "IAM policy on BigQuery dataset does not allow anonymous and/or public access.", 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.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__access__c AS CA10__access__c,
          process_CA10__CaGoogleBigQueryDataset__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__access__c AS CA10__access__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleBigQueryDataset__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
