-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(encryption): add key manager (#1706)
This patch implements KeyProvider to manage encryption key from KMS. The KeyProvider generates encryption key, IV and key version from KMS at the first launch of Replica Server. And stores them in a file in a shared directory. After then, the process posts them to KMS to decrypt key. The key is used to encrypt and decrypt data in Replica Server. A new config [pegasus.server]hadoop_kms_url has been introduced to provide the KMS URLs. ```diff [pegasus.server] + hadoop_kms_url = ```
- Loading branch information
Showing
73 changed files
with
928 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// 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. | ||
|
||
#include <string> | ||
|
||
#include "replica/kms_key_provider.h" | ||
#include "utils/errors.h" | ||
|
||
namespace dsn { | ||
namespace security { | ||
|
||
dsn::error_s kms_key_provider::DecryptEncryptionKey(const dsn::replication::kms_info &info, | ||
std::string *decrypted_key) | ||
{ | ||
return _client.DecryptEncryptionKey(info, decrypted_key); | ||
} | ||
|
||
dsn::error_s kms_key_provider::GenerateEncryptionKey(dsn::replication::kms_info *info) | ||
{ | ||
return _client.GenerateEncryptionKey(info); | ||
} | ||
|
||
} // namespace security | ||
} // namespace dsn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 kms_key_provider | ||
{ | ||
public: | ||
~kms_key_provider() {} | ||
|
||
kms_key_provider(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 &info, | ||
std::string *decrypted_key); | ||
|
||
// Generate an encryption key from KMS. | ||
dsn::error_s GenerateEncryptionKey(dsn::replication::kms_info *info); | ||
|
||
private: | ||
kms_client _client; | ||
}; | ||
} // namespace security | ||
} // namespace dsn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.