本節說明在開發階段和管道執行階段,從 Cloud Data Fusion 私人執行個體建立輸出控制項的高階架構。
下圖顯示開發管道時,私有 Cloud Data Fusion 執行個體如何連線至公用網際網路:

在管道開發或執行期間,您可以透過客戶專案路由所有輸出流量,控管與 SaaS 應用程式和第三方公有雲服務的連線。這項程序會使用下列資源:
自訂虛擬私有雲網路路徑:自訂虛擬私有雲網路會透過匯入的自訂路徑,將流量傳送至閘道 VM,然後使用 虛擬私有雲對等互連匯出至租戶專案虛擬私有雲。
Proxy VM:Proxy VM 會透過公用網際網路,將 Cloud Data Fusion 租戶專案的輸出流量,從 Google Cloud 路由至指定目的地。您可以在客戶專案中建立及管理閘道 VM。建議您使用內部負載平衡器 (ILB),在高可用性 (HA) 設定中設定這些項目。如果您有多個使用相同虛擬私有雲網路的私有 Cloud Data Fusion 執行個體,可以在虛擬私有雲內重複使用相同的 VM。
事前準備
在 Cloud Data Fusion 6.4 以上版本中,您可以從私人執行個體連線至公開來源。如要使用這些版本,您可以建立新的私人 Cloud Data Fusion 執行個體,或升級現有執行個體。
為執行個體建立虛擬私有雲網路對等互連連線時,請選取「匯出路徑」。
在管道開發期間設定輸出控制項
輸出控制項可讓您控管或篩選網路的輸出內容,這在 VPC Service Controls 環境中非常實用。沒有執行這項工作偏好的網路 Proxy。例如 Squid 代理伺服器、HAProxy 和 Envoy。
本指南中的範例說明如何在使用 Debian 映像檔的 VM 執行個體上,設定 HTTP Proxy 來進行 HTTP 篩選。這些範例使用 Squid Proxy 伺服器,這是設定 Proxy 伺服器的方式之一。
建立 Proxy VM
在與 Cloud Data Fusion 私人執行個體相同的 VPC 中建立 VM,並使用下列開機指令碼和 IP 轉送。
這個指令碼會安裝 Squid Proxy,並設定攔截 HTTP 流量,以及允許 .squid-cache.org 和 .google.com 網域。您可以將這些網域替換為要連結至 Cloud Data Fusion 執行個體的網域。
控制台
前往「VM instances」(VM 執行個體) 頁面。
點選「建立執行個體」。
使用與私人 Cloud Data Fusion 執行個體建立網路對等互連的虛擬私有雲。如要進一步瞭解這個情境中的虛擬私有雲網路對等互連,請參閱「事前準備」。
為與 Cloud Data Fusion 執行個體位於相同網路的執行個體啟用 IP 轉送。
在「Startup script」(開機指令碼) 欄位中,輸入下列指令碼:
#! /bin/bash apt-get -y install squid3 cat <<EOF > /etc/squid/conf.d/debian.conf # # Squid configuration settings for Debian # logformat squid %ts.%03tu %6tr %>a %Ss/%03>Hs %<st %rm %ru %ssl::>sni %Sh/%<a %mt logfile_rotate 10 debug_options rotate=10 # configure intercept port http_port 3129 intercept # allow only certain sites acl allowed_domains dstdomain "/etc/squid/allowed_domains.txt" http_access allow allowed_domains # deny all other http requests http_access deny all EOF # Create a file with allowed egress domains # Replace these example domains with the domains that you want to allow # egress from in Data Fusion pipelines cat <<EOF > /etc/squid/allowed_domains.txt .squid-cache.org .google.com EOF /etc/init.d/squid restart iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3129 echo 1 > /proc/sys/net/ipv4/ip_forward echo net.ipv4.ip_forward=1 > /etc/sysctl.d/11-gce-network-security.conf iptables -t nat -A POSTROUTING -s 0.0.0.0/0 -p tcp --dport 443 -j MASQUERADE
gcloud
export CDF_PROJECT=<cdf-project>
export PROXY_VM=<proxy-vm>
export ZONE=<vm-zone>
export SUBNET=<subnet>
export VPC_NETWORK=<vpc-network>
export COMPUTE_ENGINE_SA=<compute-engine-sa>
gcloud beta compute --project=$CDF_PROJECT instances create $PROXY_VM --zone=$ZONE --machine-type=e2-medium --subnet=$SUBNET --no-address --metadata=startup-script=\#\!\ /bin/bash$'\n'apt-get\ -y\ install\ squid3$'\n'cat\ \<\<EOF\ \>\ /etc/squid/conf.d/debian.conf$'\n'\#$'\n'\#\ Squid\ configuration\ settings\ for\ Debian$'\n'\#$'\n'logformat\ squid\ \%ts.\%03tu\ \%6tr\ \%\>a\ \%Ss/\%03\>Hs\ \%\<st\ \%rm\ \%ru\ \%ssl::\>sni\ \%Sh/\%\<a\ \%mt$'\n'logfile_rotate\ 10$'\n'debug_options\ rotate=10$'\n'$'\n'\#\ configure\ intercept\ port$'\n'http_port\ 3129\ intercept$'\n'$'\n'\#\ allow\ only\ certain\ sites$'\n'acl\ allowed_domains\ dstdomain\ \"/etc/squid/allowed_domains.txt\"$'\n'http_access\ allow\ allowed_domains$'\n'$'\n'\#\ deny\ all\ other\ http\ requests$'\n'http_access\ deny\ all$'\n'EOF$'\n'$'\n'$'\n'\#\ Create\ a\ file\ with\ allowed\ egress\ domains$'\n'\#\ Replace\ these\ example\ domains\ with\ the\ domains\ that\ you\ want\ to\ allow\ $'\n'\#\ egress\ from\ in\ Data\ Fusion\ pipelines$'\n'cat\ \<\<EOF\ \>\ /etc/squid/allowed_domains.txt$'\n'.squid-cache.org$'\n'.google.com$'\n'EOF$'\n'$'\n'/etc/init.d/squid\ restart$'\n'$'\n'iptables\ -t\ nat\ -A\ PREROUTING\ -p\ tcp\ --dport\ 80\ -j\ REDIRECT\ --to-port\ 3129$'\n'echo\ 1\ \>\ /proc/sys/net/ipv4/ip_forward$'\n'echo\ net.ipv4.ip_forward=1\ \>\ /etc/sysctl.d/11-gce-network-security.conf$'\n'iptables\ -t\ nat\ -A\ POSTROUTING\ -s\ 0.0.0.0/0\ -p\ tcp\ --dport\ 443\ -j\ MASQUERADE --can-ip-forward --maintenance-policy=MIGRATE --service-account=$COMPUTE_ENGINE_SA --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append --tags=http-server,https-server --image=debian-10-buster-v20210420 --image-project=debian-cloud --boot-disk-size=10GB --boot-disk-type=pd-balanced --boot-disk-device-name=instance-1 --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any
gcloud compute --project=$CDF_PROJECT firewall-rules create egress-allow-http --direction=INGRESS --priority=1000 --network=$VPC_NETWORK --action=ALLOW --rules=tcp:80 --source-ranges=0.0.0.0/0 --target-tags=https-server
gcloud compute --project=$CDF_PROJECT firewall-rules create egress-allow-https --direction=INGRESS --priority=1000 --network=$VPC_NETWORK --action=ALLOW --rules=tcp:443 --source-ranges=0.0.0.0/0 --target-tags=https-server
建立自訂路線
建立自訂路徑,連線至您建立的閘道 VM 執行個體。
控制台
如要在 Google Cloud 控制台中建立路徑,請參閱「新增靜態路徑」。
設定路徑時,請按照下列步驟操作:
- 將「Priority」設為大於或等於
1001。 - 使用與 Cloud Data Fusion 私人執行個體相同的專案和 VPC。
- 請務必確認虛擬私有雲網路對等互連設定允許匯出路徑,這樣 Cloud Data Fusion 租戶專案虛擬私有雲才能透過虛擬私有雲網路對等互連匯入這個自訂路徑。
gcloud
如要在 gcloud CLI 中建立路徑:
gcloud beta compute routes create $ROUTE --project=$CDF_PROJECT \ --network=$VPC_NETWORK --priority=1001 \ --destination-range=0.0.0.0/0 \ --next-hop-instance=$PROXY_VM \ --next-hop-instance-zone=$ZONE
為管道執行作業設定輸出控制項
在設計環境中,您可以在「預覽」和「Wrangler」中,使用允許的主機名稱存取公用網際網路,然後部署管道。預設情況下,已部署的 Cloud Data Fusion 管道會在 Managed Service for Apache Spark 叢集上執行。
如要確保 Managed Service for Apache Spark 叢集的所有公開網路流量都經過一或多個 Proxy VM,請新增私人 DNS 區域和記錄。由於 Cloud NAT 不支援篩選,因此必須執行這個步驟。
在 DNS 記錄中,加入 Proxy VM 或 ILB 的 IP 位址。
部署管道
在設計階段驗證管道後,請部署管道。根據預設,已部署的管道會在 Managed Service for Apache Spark 叢集上執行。
如要確保 Managed Service for Apache Spark 叢集的所有公用網際網路流量都經過一或多個 Proxy VM,請在與 Managed Service for Apache Spark VM 相同的 VPC 中,新增具有執行個體標記 proxy 和優先順序 1000 的自訂路徑:

修改管道以使用 Managed Service for Apache Spark 標記,因為 Cloud NAT 目前不支援任何輸出篩選。
後續步驟
- 進一步瞭解 Cloud Data Fusion 中的網路。