<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yvette Zhang on Medium]]></title>
        <description><![CDATA[Stories by Yvette Zhang on Medium]]></description>
        <link>https://medium.com/@yyzh?source=rss-59e97308365a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ZG2EKdNSM_fJjydc</url>
            <title>Stories by Yvette Zhang on Medium</title>
            <link>https://medium.com/@yyzh?source=rss-59e97308365a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 14:25:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yyzh/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Cloud Build with Background Proxy Connection]]></title>
            <link>https://medium.com/@yyzh/cloud-build-with-background-proxy-connection-140955b2af9a?source=rss-59e97308365a------2</link>
            <guid isPermaLink="false">https://medium.com/p/140955b2af9a</guid>
            <dc:creator><![CDATA[Yvette Zhang]]></dc:creator>
            <pubDate>Mon, 12 Dec 2022 08:34:44 GMT</pubDate>
            <atom:updated>2022-12-12T14:15:53.638Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why do you need Cloud Build with Background Proxy Connection</h3><p>Cloud Build is the serverless CI/CD platform that executes build steps on Google Cloud.</p><p><strong>Cloud Build Default Pool</strong></p><p>By default, when you run a build on Cloud Build, the build runs in a secure, hosted environment with access to the public internet. With those default Cloud Build worker pools, the Cloud Build servers being used are managed by GCP where the public IP can vary across a huge IP range, with the same source ranges as the general Google Compute Engines. This can be challenging if you want to apply firewall policies or source IP filters from services that expect interaction with Cloud Build.</p><p>E.g. If you want Cloud Build to modify configurations from your source repositories from specific Public IP, or if you want Cloud Build to deploy GKE workloads in a public GKE cluster from specific Authorized Networks, etc.</p><p><strong>Cloud Build Private Pool</strong></p><p>It is usually recommended that you use Cloud Build’s <strong>private pool</strong> to resolve problems like this. Private pools are private, dedicated pools of workers that offer greater customization over the build environment, including the ability to access resources in a private network. With a private pool, you can use Cloud NAT with a reserved public IP address to ensure that Cloud Build’s internet access originates from deterministic sources.</p><p>While Private pool is the official recommendation for using a specific network for Cloud Build, it has its own issues today. E.g. it takes ~ 1 min to start every time, because it requires dedicated VMs to start up before a Build can start.</p><p><strong>Cloud Build Default Pool with Proxy Connection</strong></p><p>It is quite common to solve the aforementioned problems by adding a Proxy with Cloud Build’s default pool. From any build servers from the default pool, with TCP proxy connection to a specific VM in a VPC network, it can easily make the Cloud Build source IP deterministic.</p><p>However, it will be hectic to connect to a TCP proxy in each Cloud Build step, especially for some Builder images that do not have pre-installed tools to make proxy connections where a separate image might have to be created to achieve this.</p><p>At this point, we might want to have a way to run Cloud Build default pool with Background Proxy Connection throughout all build steps.</p><h3>How to run Cloud Build with Background Proxy Connection</h3><p>A working example of running Cloud Build with background proxy connection can be found in <a href="https://github.com/GoogleCloudPlatform/professional-services/tree/main/examples/cloudbuild-with-tcp-proxy">https://github.com/GoogleCloudPlatform/professional-services/tree/main/examples/cloudbuild-with-tcp-proxy</a>.</p><p>Cloud Build runs on GCP managed compute instance hosts. By default it spins up a container for each build step, and stops the container at the end of the step. In order to have a TCP connection running in the background that can be used by containers of other build steps, a few problems that need to be solved here.</p><ol><li>Having the proxy connection running throughout all build steps.</li><li>Sharing the proxy connection made from one container with other containers in the subsequent build steps.</li><li>Waiting for proxy connection to establish, before moving to subsequent build steps.</li></ol><p>And here’s some more details on how these are done.</p><ol><li><strong>Running proxy connection in the background</strong></li></ol><p>Compose is a tool for defining and running multi-container Docker applications. With Compose, you can configure the proxy connection as a service that does not get turned down at the end of the build step, so it can keep the proxy connection up throughout all the build steps, until explicitly stopped.</p><ul><li>Making proxy connection using Docker-Compose config</li></ul><p>e.g. docker-compose.yaml</p><pre>services:<br>  gcloud_ssh_proxy:<br>    build: .<br>    entrypoint:<br>      &#39;/gssh_proxy.sh&#39; # &lt;- this is the script that makes proxy connection.<br>    ports:<br>      - &#39;$PORT:$PORT&#39;</pre><ul><li>Bring up and turn down docker compose service that makes proxy connection</li></ul><p>e.g. cloudbuid.yaml</p><pre>steps:<br>  - id: connect_to_proxy <br>    name: &#39;docker/compose:1.28.2&#39;<br>    args: [&#39;-f&#39;, &#39;docker-compose-cloudbuild.yaml&#39;, &#39;up&#39;, &#39;-d&#39;, &#39;--build&#39;]<br>    env:<br>    - &#39;PORT=$_PORT&#39;<br>    - &#39;PROXY_SERVER=$_PROXY_SERVER&#39;<br>    # ...<br><br>  - id: disconnect_docker_compose <br>    name: &#39;docker/compose:1.28.2&#39;<br>    args: [&#39;-f&#39;, &#39;docker-compose-cloudbuild.yaml&#39;, &#39;down&#39;]</pre><p><strong>2. Sharing proxy connection with containers from other Build Steps</strong></p><p>Each step in Cloud Build creates its own docker container, by default, they will be running with the default docker network (<a href="https://docs.docker.com/compose/networking/">https://docs.docker.com/compose/networking/</a>) and will not be able to communicate with each other. In order to share the proxy network connection with containers in other build steps, the connection should be made to the docker network called cloudbuild for other build steps to refer.</p><ul><li>Running docker-compose service with proxy connection with cloudbuild network.</li></ul><p>e.g. docker-compose.yaml</p><pre>services:<br>  gcloud_ssh_proxy:<br>    build: .<br>    entrypoint:<br>      &#39;/gssh_proxy.sh&#39;<br><br><br># docker-compose uses builders_default network by default.<br># cloudbuild steps uses docker network cloudbuild by default.<br># must specify cloudbuild network explicitly if running in cloudbuild.<br>networks:<br>  default:<br>    external:<br>      name: cloudbuild</pre><ul><li>Using proxy connection established in another build steps</li></ul><p>After the proxy connection build step runs a container with background connectivity to proxy server, other containers can use it as proxy for further HTTP connections. From a different container, the proxy needs to be referred to in the format of &lt;container&gt;.&lt;network&gt;:&lt;port&gt;,while &lt;container&gt;needs to be something that can be resolved by the docker network on the host. e.g. for Cloud Build, it will be using something like workspace_&lt;docker-compose_service_name&gt;_1 as the default.</p><p>e.g. cloudbuild.yaml to configure HTTPS proxy connected from a build step with above docker-compose configuration.</p><pre>  - id: verify_proxy<br>    name: gcr.io/cloud-builders/curl<br>    args:<br>      https://api.ipify.org?format=json<br>    env:<br>      - HTTPS_PROXY=workspace_gcloud_ssh_proxy_1.cloudbuild:$_PORT<br>        # docker-compose container: workspace_gcloud_ssh_proxy_1<br>        # docker-compose container network: cloudbuild</pre><p><strong>3. Waiting for proxy connection to establish before subsequent build steps</strong></p><p>With docker-compose, multiple services and containers can be running in parallel with each other. It is important to make sure that the connection to the proxy server is successfully established before moving to the next build steps which depend on proxy configurations.</p><p>Docker-compose has a health check function designed for this. (Note that this is not available for all docker-compose versions, make sure a correct version is used if a health-check function is needed for your use case.)</p><p>This requires the proxy connection container with a health-check function configured. In this example, <a href="https://en.wikipedia.org/wiki/Netstat">netstat</a> is used to ensure that the proxy forwarding port is opened.</p><p>e.g. proxy connection service in docker-compose.yaml</p><pre>services:<br>  gcloud_ssh_proxy:<br>    build: .<br>    # ...<br>    healthcheck:<br>      test: &#39;netstat -ltn | grep -c $PORT || exit 1&#39;<br>      interval: 5s<br>      timeout: 5s<br>      retries: 10</pre><p>Then, another docker-compose service is used to continuously check the healthiness of the proxy connection service until it becomes available.</p><p>e.g. proxy connection service in docker-compose.yaml</p><pre>services:<br>  gcloud_ssh_proxy:<br>    # ...<br><br>  # proxy_waiter runs a dummy container to wait for healt-check of gcloud ssh proxy<br>  proxy_waiter:<br>    image: gcr.io/cloud-builders/gcloud-slim:latest<br>    depends_on:<br>      gcloud_ssh_proxy:<br>        condition: service_healthy</pre><h3>Summary</h3><p>This concludes the detail explanation of a working example of configuring Cloud Build to run with a proxy connection throughout all build steps. For more details or a complete sample config files, please refer to this github repository: <a href="https://github.com/GoogleCloudPlatform/professional-services/tree/main/examples/cloudbuild-with-tcp-proxy">https://github.com/GoogleCloudPlatform/professional-services/tree/main/examples/cloudbuild-with-tcp-proxy</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=140955b2af9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building your own BGP with Network Virtual Appliances on GCP]]></title>
            <link>https://medium.com/@yyzh/building-your-own-bgp-with-network-virtual-appliances-on-gcp-6852ce8fd5bc?source=rss-59e97308365a------2</link>
            <guid isPermaLink="false">https://medium.com/p/6852ce8fd5bc</guid>
            <dc:creator><![CDATA[Yvette Zhang]]></dc:creator>
            <pubDate>Tue, 04 Oct 2022 14:22:52 GMT</pubDate>
            <atom:updated>2022-10-04T14:22:52.638Z</atom:updated>
            <content:encoded><![CDATA[<p>While GCP provides convenient cloud native solutions to connect VPCs via <a href="https://cloud.google.com/vpc/docs/vpc-peering">VPC Peering</a> or <a href="https://cloud.google.com/network-connectivity/docs/vpn/concepts/overview">Cloud VPN</a>, some use cases benefit from segmenting VPC networks and connecting them with virtualized network appliances.</p><p>When this type of design scales, it could be beneficial to manage and exchange IP routes across multiple VPCs using <a href="https://en.wikipedia.org/wiki/Border_Gateway_Protocol">BGP</a> protocol, which dynamically helps to find the best route for network traffic seeking to reach a destination, either in the same autonomous system (AS) using iBGP, or another AS using eBGP.</p><p>Running BGP on Google Cloud has its own trickiness compared to running BGP on an on-prem router, where a pair of direct BGP peers are usually connected by layer 2 network. On GCP, hosts within the same VPC, and even the same subnet do NOT have L2 reachability.</p><p>What does this mean? Let’s take a look at an example.</p><ol><li>In an on-prem like network, with L2 connectivity</li></ol><p>The below diagram shows how BGP route is exchanged, and how destination is reached, between peers that have direct L2 network connectivity.</p><p>Router-1 has 1.1.1.1 (loopback in this test) directly connected.<br>Router-1 advertised 1.1.1.0/24 to Router 2, which is accepted and added to Router-2’s routing table<br>When Router-2 pings 1.1.1.1, Router-2 sends out the packet with peering interfaces’ MAC addresses in the L2 header. In the L3 header, the destination IP address is set to be 1.1.1.1.</p><p>When this packet leaves Router-2’s peering interface, the L2 network can properly forward the packet to Router-1, only based on the destination MAC address. This is the magic of the L2 network, forwarding packets with MAC addresses within its broadcast domain.</p><p>After the packet gets into Router-1, the L3 destination IP address can obviously be successfully reached.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d7J7abWaNRy_W6tbfTorDA.png" /><figcaption>BGP over Peers with L2 connectivity</figcaption></figure><p>2. In the GCP network, without L2 connectivity</p><p>The on-prem BGP setup will see its challenges on GCP. Because, on GCP, there’s no L2 connectivity within a VPC, or even within a subnet.</p><p>A simple illustration is that when you run ifconfig in a VM on GCP, the netmask is set to 255.255.255.255, which implies that the VM is running in a subnet with prefix length /32, and this subnet contains only a single host — itself.</p><p>Hence, the broadcast domain reaches no one but itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*oo0QGEhW4rijFDxfvfUKdw.png" /><figcaption>Default ifconfig output of a debian VM on GCP</figcaption></figure><p>Now what happens if we run the same BGP over peers that’s connected by such a GCP VPC network without L2 connectivity?</p><p>The BGP route advertisement from Router-1 to Router-2 works similarly as before. But things change when the packet towards 1.1.1.1 leaves Router-2.</p><p>At this point, Router-2 runs in its own L2 network, where the destination MAC address does not reach anywhere within the broadcast domain of Router-2’s subnet.</p><p>This is when the control plane has to unwrap the L3 headers to search for the destination IP address, which is set to 1.1.1.1, which is not routable within the VPC, simply because the VPC did not install anything that talks BGP with Router-1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*Iwv7n0_pmJv6GgSB94MA6A.png" /><figcaption>BGP over Peers in the same VPC without L2 connectivity</figcaption></figure><p>3. What can we do about it?</p><p>There might be multiple answers to this. One easy config for appliances like <a href="https://www.cisco.com/c/en/us/products/routers/cloud-services-router-1000v-series/index.html">Cisco Cloud Services Router</a>(CSR) is to setup the BGP to run over tunnel, e.g. <a href="https://en.wikipedia.org/wiki/IP_in_IP">IP in IP</a> Tunnel.</p><p>With this, instead of setting up BGP peers with Router-1 and Router-2’s Network Interface Card(NIC) IP, a separate pair of tunnel IPs are configured in both routers, to be used as the endpoints of the BGP session.</p><p>With this, the L3 headers have 2 IP layers, one wrapping over the other as shown in the below diagram.</p><p>Now, when the packet departs Router-2, the destination MAC address is still not reachable. <br>Packet’s L2 header is stripped off, and the outer L3 IP header has destination IP of Router-1’s NIC address, which is routable within the VPC. <br>Packet is then sent to Router-1 where tunnel-0 terminates BGP and unwraps the outer IP header. <br>Now it’s up for Router-1 to finally forward the payload to the inner IP header — 1.1.1.1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*Yb1TTMBg8VbraKRhwsv3gA.png" /><figcaption>BGP over Peers IP-IP tunnel between Peers in the same VPC</figcaption></figure><p>If you’re looking to set this up, <a href="https://github.com/GoogleCloudPlatform/bgp-with-nva-on-gcp">this github project</a> has some sample config for a design that includes a few BGP sessions over IP-IP tunnels on GCP.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6852ce8fd5bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>