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

# Ensure that Secure Boot is enabled for your Vertex AI notebook instances

### More Info:

Ensure that Secure Boot is enabled for your Vertex AI notebook instances

### Risk Level

Medium

### Address

Security

### Compliance Standards

* CIS GCP

### Triage and Remediation

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

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        Below are step-by-step GCP Console instructions to ensure Secure Boot is enabled for Vertex AI notebook instances. The key point: Secure Boot (a Shielded VM feature) can only be enabled when the VM is created. So existing notebook instances generally need to be recreated with Secure Boot enabled.

        ***

        ## A. Create a new Vertex AI Workbench notebook with Secure Boot enabled

        1. **Open Vertex AI Workbench**
           * Go to **Google Cloud Console**.
           * In the left menu, navigate to:\
             **Vertex AI → Workbench**.

        2. **Start creating a new notebook**
           * Click **+ New notebook**.
           * Choose the type (e.g., **User-managed notebooks** or **Managed notebooks**) and select an image / environment.

        3. **Open advanced VM configuration**
           * After selecting the base image/config:
             * For **Managed notebooks**:
               * In the notebook creation panel, click **Advanced options** or **Customize** to show VM-level settings.
             * For **User-managed notebooks**:
               * After selecting the image, scroll down to the **Machine configuration**, then expand **Advanced options** or **Security** (wording may vary slightly by UI version).

        4. **Enable Shielded VM and Secure Boot**
           * Look for a section named **Security**, **Shielded VM**, or **Security and access**.
           * Ensure **Shielded VM** is enabled (if it’s a separate checkbox).
           * Then check the box for **Secure Boot** (sometimes labeled as **Turn on Secure Boot**).
           * Optionally also enable:
             * **vTPM** (virtual TPM)
             * **Integrity monitoring**, if available (both part of Shielded VM).

        5. **Finish notebook creation**
           * Complete any remaining fields (name, region/zone, machine type, disk, networking, etc.).
           * Click **Create**.
           * The resulting Vertex AI notebook VM will now have Secure Boot enabled.

        ***

        ## B. Handling existing Vertex AI notebook instances

        Secure Boot cannot be toggled on/off on an already-created VM; it’s a **creation-time setting**. To “enable” Secure Boot for an existing workload:

        1. **Identify the existing notebook**
           * Go to **Vertex AI → Workbench**.
           * Find the notebook instance that does not have Secure Boot enabled.

        2. **Export / back up work**
           * Open the notebook (JupyterLab/Jupyter).
           * Copy notebooks, scripts, and data to a durable location:
             * A **Cloud Storage bucket**, or
             * A **Git repository**, or
             * Another shared storage solution.

        3. **Recreate the notebook with Secure Boot**
           * Stop the old instance if you wish (optional, for cost).
           * Follow Section A above to create a new notebook instance with the same:
             * Region/Zone
             * Machine type
             * Image / environment
             * Disk size
           * Ensure you **enable Shielded VM + Secure Boot** in the advanced/security settings.

        4. **Restore your work**
           * Open the new notebook instance.
           * Pull your notebooks and data back from Cloud Storage / Git / other backup.
           * Validate the environment and dependencies (packages, libraries) match your prior setup.

        5. **Decommission the old instance**
           * Once the new Secure-Boot-enabled notebook is working, return to **Vertex AI → Workbench**.
           * Select the old instance and click **Delete** (if no longer needed), or leave it stopped.

        ***

        ## C. Verify Secure Boot is enabled (optional)

        You can verify from the underlying VM:

        1. Go to **Compute Engine → VM instances** in the console.
        2. Locate the VM created for your Vertex AI notebook (name will match or be similar).
        3. Click the instance name.
        4. In the **Details** tab, look at the **Security** or **Shielded VM** section.
        5. Confirm that **Secure Boot** is shown as **On** / **Enabled**.

        This ensures your Vertex AI notebook instance is using Secure Boot via Shielded VM.
      </Accordion>

      <Accordion title="Using CLI">
        Below are CLI-focused steps to ensure Secure Boot is enabled on Vertex AI Workbench (Notebooks) instances.

        > Note: Secure Boot is a Shielded VM feature. It can only be enabled on instances that support Shielded VM. For some existing instances, you may need to recreate them with Secure Boot enabled.

        ***

        ## 1. Identify your notebook instance

        List your instances to find the `INSTANCE_ID` and `REGION`:

        ```bash theme={null}
        gcloud notebooks instances list
        ```

        or for a specific region:

        ```bash theme={null}
        gcloud notebooks instances list --location=us-central1
        ```

        Note the values:

        * `INSTANCE_ID`
        * `REGION` (e.g., `us-central1`)

        ***

        ## 2. Stop the notebook instance

        You must stop the instance before updating Shielded VM settings:

        ```bash theme={null}
        gcloud notebooks instances stop INSTANCE_ID \
          --location=REGION
        ```

        Wait until it reaches the `STOPPED` state.

        ***

        ## 3. Enable Secure Boot on the instance (if supported)

        Try updating in place:

        ```bash theme={null}
        gcloud notebooks instances update INSTANCE_ID \
          --location=REGION \
          --shielded-secure-boot
        ```

        If this command succeeds, Secure Boot is now enabled.

        If you get an error indicating the setting cannot be updated (e.g., instance type or image doesn’t support Shielded VM), proceed to recreate with Secure Boot enabled (next section).

        ***

        ## 4. Verify Secure Boot is enabled

        Describe the instance and check Shielded VM settings:

        ```bash theme={null}
        gcloud notebooks instances describe INSTANCE_ID \
          --location=REGION \
          --format="yaml|shieldedInstanceConfig"
        ```

        Ensure `enableSecureBoot: true` is present in `shieldedInstanceConfig`.

        ***

        ## 5. If update fails: recreate the notebook with Secure Boot

        1. Export the configuration (for reference):

           ```bash theme={null}
           gcloud notebooks instances describe INSTANCE_ID \
             --location=REGION > old-notebook-config.yaml
           ```

        2. (Optional) Back up important data (e.g., copy notebooks to a GCS bucket):

           ```bash theme={null}
           gsutil -m cp -r /path/to/notebooks gs://YOUR_BUCKET/path/
           ```

        3. Delete the old instance (if acceptable):

           ```bash theme={null}
           gcloud notebooks instances delete INSTANCE_ID \
             --location=REGION
           ```

        4. Recreate with Secure Boot enabled (adjust flags to match your previous config: machine type, image family, etc.):

           ```bash theme={null}
           gcloud notebooks instances create NEW_INSTANCE_ID \
             --location=REGION \
             --vm-image-project=deeplearning-platform-release \
             --vm-image-family=tf-latest-gpu \
             --machine-type=n1-standard-4 \
             --shielded-secure-boot
           ```

        5. Restore your notebooks/data from backup if needed.

        ***

        These steps ensure Secure Boot is enabled on your Vertex AI notebook instances using the GCP CLI.
      </Accordion>

      <Accordion title="Using Python">
        Below is how to enable Secure Boot on Vertex AI notebook instances (user‑managed or classic/AI Platform Notebooks) using Python.

        > Important: For Shielded VM options (including Secure Boot), the instance must be **stopped** before updating.

        ***

        ## 1. Prerequisites

        1. **Install the Notebooks client library**

        ```bash theme={null}
        pip install google-cloud-notebooks
        ```

        2. **Authenticate**

        Use an environment where `gcloud auth application-default login` has been run, or a service account with at least:

        * `roles/notebooks.admin` (or equivalent permissions)
        * `roles/compute.instanceAdmin.v1` (for Shielded VM config on underlying VM)

        ```bash theme={null}
        gcloud auth application-default login
        ```

        ***

        ## 2. Python script to enable Secure Boot

        This script:

        1. Stops the notebook instance (if needed).
        2. Updates the Shielded VM configuration to enable Secure Boot.
        3. Restarts the instance.

        ```python theme={null}
        from google.cloud import notebooks_v1
        from google.protobuf import field_mask_pb2
        import time

        PROJECT_ID = "YOUR_PROJECT_ID"
        LOCATION = "YOUR_REGION"          # e.g. "us-central1-b" or "us-central1"
        INSTANCE_ID = "YOUR_NOTEBOOK_NAME"

        def wait_for_operation(client, operation):
            """Waits for a long‑running operation to complete."""
            name = operation.name
            while not operation.done:
                time.sleep(5)
                operation = client.get_operation(name=name)
            if operation.error.code != 0:
                raise RuntimeError(f"Operation failed: {operation.error.message}")
            return operation

        def main():
            client = notebooks_v1.NotebookServiceClient()
            operations_client = client.transport.operations_client

            instance_name = client.instance_path(PROJECT_ID, LOCATION, INSTANCE_ID)

            # 1. Get current instance
            instance = client.get_instance(name=instance_name)

            # 2. Stop instance if it is running
            if instance.state == notebooks_v1.Instance.State.ACTIVE:
                print("Stopping instance...")
                op = client.stop_instance(name=instance_name)
                wait_for_operation(operations_client, op)
                print("Instance stopped.")

            # 3. Enable Secure Boot in Shielded VM config
            #    (preserve other existing shielded settings if present)
            current_shielded = instance.shielded_instance_config
            if current_shielded is None:
                current_shielded = notebooks_v1.Instance.ShieldedInstanceConfig()

            current_shielded.enable_secure_boot = True

            updated_instance = notebooks_v1.Instance(
                name=instance_name,
                shielded_instance_config=current_shielded,
            )

            update_mask = field_mask_pb2.FieldMask(
                paths=["shielded_instance_config.enable_secure_boot"]
            )

            print("Updating instance to enable Secure Boot...")
            op = client.update_instance(
                instance=updated_instance,
                update_mask=update_mask,
            )
            wait_for_operation(operations_client, op)
            print("Secure Boot enabled.")

            # 4. Start the instance again (optional)
            print("Starting instance...")
            op = client.start_instance(name=instance_name)
            wait_for_operation(operations_client, op)
            print("Instance started with Secure Boot enabled.")

        if __name__ == "__main__":
            main()
        ```

        ***

        ## 3. Notes / Variations

        * **New instances**: To enforce Secure Boot for all new user-managed notebook instances, always set `shielded_instance_config.enable_secure_boot = True` in your creation code.
        * **Managed notebooks**: Fully managed Vertex AI Workbench notebooks may not expose Shielded VM settings directly; in that case, you must enforce Secure Boot at the **project / organization** policy level for Shielded VMs or use user‑managed notebooks where this option is configurable.
      </Accordion>

      <Accordion title="Using Terraform">
        ```hcl theme={null}
        resource "google_notebook_instance" "VERTEX_AI_NOTEBOOK" {
          name         = "VERTEX_AI_NOTEBOOK_NAME"          # replace with your notebook instance name
          location     = "VERTEX_AI_NOTEBOOK_REGION"        # e.g. "us-central1-b"
          machine_type = "VERTEX_AI_MACHINE_TYPE"           # e.g. "n1-standard-4"

          # ...existing configuration (vm_image / container_image, disk, network, etc.)...

          shielded_instance_config {
            enable_secure_boot = true
          }
        }
        ```

        This enables Secure Boot via the Shielded VM configuration on the Vertex AI Notebook instance.

        Verification: `terraform plan` should show `shielded_instance_config.enable_secure_boot` being added or changing from `false` to `true` on the `google_notebook_instance.VERTEX_AI_NOTEBOOK` resource.
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>
