---
policy: /ce/ca/google/storage/uniform-bucket-level-access
logic: /ce/ca/google/storage/uniform-bucket-level-access/prod.logic.yaml
executionTime: 2025-04-24T23:47:38.685673666Z
rows:
  - id: a8O1
    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: a8O2
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__levelAccessState__c') == 'Enabled'
      actual: extract('CA10__levelAccessState__c') == 'Enabled'
    runtimeError: {}
  - id: a8O3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/storage/uniform-bucket-level-access/policy.yaml
    md5Hash: EDD93A11B1C3C9D8A932FAC7FBF3A877
    content: "---\nnames: \n  full: \"Google Storage Bucket Uniform Bucket-Level Access\
      \ is not enabled\"\n  contextual: \"Bucket Uniform Bucket-Level Access is not\
      \ enabled\"\ndescription: \"It is recommended that uniform bucket-level access\
      \ is enabled on Cloud Storage buckets.\"\ntype: COMPLIANCE_POLICY\ncategories:\n\
      \  - \"SECURITY\"\nframeworkMappings:\n  - /frameworks/cis-gcp-v3.0.0/05/02\n\
      \  - /frameworks/cloudaware/resource-security/secure-access\nsimilarPolicies:\n\
      \  cloudConformity:\n    - url: \"https://www.trendmicro.com/cloudoneconformity-staging/knowledge-base/gcp/CloudStorage/enable-uniform-bucket-level-access.html\"\
      \n      name: \"Enable Uniform Bucket-Level Access for Cloud Storage Buckets\"\
      \n"
  - path: /ce/ca/google/storage/uniform-bucket-level-access/prod.logic.yaml
    md5Hash: 63B4D63A52188BA048A34AFB418FD72D
    content: |-
      ---

      inputType: "CA10__CaGoogleStorageBucket__c"
      testData:
        - file: test-data.json
      importExtracts:
        - file: /types/CA10__CaGoogleStorageBucket__c/object.extracts.yaml
      conditions:
        - status: "COMPLIANT"
          currentStateMessage: "Cloud Storage bucket has uniform bucket-level access enabled."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__levelAccessState__c"
              right:
                TEXT: "Enabled"
      otherwise:
        status: "INCOMPLIANT"
        currentStateMessage: "Cloud Storage bucket has uniform bucket-level access disabled."
  - path: /ce/ca/google/storage/uniform-bucket-level-access/test-data.json
    md5Hash: E79A1926EC76F222E4D85463B2FB5CCE
    content: |
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-03T17:55:55Z" },
          "Id": "a8O1",
          "CA10__disappearanceTime__c": "2024-09-02T17:02:49Z",
          "CA10__levelAccessState__c": "Enabled"
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "199",
            "conditionText": "extract('CA10__levelAccessState__c') == 'Enabled'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-03T17:55:55Z" },
          "Id": "a8O2",
          "CA10__disappearanceTime__c": null,
          "CA10__levelAccessState__c": "Enabled"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2024-09-03T17:55:55Z" },
          "Id": "a8O3",
          "CA10__disappearanceTime__c": null,
          "CA10__levelAccessState__c": "Disabled"
        }
      ]
  - path: /types/CA10__CaGoogleStorageBucket__c/object.extracts.yaml
    md5Hash: 3651E2495E157A71A7AF35D341E7F6F2
    content: "---\nextracts:\n  - name: \"CA10__levelAccessState__c\"\n    value:\
      \ \n      FIELD:\n        path: \"CA10__levelAccessState__c\"\n  - name: \"\
      CA10__retentionPolicyLock__c\"\n    value: \n      FIELD:\n        path: \"\
      CA10__retentionPolicyLock__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" : "a8O1",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "a8O2",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__levelAccessState__c') == 'Enabled'",
      "runtimeError" : null
    }
  }, {
    "Id" : "a8O3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaGoogleStorageBucket__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__levelAccessState__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-09-03T17:55:55Z")
    },
    "Id" : "a8O1",
    "CA10__disappearanceTime__c" : new Date("2024-09-02T17:02:49Z"),
    "CA10__levelAccessState__c" : "Enabled"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-03T17:55:55Z")
    },
    "Id" : "a8O2",
    "CA10__levelAccessState__c" : "Enabled"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-09-03T17:55:55Z")
    },
    "Id" : "a8O3",
    "CA10__levelAccessState__c" : "Disabled"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaGoogleStorageBucket__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__levelAccessState__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__levelAccessState__c; } return this.out; };
      references1.push('Level Access: State [obj.CA10__levelAccessState__c]: ' + obj.CA10__levelAccessState__c);
      if (TextLib.equal(extract3.call(extract3), 'Enabled')) {
          return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__levelAccessState__c') == 'Enabled'", currentStateMessage: "Cloud Storage bucket has uniform bucket-level access enabled.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INCOMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "Cloud Storage bucket has uniform bucket-level access disabled.", 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__levelAccessState__c AS CA10__levelAccessState__c,
          process_CA10__CaGoogleStorageBucket__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__levelAccessState__c AS CA10__levelAccessState__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaGoogleStorageBucket__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
