1. Giriş
Cloud Armor güvenlik politikaları, Google'ın ağının kenarında, altyapınızın yukarısında trafiği filtrelemek için kullanıcı tanımlı kuralları yapılandırmak üzere kullanılır. Network Edge güvenlik politikaları, aşağıdaki uç nokta türlerini hedefleyen trafiği korumaya ve trafiğe izin vermeye veya trafiği engellemeye yardımcı olmak için kullanılabilir: ağ yük dengeleyici, protokol yönlendirme ve genel IP'lere sahip sanal makineler.

Bu kod laboratuvarında, DDoS saldırılarını önlemek için kullanıcı tanımlı kurallarla Cloud Armor güvenlik politikalarının nasıl yapılandırılacağını göstereceğiz.

Şekil 1. Herkese açık IP koruması olan VM için Cloud Armor.
Neler öğreneceksiniz?
- Kullanıcı tanımlı kurallar yapılandırması içeren Cloud Armor güvenlik politikaları
- UDP Offset yapılandırmaları ve testi.
Gerekenler
- TCP/IP bilgisi
- Unix/Linux komut satırı bilgisi
2. Başlamadan önce
Cloud Shell'de proje kimliğinizin ayarlandığından emin olun.
gcloud config list project gcloud config set project [YOUR-PROJECT-NAME] prodproject=YOUR-PROJECT-NAME echo $prodproject
3. Hedef VPC ağı oluşturma
Aşağıdaki bölümde VPC ağlarını ve ilgili ağ yapılandırmalarını ayarlayacağız. Cloud Armor ağ kenarı güvenlik politikası bölgeseldir. İlgili tüm kaynakları asia-southeast1 bölgesinde ayarladık.
VPC Ağı
Cloud Shell'den
gcloud compute networks create ca4nlb --project=$prodproject --subnet-mode=custom
Alt Ağ Oluştur
Cloud Shell'den
gcloud compute networks subnets create ca4nlb-asia-southeast1 --project=$prodproject --range=10.0.0.0/24 --network=ca4nlb --region=asia-southeast1
Güvenlik duvarı kuralları oluşturun.
Bu bölümde, beklenen UDP trafiğinin 10000 numaralı bağlantı noktasına ulaşmasına izin vermek için bir güvenlik duvarı kuralı ekleyeceğiz.
Cloud Shell'den, aşağıdaki test için UDP bağlantı noktası 10000'i açacak bir güvenlik duvarı kuralı oluşturun.
gcloud compute firewall-rules create ca4nlb-udp10000 --allow udp:10000 --network ca4nlb --source-ranges 0.0.0.0/0 --enable-logging
Cloud Shell'den, IAP'nin sanal makine örneklerinize bağlanmasına izin veren bir güvenlik duvarı kuralı oluşturun.
gcloud compute firewall-rules create ca4nlb-iap-prod --network ca4nlb --allow tcp:22 --source-ranges=35.235.240.0/20 --enable-logging
4. Hedef sanal makine örnekleri oluşturma
Güvenlik politikalarını test etmek için bir hedef sanal makine oluşturun. Bu sanal makinenin herkese açık bir IP adresi olmalı ve 10000 numaralı UDP bağlantı noktası açık olmalıdır.
Cloud Shell'den instance targetvm oluşturun.
gcloud compute instances create targetvm \ --zone=asia-southeast1-b \ --image-family=debian-11 \ --image-project=debian-cloud \ --network-interface=network-tier=PREMIUM,nic-type=GVNIC,stack-type=IPV4_ONLY,subnet=ca4nlb-asia-southeast1 \ --shielded-secure-boot \ --shielded-vtpm \ --shielded-integrity-monitoring
5. Gelişmiş ağ DDoS korumasını yapılandırma
Cloud Shell'den
gcloud compute security-policies create ca_advanced_ddos \
--type CLOUD_ARMOR_NETWORK \
--region asia-southeast1
gcloud compute security-policies update ca_advanced_ddos \
--network-ddos-protection ADVANCED \
--region asia-southeast1
gcloud compute network-edge-security-services create caedgepolicy \
--security-policy ca_advanced_ddos \
--region asia-southeast1
6. Varsayılan kurallarla Network Edge güvenlik politikası oluşturma
Ağ ucu güvenlik politikası oluşturma
Cloud Shell'den
gcloud alpha compute security-policies create customnetworkedge --type=CLOUD_ARMOR_NETWORK --region=asia-southeast1
Varsayılan kuralı değiştirme
Cloud Shell'den
gcloud alpha compute security-policies rules update 2147483647 --security-policy=customnetworkedge --action=deny --region=asia-southeast1
7. Kullanıcı tarafından yapılandırılan kurallarla Network Edge güvenlik politikası oluşturma
Kullanıcı tarafından önceden tanımlanmış UDP ofseti ve Cloud Armor politikasında yapılandırılmış. Bu "ofset değerlerine" sahip paket, politika kontrolünden geçer ve arka uç VM'sine gönderilir. Aşağıdaki örnekte, farklı değerlere sahip iki "offset" tanımlayacağız.
İlk değer, UDP üstbilgisinden hemen sonra gelir ve tam olarak 2 baytlık 0x1700 ile eşleşir.
İkinci değer, UDP üstbilgisinin 8 baytlık ofsetidir ve tam olarak 4 baytla eşleşir 0x12345678
Önceden tanımlanmış değerin üzerindeki değerler, UDP paketi bit görünümüne dönüştürülür.

Cloud Shell'den
gcloud alpha compute security-policies add-user-defined-field customnetworkedge \ --user-defined-field-name=SIG1_AT_0 \ --base=udp --offset=8 --size=2 --mask=0xFF00 \ --region=asia-southeast1 gcloud alpha compute security-policies add-user-defined-field customnetworkedge \ --user-defined-field-name=SIG2_AT_8 \ --base=udp --offset=16 --size=4 --mask=0xFFFFFFFF \ --region=asia-southeast1 gcloud alpha compute security-policies rules create 1000 \ --security-policy=customnetworkedge \ --network-user-defined-fields="SIG1_AT_0;0x1700,SIG2_AT_8;0x12345678" \ --action=allow --region=asia-southeast1
8. Güvenlik politikasını hedef sanal makineye ekleme
Cloud Shell'den güvenlik politikasını korumalı sanal makineye ekleyin.
gcloud alpha compute instances network-interfaces update targetvm \ --security-policy=customnetworkedge \ --security-policy-region=asia-southeast1 \ --network-interface=nic0 \ --zone=asia-southeast1-b
Cloud Shell'den hedef sanal makineyi açıklayın. securityPolicy'nin eklendiğini görürsünüz. Aşağıdaki test için genel IP'yi kaydedin.
gcloud alpha compute instances describe targetvm --zone=asia-southeast1-b
networkInterfaces:
- accessConfigs:
- kind: compute#accessConfig
name: External NAT
natIP: 35.240.148.100
networkTier: PREMIUM
securityPolicy: https://www.googleapis.com/compute/alpha/projects/<project>/regions/asia-southeast1/securityPolicies/customnetworkedge
Cloud Shell'den güvenlik politikasını korumalı sanal makineden ayırın.
gcloud alpha compute instances network-interfaces update targetvm \ --network-interface=nic0 \ --zone=asia-southeast1-b \ --security-policy=
9. Test kaynaklarını hazırlayın.
Test VPC Ağı Oluşturma
Cloud Shell'den
gcloud compute networks create test --project=$prodproject --subnet-mode=custom
Test alt ağı oluşturma
Cloud Shell'den
gcloud compute networks subnets create test-asia-southeast1 --project=$prodproject --range=10.0.1.0/24 --network=test --region=asia-southeast1
Güvenlik Duvarı Oluşturma
Cloud Shell'den, IAP'nin sanal makine örneklerinize bağlanmasına izin veren bir güvenlik duvarı kuralı oluşturun.
gcloud compute firewall-rules create test-iap-prod --network test --allow tcp:22 --source-ranges=35.235.240.0/20 --enable-logging
Test sanal makinesi oluşturma
Cloud Shell'den
gcloud compute instances create test01 \
--zone=asia-southeast1-b \
--image-family=debian-11 \
--image-project=debian-cloud \
--network-interface=network-tier=PREMIUM,nic-type=GVNIC,stack-type=IPV4_ONLY,subnet=test-asia-southeast1 \
--shielded-secure-boot \
--shielded-vtpm \
--shielded-integrity-monitoring
10. Doğrulama
Login Test VM Console'a giriş yapın ve paket oluşturucu packit'yı yükleyin.
sudo apt install packit
Aşağıdaki UDP ofset tasarımına göre, UDP paketleri oluşturmak için packit'i kullanın. Kaynak bağlantı noktaları (-S 10000) ile arayüz (-s ens4) kaynak IP adresinden (-s 10.0.1.2) hedef bağlantı noktaları (-D 10000) ile hedefVM hedef IP adresine (-d 35.240.148.100) bir (-t udp) paketi simüle ediyoruz. Paket içeriği değerlerle eşleşiyor (-p "0x 17 00 00 00 00 00 00 00 12 34 56 78"). 4 paket (-c 4) göndereceğiz.
sudo packit -m inject -t UDP -i ens4 -s 10.0.1.2 -d 35.240.148.100 -S 10000 -D 10000 -p '0x 17 00 00 00 00 00 00 00 12 34 56 78' -c 4
Hedef sanal makinede, UDP paketini yakalamak için tcpdump'ı çalıştırın.
sudo tcpdump port 10000 -v -n
tcpdump: listening on ens4, link-type EN10MB (Ethernet), snapshot length 262144 bytes
06:36:18.434106 IP (tos 0x0, ttl 128, id 17173, offset 0, flags [none], proto UDP (17), length 40)
35.197.157.140.10000 > 10.0.0.2.10000: UDP, length 12
06:36:19.433656 IP (tos 0x0, ttl 128, id 55641, offset 0, flags [none], proto UDP (17), length 40)
35.197.157.140.10000 > 10.0.0.2.10000: UDP, length 12
06:36:20.433935 IP (tos 0x0, ttl 128, id 27161, offset 0, flags [none], proto UDP (17), length 40)
35.197.157.140.10000 > 10.0.0.2.10000: UDP, length 12
06:36:21.434150 IP (tos 0x0, ttl 128, id 46782, offset 0, flags [none], proto UDP (17), length 40)
35.197.157.140.10000 > 10.0.0.2.10000: UDP, length 12
Test sanal makinesindeki trafik kalıplarını değiştirirsek hedef sanal makinede paket yakalayamayız.
sudo packit -m inject -t UDP -i ens4 -s 10.148.0.6 -d 34.87.79.31 -S 10000 -D 10000 -p '0x 33 33 00 00 00 00 00 00 12 34 56 78' -c 4
11. Telemetri
Cloud Metric'i açın ve NetworkSercurityPolicy telemetri verilerini sorgulamak için aşağıdaki MQL'yi kullanın.
fetch networksecurity.googleapis.com/RegionalNetworkSecurityPolicy | metric 'networksecurity.googleapis.com/l3/external/packet_count' | filter (resource.policy_name == 'customnetworkedge') | align rate(1m) | every 1m | group_by [metric.blocked], [value_packet_count_mean: mean(value.packet_count)] | group_by 1m, [value_packet_count_mean_mean: mean(value_packet_count_mean)] | every 1m
Eşleşme kaydırma komutuyla yüksek hacimli trafik oluşturun.
sudo packit -m inject -t UDP -i ens4 -s 10.148.0.6 -d 34.87.79.31 -S 10000 -D 10000 -p '0x 17 00 00 00 00 00 00 00 12 34 56 78' -c 1000000 -w 0.001 [result] Injected: 1000000 Packets/Sec: 10309.27 Bytes/Sec: 412371.13 Errors: 0
Eşleşmeyen bir dengeleme komutuyla yüksek hacimli trafik oluşturun.
sudo packit -m inject -t UDP -i ens4 -s 10.148.0.6 -d 34.87.79.31 -S 10000 -D 10000 -p '0x 11 00 00 00 00 00 00 00 12 34 56 78' -c 1000000 -w 0.001 [result] Injected: 1000000 Packets/Sec: 10309.27 Bytes/Sec: 412371.13 Errors: 0
Telemetri, policy_name'e göre filtrelenir ve engellenenlere göre gruplandırılır. Mavi çizgi, politika kuralları tarafından izin verilen trafiği gösterir. Yeşil çizgi, politika kuralları tarafından engellenen trafiği gösterir.

12. Temizleme adımları
Terminaldeki tek bir Cloud Shell'den laboratuvar bileşenlerini silme
gcloud compute instances delete targetvm --zone=asia-southeast1-b gcloud compute firewall-rules delete ca4nlb-udp10000 gcloud compute firewall-rules delete ca4nlb-iap-prod gcloud compute networks subnets delete ca4nlb-asia-southeast1 --region=asia-southeast1 gcloud compute networks delete ca4nlb gcloud alpha compute security-policies delete customnetworkedge --region=asia-southeast1 gcloud alpha compute network-edge-security-services delete caedgepolicy --region=asia-southeast1 gcloud alpha compute security-policies delete ca_advanced_ddos --region=asia-southeast1 gcloud compute instances delete test01 --zone=asia-southeast1-b gcloud compute firewall-rules delete test-iap-prod gcloud compute networks subnets delete test-asia-southeast1 --region=asia-southeast1 gcloud compute networks delete test
13. Tebrikler!
Codelab'i tamamladığınız için tebrik ederiz.
İşlediğimiz konular
- Müşteri tanımlı kurallara sahip Cloud Armor güvenlik politikaları