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":""}
- ์์: Azure์ ๊ฐ์ด SecurityGroup์ด VPC์ ์์ ๋์ง ์๋ ๊ฒฝ์ฐ, SG๋ฅผ ์์ ํ๋ VPC ID ์์ฒญ์
- ์
๋ ฅ ์์์ด ์กด์ฌํ์ง ์๊ฑฐ๋ ์ค๋ฅ ๋ฐ์์, 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"}
- ์์:
- ์ด๋ฏธ Spider์ ๋ฑ๋ก๋ ์์์ด๋ฉด, NameId, SystemId ํฌํจ
-
ํน์ด ์ฌํญ
- Security Group
- Azure์ ๊ฐ์ด VCP์ ์์ ๊ฐ ์๋ SG๋ฅผ ์ ๊ณตํ๋ CSP๊ฐ ์์
- GCP ๊ฒฝ์ฐ SG ๊ฐ๋
์ด ์๋ ๊ฐ๋ณ Firewall๋ง ์ ๊ณตํ๊ณ ์์ด,
- Spider๋ฅผ ํตํด์ ์์ฑ์์ ํน์ ๊ท์น์ ์ํ ์ฌ๋ฌ๊ฐ์ firewall์ด ์์ฑ ๋์ด ๋งตํ๋์ง๋ง,
- ๊ธฐ์กด ์กด์ฌํ๋ firewall์ ์ด์ฉํ์ฌ Spider ํตํ ์์ฑ์ฒ๋ผ SG ๊ตฌ์ฑํ๋ ๊ฒ์ ์ถ๊ฐ ์ด์๊ฐ ์กด์ฌํจ.
- GCP SG ์์ฑ ๊ท์น: ๋ค์ ๋งํฌ์์ [2.GCP ์ด์ ๋ฐฉ์] ์ฐธ๊ณ
- KeyPair
- CSP๊ฐ KeyPair๋ฅผ ์ ๊ณตํ์ง ์๊ฑฐ๋,
- Driver์์ ๋ณ๋๋ก ์ ๊ณตํ๋ KeyPair๋ฅผ ํ์ฉํ๋ CSP๊ฐ ์์
- VM
- Public IP๊ฐ ์กด์ฌํ์ง ์์ ์ ์์
- cb-user ๊ณ์ ์ด ์กด์ฌํ์ง ์์
- DF-Agent๊ฐ ์ค์น ๋์ด ์์ง ์์
- Security Group
-
Pseudo API
- IID GetSGOwnerVPC()
- {VPC:IID, SG:[IID], Key:IID} GetVMUsingRS()
1. GetSGOwnerVPC() ์ํ ํญ๋ชฉ ๋ฐ ๊ฒฐ๊ณผ
- ์ํ ๋ฒ์ : 36549a5
[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() ์ํ ํญ๋ชฉ ๋ฐ ๊ฒฐ๊ณผ
- ์ํ ๋ฒ์ : 03929ed
[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
- ํ์์ ์ฐธ๊ณ : ์ํ์ ์ํด์ VM์ unregister ํ๋ ๋ฐฉ๋ฒ
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
- ํ์์ ์ฐธ๊ณ : ์ํ์ ์ํด์ VPC๋ฅผ unregister ํ๋ ๋ฐฉ๋ฒ
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" : "" } } }
- ์ด๋, VM์ VPC, SG๋ Relationship ์ ๋ณด๋ ์ฌ๋ผ์ง
- ์ฐธ๊ณ : AWS ๊ฒฝ์ฐ์๋ terminating ์์ผ๋ ํ๋์ ๋ชฉ๋ก์ ๋ํ๋จ
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
- ํ์์ ์ฐธ๊ณ : ์ํ์ ์ํด์ VM์ unregister ํ๋ ๋ฐฉ๋ฒ
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
- ํ์์ ์ฐธ๊ณ : ์ํ์ ์ํด์ VPC๋ฅผ unregister ํ๋ ๋ฐฉ๋ฒ
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\""
}