acelyc111 commented on code in PR #1360: URL: https://github.com/apache/incubator-pegasus/pull/1360#discussion_r1118250747
########## src/runtime/ranger/ranger_resource_policy.cpp: ########## @@ -0,0 +1,79 @@ +// 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 "ranger_resource_policy.h" + +namespace dsn { +namespace ranger { + +bool policy_item::match(const access_type &ac_type, const std::string &user_name) const +{ + return (access_types & ac_type) != 0 && users.count(user_name) != 0; +} + +bool acl_policies::allowed(const access_type &ac_type, const std::string &user_name) const +{ + // 1. Check if it is not allowed. + for (const auto &deny_policy : deny_policies) { + // 1.1. In 'deny_policies'. + if (!deny_policy.match(ac_type, user_name)) { + continue; + } + bool in_deny_policies_exclude = false; + for (const auto &deny_policy_exclude : deny_policies_exclude) { + if (deny_policy_exclude.match(ac_type, user_name)) { + in_deny_policies_exclude = true; + break; + } + } + // 1.2. Not in any 'deny_policies_exclude', it's not allowed. + if (!in_deny_policies_exclude) { + return false; + } + } + + // 2. Check if it is allowed. + for (const auto &allow_policy : allow_policies) { + // 2.1. In 'allow_policies'. + if (!allow_policy.match(ac_type, user_name)) { + continue; + } + for (const auto &allow_policy_exclude : allow_policies_exclude) { + // 2.2. In some 'allow_policies_exclude', it's not allowed. + if (allow_policy_exclude.match(ac_type, user_name)) { + return false; + } + } + // 2.3. Not in any 'allow_policies_exclude', it's allowed. + return true; + } + + // 3. Otherwise, it's not allowed. + return false; +} + +void ranger_resource_policy::create_default_database_policy(ranger_resource_policy &acl) +{ + acl.name = "default database policy"; + acl.database_names = {"*"}; + policy_item item; + item.access_types = CREATE | DROP | LIST | METADATA | CONTROL; Review Comment: miss READ and WRITE? -- 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]
