Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> ระบบเครือข่าย >> ความปลอดภัยเครือข่าย

Final Rule ใน Azure Network Security Group (NSG) คืออะไร? ทำความเข้าใจ Default Rules และ Priority

Azure Network Security Group (NSG) คืออะไร?

Network Security Group (NSG) เป็น Virtual Firewall ระดับ Network Layer (Layer 3/4) ใน Azure ใช้ควบคุม Inbound และ Outbound Traffic ไปยัง Azure Resources (VM, Subnet, NIC) ผ่าน Access Control Lists (ACLs)

NSG Rules: โครงสร้างและ Priority

แต่ละ Rule ประกอบด้วย:

  • Name: ชื่อกฎ (Unique ใน NSG)
  • Priority: หมายเลข 100-4096 (ยิ่งน้อยยิ่งประมวลผลก่อน)
  • Source/Destination: IP Range (CIDR), Service Tag, Application Security Group (ASG)
  • Protocol: TCP, UDP, ICMP, ESP, AH, * (All)
  • Direction: Inbound / Outbound
  • Port Range: 1-65535, * (All)
  • Action: Allow / Deny

Default Rules (กฎเริ่มต้น) ใน NSG ใหม่

เมื่อสร้าง NSG ใหม่ จะมี Default Rules ดังนี้ (Priority สูง = ตัวเลขมาก = ประมวลผลทีหลัง):

Inbound Default Rules

PriorityNameSourceDestinationServiceAction
65000AllowVNetInBoundVirtualNetworkVirtualNetworkAnyAllow
65001AllowAzureLoadBalancerInBoundAzureLoadBalancerAnyAnyAllow
65500DenyAllInBoundAnyAnyAnyDeny

Outbound Default Rules

PriorityNameSourceDestinationServiceAction
65000AllowVNetOutBoundVirtualNetworkVirtualNetworkAnyAllow
65001AllowInternetOutBoundAnyInternetAnyAllow
65500DenyAllOutBoundAnyAnyAnyDeny

Final Rule (กฎสุดท้าย) คืออะไร?

Final Rule = DenyAllInBound (Priority 65500) และ DenyAllOutBound (Priority 65500)

นี่คือ Implicit Deny Rule ที่ Azure สร้างไว้โดยอัตโนมัติ ไม่สามารถลบ แก้ไข หรือปิดใช้งานได้ หาก Traffic ไม่ Match กับ Rule ใดๆ ที่ Priority ต่ำกว่า (Allow Rules) จะถูก Deny โดยกฎนี้

ลำดับการประมวลผล (Processing Order)

  1. Rules ที่ Priority ต่ำกว่า (ตัวเลขน้อย) → ประมวลผลก่อน
  2. หาก Match Rule ใด Rule หนึ่ง → หยุดประมวลผล (First Match Wins)
  3. หากไม่ Match Rule ใดๆ ทั้งสิ้น → ถูกจับโดย DenyAll (Final Rule)

NSG Limits และ Quotas

  • สูงสุด 200 Rules ต่อ 1 NSG (ขอเพิ่มได้ถึง 1,000 ผ่าน Support Ticket)
  • สูงสุด 100 NSG ต่อ Subscription (ขอเพิ่มได้)
  • NSG 1 ตัว ผูกกับ Subnet ได้หลายตัว, NIC ได้หลายตัว

NSG vs ASG (Application Security Group)

  • NSG: กฎระเบียบ Firewall (Allow/Deny Traffic)
  • ASG: กลุ่ม VM ตาม Application (เช่น Web-Servers, DB-Servers) ใช้เป็น Source/Destination ใน NSG Rule แทน IP Address

NSG vs Azure Firewall

FeatureNSGAzure Firewall
OSI LayerLayer 3/4Layer 3, 4, 7
FQDN Filteringไม่รองรับรองรับ (SQL, FQDN Tags)
SNAT/DNATไม่รองรับรองรับ
Threat IntelligenceBasic (Service Tags)Advanced (IDPS, TLS Inspect)
Costฟรีจ่ายตามชั่วโมง + Data Processed
High AvailabilityN/A (Stateless)Built-in (Availability Zones)

Best Practices

  • ใช้ Priority ห่างกัน (100, 200, 300...) เพื่อแทรก Rule ใหม่ได้
  • ใช้ Service Tags (VirtualNetwork, AzureLoadBalancer, Internet, Storage, Sql) แทน IP คงที่
  • ใช้ ASG จัดกลุ่ม Workload เพื่อลด Complexity ของ Rules
  • แยก NSG ต่อ Subnet (Subnet-level) แทน NIC-level เพื่อจัดการง่ายขึ้น
  • Log 流量ไป Log Analytics Workspace เพื่อ Analyze/Detection
  • Review Rules เป็นประจำ ลบ Rules ที่ไม่ใช้

สรุป

Final Rule ใน NSG คือ DenyAllInBound และ DenyAllOutBound (Priority 65500) เป็น Implicit Deny ที่บังคับให้ Traffic ที่ไม่ได้ Allow ไว้โดยเฉพาะ จะถูก Block ทั้งหมด นี่คือหลักการ Default Deny / Zero Trust ของ Azure Network Security