Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RND-1603] NES ranger 인가 정책 연동에 특수 문자가 포함된 사용자 지원 추가 #45

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/pybind/mgr/objstore_usersync/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,13 +550,17 @@ def _enable_ranger_service(self, user_name, endpoint = {}):
endp_key = user_name if user_name in self.endpoint_map['ranger'] else '_default'
endpoint = self.endpoint_map['ranger'][endp_key]

resp, scode = self._request_ranger_rest("get", "/service/plugins/services/name/" + str(user_name), endpoint)
service_name = user_name
service_name = re.sub("@", "_at_", service_name)
service_name = re.sub("\.", "_dot_", service_name)

resp, scode = self._request_ranger_rest("get", "/service/plugins/services/name/" + str(service_name), endpoint)
is_success = (scode == 200 or scode == 404)
is_service_exist = (scode == 200)
is_service_enabled = (is_service_exist and resp['isEnabled'] == True)

if not is_success:
self.log.warning("Failed to get service of '%s'" % user_name)
self.log.warning("Failed to get service of '%s'" % service_name)
return is_success

service_endpoint = self.ranger_service_initial_endpoint
Expand All @@ -580,7 +584,7 @@ def _enable_ranger_service(self, user_name, endpoint = {}):

if not is_service_exist:
service_define_data = {
'name': s3_key_info['user'],
'name': service_name,
'type': 's3',
'description': "created by nes. " \
+ "If want to change initail endpoint, " \
Expand All @@ -602,7 +606,7 @@ def _enable_ranger_service(self, user_name, endpoint = {}):

owner_policy_data = {
'name': 'nes_default_policy',
'service': user_name,
'service': service_name,
'description': 'created by nes.',
'resources': {
'path': {
Expand All @@ -626,7 +630,7 @@ def _enable_ranger_service(self, user_name, endpoint = {}):
is_success = (scode == 200)

if not is_success:
self.log.warning("Failed to create default owner_policy of '%s'" % user_name)
self.log.warning("Failed to create default owner_policy of '%s'" % service_name)
return is_success

elif not is_service_enabled:
Expand Down Expand Up @@ -666,13 +670,17 @@ def _disable_ranger_service(self, user_name, endpoint = {}):
endp_key = user_name if user_name in self.endpoint_map['ranger'] else '_default'
endpoint = self.endpoint_map['ranger'][endp_key]

resp, scode = self._request_ranger_rest("get", "/service/plugins/services/name/" + str(user_name), endpoint)
service_name = user_name
service_name = re.sub("@", "_at_", service_name)
service_name = re.sub("\.", "_dot_", service_name)

resp, scode = self._request_ranger_rest("get", "/service/plugins/services/name/" + str(service_name), endpoint)
is_success = (scode == 200 or scode == 404)
is_service_exist = (scode == 200)
is_service_enabled = (is_service_exist and resp['isEnabled'] == True)

if not is_success:
self.log.warning("Failed to get s3 service of '%s'" % user_name)
self.log.warning("Failed to get s3 service of '%s'" % service_name)
return is_success

if is_service_enabled:
Expand All @@ -682,7 +690,7 @@ def _disable_ranger_service(self, user_name, endpoint = {}):
is_success = (scode == 200)

if not is_success:
self.log.warning("Failed to disable s3 service of '%s'" % user_name)
self.log.warning("Failed to disable s3 service of '%s'" % service_name)
return is_success

return is_success
Expand Down
9 changes: 9 additions & 0 deletions src/rgw/rgw_ranger.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "rgw_http_client.h"

#include <jni.h>
#include <regex>

#define dout_context g_ceph_context
#define dout_subsys ceph_subsys_rgw
Expand Down Expand Up @@ -118,6 +119,14 @@ class RGWRangerManager {
string policy_cache_dir;
time_t cache_update_interval;

string change_owner_to_svc_name(string owner_name) {
string svc_name = owner_name;
svc_name = regex_replace(svc_name, regex("@"), "_at_");
svc_name = regex_replace(svc_name, regex("\\."), "_dot_");
ldout(cct, 20) << __func__ << "(): owner '" << owner_name << "' refers the '" << svc_name << "' ranger service" << dendl;
return svc_name;
}

public:
RGWRangerManager(CephContext* const _cct) : cct(_cct) {
use_cached_one = cct->_conf->rgw_ranger_use_cached_one_if_not_cache_updating;
Expand Down
2 changes: 1 addition & 1 deletion src/rgw/rgw_ranger_jni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ int RGWRangerJniManager::is_access_allowed(RGWUserEndpoint endp, RGWOp *& op, re

rgw_user bucket_owner = s->bucket_owner.get_id();

string service_name = bucket_owner.to_str();
string service_name = change_owner_to_svc_name(bucket_owner.to_str());

if ( (use_cached_one && can_i_use_cached_policy(service_name)) \
|| (!is_connection_ok(endp)) )
Expand Down
3 changes: 1 addition & 2 deletions src/rgw/rgw_ranger_native.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "include/ipaddr.h"

#include <regex>
#include <fstream>

RGWRangerNativeManager* rgw_rnm = nullptr;
Expand Down Expand Up @@ -831,7 +830,7 @@ int RGWRangerNativeManager::is_access_allowed(RGWUserEndpoint endpoint, RGWOp *&
const string bucket_owner = s->bucket_owner.get_id().to_str();

vector<ranger_policy> related_policies;
int ret = get_related_policies(related_policies, endpoint, s, bucket_owner);
int ret = get_related_policies(related_policies, endpoint, s, change_owner_to_svc_name(bucket_owner));
if (ret != 0) {
ldpp_dout(op, 2) << __func__ << "(): Failed to get related policies" << dendl;
return ret;
Expand Down