Skip to content

Security Group Rules and Driver API

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

1. CB-Spider Security Group and Rules

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

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

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

    • inbound: 모든 트래픽 차단
    • outbound: 모든 트래픽 허용
  • Rule은 다음과 같은 속성들로 정의할 수 있다.

    • Direction: 트래픽 방향
      • inbound | outbound
    • Protocol: 대상 프로토콜
      • ALL: 모든 트래픽 허용
      • TCP | UDP | ICMP
    • Port Range: 대상 포트 범위
      • FromPort: 22, ToPort: 22
      • FromPort: 1, ToPort: 65535
      • FromPort: -1, ToPort: -1: 포트 설정이 무의미, 또는 모든 포트 대상
    • Source or Destination: 적용 대상, Address CIDR Block으로 표현
      • 0.0.0.0/0, ::/0, 1.2.3.4/32, ...
  • CSP Driver 개발 가이드

    • Security Group 생성시 대상 CSP의 default Rule 규칙 확인
      • Spider default rule과 다를 경우 Spider default rule로 설정 필요
    • ALL, -1 관련: 대상 CSP에서 Spider와 의미가 다를 경우 변환 처리 필요
      • ex) ALL <---> ANY
  • 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 지정 불필요(-1로 설정)
    - ICMP 예시: ping, echo, tracert 등
  • CSP별 Security Group Rule 참고

2. Security Group 기능 개선

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

2.2. 변경된 Driver API

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 *[]SecurityRuleInfo) (SecurityInfo, error)                 <==== Added
        RemoveRules(sgIID IID, securityRules *[]SecurityRuleInfo) (bool, error)                      <==== Added
}

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


3. 주요 Test Cases

3.1. Security Group 시험 분류

  • Security Group 및 Rule 기능 시험
    • SG 생성/삭제, Rule 추가/삭제 등
    • 담당: 각 Driver 개발팀
  • Rule 적용 검증 시험
    • Rule이 적용된 VM의 in/out traffic 접근 여부 등
    • 담당: Server팀(시험항목/도구 제공) + 각 Driver 개발팀

3.2. 세부 시험 항목 및 가이드 참고


4. Security Group Rules 검증 시험 도구 가이드

4.1. 도구 위치

4.2. 도구 구성

  • (1) inbound Rule Test 도구
    • inbound-case-01 Case 개발 및 AWS 대상 검증 시험 완료
      • inbound-case-01: 위 3.2. excel 첫줄 시험 케이스, 가장 기본적인 All 규칙 시험
      • 다른 시험 항목: 4/21(목) 배포 예정
  • (2) outbound Rule Test 도구
    • 4/21(목) 배포 예정
  • (3) Inbound+Outbound Rule Test 도구
    • GCP 이슈 해결 후 추진

4.3. 시험 방법 및 절차

  • (1) 대상 CSP connection config 준비

    • aws 경우: 1.inbound-rule-test/aws/setup.env 확인
    • aws2와 같이 경로 추가하여 새로운 설정 구성 가능
  • (2) Client1 환경 준비

    • Client1: 대상 VM -> outbound 시험을 위한 노드
      • 본 예시에서는 시험을 실행하는 노드를 활용
    • 포트 및 ICMP 개방 필요: 22, 1000, 2000, ICMP
    • Client1_IP 설정 확인 필요
      • 위치: 1.inbound-rule-test/setup.env
  • (3) 시험 절차

    • 시험 도구 위치로 이동
      cd $CBSPIDER_ROOT/test/sg-rules-validation-cli/1.inbound-rule-test
      
    • 기본 자원 생성 스크립트 실행 (VPC/Subnet => SG(inbound/ALL/-1/-1) => Key 생성)
      ./00.prepare-00.sh aws
      
    • VM 생성 및 Rule 검증 시험 실행
      ./01.inbound-case-01.sh aws
      

    -생성 자원 반납 스크립트 실행(option)

    ./clear_resouces.sh aws
    
  • (4) 결과 확인 방법

    • 시험 결과는 다음 형식의 날자 단위의 파일 끝에 추가
      • 결과 출력 파일 위치 및 예시: ./1.inbound-rule-test/aws-result-04.15.out
    • 시험 결과 형식: Markup Table 형식
    • 결과 예시

[aws-01.inbound-case-01.sh-Test:2022.04.15-16:04:37]

I:TCP-01
(22)
I:TCP-02
(1000)
I:UDP-01
(2000)
I:ICMP-01
(ping)
O:TCP-01
(22)
O:TCP-02
(1000)
O:UDP-01
(2000)
O:ICMP-01
(ping)
pass / pass pass / pass pass / pass pass / pass pass / pass pass / pass pass / pass pass / fail

[aws-01.inbound-case-01.sh-Test:2022.04.15-16:05:55]

I:TCP-01
(22)
I:TCP-02
(1000)
I:UDP-01
(2000)
I:ICMP-01
(ping)
O:TCP-01
(22)
O:TCP-02
(1000)
O:UDP-01
(2000)
O:ICMP-01
(ping)
pass / pass pass / pass pass / pass pass / pass pass / pass pass / pass pass / pass pass / pass


참고

  • nc(netcat) 도구를 이용한 SG Port 개방 및 서버 유무 시험 결과
  • 시험 환경: AWS VM

----------- Test: All Closed

  • [TCP]

    $ nc -w3 -zvt 52.40.252.40 22
    nc: connect to 52.40.252.40 port 22 (tcp) timed out: Operation now in progress
    
  • [UDP]

    $ nc -w3 -zvu 52.40.252.40 2000
    Connection to 52.40.252.40 2000 port [udp/cisco-sccp] succeeded!          <=============
    
  • [ICMP:ping]

    $ ping -w3 -c3 52.40.252.40
    PING 52.40.252.40 (52.40.252.40) 56(84) bytes of data.
    
    --- 52.40.252.40 ping statistics ---
    3 packets transmitted, 0 received, 100% packet loss, time 2033ms
    

----------- Test: All Opened

  • [TCP] listening

    $ nc -w3 -zvt 52.40.252.40 22
    Connection to 52.40.252.40 22 port [tcp/ssh] succeeded!
    
  • [TCP] no listener

    $ nc -w3 -zvt 52.40.252.40 1000
    nc: connect to 52.40.252.40 port 1000 (tcp) failed: Connection refused
    
  • [UDP] listening

    $ nc -w3 -zvu 52.40.252.40 2000
    Connection to 52.40.252.40 2000 port [udp/cisco-sccp] succeeded!
    
  • [UDP] : no listener

    $ nc -w3 -zvu 52.40.252.40 2000
    $                                                                     <============= no return
    
  • [ICMP:ping]

    $ ping -w3 -c3 52.40.252.40
    PING 52.40.252.40 (52.40.252.40) 56(84) bytes of data.
    64 bytes from 52.40.252.40: icmp_seq=1 ttl=42 time=125 ms
    64 bytes from 52.40.252.40: icmp_seq=2 ttl=42 time=124 ms
    64 bytes from 52.40.252.40: icmp_seq=3 ttl=42 time=124 ms
    
    --- 52.40.252.40 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2002ms
    rtt min/avg/max/mdev = 124.951/124.970/125.009/0.289 ms
    

Table of contents



Clone this wiki locally