acelyc111 commented on code in PR #1706:
URL: 
https://github.com/apache/incubator-pegasus/pull/1706#discussion_r1431148848


##########
src/runtime/security/replica_kms_info.h:
##########
@@ -0,0 +1,63 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2015 Microsoft Corporation
+ *
+ * -=- Robust Distributed System Nucleus (rDSN) -=-
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#pragma once
+
+#include <string>
+
+#include "common/json_helper.h"
+#include "utils/error_code.h"
+#include "utils/ports.h"
+
+namespace dsn {
+namespace replication {
+
+class replica_kms_info
+{
+public:
+    std::string encryption_key;
+    std::string iv;
+    std::string key_version;
+    DEFINE_JSON_SERIALIZATION(encryption_key, iv, key_version)
+    static const std::string kKmsInfo;
+
+public:
+    replica_kms_info(const std::string &e_key = "",
+                     const std::string &i = "",
+                     const std::string &k_version = "")
+        : encryption_key(e_key), iv(i), key_version(k_version)
+    {
+    }
+    error_code load(const std::string &dir) WARN_UNUSED_RESULT;
+    error_code store(const std::string &dir);
+
+private:
+    error_code load_json(const std::string &fname);
+    error_code store_json(const std::string &fname);
+};
+
+} // namespace replication
+} // namespace dsn

Review Comment:
   Add a blank line at the end.



##########
src/runtime/security/replica_kms_info.h:
##########
@@ -0,0 +1,63 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2015 Microsoft Corporation
+ *
+ * -=- Robust Distributed System Nucleus (rDSN) -=-
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#pragma once
+
+#include <string>
+
+#include "common/json_helper.h"
+#include "utils/error_code.h"
+#include "utils/ports.h"
+
+namespace dsn {
+namespace replication {
+
+class replica_kms_info

Review Comment:
   It's needed to add comments to all newly added class.



##########
src/replica/default_key_provider.h:
##########
@@ -0,0 +1,87 @@
+// 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 <openssl/rand.h>
+
+#include "absl/strings/escaping.h"
+#include "replica/key_provider.h"
+#include "utils/error_code.h"
+#include "utils/fmt_logging.h"
+
+namespace dsn {
+namespace security {
+
+class DefaultKeyProvider : public KeyProvider

Review Comment:
   Add some comments about its usage.



##########
src/runtime/security/replica_kms_info.h:
##########
@@ -0,0 +1,63 @@
+/*

Review Comment:
   Use Apache license.



##########
src/runtime/security/replica_kms_info.h:
##########
@@ -0,0 +1,63 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2015 Microsoft Corporation
+ *
+ * -=- Robust Distributed System Nucleus (rDSN) -=-
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#pragma once
+
+#include <string>
+
+#include "common/json_helper.h"
+#include "utils/error_code.h"
+#include "utils/ports.h"
+
+namespace dsn {
+namespace replication {
+
+class replica_kms_info
+{
+public:
+    std::string encryption_key;
+    std::string iv;
+    std::string key_version;

Review Comment:
   Is the iv and key_version actually used? Add some comments if not.



##########
src/runtime/security/kms_client.h:
##########
@@ -0,0 +1,72 @@
+// 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 "absl/strings/str_split.h"
+#include "utils/errors.h"
+
+namespace dsn {
+namespace security {
+// A class to generate encryption_key from kms for writing file which 
implemented based on http
+// client

Review Comment:
   Add a dot at the end of a sentence.



##########
src/runtime/security/replica_kms_info.h:
##########
@@ -0,0 +1,63 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2015 Microsoft Corporation
+ *
+ * -=- Robust Distributed System Nucleus (rDSN) -=-
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#pragma once
+
+#include <string>
+
+#include "common/json_helper.h"
+#include "utils/error_code.h"
+#include "utils/ports.h"
+
+namespace dsn {
+namespace replication {
+
+class replica_kms_info
+{
+public:
+    std::string encryption_key;

Review Comment:
   Is the key encrypted? add some comments please.



##########
src/runtime/security/kms_client.h:
##########
@@ -0,0 +1,72 @@
+// 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 "absl/strings/str_split.h"
+#include "utils/errors.h"
+
+namespace dsn {
+namespace security {
+// A class to generate encryption_key from kms for writing file which 
implemented based on http
+// client
+// This class is not thread-safe. Thus maintain one instance for each thread.
+//
+// Example of using Kms client:
+// --------------------------------------------------------
+// Generate and get the Encrypted Encryption Key(eek),Initialization 
Vector(iv),Key Version from
+// kms:
+// std::string encryption_key;
+// std::string iv;
+// std::string key_version;
+// err = GenerateEncryptionKey(key_name, &encryption_key, &iv, &key_version);
+//
+// Get the Decrypted Encryption Key(dek) back from kms. The eek,iv,kv need 
generated from kms:
+// std::string decryption_key;
+// err = DecryptEncryptionKey(encryption_key, iv, key_version, &decrypted_key);

Review Comment:
   This is not necessary, instead, you can add commentd for the two functions.



##########
src/replica/replication_app_base.h:
##########
@@ -83,6 +84,21 @@ error_code write_blob_to_file(const std::string &fname,
                             fname);
     return ERR_OK;
 }
+
+template <typename T, dsn::utils::FileDataType FileType>
+error_code load_json_generic(const std::string &fname, T &object)

Review Comment:
   This refactor is not enough, it is just called by itself?



##########
src/runtime/security/replica_kms_info.h:
##########
@@ -0,0 +1,63 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2015 Microsoft Corporation
+ *
+ * -=- Robust Distributed System Nucleus (rDSN) -=-
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#pragma once
+
+#include <string>
+
+#include "common/json_helper.h"
+#include "utils/error_code.h"
+#include "utils/ports.h"
+
+namespace dsn {
+namespace replication {
+
+class replica_kms_info
+{
+public:
+    std::string encryption_key;
+    std::string iv;
+    std::string key_version;
+    DEFINE_JSON_SERIALIZATION(encryption_key, iv, key_version)
+    static const std::string kKmsInfo;
+
+public:
+    replica_kms_info(const std::string &e_key = "",
+                     const std::string &i = "",
+                     const std::string &k_version = "")
+        : encryption_key(e_key), iv(i), key_version(k_version)
+    {
+    }
+    error_code load(const std::string &dir) WARN_UNUSED_RESULT;
+    error_code store(const std::string &dir);
+
+private:
+    error_code load_json(const std::string &fname);
+    error_code store_json(const std::string &fname);

Review Comment:
   The two functions are not necesary IMO, there is only one line in it.



##########
src/replica/replica_stub.cpp:
##########
@@ -272,6 +282,16 @@ DSN_DEFINE_uint32(
     "The interval milliseconds of replica server to syncs replica 
configuration with meta server");
 DSN_TAG_VARIABLE(config_sync_interval_ms, FT_MUTABLE);
 DSN_DEFINE_validator(config_sync_interval_ms, [](uint32_t value) -> bool { 
return value > 0; });
+DSN_DEFINE_group_validator(encrypt_data_at_rest, [](std::string &message) -> 
bool {
+    if (!dsn::security::FLAGS_enable_acl || !FLAGS_encrypt_data_at_rest) {
+        message = fmt::format("FLAGS_enable_acl = ({}) 
FLAGS_encrypt_data_at_rest = ({}),should be "

Review Comment:
   Use the identify in the config file (i.e. `[security] enable_acl`) would be 
more readablity for Pegasus users, they don't know what does FLAGS_xxx mean.



##########
src/replica/replica_stub.cpp:
##########
@@ -178,6 +182,14 @@ DSN_DEFINE_int32(
     10,
     "if tcmalloc reserved but not-used memory exceed this percentage of 
application allocated "
     "memory, replica server will release the exceeding memory back to 
operating system");
+DSN_DEFINE_string(pegasus.server,
+                  encryption_cluster_key_name,
+                  "pegasus",
+                  "The cluster name of encrypted server which use to get 
server key from kms.");
+DSN_DEFINE_string(pegasus.server,
+                  hadoop_kms_url,
+                  "",
+                  "Where the server encrypted key of file system can get 
from.");

Review Comment:
   Didn't update?



##########
src/runtime/security/kms_client.h:
##########
@@ -0,0 +1,72 @@
+// 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 "absl/strings/str_split.h"
+#include "utils/errors.h"
+
+namespace dsn {
+namespace security {
+// A class to generate encryption_key from kms for writing file which 
implemented based on http
+// client
+// This class is not thread-safe. Thus maintain one instance for each thread.
+//
+// Example of using Kms client:
+// --------------------------------------------------------
+// Generate and get the Encrypted Encryption Key(eek),Initialization 
Vector(iv),Key Version from
+// kms:
+// std::string encryption_key;
+// std::string iv;
+// std::string key_version;
+// err = GenerateEncryptionKey(key_name, &encryption_key, &iv, &key_version);
+//
+// Get the Decrypted Encryption Key(dek) back from kms. The eek,iv,kv need 
generated from kms:
+// std::string decryption_key;
+// err = DecryptEncryptionKey(encryption_key, iv, key_version, &decrypted_key);
+class KMSClient
+{
+public:
+    KMSClient(const std::string kms_url, std::string cluster_key_name)
+        : kms_urls_(::absl::StrSplit(kms_url, ",", ::absl::SkipEmpty())),

Review Comment:
   Avoid to call functions in initialize list, you can call the StrSplit when 
construct KMSClient objects.



##########
src/replica/replica_stub.cpp:
##########
@@ -272,6 +282,16 @@ DSN_DEFINE_uint32(
     "The interval milliseconds of replica server to syncs replica 
configuration with meta server");
 DSN_TAG_VARIABLE(config_sync_interval_ms, FT_MUTABLE);
 DSN_DEFINE_validator(config_sync_interval_ms, [](uint32_t value) -> bool { 
return value > 0; });
+DSN_DEFINE_group_validator(encrypt_data_at_rest, [](std::string &message) -> 
bool {
+    if (!dsn::security::FLAGS_enable_acl || !FLAGS_encrypt_data_at_rest) {

Review Comment:
   The condituon is incorrect?



##########
src/runtime/security/replica_kms_info.cpp:
##########
@@ -0,0 +1,85 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2015 Microsoft Corporation
+ *
+ * -=- Robust Distributed System Nucleus (rDSN) -=-
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#pragma GCC diagnostic ignored "-Wclass-memaccess"
+#include <stdint.h>
+
+#include "replica/replication_app_base.h"
+#include "runtime/api_layer1.h"
+#include "runtime/security/replica_kms_info.h"
+#include "utils/blob.h"
+#include "utils/env.h"
+#include "utils/filesystem.h"
+#include "utils/fmt_logging.h"
+
+namespace dsn {
+
+namespace replication {
+
+const std::string replica_kms_info::kKmsInfo = ".kms-info";
+
+error_code replica_kms_info::load(const std::string &dir)

Review Comment:
   It's duplicate with replication_app_base.cpp, you can do a refactor at first.



-- 
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]

Reply via email to