# Accessing a Private GCP Database via a Jumpbox

Accessing a private **Cloud SQL** instance is a common challenge in cloud-based architectures. Exposing your database directly to the internet poses significant security risks — which is why using a **jumpbox (bastion host)** within a private subnet is an established best practice.

This guide walks you through **configuring and using an SSH tunnel via a jumpbox** to connect to your private Cloud SQL instance on **Google Cloud**.\
By following these steps, you’ll be able to **securely manage your database** while keeping it **isolated and protected within your private network**.

1. In the **GCP Console**, navigate to **Compute Engine → VM instances**, then click **“Create Instance.”**<br>

   <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2FCOTsnhPVqT1tmSPmScRo%2Fimage.png?alt=media&#x26;token=fd5d4f35-8b76-4305-87fd-011105dae55a" alt=""><figcaption></figcaption></figure>

2. You can use the **default machine type (2 vCPU, 4 GB RAM)** — there’s **no need to modify the default configuration**, as it provides sufficient resources for the jumpbox.<br>

   <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2FNoddQXHMO8RzQkueYoXs%2Fimage.png?alt=media&#x26;token=e358a1b8-6090-4ca7-86a0-f38b7379c48e" alt=""><figcaption></figcaption></figure>

3. For each client that requires access to the Jumpbox, **add their public SSH keys** under the **Managed Access** section in the **Security** tab.

   Always **add SSH keys through the GCP Console or CLI** — **do not edit** the `.ssh/authorized_keys` file directly on the VM.\
   GCP periodically overwrites this file automatically, so manual edits will be lost.<br>

   <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2FkHiNrujHF0MwRXwEe7jd%2Fimage.png?alt=media&#x26;token=aa42a9e7-fee7-417f-807c-e85de3f01284" alt=""><figcaption></figcaption></figure>

4. Click **“Create”** to launch the instance.

5. Connect to your Jumpbox using SSH.\
   The **SSH username** corresponds to the **user portion of your SSH key**.

   For example, if your public key looks like:

   ```
   ssh-rsa AAAAB3... hello@example.com
   ```

   then connect using:

   ```bash
   ssh hello@<jumpbox_public_ip>
   ```

   The **public IP address** (also called the **External IP** in GCP) is visible on the **VM Instances** page in the **Compute Engine** section.<br>

   <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2FY2jheDrrBakKHOqeQKb9%2Fimage.png?alt=media&#x26;token=33de551d-7241-4813-8ea7-c33176cdf46b" alt=""><figcaption></figcaption></figure>

6. In the **Cloud SQL** console, open your database configuration page to find the **Private IP address** listed on the main overview tab.

   If a private IP hasn’t been allocated yet, **edit the instance** and enable **Private Service Access**.\
   The setup is straightforward — you can safely proceed with the **default suggested configuration**.<br>

   <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2FZCITuwywoRtfr9ywEA0x%2Fimage.png?alt=media&#x26;token=63d59eb7-9b85-46d9-bcbe-95ea086e073e" alt=""><figcaption></figcaption></figure>

7. From your **Jumpbox VM**, verify that the database is reachable by running the following commands:

   ```bash
   # Install telnet if not already installed
   sudo apt install telnet -y

   # Test the connection to your database
   telnet <db_private_ip> <db_port>
   ```

   **Database port reference:**

   * PostgreSQL → `5432`
   * MySQL → `3306`
   * SQL Server → `1433`

   **Expected output:**

   ```
   hello@jumpbox:~$ telnet <db_private_ip> <db_port>
   Trying <db_private_ip>...
   Connected to <db_private_ip>.
   Escape character is '^]'.
   ```

   If the command only shows:

   ```
   Trying <db_private_ip>...
   ```

   and does **not** connect, it means the database is **unreachable**.\
   Double-check the following:

   * You’re using the **correct private IP** and **port**.
   * The **Jumpbox subnet** has a valid **route** to the **database subnet**.
   * **Firewall or security group rules** allow inbound traffic from the Jumpbox.

8. To strengthen security, **limit SSH access to your Jumpbox** by allowing only trusted IP addresses.

   Go to the **Firewall Policies** section in the **GCP Console**, and **create a new firewall rule** that permits inbound SSH traffic **only from your approved IP list**.<br>

   <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2FGSFk5HCUBAVGPuHvbhfA%2Fimage.png?alt=media&#x26;token=3c7d8beb-fe74-401b-b033-b20c9e5f2dea" alt=""><figcaption></figcaption></figure>

9. Select the **network (VPC)** where your **Jumpbox instance** is running to apply the firewall rule to the correct environment.<br>

   <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2Ffk6E5cuhh7sHtgzll4O9%2Fimage.png?alt=media&#x26;token=d1ed3969-eca2-4426-abfe-e1df2fe919e7" alt=""><figcaption></figcaption></figure>

10. To grant a client access to your Jumpbox, **whitelist their public IP** in your firewall rule.\
    Configure the rule with the following parameters:

    * **Priority:** `0` (highest priority)
    * **Direction of traffic:** `Ingress`
    * **Action on match:** `Allow`
    * **Source IPv4 ranges:** `<client_public_ip_to_whitelist>/32`
    * **Destination IPv4 ranges:** `<jumpbox_private_ip>/32`

    This ensures that only the specified client IP can initiate SSH connections to your Jumpbox.<br>

    <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2FItJmJO7iYLWM3WuPUfpX%2Fimage.png?alt=media&#x26;token=2fb08bd9-c851-4fd7-86b7-57fcac11ccbd" alt=""><figcaption></figcaption></figure>

11. Allow access **exclusively through SSH** by whitelisting **port 22**, the default SSH port.\
    All other ports and protocols should be **explicitly denied** to prevent unauthorized access.

    Once these settings are configured, click **“Create”** to finalize the firewall rule.<br>

    <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2FKFj55yFcY2381xP2aZrP%2Fimage.png?alt=media&#x26;token=774a958d-d0f0-4fa3-aa2c-91bdb26e4eb5" alt=""><figcaption></figcaption></figure>

12. Now that access from the client’s public IP is allowed, you should **block all other incoming traffic** to the Jumpbox.

    Create a **new firewall rule** using the **same network (VPC)** as in the previous step, and configure it as follows:

    * **Priority:** `1` (lower priority than the allow rule)
    * **Action:** Deny all inbound traffic from any other IP address

    This ensures that **only the whitelisted client** can connect to the Jumpbox, while all other sources are **securely blocked**.

    <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2FKaPQkAaHdEEh97n5gevg%2Fimage.png?alt=media&#x26;token=d92b976c-2d33-4552-a5ea-66372cee55b1" alt=""><figcaption></figcaption></figure>

13. Set the **Source IPv4 range** to `0.0.0.0/0` to **deny access from all IP addresses**.\
    Ensure that **all protocols and ports** are **disabled** to completely block unwanted traffic.

    Once configured, click **“Create”** to finalize the firewall rule.<br>

    <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2FnJIijPcFWoLWvswCp1gJ%2Fimage.png?alt=media&#x26;token=5f7a54d3-e576-4ac6-97fa-897a9abf93a2" alt=""><figcaption></figcaption></figure>

14. Next, confirm that the Jumpbox is **reachable only from the whitelisted client(s)**.\
    Try connecting via SSH from any other machine — the connection should **time out**, indicating that access is correctly restricted to authorized IPs only.

#### 🎉 Congratulations!

You’ve successfully allowed an **external client** to **securely access your private Cloud SQL database** through the Jumpbox.

If you need any assistance or have questions, feel free to reach out at <hello@stacksync.com> — our team is always happy to help!
