Skip to content

Security Group Rules and Driver API

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

WIP


1. CB-Spider Security Group Rules

  • Data Structure

    type SecurityRuleInfo struct {
          Direction  string
          IPProtocol string
          FromPort   string
          ToPort     string
          CIDR       string
    }
  • Rules Spec (CSP common spec)

    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
    * -1: 보안 측면에서 명시적인 입력을 요함
    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 세부 타입 설정 미제공
    - ICMP 예시: ping, echo, tracert 등
    * -1: 보안 측면에서 명시적인 입력을 요함
  • Default Rule: Security Group 생성시 사용자가 추가 설정하지 않아도 다음처럼 자동 설정

    • inbound default rule: no (All traffic 차단)
    • outbound default rule: ALL -1 -1 0.0.0.0/0 (All traffic 허용)

2. Security Group 기능 개선

  • 생성한 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, Driver/Test, Tumblebug/Test 등 반영 작업 전파 필요
  • CSP와 Spider의 'ALL', '-1' 의미가 다를 경우 Spider 의미로 변환하여 입출력 필요

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

    • Spider Rules는 ID가 존재 하지 않음
    • 대부분의 CSP Rule은 ID로 관리 되고 있음
    • (1) Driver 내부에서 Rule's ID 생성 및 처리 필요 <=========== (1)
      • Rule ID's Max Length 초과하지 않도록 고려 필요
    • (2) AddRules() 시 Rule 중복 체크 <=========== (2)
      • CSP 포맷 또는 구조체로 변환 후 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