Skip to content

Commit

Permalink
Use Apache Ranger for access control
Browse files Browse the repository at this point in the history
  • Loading branch information
wh002 committed Feb 21, 2023
1 parent 4c76112 commit 3fbc129
Show file tree
Hide file tree
Showing 50 changed files with 1,731 additions and 221 deletions.
21 changes: 21 additions & 0 deletions src/common/json_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <string>
#include <type_traits>
Expand Down Expand Up @@ -493,6 +494,26 @@ inline bool json_decode(const JsonObject &in, std::set<T> &t)
return true;
}

template <typename T1, typename T2>
inline void json_encode(JsonWriter &out, const std::unordered_set<T1, T2> &t)
{
json_encode_iterable(out, t);
}

template <typename T1, typename T2>
inline bool json_decode(const JsonObject &in, std::unordered_set<T1, T2> &t)
{
dverify(in.IsArray());
t.clear();

for (rapidjson::Value::ConstValueIterator it = in.Begin(); it != in.End(); ++it) {
T1 value;
dverify(json_forwarder<T1>::decode(*it, value));
dverify(t.emplace(std::move(value)).second);
}
return true;
}

template <typename T1, typename T2>
inline void json_encode(JsonWriter &out, const std::unordered_map<T1, T2> &t)
{
Expand Down
1 change: 1 addition & 0 deletions src/common/replica_envs.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class replica_envs
static const std::string MANUAL_COMPACT_PERIODIC_BOTTOMMOST_LEVEL_COMPACTION;
static const std::string BUSINESS_INFO;
static const std::string REPLICA_ACCESS_CONTROLLER_ALLOWED_USERS;
static const std::string REPLICA_ACCESS_CONTROLLER_RANGER_POLICIES;
static const std::string READ_QPS_THROTTLING;
static const std::string READ_SIZE_THROTTLING;
static const std::string BACKUP_REQUEST_QPS_THROTTLING;
Expand Down
1 change: 1 addition & 0 deletions src/common/replication.codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ MAKE_EVENT_CODE_RPC(RPC_CM_START_MANUAL_COMPACT, TASK_PRIORITY_COMMON)
MAKE_EVENT_CODE_RPC(RPC_CM_QUERY_MANUAL_COMPACT_STATUS, TASK_PRIORITY_COMMON)
MAKE_EVENT_CODE_RPC(RPC_CM_GET_MAX_REPLICA_COUNT, TASK_PRIORITY_COMMON)
MAKE_EVENT_CODE_RPC(RPC_CM_SET_MAX_REPLICA_COUNT, TASK_PRIORITY_COMMON)
MAKE_EVENT_CODE(LPC_CM_GET_RANGER_POLICY, TASK_PRIORITY_COMMON)
#undef CURRENT_THREAD_POOL

#define CURRENT_THREAD_POOL THREAD_POOL_META_STATE
Expand Down
2 changes: 2 additions & 0 deletions src/common/replication_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,8 @@ const std::string replica_envs::ROCKSDB_BLOCK_CACHE_ENABLED("replica.rocksdb_blo
const std::string replica_envs::BUSINESS_INFO("business.info");
const std::string replica_envs::REPLICA_ACCESS_CONTROLLER_ALLOWED_USERS(
"replica_access_controller.allowed_users");
const std::string replica_envs::REPLICA_ACCESS_CONTROLLER_RANGER_POLICIES(
"replica_access_controller.ranger_policies");
const std::string replica_envs::READ_QPS_THROTTLING("replica.read_throttling");
const std::string replica_envs::READ_SIZE_THROTTLING("replica.read_throttling_by_size");
const std::string
Expand Down
3 changes: 2 additions & 1 deletion src/meta/app_env_validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ void app_env_validator::register_all_validators()
{replica_envs::MANUAL_COMPACT_PERIODIC_TRIGGER_TIME, nullptr},
{replica_envs::MANUAL_COMPACT_PERIODIC_TARGET_LEVEL, nullptr},
{replica_envs::MANUAL_COMPACT_PERIODIC_BOTTOMMOST_LEVEL_COMPACTION, nullptr},
{replica_envs::REPLICA_ACCESS_CONTROLLER_ALLOWED_USERS, nullptr}};
{replica_envs::REPLICA_ACCESS_CONTROLLER_ALLOWED_USERS, nullptr},
{replica_envs::REPLICA_ACCESS_CONTROLLER_RANGER_POLICIES, nullptr}};
}

} // namespace replication
Expand Down
31 changes: 27 additions & 4 deletions src/meta/meta_backup_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@ void backup_service::add_backup_policy(dsn::message_ex *msg)
configuration_add_backup_policy_request request;
configuration_add_backup_policy_response response;

dsn::message_ex *copied_msg = message_ex::copy_message_no_reply(*msg);
::dsn::unmarshall(msg, request);
std::set<int32_t> app_ids;
std::map<int32_t, std::string> app_names;
Expand Down Expand Up @@ -1256,6 +1257,20 @@ void backup_service::add_backup_policy(dsn::message_ex *msg)
msg->release_ref();
return;
}
// when the Ranger ACL is enabled, access control will be checked for each table.
auto access_controller = _meta_svc->get_access_controller();
// adding multiple judgments here is to adapt to the old ACL and avoid checking again.
if (access_controller->is_enable_ranger_acl() &&
!access_controller->allowed(copied_msg, app->app_name)) {
response.err = ERR_ACL_DENY;
response.hint_message =
fmt::format("not authorized to add backup policy({}) for app id: {}",
request.policy_name,
app_id);
_meta_svc->reply_data(msg, response);
msg->release_ref();
return;
}
app_ids.insert(app_id);
app_names.insert(std::make_pair(app_id, app->app_name));
}
Expand Down Expand Up @@ -1486,16 +1501,24 @@ void backup_service::modify_backup_policy(configuration_modify_backup_policy_rpc

for (const auto &appid : request.add_appids) {
const auto &app = _state->get_app(appid);
auto access_controller = _meta_svc->get_access_controller();
// TODO: if app is dropped, how to process
if (app == nullptr) {
LOG_WARNING("{}: add app to policy failed, because invalid app({}), ignore it",
cur_policy.policy_name,
appid);
} else {
valid_app_ids_to_add.emplace_back(appid);
id_to_app_names.insert(std::make_pair(appid, app->app_name));
have_modify_policy = true;
continue;
}
if (access_controller->is_enable_ranger_acl() &&
!access_controller->allowed(rpc.dsn_request(), app->app_name)) {
LOG_WARNING("not authorized to modify backup policy({}) for app id: {}, skip it",
cur_policy.policy_name,
appid);
continue;
}
valid_app_ids_to_add.emplace_back(appid);
id_to_app_names.insert(std::make_pair(appid, app->app_name));
have_modify_policy = true;
}
}

Expand Down
Loading

0 comments on commit 3fbc129

Please sign in to comment.