+86 135 410 16684Mon. - Fri. 10:00-22:00

AWS Security Groups and Network ACLs

Security Groups and Network ACLs

AWS Security Groups and Network ACLs

整理 AWS Security GroupsNetwork ACLs 的差異,特別是 rule 的 statefulstateless 的差異。主要參考自下表:

Comparison-of-Security-Groups-and-Network-ACLs
摘錄自 Security in Your VPC

Security Groups

  • 針對 EC2 Instance 使用. 通常是針對一群一樣的角色, 像是 Web, DB, Batch, Log …
  • Rules of Security Group:
    • 只能設定 Allow 規則, 預設全部都是 Deny
    • Rule 之間沒有次序
    • 每一條 Rule 都是狀態性 (Stateful)
    • Rule 的 destination 可以是 CIDR, IP, Security Group, 還有其他 VPC RouteTable 的 Destination, 像是 VPC Endpoint 的 ID: pl-61a540xxx
  • Security Group 會主動套用到 EC2 第一張網卡 (ENI),但是第二張要手動更改。
    • 如果針對 EC2 Instance 更換 SG, 同時 Instance 有兩張以上的 ENI ,那麼第二張之後記得要手動更改 SG。
  • Stateful (狀態性): 如果允出 inbound ,那麼針對該 inbound 的 response 就不需要特別指定。反之 outbound 也是。
    • 意思是說,如果設定允許 SSH 進來,那麼 response 回去的 destination / port 不用特別指定。
    • 通常 response port 會大於 1024 之後

針對 Security Group 狀態性的說明,原文如下:

Security groups are stateful — responses to inbound traffic are allowed to flow out of the instance regardless of outbound security group rules, and vice versa (反之亦然).

參閱:Security Groups for Your VPC

Network ACLs (Access Control Level)

  • 針對 Subnet 限定.
  • Rules of ACL
    • 可以同時有 Allow, Deny 兩種,但是系統最後會自動放一條 Deny All
    • Rule 之間有次序
    • 每一條 Rule 都是無狀態 (Stateless)
    • Rule 的 destination 可以是 CIDR, IP.
  • Stateless (無狀態性): 如果允出 inbound ,那麼針對該 inbound 的 response 就需要特別指定。反之 outbound 也是。
    • 意思是說,如果設定允許 SSH 進來,那麼 response 回去的 destination / port 要特別指定範圍。
    • 通常 response port 會大於 1024 之後

Network ACLs 狀態性說明原文如下:

Network ACLs are stateless and therefore do not automatically allow response traffic.

see: Connection Tracking

參考資料