Cloud Secure Web Proxy (SWP) 程式碼研究室

1. 簡介

雲端安全網路 Proxy

Cloud SWP 是一項雲端優先服務,提供安全網路 Proxy,協助您保護輸出網路流量 (HTTP/S)。您將用戶端設定為明確使用 Cloud SWP 做為 Proxy。網路要求可能來自下列來源:

  • 虛擬機器 (VM) 執行個體
  • 容器
  • 使用無伺服器連接器的無伺服器環境
  • 跨虛擬私有雲對等互連的工作負載
  • 透過 Cloud VPN 或 Cloud Interconnect 連線的 Google Cloud 外部工作負載

雲端 SWP 可根據雲端優先身分和網頁應用程式,彈性制定精細政策。

優點

以下列舉幾個範例,說明 Cloud SWP 可為機構帶來的優勢:

遷移至 Google Cloud

有了 Cloud SWP,您就能遷移至 Google Cloud,同時保留既有的安全性政策和輸出網站流量規定。您可以避免使用需要其他管理控制台或手動編輯設定檔的第三方解決方案。

存取信任的外部網路服務

Cloud SWP 可讓您對輸出網路流量套用精細的存取權政策,方便您保護網路安全。您可以建立及識別工作負載或應用程式身分,然後套用政策。

監控對不信任網路服務的存取活動

您可以使用 Cloud SWP,為不受信任的網路服務提供受監控的存取權。Cloud SWP 會識別不符合政策規定的流量,並將流量記錄在 Cloud Logging (記錄) 中。然後監控網際網路用量、找出網路威脅,並採取行動。

Google API 的精細政策控制項

您可以使用 Cloud SWP 為 Google API 提供精細的政策。舉例來說,您可以運用一般運算語言 (CEL) 設定 bucket/物件層級政策。

支援功能

Cloud SWP 支援下列功能:

明確 Proxy 服務

用戶端必須明確設定為使用 Proxy 伺服器。Cloud SWP Proxy 會代表用戶端建立新的 TCP 連線,將用戶端與網際網路隔離。

自動調度 Cloud SWP Envoy Proxy 資源

支援自動調整 Envoy 代理程式集區大小和區域中的集區容量,在需求量高的期間以最低成本維持一致的效能。

模組化輸出存取權政策

Cloud SWP 具體支援下列輸出政策:

  • 以安全標記、服務帳戶或 IP 位址為依據的來源身分。
  • 根據網址和主機名稱設定目的地。
  • 根據方法、標頭或網址提出要求。您可以使用清單、萬用字元或模式來指定網址。
  • 端對端加密:用戶端與 Proxy 之間的通道可能會透過 TLS 傳輸。Cloud SWP 也支援 HTTP/S CONNECT,可供用戶端啟動與目的地伺服器的端對端 TLS 連線。

簡化 Cloud NAT 整合程序

當處理 Cloud SWP 流量的 Proxy 數量增加時,Cloud NAT 會自動佈建額外的公開 IP 位址。

如要使用已知的輸出 IP,也可以手動設定靜態公開 IP 位址。

Cloud 稽核記錄和 Google Cloud 作業套件整合

Cloud 稽核記錄和 Google Cloud 作業套件會記錄 Cloud SWP 相關資源的管理活動和存取要求。此外,也會記錄 Proxy 處理的要求的指標和交易記錄。

TLS 檢查

Secure Web Proxy 提供 TLS 檢查服務,可讓您攔截 TLS 流量、檢查加密要求並強制執行安全性政策。

  • 憑證授權單位服務 (CAS) 緊密整合,CAS 是可用性高且可擴充的私人 CA 存放區。
  • 如有需要,可使用自己的信任根。您也可以使用現有的根 CA,為 CAS 持有的從屬 CA 簽署憑證。您也可以視需要在 CAS 中生成新的根憑證。
  • 在 Secure Web Proxy 政策規則中使用 SessionMatcher 和 ApplicationMatcher,設定精細的解密條件。這項條件包括比對網址清單、規則運算式、IP 位址範圍和類似運算式中的主機。如有需要,條件可以搭配布林運算式。
  • 每項 Secure Web Proxy 政策都可以設定專屬的 TLS 檢查政策和 CA 集區。或者,多項 Secure Web Proxy 政策也可以共用單一 TLS 檢查政策。

課程內容

  • 如何部署及管理 Cloud SWP。

軟硬體需求

  • 瞭解如何部署執行個體及設定網路元件
  • 虛擬私有雲防火牆設定知識

2. 測試環境

本程式碼研究室將使用單一 VPC。如以下圖表所示,這個環境中的運算資源會使用 Cloud SWP 輸出流量。

1264e30caa136365.png

在本實驗室中,我們會有 2 部工作負載 VM。

用戶端 A 會設定為將所有 HTTP/HTTPS 要求傳送至 Cloud SWP。

用戶端 B不會設定為明確傳送 HTTP/HTTPS 要求至 Cloud SWP,而是利用 Cloud NAT 處理網際網路流量。

3. 事前準備

Codelab 只需要一個專案。

在 Cloud Shell 中,確認專案 ID 已設定完畢

export project_id=`gcloud config list --format="value(core.project)"`
export project_number=`gcloud projects describe $project_id --format="value(projectNumber)"`
export region=us-west1
export zone=us-west1-a
export prefix=codelab-swp
export member="serviceAccount:service-$project_number@gcp-sa-networksecurity.iam.gserviceaccount.com"

4. 啟用 API

啟用 API 以使用產品

gcloud services enable networksecurity.googleapis.com
gcloud services enable certificatemanager.googleapis.com
gcloud services enable networkservices.googleapis.com

5. 建立虛擬私有雲網路、子網路和僅限 Proxy 的子網路

虛擬私人雲端網路

建立 codelab-swp-vpc VPC:

gcloud compute networks create $prefix-vpc --subnet-mode=custom 

子網路

在所選區域中建立對應的子網路:

gcloud compute networks subnets create $prefix-vpc-subnet \
   --range=10.10.10.0/24 --network=$prefix-vpc --region=$region

僅限 Proxy 的子網路

在所選區域中建立僅限 Proxy 的子網路:

gcloud compute networks subnets create $prefix-proxy-only-subnet --purpose=REGIONAL_MANAGED_PROXY --role=ACTIVE --region=$region --network=$prefix-vpc --range=172.16.0.0/23

6. 建立防火牆規則

如要允許 IAP 連線至您的 VM 執行個體,請根據以下條件建立防火牆規則:

  • 套用至所有您希望能透過 IAP 存取的 VM 執行個體。
  • 允許來自 IP 範圍 35.235.240.0/20 的輸入流量。這個範圍包含 IAP 用於 TCP 轉送的所有 IP 位址。

從 Cloud Shell:

gcloud compute firewall-rules create $prefix-allow-iap-proxy \
--direction=INGRESS \
--priority=1000 \
--network=$prefix-vpc \
--action=ALLOW \
--rules=tcp:22 \
--source-ranges=35.235.240.0/20

7. 建立 Cloud Router 和 Cloud NAT

為 Cloud NAT 建立 Cloud Router。

gcloud compute routers create ${prefix}-cr \
--region=$region \
--network=${prefix}-vpc

為用戶端 B 建立 Cloud NAT 閘道。

gcloud compute routers nats create $prefix-nat-gw-$region \
--router=$prefix-cr \
--router-region=$region \
--auto-allocate-nat-external-ips \
--nat-all-subnet-ip-ranges

8. 建立閘道安全性政策

建立包含政策相關資訊的 yaml 檔案:

cat > /tmp/policy.yaml << EOF
description: Policy to allow .com traffic, then (/index.html), and finally TLS.
name: projects/${project_id}/locations/${region}/gatewaySecurityPolicies/${prefix}-policy
EOF

執行 gcloud 指令,從 YAML 檔案建立政策:

gcloud network-security gateway-security-policies import ${prefix}-policy --source=/tmp/policy.yaml --location=${region}

9. 建立閘道安全性政策規則

建立包含規則的 yaml 檔案。這些規則以一般運算語言 (CEL) 表示。本實驗室將使用簡單的規則,允許流量前往 .com 網域,並封鎖所有其他網域:

cat > /tmp/rule-com.yaml << EOF
name: projects/${project_id}/locations/${region}/gatewaySecurityPolicies/${prefix}-policy/rules/rule-com
enabled: true
priority: 1
description: Allow .com traffic
basicProfile: ALLOW
sessionMatcher: host().endsWith('com')
EOF

現在,我們可以將規則繫結至閘道安全性政策:

gcloud network-security gateway-security-policies rules import rule-com --source=/tmp/rule-com.yaml --location=${region} --gateway-security-policy=${prefix}-policy

10. 建立憑證並上傳至 Cloud Certificate Manager

建立憑證,終止工作負載流量:

openssl req -x509 -newkey rsa:2048 -keyout /tmp/key.pem -out /tmp/cert.pem -days 365 -subj '/CN=www.codelab-swp.com' -nodes -addext \
  "subjectAltName = DNS:www.codelab-swp.com"

將憑證上傳至 Cloud Certificate Manager,以便 SWP 在安全防護閘道政策中參照該憑證。

gcloud certificate-manager certificates create ${prefix}-cert --location=${region} --private-key-file=/tmp/key.pem --certificate-file=/tmp/cert.pem

11. 建立 SWP 閘道

建立 SWP 閘道的 YAML 檔案,以參照先前的資訊,例如憑證、閘道安全政策、網路和子網路。

cat > /tmp/gateway.yaml << EOF
name: projects/${project_id}/locations/${region}/gateways/${prefix}-gateway
type: SECURE_WEB_GATEWAY
addresses: [10.10.10.50]
ports: [443]
certificateUrls: [projects/${project_id}/locations/${region}/certificates/${prefix}-cert]
gatewaySecurityPolicy: projects/${project_id}/locations/${region}/gatewaySecurityPolicies/${prefix}-policy
network: projects/${project_id}/global/networks/${prefix}-vpc
subnetwork: projects/${project_id}/regions/${region}/subnetworks/${prefix}-vpc-subnet
EOF

建立閘道:

gcloud network-services gateways import ${prefix}-swp --source=/tmp/gateway.yaml --location=${region}

確認閘道已建立:

gcloud network-services gateways describe ${prefix}-swp --location ${region}

12. 建立運算執行個體

由於 Cloud SWP 是明確的 Proxy,因此我們需要為工作負載流量明確指定 Proxy IP。Compute 執行個體 clientA 會設定環境變數。ClientB 則不會。

建立運算執行個體 ClientA 和 ClientB:

gcloud compute instances create clienta \
   --subnet=$prefix-vpc-subnet \
   --no-address \
   --private-network-ip=10.10.10.10 \
   --zone $zone \
   --metadata startup-script='#! /bin/bash
apt-get update
sudo echo http_proxy=https://10.10.10.50:443/ >> /etc/environment
sudo echo https_proxy=https://10.10.10.50:443/ >> /etc/environment
'
gcloud compute instances create clientb \
   --subnet=$prefix-vpc-subnet \
   --no-address \
   --private-network-ip=10.10.10.200 \
   --zone $zone \
   --metadata startup-script='#! /bin/bash
apt-get update
'

13. 測試工作階段比對

透過 SSH 連線至最近建立的「clienta」Compute VM。這部 VM 已設定環境變數,可使用 Cloud SWP。

從 Cloud Shell:

gcloud compute ssh clienta --zone=$zone --tunnel-through-iap

執行一些網路查詢來驗證功能。我們需要使用「-proxy-insecure」,因為我們為本實驗室建立了自行簽署的憑證:

curl https://google.com --proxy-insecure

預期輸出內容:

davidtu@clienta:~$ curl https://google.com --proxy-insecure
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>

如您所見,要求「成功」了。由於網站會重新導向至 https://www.google.com,因此我們預期會看到 301 重新導向。

執行下列指令會提供詳細記錄,其中包含連線的詳細資料:

curl https://google.com --proxy-insecure -v

醒目顯示部分輸出內容,顯示 Proxy 連線詳細資料、憑證和目的地。

davidtu@clienta:~$ curl https://google.com --proxy-insecure -v
* Uses proxy env variable https_proxy == 'https://10.10.10.50:443/'
*   Trying 10.10.10.50:443...
* Connected to 10.10.10.50 (10.10.10.50) port 443 (#0)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*  CAfile: /etc/ssl/certs/ca-certificates.crt
*  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use http/1.1
* Proxy certificate:
*  subject: CN=www.codelab-swp.com
*  start date: Dec 12 17:16:35 2022 GMT
*  expire date: Dec 12 17:16:35 2023 GMT
*  issuer: CN=www.codelab-swp.com
*  SSL certificate verify result: self signed certificate (18), continuing anyway.
* allocate connect buffer!
* Establish HTTP proxy tunnel to google.com:443
> CONNECT google.com:443 HTTP/1.1
> Host: google.com:443
> User-Agent: curl/7.74.0
> Proxy-Connection: Keep-Alive
> 
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
< HTTP/1.1 200 OK
< date: Mon, 12 Dec 2022 19:22:04 GMT
< 
* Proxy replied 200 to CONNECT request
* CONNECT phase completed!
...

歡迎嘗試其他 .com 網域,驗證功能是否正常運作。

現在請嘗試使用其他非 .com 網域,驗證預設封鎖行為:

curl https://wikipedia.org --proxy-insecure

預期輸出內容:

curl: (56) Received HTTP code 403 from proxy after CONNECT

同樣地,請查看詳細輸出記錄,確認 Cloud SWP 是否封鎖這項流量:

curl https://wikipedia.org --proxy-insecure -v
davidtu@clienta:~$ curl https://wikipedia.org --proxy-insecure -v
* Uses proxy env variable https_proxy == 'https://10.10.10.50:443/'
*   Trying 10.10.10.50:443...
* Connected to 10.10.10.50 (10.10.10.50) port 443 (#0)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*  CAfile: /etc/ssl/certs/ca-certificates.crt
*  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use http/1.1
* Proxy certificate:
*  subject: CN=www.codelab-swp.com
*  start date: Dec 12 17:16:35 2022 GMT
*  expire date: Dec 12 17:16:35 2023 GMT
*  issuer: CN=www.codelab-swp.com
*  SSL certificate verify result: self signed certificate (18), continuing anyway.
* allocate connect buffer!
* Establish HTTP proxy tunnel to wikipedia.org:443
> CONNECT wikipedia.org:443 HTTP/1.1
> Host: wikipedia.org:443
> User-Agent: curl/7.74.0
> Proxy-Connection: Keep-Alive
> 
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
< HTTP/1.1 403 Forbidden
< content-length: 13
< content-type: text/plain
< date: Mon, 12 Dec 2022 19:35:09 GMT
< connection: close
< 
* Received HTTP code 403 from proxy after CONNECT
* CONNECT phase completed!
* Closing connection 0
curl: (56) Received HTTP code 403 from proxy after CONNECT

歡迎嘗試其他網域,驗證行為。

結束與「clienta」的安全殼層工作階段,並啟動與「clientb」的新安全殼層連線。

gcloud compute ssh clientb --zone=$zone --tunnel-through-iap

執行一些 curl 指令來檢查行為:

curl https://google.com

這應該會如預期在 clientb VM 上運作:

davidtu@clientb:~$ curl https://google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>

針對機構網域進行測試:

curl https://wikipedia.org

這是預期行為,因為 clientb 並未運用 Cloud SWP:

davidtu@clientb:~$ curl https://wikipedia.org
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://www.wikipedia.org/">here</a>.</p>
</body></html>

測試透過 Cloud SWP 明確傳送流量:

curl -x https://10.10.10.50:443/ https://wikipedia.org --proxy-insecure 

我們發現這項流量遭到 Cloud SWP 政策拒絕:

davidtu@clientb:~$ curl -x https://10.10.10.50:443/ https://wikipedia.org --proxy-insecure
curl: (56) Received HTTP code 403 from proxy after CONNECT

如您所驗證,系統會針對設定的安全政策,強制執行使用 Cloud SWP 的流量。允許傳送至 .com 的流量,拒絕傳送至所有其他目的地的流量。

結束 clientb。

14. 更新 ApplicationMatching 的閘道安全性政策規則

現在來更新規則,比對應用程式層級的詳細資料。我們會建立規則來查看要求路徑,並只允許與 index.html 相符的要求。

cat > /tmp/rule-com.yaml << EOF
name: projects/${project_id}/locations/${region}/gatewaySecurityPolicies/${prefix}-policy/rules/rule-com
enabled: true
priority: 1
description: Allow .com traffic with path index.html
basicProfile: ALLOW
sessionMatcher: host().endsWith('com')
applicationMatcher: request.path.matches('index.html')
EOF

現在,我們可以將更新後的規則繫結至閘道安全政策:

gcloud network-security gateway-security-policies rules import rule-com --source=/tmp/rule-com.yaml --location=${region} --gateway-security-policy=${prefix}-policy

15. 測試 ApplicationMatcher 規則

透過 SSH 連線至 clienta Compute VM。這部 VM 已設定環境變數,可使用 Cloud SWP。

從 Cloud Shell:

gcloud compute ssh clienta --zone=$zone --tunnel-through-iap

執行一些網路查詢來驗證功能。我們需要使用「-proxy-insecure」,因為我們為本實驗室建立了自行簽署的憑證:

curl http://google.com --proxy-insecure

請注意,這項查詢先前通過時,會失敗。

Access denied

除了「index.html」以外,所有要求路徑都應遭到封鎖,並傳回 403 錯誤。歡迎進一步測試。

修改查詢,加入路徑 /index.html

curl http://google.com/index.html --proxy-insecure

這項要求應會成功:

davidtu@clienta:~$ curl http://google.com/index.html --proxy-insecure
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/index.html">here</A>.
</BODY></HTML>

由於網站會重新導向至 http://www.google.com/index.html,因此我們預期會看到 301 重新導向。

請注意,這是 HTTP 要求。接著,您需要啟用 SWP 的 TLS 檢查功能。

接著,請透過 TLS 執行相同查詢:

curl -k https://google.com/index.html --proxy-insecure

預期輸出內容:

curl: (56) Received HTTP code 403 from proxy after CONNECT

由於 SWP 未設定檢查 TLS,且無法根據 applicationMatcher 規則評估路徑,因此這項要求應會失敗。

退出 clenta。

16. 啟用 TLS 檢查

如未啟用 TLS 檢查功能,applicationMatcher 就無法比對 HTTPS 流量。

「applicationMatcher」可依下列條件篩選:

  • 要求標頭對應
  • 要求方法
  • 要求代管
  • 要求路徑
  • 要求查詢
  • 要求協定名
  • 完整要求網址
  • 要求提供 useragent

建立服務帳戶

這個服務帳戶將有權為 SWP TLS 檢查產生憑證。

gcloud beta services identity create \
    --service=networksecurity.googleapis.com \
    --project=$project_id

確認已啟用 CAS

gcloud services enable privateca.googleapis.com

建立憑證授權單位集區

gcloud privateca pools create $prefix-ca-pool \
    --tier=devops \
    --project=$project_id \
    --location=$region 

建立根 CA

用於簽署憑證的 CA。

gcloud privateca roots create $prefix-root-ca --pool=$prefix-ca-pool \
  --location=$region \
  --auto-enable \
  --subject="CN=my-swp-ca, O=SWP LLC"

建立憑證核發政策檔案

cat > /tmp/tls-issuance-policy.yaml << EOF
maximumLifetime: 1209600s
baselineValues:
  caOptions:
    isCa: false
  keyUsage:
    extendedKeyUsage:
      serverAuth: true
EOF

建立 TLS 檢查 yaml 檔案

cat > /tmp/tls-inspection-policy.yaml << EOF
caPool: projects/$project_id/locations/$region/caPools/$prefix-ca-pool
name: projects/$project_id/locations/$region/tlsInspectionPolicies/$prefix-tls-inspection
EOF

建立 TLS 檢查政策

gcloud network-security tls-inspection-policies import $prefix-tls-inspection \
    --source=/tmp/tls-inspection-policy.yaml \
    --location=$region

更新 CA 集區,以使用憑證核發政策

gcloud privateca pools update $prefix-ca-pool    --issuance-policy=/tmp/tls-issuance-policy.yaml --location=$region

授予權限

這樣一來,服務帳戶就能使用 CA 集區產生憑證。

gcloud privateca pools add-iam-policy-binding $prefix-ca-pool \
    --member=$member \
    --role='roles/privateca.certificateManager' \
    --location=$region

更新 Policy yaml,加入 TLS 檢查

cat > /tmp/policy.yaml << EOF
description: some policy description
name: projects/${project_id}/locations/${region}/gatewaySecurityPolicies/${prefix}-policy
tlsInspectionPolicy: projects/${project_id}/locations/${region}/tlsInspectionPolicies/${prefix}-tls-inspection
EOF

執行指令,套用更新後的政策

gcloud network-security gateway-security-policies import ${prefix}-policy --source=/tmp/policy.yaml --location=${region}

更新規則,加入 TLS 檢查

接著,請指定哪些規則應具有 TLS 檢查「enabtlsInspectionEnabled: true」旗標。

cat > /tmp/rule-com.yaml << EOF
name: projects/${project_id}/locations/${region}/gatewaySecurityPolicies/${prefix}-policy/rules/rule-com
enabled: true
priority: 1
description: Allow .com traffic with path index.html
basicProfile: ALLOW
sessionMatcher: host().endsWith('com')
applicationMatcher: request.path.matches('index.html')
tlsInspectionEnabled: true
EOF

執行指令來套用更新的規則

gcloud network-security gateway-security-policies rules import rule-com --source=/tmp/rule-com.yaml --location=${region} --gateway-security-policy=${prefix}-policy

17. 測試 TLS 檢查

透過 SSH 連線至 clienta Compute VM。這部 VM 已設定環境變數,可使用 Cloud SWP。

從 Cloud Shell:

gcloud compute ssh clienta --zone=$zone --tunnel-through-iap

執行先前的網路查詢,確認 SWP 是否正在執行 TLS 檢查來擷取路徑

curl -k https://google.com/index.html --proxy-insecure

這次應該會成功,因為 SWP 可以評估 ApplicationMatcher。

預期輸出內容:

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/index.html">here</A>.
</BODY></HTML>

我們已成功設定 Cloud SWP,檢查 TLS 並評估 applicationMatcher 邏輯!

從 clienta 結束。

18. 清除步驟

在 Cloud Shell 中,移除 SWP 閘道、安全性政策、憑證、執行個體、Cloud NAT 和 Cloud Router:

gcloud -q network-services gateways delete ${prefix}-swp --location=${region}

gcloud -q network-security gateway-security-policies rules delete rule-com --location=${region} --gateway-security-policy=${prefix}-policy

gcloud -q network-security gateway-security-policies delete ${prefix}-policy --location=${region}

gcloud -q certificate-manager certificates delete ${prefix}-cert --location=${region}

gcloud -q network-security tls-inspection-policies delete $prefix-tls-inspection --location=$region

gcloud -q privateca roots disable $prefix-root-ca --pool=$prefix-ca-pool --location=$region

gcloud -q privateca roots delete $prefix-root-ca --pool=$prefix-ca-pool --location=$region --ignore-active-certificates --skip-grace-period

gcloud -q privateca pools delete $prefix-ca-pool --location=$region

gcloud -q compute instances delete clienta --zone=$zone

gcloud -q compute instances delete clientb --zone=$zone

gcloud -q compute routers nats delete ${prefix}-nat-gw-${region} \
--router=$prefix-cr --router-region=$region

gcloud -q compute routers delete `gcloud compute routers list --regions=$region --format="value(NAME)" | grep -e swg-autogen -e codelab-swp` --region=$region

移除子網路、防火牆規則和虛擬私有雲:

gcloud -q compute networks subnets delete $prefix-vpc-subnet \
    --region $region

gcloud -q compute networks subnets delete $prefix-proxy-only-subnet \
    --region=$region

gcloud -q compute firewall-rules delete $prefix-allow-iap-proxy

gcloud -q compute networks delete $prefix-vpc

19. 恭喜!

恭喜您完成本程式碼研究室。您已成功在 Google Cloud 中設定及部署 Cloud Secure Web Proxy。

涵蓋內容

  • Cloud SWP 和優點!