> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-vortex-format.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# BYOC GCP private networking setup

> Set up VPC Peering or Private Service Connect for BYOC on GCP

export const Image = ({img, alt, size = "lg"}) => {
  const normalizedSize = ["sm", "md", "lg"].includes(size) ? size : "lg";
  return <div className={`ch-image-${normalizedSize}`}>
      <Frame>
        <img src={img} alt={alt} />
      </Frame>
    </div>;
};

ClickHouse BYOC on GCP supports two private connection options including VPC Peering and PSC (Private Service Connect).

<h2 id="common-prerequisites">
  Prerequisites
</h2>

Common steps required by both VPC peering and PSC.

<h3 id="step-enable-private-load-balancer-for-clickhouse-byoc">
  Enable private load balancer for ClickHouse BYOC
</h3>

In the ClickHouse Cloud console, enable the **Private load balancer** for your BYOC infrastructure.

<Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/N5J92FpLvYKK3vEv/images/cloud/reference/byoc-private-load-balancer.webp?fit=max&auto=format&n=N5J92FpLvYKK3vEv&q=85&s=1068a3ea0c5826a85c5b1d43f581058c" size="md" alt="BYOC Enable Private Load Balancer" border width="2438" height="1724" data-path="images/cloud/reference/byoc-private-load-balancer.webp" />

<h2 id="gcp-vpc-peering">
  Set up VPC peering
</h2>

Please familiarize yourself with [GCP VPC peering feature](https://docs.cloud.google.com/vpc/docs/vpc-peering) and note the limitations of VPC peering (for example subnet IP ranges can't overlap across peered VPC networks). ClickHouse BYOC utilizes a private load balancer to allow network connectivity through the peering to ClickHouse services.

To create or delete VPC peering for ClickHouse BYOC, follow the steps:

<Note>
  The example steps are for a simple scenario, for advanced scenarios such as peering with on-premises connectivity, some adjustments may be required.
</Note>

<Steps>
  <Step title="Create a peering connection" id="step-1-create-a-peering-connection">
    In this example, we are setting up peering between the BYOC VPC network and another existing VPC network.

    1. Navigate to the "VPC Network" in ClickHouse BYOC Google Cloud Project.
    2. Select "VPC network peering".
    3. Click "Create connection".
    4. Input the necessary fields as per your requirements. Below is a screenshot for creating a peering within same GCP project.

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/0Bwb4z8TuZiplPdq/images/cloud/reference/byoc-vpcpeering-gcp-1.webp?fit=max&auto=format&n=0Bwb4z8TuZiplPdq&q=85&s=f7bf651186dd7562f812e93849d4d3d0" size="md" alt="BYOC Create Peering Connection" border width="1552" height="1740" data-path="images/cloud/reference/byoc-vpcpeering-gcp-1.webp" />

    GCP VPC peering requires 2 connections between the 2 networks to work (i.e. a connection from BYOC network to the existing VPC network and a connection from the existing VPC network to the BYOC network). So you need to similarly create 1 more connection in reverse direction, below is a screenshot for the second peering connection creation:

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/0Bwb4z8TuZiplPdq/images/cloud/reference/byoc-vpcpeering-gcp-2.webp?fit=max&auto=format&n=0Bwb4z8TuZiplPdq&q=85&s=46ec7ccad5fa698e57e49eda54b1fbf8" size="md" alt="BYOC Accept Peering Connection" border width="1560" height="1744" data-path="images/cloud/reference/byoc-vpcpeering-gcp-2.webp" />

    After both connections are created, the status of the 2 connections should become "Active" after refreshing the Google Cloud Console webpage:

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/0Bwb4z8TuZiplPdq/images/cloud/reference/byoc-vpcpeering-gcp-3.webp?fit=max&auto=format&n=0Bwb4z8TuZiplPdq&q=85&s=31a814d4bc9e9ff9d1d9103fc6f4c69d" size="lg" alt="BYOC Accept Peering Connection" border width="3134" height="640" data-path="images/cloud/reference/byoc-vpcpeering-gcp-3.webp" />

    The ClickHouse service should now be accessible from the peered VPC.
  </Step>

  <Step title="Access ClickHouse service via peering connection" id="step-2-access-ch-service-via-peering">
    To access ClickHouse privately, a private load balancer and endpoint are provisioned for secure connectivity from the user's peered VPC. The private endpoint follows the public endpoint format with a `-private` suffix. For example:

    * **Public endpoint**: `h5ju65kv87.mhp0y4dmph.us-east1.gcp.clickhouse-byoc.com`
    * **Private endpoint**: `h5ju65kv87-private.mhp0y4dmph.us-east1.gcp.clickhouse-byoc.com`
  </Step>
</Steps>

<h2 id="setup-psc">
  Set up PSC (Private Service Connect)
</h2>

GCP PSC (Private Service Connect) provides a secure and private connection to your ClickHouse BYOC services without the need for VPC peering or internet gateways. All traffic flows within the GCP network, ensuring that it never traverses the public internet.

<Steps>
  <Step title="Enable private link in ClickHouse console" id="step-1-enable-private-link">
    <Note>
      Make sure the **private load balancer** is turned on as a prerequisite.
    </Note>

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/0Bwb4z8TuZiplPdq/images/cloud/reference/byoc-privatelink.webp?fit=max&auto=format&n=0Bwb4z8TuZiplPdq&q=85&s=a114025758f21cbb43a9147128d9b93a" size="md" alt="BYOC PrivateLink Enable" width="2800" height="1848" data-path="images/cloud/reference/byoc-privatelink.webp" />
  </Step>

  <Step title={<>Obtain endpoint <code>Service name</code></>} id="step-2-obtain-endpoint-service-name">
    1. In the ClickHouse Cloud console, navigate to the service's Settings page that you would like to connect to via PSC.
    2. Click "Set up private endpoint".
    3. In the opened flyout, copy the `Service name` and `DNS name` value — you'll use them in the next step. (It may take a while for the value to be generated after enabling private link.)
           <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/0Bwb4z8TuZiplPdq/images/cloud/security/gcp-privatelink-pe-create.webp?fit=max&auto=format&n=0Bwb4z8TuZiplPdq&q=85&s=a9884ff7ec69788cdca4052c972b7996" size="md" alt="Private Endpoints" border width="1368" height="719" data-path="images/cloud/security/gcp-privatelink-pe-create.webp" />
  </Step>

  <Step title="Create endpoint in your network" id="step-3-create-endpoint">
    1. Open your **own GCP console** (i.e. the GCP account where your client application is) → Network Services → Private Service Connect → Connected Endpoints.

    2. Open the Private Service Connect creation dialog by clicking the "Connect Endpoint" button.
           <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/cP-KD3JhbRw-Qtc-/images/cloud/security/gcp-psc-open.webp?fit=max&auto=format&n=cP-KD3JhbRw-Qtc-&q=85&s=597b5b36cf3f93016cfc97faf920884b" size="md" alt="Open Private Service Connect in Google Cloud console" border width="1892" height="737" data-path="images/cloud/security/gcp-psc-open.webp" />

    3. Input the following fields:
       * **Target**: use `Published service`
       * **Target service**: use `Service name` obtained from the last step
       * **Endpoint name**: input a valid endpoint name
       * **Network/Subnetwork**: choose the network you want to use for the connection; this is the network where your client application will be connecting from
       * **IP address**: choose or create a new IP address for the endpoint; the IP address needs to be used by step [Set private DNS name for endpoint](#step-5-set-private-dns-name-for-endpoint)
       * (optional) **Enable global access**: enable it if you want to make the endpoint available from any region
             <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/cP-KD3JhbRw-Qtc-/images/cloud/security/gcp-psc-enable-global-access.webp?fit=max&auto=format&n=cP-KD3JhbRw-Qtc-&q=85&s=b296b2f29f55292f48da417ce8b17f58" size="md" alt="Enable Global Access for Private Service Connect" border width="545" height="660" data-path="images/cloud/security/gcp-psc-enable-global-access.webp" />
       * Click "ADD ENDPOINT" button to create the endpoint.

    4. The Status column will change from Pending to Accepted once the connection is approved.

    5. After creating the endpoint, copy the `PSC Connection ID` value — you'll use it in the next step.
           <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/cP-KD3JhbRw-Qtc-/images/cloud/security/gcp-psc-copy-connection-id.webp?fit=max&auto=format&n=cP-KD3JhbRw-Qtc-&q=85&s=8576aae0ba7c2f368fc9e3f968f11513" size="md" alt="Copy PSC Connection ID" border width="1441" height="116" data-path="images/cloud/security/gcp-psc-copy-connection-id.webp" />
  </Step>

  <Step title={<>Add <code>Endpoint ID</code> to ClickHouse service allow list</>} id="step-4-add-endpoint-id-to-services-allow-list">
    1. In the ClickHouse Cloud console, navigate to the service's Settings page that you would like to connect to via PSC.
    2. Click "Set up private endpoint".
    3. In the opened flyout, enter the `PSC Connection ID` obtained from the last step into the `Endpoint ID` field with an optional description.
    4. Click "Create endpoint".

    <Note>
      If you want to allow access from an existing PSC connection, use the existing endpoint dropdown menu.
      The dropdown will show the existing PSC connections to the services within the same infrastructure.
    </Note>

    <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/cP-KD3JhbRw-Qtc-/images/cloud/security/gcp-privatelink-pe-filters.webp?fit=max&auto=format&n=cP-KD3JhbRw-Qtc-&q=85&s=3adca292a931d4582646ad74c0ba5538" size="md" alt="Private Endpoints Filter" border width="1367" height="768" data-path="images/cloud/security/gcp-privatelink-pe-filters.webp" />
  </Step>

  <Step title="Set private DNS name for endpoint" id="step-5-set-private-dns-name-for-endpoint">
    <Note>
      There are various ways to configure DNS. Please set up DNS according to your specific use case.
    </Note>

    You need to point all subdomains (wildcard) of the "DNS name" to GCP PSC endpoint IP address. This ensures that services/components within your VPC/Network can resolve it properly.
  </Step>

  <Step title="Access an instance using PSC" id="step-6-connect-via-psc">
    1. In the ClickHouse Cloud console, navigate to service's Settings page.
    2. Click "Set up private endpoint".
    3. In the opened flyout, copy the `DNS name`.
           <Image img="https://mintcdn.com/private-7c7dfe99-vortex-format/0Bwb4z8TuZiplPdq/images/cloud/security/gcp-privatelink-pe-dns.webp?fit=max&auto=format&n=0Bwb4z8TuZiplPdq&q=85&s=3dec051d786d58bf445d0d87f6fccdd0" size="md" alt="Private Endpoint DNS Name" border width="1367" height="768" data-path="images/cloud/security/gcp-privatelink-pe-dns.webp" />
           <Note>
             Access to ClickHouse services via PSC is controlled by ClickHouse Cloud's service-level **Istio Authorization Policy**.
           </Note>
  </Step>
</Steps>
