Skip to content

Security Group Rules and Driver API

ByoungSeob Kim edited this page Apr 5, 2022 · 47 revisions

WIP


1. CB-Spider Security Group and Rules

  • VM 트래픽 제어를 위해서 특정 VPC에 소속되는 Security Group을 정의할 수 있다.

  • 하나의 Security Group은 하나 이상의 허용 규칙(Allow Rule을 포함할 수 있다.

  • Rule은 다음과 같은 속성들로 정의할 수 있다.

    • Direction: 트래픽 방향
      • inbound | outbound
    • Protocol: 대상 프로토콜
      • ALL: 모든 트래픽 허용
      • TCP | UDP | ICMP
    • Port Range: 대상 포트 범위
      • FromPort: 1, ToPort: 65535, ...
      • -1: 포트 설정이 무의미함 또는 모든 포트 대상
    • Source or Destination: 적용 대상, Address CIDR Block으로 표현
      • 0.0.0.0/0, ::/0, 1.2.3.4/32, ...
  • Security Group 생성시에는 최소 1개 이상의 Rule을 포함해야 하며, 이후 Rule의 추가 삭제가 가능하다.

  • Security Group의 default Rule은 다음과 같고, CSP별로 관련 Rule이 보일 수도 있고 안보일 수도 있다.

    • inbound: 모든 트래픽 차단
    • outbound: 모든 트래픽 허용
  • CSP Driver 개발 가이드

    • Cloud Driver: Security Group 생성시 default Rule 확인 및 필요시 설정 필요
    • ALL, -1: 대상 CSP에서 의미가 다를 경우 변환 필요, ex) ALL <-> -1
  • Rule's Data Structure

    type SecurityRuleInfo struct {
          Direction  string
          IPProtocol string
          FromPort   string
          ToPort     string
          CIDR       string
    }
  • 프로토콜별 Rule 규칙 참고

    Direction IPProtocol FromPort ToPort CIDR Block (source or destination) 비고
    inbound, outbound ALL -1 -1 IPv4 ex) 0.0.0.0/0
    IPv6 ex) ::/0
    * ALL: All traffic
    inbound, outbound TCP 1~65535
    ex) 443
    1~65535
    ex) 443
    IPv4 ex) 0.0.0.0/8
    IPv6 ex) ::/8
    inbound, outbound UDP 1~65535
    ex) 6000
    1~65535
    ex) 8000
    IPv4 ex) 0.0.0.0/32
    IPv6 ex) ::/32
    inbound, outbound ICMP -1 -1 IPv4 ex) 1.2.3.4/32
    IPv6 ex) ::/64
    * ICMP: network layer
    - Port 지정 불필요
    - ICMP 예시: ping, echo, tracert 등
  • CSP별 Security Group Rule 참고

  • Known Issues

    • GCP 이슈: 하나의 Security Group에는 동일 Direction만 포함 가능, 1개의 CIDR 값만 유효
    • NCP Classic: Security Group 생성은 웹 console로만 가능, API는 List/Get만 가능

2. Security Group 기능 및 API 개선

  • 생성한 Security Group에 Rule 추가/삭제 기능 추가
  • AddRules(), RemoveRules() API 추가

2.1. AS-IS

type SecurityReqInfo struct {
        IId IID // {NameId, SystemId}

        VpcIID        IID    // {NameId, SystemId}
        Direction     string // To be deprecated
        SecurityRules *[]SecurityRuleInfo
}

type SecurityRuleInfo struct {
        Direction  string
        IPProtocol string
        FromPort   string
        ToPort     string
        CIDR       string
}

type SecurityInfo struct {
        IId IID // {NameId, SystemId}

        VpcIID        IID    // {NameId, SystemId}
        Direction     string // To be deprecated
        SecurityRules *[]SecurityRuleInfo

        KeyValueList []KeyValue
}

type SecurityHandler interface {
        CreateSecurity(securityReqInfo SecurityReqInfo) (SecurityInfo, error)
        ListSecurity() ([]*SecurityInfo, error)
        GetSecurity(securityIID IID) (SecurityInfo, error)
        DeleteSecurity(securityIID IID) (bool, error)
}

2.2. TO-BE

type SecurityReqInfo struct {
        IId IID // {NameId, SystemId}

        VpcIID        IID    // {NameId, SystemId}
        //Direction     string // To be deprecated                                              <=== Deleted
        SecurityRules *[]SecurityRuleInfo
}

type SecurityRuleInfo struct {
        Direction  string
        IPProtocol string
        FromPort   string
        ToPort     string
        CIDR       string
}

type SecurityInfo struct {
        IId IID // {NameId, SystemId}

        VpcIID        IID    // {NameId, SystemId}
        //Direction     string // To be deprecated                                              <=== Deleted
        SecurityRules *[]SecurityRuleInfo

        KeyValueList []KeyValue
}

type SecurityHandler interface {
        CreateSecurity(securityReqInfo SecurityReqInfo) (SecurityInfo, error)
        ListSecurity() ([]*SecurityInfo, error)
        GetSecurity(securityIID IID) (SecurityInfo, error)
        DeleteSecurity(securityIID IID) (bool, error)

        AddRules(sgIID IID, securityRules *[]SecurityRulesInfo) (SecurityInfo, error)                 <==== Added
        RemoveRules(sgIID IID, securityRules *[]SecurityRulesInfo) (bool, error)                      <==== Added
}

2.3. 주의 사항

  • SecurityReqInfo.DirectionSecurityInfo.Direction 삭제 예정

    • AdminWeb, Test Scripts, Driver/Test, Tumblebug/Test 등 전파 되는 공수 파악 필요
    • 현황 파악 후 결정 예정
  • Driver: CSP와 Spider의 'ALL', '-1' 의미가 다를 경우 Spider 의미로 변환하여 입출력 필요

  • AddRules()/RemoveRules() Driver 구현시 고려 사항

    • Spider는 Rule들의 ID를 관리하지 않음
    • 대부분의 CSP들은 Rule를 ID로 관리하고 있음
      • (1) Driver 내부에서 Rule's ID 생성 및 처리 필요 <=============================== (1)
        • 이 경우 Rule ID's Max Length 초과하지 않도록 고려 필요
      • (2) AddRules() 시 기존 등록된 Rule과의 중복 체크 및 규칙 충돌 등 체크 필요 <========== (2)
        • 일단, CSP에 던진 후 반환 결과로 확인
      • (3) RemoveRules()시 삭제 대상 Rule 찾는 방법 <=========== (3)
        • CSP 포맷 또는 구조체로 변환 후 SecurityRuleInfo의 모든 속성 값을 비교

2.4. SG 관련 이슈 및 참고 사항

3. 주요 Test Cases

3.1. Inbound Test Cases

  • 시험용 Security Group으로 생성된 대상 VM을 향한 Test

  • CASE-1: default inbound test

    • Test Command
      nc -w 2 -zv {$VM_IP} 22
      
      • Expected Results
      Connection to {$VM_IP} port [tcp/http] succeeded!
      
  • WIP

3.2. Outbound Test Cases

  • 이후 생성된 대상 VM에 로그인 후 Test

  • CASE-1: default outbound test

    • Test Command
      nc -w 2 -zv 142.250.190.99 80
      
      • Expected Results
      Connection to 142.250.190.99 80 port [tcp/http] succeeded!
      
  • CASE-2: remove default outbound test

    • 설정: remove default rule (outbound TCP 80 80 0.0.0.0/0)
    • Test Command
      nc -w 2 -zv 142.250.190.99 80
      
      • Expected Results
      nc: connect to 142.250.190.99 port 80 (tcp) timed out: Operation now in progress
      
  • CASE-3: add outbound 80 port test

    • 설정: add rule (outbound TCP 80 80 0.0.0.0/0)
    • Test Command
      nc -w 2 -zv 142.250.190.99 80
      
      • Expected Results
      Connection to 142.250.190.99 80 port [tcp/http] succeeded!
      

Table of contents



Clone this wiki locally