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

Azure Network Security Group (NSG) คืออะไร ทำงานอย่างไร และแตกต่างจาก Firewall อย่างไร

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

Azure Network Security Group (NSG) เป็นบริการ Network Filtering (Layer 3 & 4) ใน Azure ที่ใช้ควบคุม Inbound และ Outbound Traffic ไป/มาจาก Azure Resources (VM, VMSS, App Service Environment, AKS, Azure SQL, ฯลฯ) ผ่าน Security Rules

NSG ทำงานอย่างไร?

โครงสร้าง Security Rule

การประมวลผล Rules (Rule Processing)

  1. เรียงตาม Priority (Ascending) 100 → 4096
  2. จับคู่ 5-tuple: Source IP, Source Port, Dest IP, Dest Port, Protocol
  3. First Match Wins - หาตรงกฎแรก หยุดประมวลผล (Allow หรือ Deny)
  4. Default Rules (Implicit): Priority 65000+ (ไม่เห็น/ลบไม่ได้)
    • AllowVNetInBound: Allow ทุกอย่างภายใน VNet
    • AllowAzureLoadBalancerInBound: Allow Azure LB Health Probes
    • DenyAllInBound: Deny ทุกอย่างจากภายนอก VNet
    • AllowVNetOutBound: Allow ออกไปภายใน VNet
    • AllowInternetOutBound: Allow ออก Internet
    • DenyAllOutBound: Deny ออกไปที่ไม่ใช่ VNet/Internet

NSG Association (การเชื่อมโยง)

Propertyคำอธิบายตัวอย่าง
Nameชื่อกฎ (Unique ใน NSG)Allow-HTTP-Inbound
Priorityลำดับประมวลผล (100-4096) เลขน้อย = ประมวลผลก่อน100, 200, 300
Source / DestinationIP Address, CIDR, Service Tag, Application Security Group (ASG)Source: Internet, Destination: 10.0.1.0/24
ProtocolTCP, UDP, ICMP, ESP, AH, * (All)TCP
DirectionInbound (เข้ามา) / Outbound (ออกไป)Inbound
Port RangePort หรือ Range (80, 443, 1000-2000, *)443
ActionAllow / DenyAllow

NSG vs Azure Firewall - ความแตกต่างสำคัญ

Scopeรายละเอียด
Subnet (แนะนำ)1 NSG ต่อ 1 Subnet ใช้ร่วมได้หลาย Subnet ใช้กับทุก NIC ใน Subnet นั้น
Network Interface (NIC)1 NSG ต่อ 1 NIC เฉพาะเจาะจง VM นั้นๆ (Override Subnet NSG)
ไม่รองรับResource Group, VNet Level, Subscription Level
FeatureNSG (Network Security Group)Azure Firewall
OSI LayerLayer 3 (Network) + Layer 4 (Transport)Layer 3, 4, 7 (Application)
InspectionStateless/Stateful (5-tuple)Stateful L7 Deep Packet Inspection
FQDN Filtering❌ ไม่ได้ (ต้องใช้ Service Tag)✅ FQDN Tags, Custom FQDN, SQL/Storage FQDN
IDPS (Intrusion Detection/Prevention)❌ ไม่มี✅ Signature-based IDPS (Managed Rules)
Threat Intelligence❌✅ Microsoft Threat Intelligence Feed
SNAT/DNAT❌✅ Source/Destination NAT
LoggingFlow Logs (NSG Flow Logs → Storage/Log Analytics)Structured Logs (App/Network/DNS/Threat) → Log Analytics/Event Hub/Storage
High AvailabilityRegional (Implicit)Zone Redundant (AZ), Forced Tunneling
CostFree (จ่ายแค่ Flow Logs Storage)~$1.25/hr + Data Processing (~$0.016/GB)
DeploymentInstant, No Provisioning~5-10 นาที (Firewall Policy + Firewall)
Use CaseMicro-segmentation, Subnet/NIC Level Control, Basic FilteringPerimeter Security, Hub-spoke, L7 Inspection, Threat Protection, Centralized Logging

Application Security Groups (ASG) - เสริม NSG

  • Logical Grouping ของ VMs/NICs ตาม Application Role (Web, App, DB, Mgmt)
  • ใช้เป็น Source/Destination ใน NSG Rules แทน IP Address
  • ตัวอย่าง: Source: ASG-Web, Dest: ASG-App, Port: 8080, Allow
  • Scale ได้ดีกว่า IP-based Rules

Service Tags - จัดการ IP Ranges อัตโนมัติ

  • Microsoft จัดการ IP Ranges ของ Azure Services ให้: AzureCloud, AzureLoadBalancer, VirtualNetwork, Internet, Storage, Sql, KeyVault, EventHub, ServiceBus, ApiManagement, AppService, AzureActiveDirectory, AzureMonitor, ...
  • ใช้เป็น Source/Destination ใน NSG Rules แทน CIDR Blocks
  • Region-specific: AzureCloud.EastUS, Storage.WestEurope

NSG Flow Logs & Monitoring

  • Enable: NSG > Settings > Flow logs > On (Log Analytics / Storage Account)
  • Version 2: ระบุ Throughput (Bytes/Packets), Rule Name, Direction
  • Traffic Analytics: Microsoft-managed Analytics บน Flow Logs (Geo-map, Top Talkers, Malicious IP, Port Scanning)
  • Integrate: Microsoft Sentinel, Defender for Cloud, Third-party SIEM

Best Practices

  1. Attach NSG to Subnet (ไม่ใช่ NIC) เพื่อ Consistency และ Manageability
  2. Use ASGs สำหรับ Application-tier Rules
  3. Use Service Tags แทน Hard-coded IPs
  4. Deny by Default: Explicit Allow Rules เฉพาะที่จำเป็น Priority 100-1000
  5. Reserve Priority Gaps: 100, 200, 300... เพื่อ Insert Rules ระหว่างได้
  6. Enable Flow Logs + Traffic Analytics สำหรับ Visibility
  7. Test with Network Watcher: IP Flow Verify, Next Hop, Connection Troubleshoot, Packet Capture
  8. Combine with Azure Firewall: NSG (Micro-seg) + Azure Firewall (Perimeter/L7) = Defense in Depth

สรุป

NSG = Basic Network Filtering (L3/L4) ฟรี ใช้ทำ Micro-segmentation ระดับ Subnet/NIC
Azure Firewall = Full-featured L3/L4/L7 Firewall แบบ Managed จ่ายเงิน ใช้ทำ Perimeter/Hub Security
Best Practice: ใช้ ทั้งคู่ร่วมกัน (NSG ใกล้ Workload + Azure Firewall ที่ Hub) + ASG + Service Tags + Flow Logs + Traffic Analytics