> ## 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

Security, Operational Maturity, Reliability

### Compliance Standards

PCIDSS, HITRUST, SOC2, NISTCSF

### 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>
    </AccordionGroup>
  </Tab>
</Tabs>

### Additional Reading:

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