empiredan commented on code in PR #1706: URL: https://github.com/apache/incubator-pegasus/pull/1706#discussion_r1472824343
########## src/replica/kms_key_provider.h: ########## @@ -0,0 +1,56 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <string> +#include <utility> +#include <vector> + +#include "security/kms_client.h" +#include "utils/errors.h" + +namespace dsn { +namespace replication { +struct kms_info; +} // namespace replication + +namespace security { +// This class generates EEK IV KV from KMS (a.k.a Key Management Service) and retrieves DEK from +// KMS. +class KMSKeyProvider +{ +public: + ~KMSKeyProvider() {} + + KMSKeyProvider(const std::vector<std::string> &kms_url, std::string cluster_key_name) + : client_(kms_url, std::move(cluster_key_name)) + { + } + + // Decrypt the encryption key in 'kms_info' via KMS. The 'decrypted_key' will be a hex string. + dsn::error_s DecryptEncryptionKey(const dsn::replication::kms_info &kms_info, + std::string *decrypted_key); + + // Generate an encryption key from KMS. + dsn::error_s GenerateEncryptionKey(dsn::replication::kms_info *kms_info); + +private: + KMSClient client_; Review Comment: ```suggestion KMSClient _client; ``` ########## src/security/kms_client.h: ########## @@ -0,0 +1,59 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <algorithm> +#include <string> +#include <utility> +#include <vector> + +#include "utils/errors.h" + +namespace dsn { +namespace replication { +struct kms_info; +} // namespace replication + +namespace security { +// A class designed to generate an encryption key from KMS for file writing, +// implemented using an HTTP client. +// This class is not thread-safe. Thus maintain one instance for each thread. +class KMSClient +{ +public: + KMSClient(const std::vector<std::string> &kms_url, std::string cluster_key_name) + : kms_urls_(kms_url), cluster_key_name_(std::move(cluster_key_name)) + { + } + + // Retrieve the Decrypted Encryption Key (DEK) from KMS after generating the EEK, IV, and KV. + dsn::error_s DecryptEncryptionKey(const dsn::replication::kms_info &kms_info, + std::string *decrypted_key); + + // Generated the EEK, IV, KV from KMS. + dsn::error_s GenerateEncryptionKey(dsn::replication::kms_info *kms_info); + +private: + dsn::error_s GenerateEncryptionKeyFromKMS(const std::string &key_name, + dsn::replication::kms_info *kms_info); + + std::vector<std::string> kms_urls_; + std::string cluster_key_name_; Review Comment: ```suggestion std::vector<std::string> _kms_urls; std::string _cluster_key_name; ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
