GetSGOwnerVPC() and GetVMUsingRS() - cloud-barista/cb-spider GitHub Wiki

  • 사용자(Tumblebug 등)가 기존 자원 등록 시에 자원의 관계 정보가 필요함

    • 예시: 특정 SecurityGroup을 소유하는 VPC ID
    • 예시: 특정 VM이 사용하는 VPC ID, SG ID, Key ID 등
  • 반환 정보

    • 이미 Spider에 등록된 자원이면, NameId, SystemId 포함
      • 예시:
        • {"NameId":"vpc-01","SystemId":"vpc-06d9ed96c230c138f"}
    • 등록이 안된 자원이면, SystemId만 포함
      • 예시:
        • {"NameId":"","SystemId":"vpc-836f39ea"}
    • 연관 자원을 제공하지 않는 CSP 경우, 값이 빈 IID 반환
      • 예시: Azure와 같이 SecurityGroup이 VPC에 소유되지 않는 경우, SG를 소유하는 VPC ID 요청시
        • {"NameId":"","SystemId":""}
    • 입력 자원이 존재하지 않거나 오류 발생시, error 반환
      • 예시:
        • {"message":"InvalidGroup.NotFound: The security group 'sg-abcd' does not exist\n\tstatus code: 400, request id: dcfacf5a-87ec-4a72-9450-ffdcca38a865"}
        • {"message":"code=415, message=Unsupported Media Type"}
  • 특이 사항

    • Security Group
      • Azure와 같이 VCP에 소유가 안된 SG를 제공하는 CSP가 있음
      • GCP 경우 SG 개념이 없는 개별 Firewall만 제공하고 있어,
    • KeyPair
      • CSP가 KeyPair를 제공하지 않거나,
      • Driver에서 별도로 제공하는 KeyPair를 활용하는 CSP가 있음
    • VM
      • Public IP가 존재하지 않을 수 있음
      • cb-user 계정이 존재하지 않음
      • DF-Agent가 설치 되어 있지 않음
  • Pseudo API

    • IID GetSGOwnerVPC()
    • {VPC:IID, SG:[IID], Key:IID} GetVMUsingRS()

1. GetSGOwnerVPC() 시험 항목 및 결과

[AWS]
  • 대상 SG가 이미 Spider 맵핑된 케이스
curl -sX GET http://localhost:1024/spider/getsecuritygroupowner -H 'Content-Type: application/json' -d '{"ConnectionName": "aws-ohio-config", "ReqInfo": { "CSPId":"sg-08d02432bd1ddebf7"} }'
{"message":"sg-sg-08d02432bd1ddebf7 already exists with sg-01!"}
  • 대상 SG를 소유한 VPC가 Spider에 맵핑된 케이스
curl -sX GET http://localhost:1024/spider/getsecuritygroupowner -H 'Content-Type: application/json' -d '{"ConnectionName": "aws-ohio-config", "ReqInfo": { "CSPId":"sg-0bd612696ed5f83e0"} }'
{"NameId":"vpc-01","SystemId":"vpc-0d12b45a9f006afea"}
  • 대상 SG를 소유한 VPC가 Spider에 맵핑안된 케이스
curl -sX GET http://localhost:1024/spider/getsecuritygroupowner -H 'Content-Type: application/json' -d '{"ConnectionName": "aws-ohio-config", "ReqInfo": { "CSPId":"sg-0067570f557818e64"} }'
{"NameId":"","SystemId":"vpc-836f39ea"}
  • 대상 SG가 CSP에 존재하지 않는 케이스
curl -sX GET http://localhost:1024/spider/getsecuritygroupowner -H 'Content-Type: application/json' -d '{"ConnectionName": "aws-ohio-config", "ReqInfo": { "CSPId":"sg-abcd"} }'
{"message":"InvalidGroup.NotFound: The security group 'sg-abcd' does not exist\n\tstatus code: 400, request id: dcfacf5a-87ec-4a72-9450-ffdcca38a865"}
  • 내부 오류 발생하는 케이스
curl -sX GET http://localhost:1024/spider/getsecuritygroupowner -H 'Content-Type: application/json' -d '{"ConnectionName": "aws-ohio-config", "ReqInfo": { "CSPId":"sg-xxxxxx"} }'
{"message":"InvalidGroupId.Malformed: Invalid id: \"sg-xxxxxx\"\n\tstatus code: 400, request id: 1eaaf921-eaab-4939-8b62-33db95e9646a"}
[Azure]
  • 대상 SG가 이미 Spider 맵핑된 케이스
curl -sX GET http://localhost:1024/spider/getsecuritygroupowner -H 'Content-Type: application/json' -d '{"ConnectionName": "azure-northeu-config", "ReqInfo": { "CSPId":"/subscriptions/a20fed83-96bd-4480-92a9-140b8e3b7c3a/resourceGroups/cb-group-wip/providers/Microsoft.Network/networkSecurityGroups/sg01-c9s7chiba5o1unl4urmg"} }'
{"message":"sg-/subscriptions/a20fed83-96bd-4480-92a9-140b8e3b7c3a/resourceGroups/cb-group-wip/providers/Microsoft.Network/networkSecurityGroups/sg01-c9s7chiba5o1unl4urmg already exists with sg-01!"}
  • 대상 SG를 소유한 VPC가 존재하지 않는 케이스(Azure는 VPC가 SG를 소유하지 않음)
curl -sX GET http://localhost:1024/spider/getsecuritygroupowner -H 'Content-Type: application/json' -d '{"ConnectionName": "azure-northeu-config", "ReqInfo": { "CSPId":"/subscriptions/a20fed83-96bd-4480-92a9-140b8e3b7c3a/resourceGroups/cb-group-wip/providers/Microsoft.Network/networkSecurityGroups/not-used"} }'
{"NameId":"","SystemId":""}
  • 대상 SG가 CSP에 존재하지 않는 케이스
curl -sX GET http://localhost:1024/spider/getsecuritygroupowner -H 'Content-Type: application/json' -d '{"ConnectionName": "azure-northeu-config", "ReqInfo": { "CSPId":"/subscriptions/a20fed83-96bd-4480-92a9-140b8e3b7c3a/resourceGroups/cb-group-wip/providers/Microsoft.Network/networkSecurityGroups/not-exist"} }'
{"message":"network.SecurityGroupsClient#Get: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code=\"ResourceNotFound\" Message=\"The Resource 'Microsoft.Network/networkSecurityGroups/not-exist' under resource group 'cb-group-wip' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix\""}
[Alibaba]
  • 대상 SG가 이미 Spider 맵핑된 케이스
curl -sX GET http://localhost:1024/spider/getsecuritygroupowner -H 'Content-Type: application/json' -d '{"ConnectionName": "alibaba-beijing-config", "ReqInfo": { "CSPId":"sg-2zebc0fjar27rxah6b0o"} }'
{"message":"sg-sg-2zebc0fjar27rxah6b0o already exists with sg-01!"}
  • 대상 SG를 소유한 VPC가 Spider에 맵핑된 케이스
curl -sX GET http://localhost:1024/spider/getsecuritygroupowner -H 'Content-Type: application/json' -d '{"ConnectionName": "alibaba-beijing-config", "ReqInfo": { "CSPId":"sg-2zeef27fei4gk96vkhi0"} }'
{"NameId":"vpc-01","SystemId":"vpc-2zeqyg16b8njzhhnybg3s"}
  • 대상 SG를 소유한 VPC가 Spider에 맵핑안된 케이스
curl -sX GET http://localhost:1024/spider/getsecuritygroupowner -H 'Content-Type: application/json' -d '{"ConnectionName": "alibaba-beijing-config", "ReqInfo": { "CSPId":"sg-2ze9mgpkb99gy9ny0cjh"} }'
{"NameId":"","SystemId":"vpc-2zexrx06j0r42k73mde46"}
  • 대상 SG가 CSP에 존재하지 않는 케이스
curl -sX GET http://localhost:1024/spider/getsecuritygroupowner -H 'Content-Type: application/json' -d '{"ConnectionName": "alibaba-beijing-config", "ReqInfo": { "CSPId":"sg-abcd"} }'
{"message":"Notfound: 'sg-abcd' SecurityGroup Not found"}

2. GetVMUsingRS() 시험 항목 및 결과

[AWS]

  • 대상 VM이 이미 Spider에 맵핑된 케이스
curl -sX GET http://localhost:1024/spider/getvmusingresources -H 'Content-Type: application/json' -d '{"ConnectionName": "aws-ohio-config", "ReqInfo": { "CSPId":"i-093f0f5d3fc46ff60"} }' | json_pp
{"message":"vm-i-093f0f5d3fc46ff60 already exists with vm-01!"}
  • 대상 VM이 사용 중인 자원(VPC, SG, Key)들이 이미 Spider에 맵핑된 케이스
    • 필요시 참고: 시험을 위해서 VM을 unregister 하는 방법
      curl -sX DELETE http://localhost:1024/spider/regvm/vm-01 -H 'Content-Type: application/json' -d \
                  '{ 
                          "ConnectionName": "aws-ohio-config"
                  }' |json_pp
      
curl -sX GET http://localhost:1024/spider/getvmusingresources -H 'Content-Type: application/json' -d '{"ConnectionName": "aws-ohio-config", "ReqInfo": { "CSPId":"i-093f0f5d3fc46ff60"} }' | json_pp
{
   "Resources" : {
      "VPC" : {
         "NameId" : "vpc-01",
         "SystemId" : "vpc-042e2ed141a12d1a2"
      },
      "VMKey" : {
         "NameId" : "keypair-01",
         "SystemId" : "keypair-01-ca1k3gaba5o9dvmgrbi0"
      },
      "SGList" : [
         {
            "NameId" : "sg-01",
            "SystemId" : "sg-0b4bdaa8a6d7a745d"
         }
      ]
   }
}
  • 대상 VM이 사용 중인 VPC가 Spider에 맵핑 안된 케이스
    • 필요시 참고: 시험을 위해서 VPC를 unregister 하는 방법
      curl -sX DELETE http://localhost:1024/spider/regvpc/vpc-01 -H 'Content-Type: application/json' -d \
                  '{
                          "ConnectionName": "aws-ohio-config"
                  }' |json_pp
      
curl -sX GET http://localhost:1024/spider/getvmusingresources -H 'Content-Type: application/json' -d '{"ConnectionName": "aws-ohio-config", "ReqInfo": { "CSPId":"i-093f0f5d3fc46ff60"} }' | json_pp
{
   "Resources" : {
      "VPC" : {
         "NameId" : "",
         "SystemId" : "vpc-042e2ed141a12d1a2"
      },
      "SGList" : [
         {
            "SystemId" : "sg-0b4bdaa8a6d7a745d",
            "NameId" : "sg-01"
         }
      ],
      "VMKey" : {
         "SystemId" : "keypair-01-ca1k3gaba5o9dvmgrbi0",
         "NameId" : "keypair-01"
      }
   }
}
  • 대상 VM이 CSP에 존재하지 않는 케이스
    • 참고: AWS 경우에는 terminating 시켜도 한동안 목록에 나타남
      • 이때, VM의 VPC, SG는 Relationship 정보는 사라짐
        curl -sX GET http://localhost:1024/spider/getvmusingresources -H 'Content-Type: application/json' -d '{"ConnectionName": "aws-ohio-config", "ReqInfo": { "CSPId":"i-093f0f5d3fc46ff60"} }' | json_pp
        
        {
           "Resources" : {
              "VMKey" : {
                 "NameId" : "keypair-01",
                 "SystemId" : "keypair-01-ca1k3gaba5o9dvmgrbi0"
              },
              "SGList" : null,
              "VPC" : {
                 "NameId" : "",
                 "SystemId" : ""
              }
           }
        }
        
curl -sX GET http://localhost:1024/spider/getvmusingresources -H 'Content-Type: application/json' -d '{"ConnectionName": "aws-ohio-config", "ReqInfo": { "CSPId":"i-novm"} }' | json_pp
{
   "message" : "InvalidInstanceID.Malformed: Invalid id: \"i-093f0f5d3fc46ff61\"\n\tstatus code: 400, request id: 4845ee16-831c-4434-bf39-ad81b6fc3838"
}

[Azure]

  • 대상 VM이 이미 Spider에 맵핑된 케이스
curl -sX GET http://localhost:1024/spider/getvmusingresources -H 'Content-Type: application/json' -d '{"ConnectionName": "azure-northeu-config", "ReqInfo": { "CSPId":"/subscriptions/a20fed83-96bd-4480-92a9-140b8e3b7c3a/resourceGroups/cb-group-wip/providers/Microsoft.Compute/virtualMachines/vm-01-ca1klhqba5o9dvmgrbl0"} }' | json_pp
{
   "message" : "vm-/subscriptions/a20fed83-96bd-4480-92a9-140b8e3b7c3a/resourceGroups/cb-group-wip/providers/Microsoft.Compute/virtualMachines/vm-01-ca1klhqba5o9dvmgrbl0 already exists with vm-01!"
}
  • 대상 VM이 사용 중인 자원(VPC, SG, Key)들이 이미 Spider에 맵핑된 케이스
    • 필요시 참고: 시험을 위해서 VM을 unregister 하는 방법
      curl -sX DELETE http://localhost:1024/spider/regvm/vm-01 -H 'Content-Type: application/json' -d \
                  '{ 
                          "ConnectionName": "azure-northeu-config"
                  }' |json_pp
      
curl -sX GET http://localhost:1024/spider/getvmusingresources -H 'Content-Type: application/json' -d '{"ConnectionName": "azure-northeu-config", "ReqInfo": { "CSPId":"/subscriptions/a20fed83-96bd-4480-92a9-140b8e3b7c3a/resourceGroups/cb-group-wip/providers/Microsoft.Compute/virtualMachines/vm-01-ca1klhqba5o9dvmgrbl0"} }' | json_pp
{
   "Resources" : {
      "VMKey" : {
         "SystemId" : "keypair-01-ca1kldiba5o9dvmgrbkg",
         "NameId" : "keypair-01"
      },
      "SGList" : [
         {
            "NameId" : "sg-01",
            "SystemId" : "sg01-ca1kl4iba5o9dvmgrbk0"
         }
      ],
      "VPC" : {
         "NameId" : "vpc-01",
         "SystemId" : "vpc-01-ca1kkuiba5o9dvmgrbj0"
      }
   }
}
  • 대상 VM이 사용 중인 VPC가 Spider에 맵핑 안된 케이스
    • 필요시 참고: 시험을 위해서 VPC를 unregister 하는 방법
      curl -sX DELETE http://localhost:1024/spider/regvpc/vpc-01 -H 'Content-Type: application/json' -d \
                  '{
                          "ConnectionName": "azure-northeu-config"
                  }' |json_pp
      
curl -sX GET http://localhost:1024/spider/getvmusingresources -H 'Content-Type: application/json' -d '{"Connectio
nName": "azure-northeu-config", "ReqInfo": { "CSPId":"/subscriptions/a20fed83-96bd-4480-92a9-140b8e3b7c3a/resourceGroups/cb-group-wip/providers/M
icrosoft.Compute/virtualMachines/vm-01-ca1klhqba5o9dvmgrbl0"} }' | json_pp
{
   "Resources" : {
      "VPC" : {
         "SystemId" : "vpc-01-ca1kkuiba5o9dvmgrbj0",
         "NameId" : ""
      },
      "VMKey" : {
         "SystemId" : "keypair-01-ca1kldiba5o9dvmgrbkg",
         "NameId" : "keypair-01"
      },
      "SGList" : [
         {
            "NameId" : "sg-01",
            "SystemId" : "sg01-ca1kl4iba5o9dvmgrbk0"
         }
      ]

  • 대상 VM이 CSP에 존재하지 않는 케이스
curl -sX GET http://localhost:1024/spider/getvmusingresources -H 'Content-Type: application/json' -d '{"Connectio
nName": "azure-northeu-config", "ReqInfo": { "CSPId":"/subscriptions/a20fed83-96bd-4480-92a9-140b8e3b7c3a/resourceGroups/cb-group-wip/providers/M
icrosoft.Compute/virtualMachines/vm-01-ca1klhqba5o9dvmgrbl0"} }' | json_pp
{
   "message" : "Failed to Get VM. err = compute.VirtualMachinesClient#Get: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code=\"ResourceNotFound\" Message=\"The Resource 'Microsoft.Compute/virtualMachines/vm-01-ca1klhqba5o9dvmgrbl0' under resource group 'cb-group-wip' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix\""
}