diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/main/Test_Resources.go b/cloud-control-manager/cloud-driver/drivers/alibaba/main/Test_Resources.go index b3668dfd6..d28e485bd 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/main/Test_Resources.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/main/Test_Resources.go @@ -976,8 +976,8 @@ func main() { //handleVMSpec() //handleImage() //AMI //handleSecurity() - //handleKeyPair() - handleVM() + handleKeyPair() + //handleVM() //handlePublicIP() // PublicIP 생성 후 conf diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/KeyPairHandler.go b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/KeyPairHandler.go index cb70e632c..e070a6925 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/KeyPairHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/KeyPairHandler.go @@ -12,14 +12,11 @@ package resources import ( "errors" - "io/ioutil" "os" - "strings" "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs" call "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/call-log" - keypair "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/common" idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces" irs "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/resources" "github.com/davecgh/go-spew/spew" @@ -30,15 +27,6 @@ type AlibabaKeyPairHandler struct { Client *ecs.Client } -/* -// @TODO: KeyPairInfo 리소스 프로퍼티 정의 필요 -type KeyPairInfo struct { - Name string - Fingerprint string - KeyMaterial string //RSA PRIVATE KEY -} -*/ - func (keyPairHandler *AlibabaKeyPairHandler) ListKey() ([]*irs.KeyPairInfo, error) { cblogger.Debug("Start ListKey()") var keyPairList []*irs.KeyPairInfo @@ -80,7 +68,8 @@ func (keyPairHandler *AlibabaKeyPairHandler) ListKey() ([]*irs.KeyPairInfo, erro keyPairInfo, errKeyPair := ExtractKeyPairDescribeInfo(&pair) if errKeyPair != nil { - cblogger.Infof("[%s] KeyPair는 Local에서 관리하는 대상이 아니기 때문에 Skip합니다.", *&pair.KeyPairName) + // 2021-10-27 이슈#480에 의해 Local Key 로직 제거 + //cblogger.Infof("[%s] KeyPair는 Local에서 관리하는 대상이 아니기 때문에 Skip합니다.", *&pair.KeyPairName) cblogger.Info(errKeyPair.Error()) } else { keyPairList = append(keyPairList, &keyPairInfo) @@ -92,9 +81,11 @@ func (keyPairHandler *AlibabaKeyPairHandler) ListKey() ([]*irs.KeyPairInfo, erro return keyPairList, nil } +// 2021-10-27 이슈#480에 의해 Local Key 로직 제거 func (keyPairHandler *AlibabaKeyPairHandler) CreateKey(keyPairReqInfo irs.KeyPairReqInfo) (irs.KeyPairInfo, error) { cblogger.Info("Start CreateKey() : ", keyPairReqInfo) + /* 2021-10-27 이슈#480에 의해 Local Key 로직 제거 keyPairPath := os.Getenv("CBSPIDER_ROOT") + CBKeyPairPath cblogger.Infof("Getenv[CBSPIDER_ROOT] : [%s]", os.Getenv("CBSPIDER_ROOT")) cblogger.Infof("CBKeyPairPath : [%s]", CBKeyPairPath) @@ -104,7 +95,7 @@ func (keyPairHandler *AlibabaKeyPairHandler) CreateKey(keyPairReqInfo irs.KeyPai cblogger.Error(err) return irs.KeyPairInfo{}, err } - + */ request := ecs.CreateCreateKeyPairRequest() request.Scheme = "https" @@ -139,6 +130,7 @@ func (keyPairHandler *AlibabaKeyPairHandler) CreateKey(keyPairReqInfo irs.KeyPai cblogger.Infof("Created key pair %q %s\n%s\n", result.KeyPairName, result.KeyPairFingerPrint, result.PrivateKeyBody) spew.Dump(result) + /* 2021-10-27 이슈#480에 의해 Local Key 로직 제거 cblogger.Info("공개키 생성") publicKey, errPub := keypair.MakePublicKeyFromPrivateKey(result.PrivateKeyBody) if errPub != nil { @@ -148,17 +140,18 @@ func (keyPairHandler *AlibabaKeyPairHandler) CreateKey(keyPairReqInfo irs.KeyPai cblogger.Infof("Public Key") spew.Dump(publicKey) - + */ keyPairInfo := irs.KeyPairInfo{ IId: irs.IID{NameId: result.KeyPairName, SystemId: result.KeyPairName}, Fingerprint: result.KeyPairFingerPrint, PrivateKey: result.PrivateKeyBody, - PublicKey: publicKey, + //PublicKey: publicKey, KeyValueList: []irs.KeyValue{ {Key: "KeyMaterial", Value: result.PrivateKeyBody}, }, } + /* 2021-10-27 이슈#480에 의해 Local Key 로직 제거 hashString := strings.ReplaceAll(keyPairInfo.Fingerprint, ":", "") // 필요한 경우 리전 정보 추가하면 될 듯. 나중에 키 이름과 리전으로 암복호화를 진행하면 될 것같음. savePrivateFileTo := keyPairPath + hashString + ".pem" savePublicFileTo := keyPairPath + hashString + ".pub" @@ -177,15 +170,17 @@ func (keyPairHandler *AlibabaKeyPairHandler) CreateKey(keyPairReqInfo irs.KeyPai if err != nil { return irs.KeyPairInfo{}, err } - + */ return keyPairInfo, nil } +// 2021-10-27 이슈#480에 의해 Local Key 로직 제거 // 혼선을 피하기 위해 keyPairID 대신 keyPairName으로 변경 함. func (keyPairHandler *AlibabaKeyPairHandler) GetKey(keyIID irs.IID) (irs.KeyPairInfo, error) { //keyPairID := keyPairName cblogger.Infof("GetKey(keyPairName) : [%s]", keyIID.SystemId) + /* 2021-10-27 이슈#480에 의해 Local Key 로직 제거 keyPairPath := os.Getenv("CBSPIDER_ROOT") + CBKeyPairPath cblogger.Infof("Getenv[CBSPIDER_ROOT] : [%s]", os.Getenv("CBSPIDER_ROOT")) cblogger.Infof("CBKeyPairPath : [%s]", CBKeyPairPath) @@ -195,6 +190,7 @@ func (keyPairHandler *AlibabaKeyPairHandler) GetKey(keyIID irs.IID) (irs.KeyPair cblogger.Error(err) return irs.KeyPairInfo{}, err } + */ request := ecs.CreateDescribeKeyPairsRequest() request.Scheme = "https" @@ -240,6 +236,7 @@ func (keyPairHandler *AlibabaKeyPairHandler) GetKey(keyIID irs.IID) (irs.KeyPair return keyPairInfo, nil } +// 2021-10-27 이슈#480에 의해 Local Key 로직 제거 // KeyPair 정보를 추출함 func ExtractKeyPairDescribeInfo(keyPair *ecs.KeyPair) (irs.KeyPairInfo, error) { spew.Dump(keyPair) @@ -249,6 +246,7 @@ func ExtractKeyPairDescribeInfo(keyPair *ecs.KeyPair) (irs.KeyPairInfo, error) { Fingerprint: keyPair.KeyPairFingerPrint, } + /* 2021-10-27 이슈#480에 의해 Local Key 로직 제거 // Local Keyfile 처리 keyPairPath := os.Getenv("CBSPIDER_ROOT") + CBKeyPairPath hashString := strings.ReplaceAll(keyPairInfo.Fingerprint, ":", "") // 필요한 경우 리전 정보 추가하면 될 듯. 나중에 키 이름과 리전으로 암복호화를 진행하면 될 것같음. @@ -274,7 +272,7 @@ func ExtractKeyPairDescribeInfo(keyPair *ecs.KeyPair) (irs.KeyPairInfo, error) { keyPairInfo.PublicKey = string(publicKeyBytes) keyPairInfo.PrivateKey = string(privateKeyBytes) - + */ keyValueList := []irs.KeyValue{ //{Key: "ResourceGroupId", Value: keyPair.ResourceGroupId}, {Key: "CreationTime", Value: keyPair.CreationTime}, @@ -285,12 +283,13 @@ func ExtractKeyPairDescribeInfo(keyPair *ecs.KeyPair) (irs.KeyPairInfo, error) { return keyPairInfo, nil } +// 2021-10-27 이슈#480에 의해 Local Key 로직 제거 func (keyPairHandler *AlibabaKeyPairHandler) DeleteKey(keyIID irs.IID) (bool, error) { cblogger.Infof("DeleteKey(KeyPairName) : [%s]", keyIID.SystemId) // Delete the key pair by name //없는 키도 무조건 성공하기 때문에 미리 조회함. - keyPairInfo, errKey := keyPairHandler.GetKey(keyIID) + _, errKey := keyPairHandler.GetKey(keyIID) if errKey != nil { cblogger.Errorf("[%s] KeyPair Delete fail", keyIID.SystemId) cblogger.Error(errKey) @@ -331,6 +330,7 @@ func (keyPairHandler *AlibabaKeyPairHandler) DeleteKey(keyIID irs.IID) (bool, er cblogger.Info(result) cblogger.Infof("Successfully deleted %q Alibaba Cloud key pair\n", keyIID.SystemId) + /* 2021-10-27 이슈#480에 의해 Local Key 로직 제거 //==================== // Local Keyfile 처리 //==================== @@ -352,7 +352,7 @@ func (keyPairHandler *AlibabaKeyPairHandler) DeleteKey(keyIID irs.IID) (bool, er if err != nil { return false, err } - + */ return true, nil } diff --git a/cloud-control-manager/cloud-driver/drivers/tencent/main/Test_Resources.go b/cloud-control-manager/cloud-driver/drivers/tencent/main/Test_Resources.go index 2b8cc75fe..a26101774 100644 --- a/cloud-control-manager/cloud-driver/drivers/tencent/main/Test_Resources.go +++ b/cloud-control-manager/cloud-driver/drivers/tencent/main/Test_Resources.go @@ -767,8 +767,8 @@ func main() { //handleVMSpec() //handleSecurity() //handleImage() //AMI - //handleKeyPair() - handleVM() + handleKeyPair() + //handleVM() //handlePublicIP() // PublicIP 생성 후 conf //handleVNic() //Lancard diff --git a/cloud-control-manager/cloud-driver/drivers/tencent/resources/CommonTencentFunc.go b/cloud-control-manager/cloud-driver/drivers/tencent/resources/CommonTencentFunc.go index 971a9a42d..fd89364f7 100644 --- a/cloud-control-manager/cloud-driver/drivers/tencent/resources/CommonTencentFunc.go +++ b/cloud-control-manager/cloud-driver/drivers/tencent/resources/CommonTencentFunc.go @@ -28,7 +28,8 @@ const CBDefaultVNetName string = "CB-VNet" // CB Default Virtual Networ const CBDefaultSubnetName string = "CB-VNet-Subnet" // CB Default Subnet Name const CBDefaultCidrBlock string = "192.168.0.0/16" // CB Default CidrBlock -const CBKeyPairPath string = "/meta_db/.ssh-tencent/" +// 2021-10-27 이슈#480에 의해 Local Key 로직 제거 +//const CBKeyPairPath string = "/meta_db/.ssh-tencent/" const CBCloudInitFilePath string = "/cloud-driver-libs/.cloud-init-tencent/cloud-init" const CBDefaultVmUserName string = "cb-user" // default VM User Name diff --git a/cloud-control-manager/cloud-driver/drivers/tencent/resources/KeyPairHandler.go b/cloud-control-manager/cloud-driver/drivers/tencent/resources/KeyPairHandler.go index 6ef1a261b..65454433e 100644 --- a/cloud-control-manager/cloud-driver/drivers/tencent/resources/KeyPairHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/tencent/resources/KeyPairHandler.go @@ -1,17 +1,9 @@ package resources import ( - "crypto/md5" "errors" - "fmt" - "io" - "io/ioutil" - "log" - "os" - "strings" call "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/call-log" - keypair "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/common" idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces" irs "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/resources" "github.com/davecgh/go-spew/spew" @@ -61,7 +53,8 @@ func (keyPairHandler *TencentKeyPairHandler) ListKey() ([]*irs.KeyPairInfo, erro for _, pair := range response.Response.KeyPairSet { keyPairInfo, errKeyPair := ExtractKeyPairDescribeInfo(pair) if errKeyPair != nil { - cblogger.Infof("[%s] KeyPair는 Local에서 관리하는 대상이 아니기 때문에 Skip합니다.", *pair.KeyName) + // 2021-10-27 이슈#480에 의해 Local Key 로직 제거 + //cblogger.Infof("[%s] KeyPair는 Local에서 관리하는 대상이 아니기 때문에 Skip합니다.", *pair.KeyName) cblogger.Info(errKeyPair.Error()) //return nil, errKeyPair } else { @@ -72,6 +65,7 @@ func (keyPairHandler *TencentKeyPairHandler) ListKey() ([]*irs.KeyPairInfo, erro return keyPairList, nil } +// 2021-10-27 이슈#480에 의해 Local Key 로직 제거 //KeyPair 정보를 추출함 func ExtractKeyPairDescribeInfo(keyPair *cvm.KeyPair) (irs.KeyPairInfo, error) { spew.Dump(keyPair) @@ -87,6 +81,7 @@ func ExtractKeyPairDescribeInfo(keyPair *cvm.KeyPair) (irs.KeyPairInfo, error) { // } //조회 용도 + /* 2021-10-27 이슈#480에 의해 Local Key 로직 제거 // Local Keyfile 처리 keyPairPath := os.Getenv("CBSPIDER_ROOT") + CBKeyPairPath hashString := strings.ReplaceAll(*keyPair.KeyId, ":", "") // 필요한 경우 리전 정보 추가하면 될 듯. 나중에 키 이름과 리전으로 암복호화를 진행하면 될 것같음. @@ -113,7 +108,7 @@ func ExtractKeyPairDescribeInfo(keyPair *cvm.KeyPair) (irs.KeyPairInfo, error) { keyPairInfo.PublicKey = string(publicKeyBytes) keyPairInfo.PrivateKey = string(privateKeyBytes) - + */ keyValueList := []irs.KeyValue{ {Key: "KeyId", Value: *keyPair.KeyId}, //{Key: "KeyMaterial", Value: *keyPair.KeyMaterial}, @@ -124,6 +119,7 @@ func ExtractKeyPairDescribeInfo(keyPair *cvm.KeyPair) (irs.KeyPairInfo, error) { return keyPairInfo, nil } +// 2021-10-27 이슈#480에 의해 Local Key 로직 제거 //KeyPair 생성시 이름은 알파벳, 숫자 또는 밑줄 "_"만 지원 func (keyPairHandler *TencentKeyPairHandler) CreateKey(keyPairReqInfo irs.KeyPairReqInfo) (irs.KeyPairInfo, error) { cblogger.Info(keyPairReqInfo) @@ -140,6 +136,7 @@ func (keyPairHandler *TencentKeyPairHandler) CreateKey(keyPairReqInfo irs.KeyPai return irs.KeyPairInfo{}, errors.New("A keyPair with the name " + keyPairReqInfo.IId.NameId + " already exists.") } + /* 2021-10-27 이슈#480에 의해 Local Key 로직 제거 keyPairPath := os.Getenv("CBSPIDER_ROOT") + CBKeyPairPath cblogger.Infof("Getenv[CBSPIDER_ROOT] : [%s]", os.Getenv("CBSPIDER_ROOT")) cblogger.Infof("CBKeyPairPath : [%s]", CBKeyPairPath) @@ -149,6 +146,7 @@ func (keyPairHandler *TencentKeyPairHandler) CreateKey(keyPairReqInfo irs.KeyPai cblogger.Error(err) return irs.KeyPairInfo{}, err } + */ // logger for HisCall callogger := call.GetLogger("HISCALL") @@ -195,6 +193,7 @@ func (keyPairHandler *TencentKeyPairHandler) CreateKey(keyPairReqInfo irs.KeyPai //spew.Dump(keyPairInfo) + /* 2021-10-27 이슈#480에 의해 Local Key 로직 제거 //============================= // 키 페어를 로컬 파일에 기록 함. //============================= @@ -216,7 +215,7 @@ func (keyPairHandler *TencentKeyPairHandler) CreateKey(keyPairReqInfo irs.KeyPai if err != nil { return irs.KeyPairInfo{}, err } - + */ return keyPairInfo, nil } @@ -246,10 +245,12 @@ func (keyPairHandler *TencentKeyPairHandler) isExist(chkName string) (bool, erro return true, nil } +// 2021-10-27 이슈#480에 의해 Local Key 로직 제거 func (keyPairHandler *TencentKeyPairHandler) GetKey(keyIID irs.IID) (irs.KeyPairInfo, error) { //keyPairID := keyName cblogger.Infof("keyName : [%s]", keyIID.SystemId) + /* 2021-10-27 이슈#480에 의해 Local Key 로직 제거 keyPairPath := os.Getenv("CBSPIDER_ROOT") + CBKeyPairPath cblogger.Infof("Getenv[CBSPIDER_ROOT] : [%s]", os.Getenv("CBSPIDER_ROOT")) cblogger.Infof("CBKeyPairPath : [%s]", CBKeyPairPath) @@ -259,6 +260,7 @@ func (keyPairHandler *TencentKeyPairHandler) GetKey(keyIID irs.IID) (irs.KeyPair cblogger.Error(err) return irs.KeyPairInfo{}, err } + */ // logger for HisCall callogger := call.GetLogger("HISCALL") @@ -304,6 +306,7 @@ func (keyPairHandler *TencentKeyPairHandler) GetKey(keyIID irs.IID) (irs.KeyPair } } +/* 2021-10-27 이슈#480에 의해 Local Key 로직 제거 //Tencent의 경우 FingerPrint같은 고유 값을 조회할 수 없기 때문에 KeyId를 로컬 파일의 고유 키 값으로 이용함. func (keyPairHandler *TencentKeyPairHandler) GetLocalKeyId(keyIID irs.IID) (string, error) { //삭제할 Local Keyfile을 찾기 위해 조회 @@ -321,14 +324,18 @@ func (keyPairHandler *TencentKeyPairHandler) GetLocalKeyId(keyIID irs.IID) (stri return "", errors.New("InvalidKeyPair.NotFound: The KeyPair " + keyIID.SystemId + " does not exist") } } +*/ +// 2021-10-27 이슈#480에 의해 Local Key 로직 제거 func (keyPairHandler *TencentKeyPairHandler) DeleteKey(keyIID irs.IID) (bool, error) { cblogger.Infof("삭제 요청된 키페어 : [%s]", keyIID.SystemId) + /* 2021-10-27 이슈#480에 의해 Local Key 로직 제거 keyPairId, errGet := keyPairHandler.GetLocalKeyId(keyIID) if errGet != nil { return false, errGet } + */ // logger for HisCall callogger := call.GetLogger("HISCALL") @@ -360,6 +367,7 @@ func (keyPairHandler *TencentKeyPairHandler) DeleteKey(keyIID irs.IID) (bool, er cblogger.Debug(response.ToJsonString()) callogger.Info(call.String(callLogInfo)) + /* 2021-10-27 이슈#480에 의해 Local Key 로직 제거 //==================== // Local Keyfile 처리 //==================== @@ -381,10 +389,12 @@ func (keyPairHandler *TencentKeyPairHandler) DeleteKey(keyIID irs.IID) (bool, er if err != nil { return false, err } + */ return true, nil } +/* 2021-10-27 이슈#480에 의해 Local Key 로직 제거 //================================= // 공개 키 변환 및 키 정보 로컬 보관 로직 추가 //================================= @@ -422,3 +432,4 @@ func CreateHashString(credentialInfo idrv.CredentialInfo, Region idrv.RegionInfo } return fmt.Sprintf("%x", hasher.Sum(nil)), nil } +*/