Security Group Rules and Driver API - cloud-barista/cb-spider GitHub Wiki

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. Driver API

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

        VpcIID        IID    // {NameId, SystemId}
        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}
        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)
        RemoveRules(sgIID IID, securityRules *[]SecurityRuleInfo) (bool, error)
}

β€» 특이 사항

  • AddRules()/RemoveRules()에 μ˜ν•΄ Port λ°©ν™”λ²½ κ·œμΉ™ λ³€κ²½ μ™„λ£Œ 후에도 νš¨κ³Όκ°€ λ‚˜νƒ€λ‚˜λŠ”λ° μ‹œκ°„μ΄ ν•„μš”ν•¨
    • 톡상 7~10초
    • Azure: 60~80초

3. Security Group Rules 검증 μ‹œν—˜ 도ꡬ

3.1. μ‹œν—˜ ν•­λͺ© 및 κ°€μ΄λ“œ

3.2. μ‹œν—˜ 도ꡬ μœ„μΉ˜

3.3. μ‹œν—˜ 도ꡬ ꡬ성

  • (1) inbound Rule Test 도ꡬ: inbound κ·œμΉ™ λ³€κ²½ 및 VM inbound/outbound μ ‘κ·Ό 검증 μ‹œν—˜
  • (2) outbound Rule Test 도ꡬ: outbound κ·œμΉ™ λ³€κ²½ 및 VM inbound/outbound μ ‘κ·Ό 검증 μ‹œν—˜
  • (3) create-add-list-get-info 도ꡬ: SecurityGroup 정보λ₯Ό μ œκ³΅ν•˜λŠ” API λ°˜ν™˜ κ°’ 검증을 μœ„ν•œ 정보 좜λ ₯ μ‹œν—˜ 도ꡬ(μˆ˜λ™ 검증 ν•„μš”)

3.4. μ‹œν—˜ 방법 및 절차

  • (1) λŒ€μƒ CSP connection config μ€€λΉ„ 및 image, Spec λ“± μ‹œν—˜ ν™˜κ²½ μ„€μ •

    • aws 경우: 1.inbound-rule-test/aws/setup.env 확인
    • aws2와 같이 경둜 μΆ”κ°€ν•˜μ—¬ μƒˆλ‘œμš΄ μ„€μ • ꡬ성 κ°€λŠ₯
  • (2) Client1 ν™˜κ²½ μ€€λΉ„

    • Client1: SG μ‹œν—˜ λŒ€μƒ VM -> outbound μ‹œν—˜μ„ μœ„ν•œ λ…Έλ“œ
      • λ³Έ μ˜ˆμ‹œμ—μ„œλŠ” μ‹œν—˜μ„ μ‹€ν–‰ν•˜λŠ” λ…Έλ“œλ₯Ό ν™œμš©
    • Client1 λ…Έλ“œμ˜ 포트 및 ICMP 개방 ν•„μš”: 22(TCP), 1000(TCP), 2000(UDP), ICMP
    • Client1_IP μ„€μ • 확인 ν•„μš”
      • λ‹€μŒ λͺ…λ Ήμ–΄λ‘œ IP νšλ“μ΄ κ°€λŠ₯ν•΄μ•Ό 함
        curl -s ifconfig.co
        
      • λΆˆκ°€λŠ₯ν•  경우 IP μ„€μ • ν•„μš”
        • μœ„μΉ˜: 1.inbound-rule-test/setup.env
        • μœ„μΉ˜: 2.outbound-rule-test/setup.env
  • (3) μ‹œν—˜ 절차

    • μ‹œν—˜ 도ꡬ μœ„μΉ˜λ‘œ 이동(μ˜ˆμ‹œ: inbound 검증 μ‹œν—˜)

      cd $CBSPIDER_ROOT/test/sg-rules-validation-cli/1.inbound-rule-test
      
    • μ‹œν—˜ ν™˜κ²½ μ€€λΉ„ μ‹€ν–‰(VPC~VM 생성 및 TCP/UDP μ„œλ²„ λ“± 가동)(μ˜ˆμ‹œ: AWS 경우)

      ./00.prepare-00.sh aws
      
    • Rule 검증 μ‹œν—˜ 단계별 μ‹€ν–‰ (단계별 의미: 3.1. μ‹œν—˜ ν•­λͺ© 및 κ°€μ΄λ“œ μ°Έκ³ )(μ˜ˆμ‹œ: AWS 경우)

      • (단계별 μ‹€ν–‰μ‹œ: Azure의 경우 ν„°λ―Έλ„μ—μ„œ export SLEEP=80 μ‹€ν–‰ ν•„μš”, Azure μ‹œν—˜ ν›„ unset SLEEP μ‹€ν–‰ ν•„μš”)
      ./01.inbound-case-01.sh aws
      
      ./02.inbound-case-02.sh aws
      
      ./03.inbound-case-03.sh aws
      
      ./04.inbound-case-04.sh aws
      
      ./05.inbound-case-05.sh
      
      ./06.inbound-case-06.sh
      
      ./10.inbound-case-10.sh
      
      ./11.inbound-case-11.sh
      
      ./20.inbound-case-20.sh
      
      ./21.inbound-case-21.sh
      
    • 생성 μžμ› λ°˜λ‚©

      ./100.clear_all.sh aws
      
    • 검증 μ‹œν—˜ 일괄 μ‹€ν–‰: ./01.inbound-case-01.sh ~ ./21.inbound-case-21.sh κΉŒμ§€ μžλ™ μ‹€ν–‰

      ./all.inbound-case-all.sh aws
      
    • λ‹€μˆ˜ CSP 일괄 μ‹œν—˜: ./00.prepare-00.sh ~ ./100.clear_all.sh κΉŒμ§€ μ‹€ν–‰

      • 슀크립트 내뢀에 μ‹œν—˜ λŒ€μƒ CSP λͺ©λ‘ 확인/μ„€μ • ν•„μš”
      ./csp.all.inbound-case-all.sh
      
    • inbound, outbound 검증 μ‹œν—˜ λͺ¨λ‘ 일괄 μ‹€ν–‰: λŒ€μƒ CSP λŒ€μƒμœΌλ‘œ inbound 및 outbound λͺ¨λ“  μ‹œν—˜ μžλ™ μ‹€ν–‰

      • μœ„μΉ˜:

        cd $CBSPIDER_ROOT/test/sg-rules-validation-cli
        
      • 확인: λŒ€μƒ CSP λͺ©λ‘

        ./1.inbound-rule-test/csp.all.inbound-case-all.sh
        ./2.outbound-rule-test/csp.all.outbound-case-all.sh
        
      • μ‹€ν–‰:

        ./all.csp.all.case-all.sh
        
    • μ‹œν—˜ μ°Έκ³ 

      • 일괄 μ‹œν—˜μ˜ 경우: Azure μ‹œν—˜μ€ SLEEP=80 μžλ™ 섀정됨
      • 쀑간 κ²°κ³Ό 확인 방법
        • μ‹œν—˜ν•œ ν•­λͺ© 확인: $ grep case *.out or $ grep case *.out | wc -l
        • 였λ₯˜ ν•­λͺ© 확인: $ grep X *.out
  • (4) κ²°κ³Ό 확인 방법

    • μ‹œν—˜ κ²°κ³ΌλŠ” λ‹€μŒ ν˜•μ‹μ˜ λ‚ μ§œ λ‹¨μœ„μ˜ νŒŒμΌμ— 기둝

      • κ²°κ³Ό 좜λ ₯ 파일 μœ„μΉ˜ 및 μ˜ˆμ‹œ: ./1.inbound-rule-test/aws-result-04.15.out
    • μ‹œν—˜ κ²°κ³Ό ν˜•μ‹ 및 ν™œμš© κ°€μ΄λ“œ

      • μ‹œν—˜ κ²°κ³Ό ν˜•μ‹: Markup Table ν˜•μ‹
      • μ‹œν—˜ κ²°κ³Ό 좜λ ₯ Table κ·œκ²©μ€ 3.1. μ‹œν—˜ ν•­λͺ© 및 κ°€μ΄λ“œ μ‹œν—˜ ν•­λͺ©κ³Ό 동일
      • μ‹œν—˜ κ²°κ³Ό 파일 λ‚΄μš© 쀑 μ›ν•˜λŠ” μ‹œν—˜ κ²°κ³Όλ₯Ό λ³΅μ‚¬ν•˜μ—¬ Github issueλ‚˜ Wiki에 볡사/ν™œμš©/뢄석
    • κ²°κ³Ό μ˜ˆμ‹œ

[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


4. μ‹œν—˜ κ²°κ³Ό ν˜„ν™©


CSP inbouund/outbound 검증 μ‹œν—˜ λ°˜ν™˜ 정보 검증 특이 사항
AWS All Pass OK  
Azure inbound: ALL Pass
outbound: μž¬μ‹œν—˜ ν•„μš”
OK - export SLEEP=80 ν•„μš”
GCP All Pass OK
Alibaba All Pass OK  
Tencent issue OK  
IBM(VPC) All Pass OK - Regionλ³„λ‘œ Image ID 닀름
- ν•„μš”μ‹œ Image ID λ³€κ²½
OpenStack All Pass OK - DriverνŒ€ μ‹œν—˜ 결과둜 λŒ€μ²΄
- μ‚¬μœ : ETRI ν™˜κ²½ 이슈 쑴재
CloudIt All Pass(ICMPμ œμ™Έ) OK - DriverνŒ€ μ‹œν—˜ 결과둜 λŒ€μ²΄
 - μ‚¬μœ : ssh 접속 이슈
- ICMP 비지원
       
NCPVPC WIP -  
NCP WIP -  
NHNCloud WIP -  
KT(VPC) 개발 μ˜ˆμ •    

μ°Έκ³ 


⚠️ **GitHub.com Fallback** ⚠️