> ## Documentation Index
> Fetch the complete documentation index at: https://cloudanix.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Bucket Versioning Should Be Enabled

### More Info:

Ensures object versioning is enabled on storage buckets. Object versioning can help protect against the overwriting of objects or data loss in the event of a compromise.

### Risk Level

Low

### Address

Operational Maturity, Reliability, Security

### Compliance Standards

* APRA CPS 234 (Australia)
* BSI C5 (Germany)
* Brazil LGPD
* CCPA / CPRA (California)
* CIS Critical Security Controls v8
* CMMC 2.0
* CSA Cloud Controls Matrix v4
* DPDPA
* Digital Operational Resilience Act (EU)
* Essential 8
* HITRUST CSF
* ISO/IEC 27017
* ISO/IEC 27018
* ISO/IEC 27701
* KSA PDPL
* MAS Technology Risk Management (Singapore)
* MITRE ATT\&CK (Cloud)
* NIS2 Directive
* NIST CSF
* NIST SP 800-171
* NYDFS 23 NYCRR 500
* PCI
* Reserve Bank of India (RBI) Cyber Security Framework
* Reserve Bank of India (RBI) Master Direction – Information Technology Framework
* SOC2
* SWIFT Customer Security Controls Framework
* Sarbanes-Oxley IT General Controls
* UK NCSC Cyber Assessment Framework

### Triage and Remediation

<Tabs>
  <Tab title="Remediation">
    ### Remediation

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        To remediate the "Bucket Versioning Should Be Enabled" misconfiguration in GCP using GCP console, follow these steps:

        1. Go to the GCP console and select the project where the misconfigured bucket is located.

        2. In the top navigation bar, click on the "Storage" option.

        3. Click on the name of the bucket that needs to be remediated.

        4. In the left-hand menu, click on the "Versions" option.

        5. Click on the "Enable versioning" button.

        6. A pop-up window will appear asking you to confirm that you want to enable versioning. Click on the "Enable" button.

        7. Once versioning is enabled, you will see a message confirming that versioning has been enabled for the bucket.

        8. You can now exit the GCP console.

        By following these steps, you will have successfully remediated the misconfiguration "Bucket Versioning Should Be Enabled" for the specified bucket in GCP using GCP console.

        #
      </Accordion>

      <Accordion title="Using CLI">
        To remediate the bucket versioning misconfiguration in GCP using GCP CLI, you can follow the below steps:

        1. Open Cloud Shell from the GCP console.
        2. Run the following command to enable versioning for a specific bucket:

        ```
        gsutil versioning set on gs://[BUCKET_NAME]
        ```

        Note: Replace \[BUCKET\_NAME] with the name of the bucket you want to enable versioning for.

        3. Verify that versioning is enabled for the bucket by running the following command:

        ```
        gsutil versioning get gs://[BUCKET_NAME]
        ```

        Note: Replace \[BUCKET\_NAME] with the name of the bucket you enabled versioning for.

        4. The output of the above command should show "Enabled: True" indicating that versioning has been enabled for the bucket.

        By following these steps, you can remediate the misconfiguration of bucket versioning not being enabled in GCP using GCP CLI.
      </Accordion>

      <Accordion title="Using Python">
        To remediate the "Bucket Versioning Should Be Enabled" misconfiguration in GCP using Python, you can follow these steps:

        1. Install the `google-cloud-storage` library using pip:

        ```python theme={null}
        pip install google-cloud-storage
        ```

        2. Import the necessary modules:

        ```python theme={null}
        from google.cloud import storage
        ```

        3. Initialize the client object:

        ```python theme={null}
        client = storage.Client()
        ```

        4. Get the bucket object:

        ```python theme={null}
        bucket = client.get_bucket('bucket-name')
        ```

        5. Enable versioning for the bucket:

        ```python theme={null}
        bucket.versioning_enabled = True
        bucket.patch()
        ```

        6. Verify that versioning is enabled:

        ```python theme={null}
        bucket.reload()
        print(bucket.versioning_enabled)
        ```

        This will enable versioning for the specified GCP bucket and ensure that all objects uploaded to the bucket have a unique version ID.
      </Accordion>

      <Accordion title="Using Terraform">
        ```hcl theme={null}
        resource "google_storage_bucket" "TARGET_BUCKET" {
          name     = "YOUR_BUCKET_NAME" # replace with the exact bucket name
          location = "YOUR_BUCKET_LOCATION" # e.g. "US", "EU", "us-central1"

          versioning {
            enabled = true
          }

          # include any other existing arguments for this bucket here
        }
        ```

        Enabling `versioning.enabled = true` on an existing `google_storage_bucket` does not force bucket replacement; it is an in‑place change.

        To verify, `terraform plan` should show an in-place update (`~ update in-place`) for `google_storage_bucket.TARGET_BUCKET` with `versioning.enabled` changing from `false` (or `null`) to `true`.
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>

### Additional Reading:

* [https://cloud.google.com/storage/docs/using-object-versioning](https://cloud.google.com/storage/docs/using-object-versioning)
