empiredan commented on code in PR #1433:
URL: 
https://github.com/apache/incubator-pegasus/pull/1433#discussion_r1166815266


##########
src/runtime/security/replica_access_controller.cpp:
##########
@@ -62,10 +88,37 @@ void replica_access_controller::update_allowed_users(const 
std::string &users)
     utils::split_args(users.c_str(), users_set, ',');
     {
         utils::auto_write_lock l(_lock);
-        // This swap operation is in constant time
-        _users.swap(users_set);
+        _allowed_users.swap(users_set);
         _env_users = users;
+        check_allowed_users_valid();
+    }
+}
+
+void replica_access_controller::update_ranger_policies(const std::string 
&policies)
+{
+    {
+        utils::auto_read_lock l(_lock);
+        if (_env_policies == policies) {
+            return;
+        }
+    }
+    ranger::acl_policies tmp_policies;
+    std::string tmp_policies_str = policies;
+    dsn::json::json_forwarder<ranger::acl_policies>::decode(
+        dsn::blob::create_from_bytes(std::move(tmp_policies_str)), 
tmp_policies);
+    {
+        utils::auto_write_lock l(_lock);
+        _env_policies = policies;
+        _ranger_policies = std::move(tmp_policies);
     }
 }
+
+void replica_access_controller::check_allowed_users_valid()

Review Comment:
   ```suggestion
   void replica_access_controller::check_allowed_users_valid() const
   ```



##########
src/runtime/security/replica_access_controller.h:
##########
@@ -30,14 +32,39 @@ namespace security {
 class replica_access_controller : public access_controller
 {
 public:
-    explicit replica_access_controller(const std::string &name);
-    bool allowed(message_ex *msg) override;
+    explicit replica_access_controller(const std::string &replica_name);
+
+    // Check whether replica can be accessed, this method is compatible with 
ACL using
+    // '_allowed_users' and ACL using Ranger policy.
+    bool allowed(message_ex *msg, ranger::access_type req_type) override;
+
+    // Update '_allowed_users' when the 
app_env(REPLICA_ACCESS_CONTROLLER_ALLOWED_USERS) of the
+    // table changes
     void update_allowed_users(const std::string &users) override;
 
+    // Update '_ranger_policies' when the 
app_env(REPLICA_ACCESS_CONTROLLER_RANGER_POLICIES) of the
+    // table changes
+    void update_ranger_policies(const std::string &policies) override;
+
+private:
+    // Security check to avoid allowed_users is not empty in special scenarios.
+    void check_allowed_users_valid();

Review Comment:
   ```suggestion
       void check_allowed_users_valid() const;
   ```



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