From 842f74a1cf43bdb3a86a3bf519e0016179b5ba06 Mon Sep 17 00:00:00 2001 From: Abhishek Lekshmanan Date: Mon, 31 Aug 2020 16:57:49 +0200 Subject: [PATCH] svc: role: implement get/put/delete Roles Signed-off-by: Abhishek Lekshmanan --- src/rgw/CMakeLists.txt | 1 + src/rgw/services/svc_role.cc | 21 +++++++++ src/rgw/services/svc_role.h | 30 ++++++++---- src/rgw/services/svc_role_rados.cc | 75 ++++++++++++++++++++++++++++++ src/rgw/services/svc_role_rados.h | 40 ++++++++++++---- 5 files changed, 148 insertions(+), 19 deletions(-) create mode 100644 src/rgw/services/svc_role.cc diff --git a/src/rgw/CMakeLists.txt b/src/rgw/CMakeLists.txt index e46dd5fa91c..79cf80a4beb 100644 --- a/src/rgw/CMakeLists.txt +++ b/src/rgw/CMakeLists.txt @@ -39,6 +39,7 @@ set(librgw_common_srcs services/svc_quota.cc services/svc_sync_modules.cc services/svc_rados.cc + services/svc_role.cc services/svc_role_rados.cc services/svc_sys_obj.cc services/svc_sys_obj_cache.cc diff --git a/src/rgw/services/svc_role.cc b/src/rgw/services/svc_role.cc new file mode 100644 index 00000000000..58bafd7785d --- /dev/null +++ b/src/rgw/services/svc_role.cc @@ -0,0 +1,21 @@ +#include "svc_role.h" + +const std::string role_name_oid_prefix = "role_names."; +const std::string role_oid_prefix = "roles."; +const std::string role_path_oid_prefix = "role_paths."; +const std::string role_arn_prefix = "arn:aws:iam::"; + +std::string RGWSI_Role::get_role_meta_key(const std::string& role_id) +{ + return role_oid_prefix + role_id; +} + +std::string RGWSI_Role::get_role_name_meta_key(const std::string& role_name, const std::string& tenant) +{ + return tenant + role_name_oid_prefix + role_name; +} + +std::string RGWSI_Role::get_role_path_meta_key(const std::string& path, const std::string& role_id, const std::string& tenant) +{ + return tenant + role_path_oid_prefix + path + role_oid_prefix + role_id; +} diff --git a/src/rgw/services/svc_role.h b/src/rgw/services/svc_role.h index c251c48d27e..74470b7f6fd 100644 --- a/src/rgw/services/svc_role.h +++ b/src/rgw/services/svc_role.h @@ -16,6 +16,7 @@ #pragma once #include "rgw/rgw_service.h" +#include "rgw/rgw_role.h" #include "svc_meta_be.h" class RGWRole; @@ -27,50 +28,61 @@ class RGWSI_Role: public RGWServiceInstance virtual ~RGWSI_Role() {} virtual RGWSI_MetaBackend_Handler* get_be_handler() = 0; + static std::string get_role_meta_key(const std::string& role_id); + static std::string get_role_name_meta_key(const std::string& role_name, const std::string& tenant); + static std::string get_role_path_meta_key(const std::string& path, const std::string& role_id, const std::string& tenant); virtual int store_info(RGWSI_MetaBackend::Context *ctx, - const RGWRole& role, + const rgw::sal::RGWRole& role, RGWObjVersionTracker * const objv_tracker, const real_time& mtime, bool exclusive, std::map * pattrs, - optional_yield y) = 0; + optional_yield y, + const DoutPrefixProvider *dpp) = 0; virtual int store_name(RGWSI_MetaBackend::Context *ctx, const std::string& name, RGWObjVersionTracker * const objv_tracker, real_time * const pmtime, bool exclusive, - optional_yield y) = 0; + optional_yield y, + const DoutPrefixProvider *dpp) = 0; virtual int store_path(RGWSI_MetaBackend::Context *ctx, const std::string& path, RGWObjVersionTracker * const objv_tracker, real_time * const pmtime, bool exclusive, - optional_yield y) = 0; + optional_yield y, + const DoutPrefixProvider *dpp) = 0; virtual int read_info(RGWSI_MetaBackend::Context *ctx, - RGWRole *role, + const std::string& role_id, + rgw::sal::RGWRole *role, RGWObjVersionTracker * const objv_tracker, real_time * const pmtime, std::map * pattrs, - optional_yield y) = 0; + optional_yield y, + const DoutPrefixProvider *dpp) = 0; virtual int read_name(RGWSI_MetaBackend::Context *ctx, std::string& name, RGWObjVersionTracker * const objv_tracker, real_time * const pmtime, - optional_yield y) = 0; + optional_yield y, + const DoutPrefixProvider *dpp) = 0; virtual int read_path(RGWSI_MetaBackend::Context *ctx, std::string& path, RGWObjVersionTracker * const objv_tracker, real_time * const pmtime, - optional_yield y) = 0; + optional_yield y, + const DoutPrefixProvider *dpp) = 0; virtual int delete_info(RGWSI_MetaBackend::Context *ctx, const std::string& name, RGWObjVersionTracker * const objv_tracker, - optional_yield y) = 0; + optional_yield y, + const DoutPrefixProvider *dpp) = 0; }; diff --git a/src/rgw/services/svc_role_rados.cc b/src/rgw/services/svc_role_rados.cc index ec592325f12..2fd92902fda 100644 --- a/src/rgw/services/svc_role_rados.cc +++ b/src/rgw/services/svc_role_rados.cc @@ -1,6 +1,81 @@ #include "svc_role_rados.h" +#include "svc_meta_be_sobj.h" +#include "rgw_role.h" + +#define dout_subsys ceph_subsys_rgw RGWSI_MetaBackend_Handler* RGWSI_Role_RADOS::get_be_handler() { return be_handler; } + +void RGWSI_Role_RADOS::init(RGWSI_Zone *_zone_svc, + RGWSI_Meta *_meta_svc, + RGWSI_MetaBackend *_meta_be_svc, + RGWSI_SysObj *_sysobj_svc) +{ + svc.zone = _zone_svc; + svc.meta = _meta_svc; + svc.meta_be = _meta_be_svc; + svc.sysobj = _sysobj_svc; +} + +int RGWSI_Role_RADOS::store_info(RGWSI_MetaBackend::Context *ctx, + const rgw::sal::RGWRole& role, + RGWObjVersionTracker * const objv_tracker, + const real_time& mtime, + bool exclusive, + std::map * pattrs, + optional_yield y, + const DoutPrefixProvider *dpp) +{ + bufferlist data_bl; + encode(role, data_bl); + RGWSI_MBSObj_PutParams params(data_bl, pattrs, mtime, exclusive); + + return svc.meta_be->put(ctx, get_role_meta_key(role.get_id()), params, objv_tracker, y, dpp); +} + +int RGWSI_Role_RADOS::read_info(RGWSI_MetaBackend::Context *ctx, + const std::string& role_id, + rgw::sal::RGWRole *role, + RGWObjVersionTracker * const objv_tracker, + real_time * const pmtime, + std::map * pattrs, + optional_yield y, + const DoutPrefixProvider *dpp) +{ + bufferlist data_bl; + RGWSI_MBSObj_GetParams params(&data_bl, pattrs, pmtime); + + int r = svc.meta_be->get_entry(ctx, get_role_meta_key(role_id), params, objv_tracker, y, dpp); + if (r < 0) + return r; + + auto bl_iter = data_bl.cbegin(); + try { + decode(*role, bl_iter); + } catch (buffer::error& err) { + ldout(svc.meta_be->ctx(),0) << "ERROR: failed to decode RGWRole, caught buffer::err " << dendl; + return -EIO; + } + + return 0; +} + +int RGWSI_Role_RADOS::delete_info(RGWSI_MetaBackend::Context *ctx, + const std::string& role_id, + RGWObjVersionTracker * const objv_tracker, + optional_yield y, + const DoutPrefixProvider *dpp) +{ + RGWSI_MBSObj_RemoveParams params; + + int r = svc.meta_be->remove(ctx, get_role_meta_key(role_id), params, objv_tracker, y, dpp); + if (r < 0 && r != -ENOENT && r != -ECANCELED) { + ldout(svc.meta_be->ctx(),0) << "ERROR: could not remove RGWRole, id = " + << role_id << " r = "<< r << dendl; + return r; + } + return 0; +} diff --git a/src/rgw/services/svc_role_rados.h b/src/rgw/services/svc_role_rados.h index 44dbc5aa848..eda800842f2 100644 --- a/src/rgw/services/svc_role_rados.h +++ b/src/rgw/services/svc_role_rados.h @@ -21,56 +21,76 @@ class RGWSI_Role_RADOS: public RGWSI_Role { public: + struct Svc { + RGWSI_Zone *zone{nullptr}; + RGWSI_Meta *meta{nullptr}; + RGWSI_MetaBackend *meta_be{nullptr}; + RGWSI_SysObj *sysobj{nullptr}; + } svc; + RGWSI_Role_RADOS(CephContext *cct) : RGWSI_Role(cct) {} ~RGWSI_Role_RADOS() {} + void init(RGWSI_Zone *_zone_svc, + RGWSI_Meta *_meta_svc, + RGWSI_MetaBackend *_meta_be_svc, + RGWSI_SysObj *_sysobj_svc); + RGWSI_MetaBackend_Handler * get_be_handler() override; int store_info(RGWSI_MetaBackend::Context *ctx, - const RGWRole& role, + const rgw::sal::RGWRole& role, RGWObjVersionTracker * const objv_tracker, - real_time * const pmtime, + const real_time& pmtime, bool exclusive, std::map * pattrs, - optional_yield y) override; + optional_yield y, + const DoutPrefixProvider *dpp) override; int store_name(RGWSI_MetaBackend::Context *ctx, const std::string& name, RGWObjVersionTracker * const objv_tracker, real_time * const pmtime, bool exclusive, - optional_yield y) override; + optional_yield y, + const DoutPrefixProvider *dpp) override; int store_path(RGWSI_MetaBackend::Context *ctx, const std::string& path, RGWObjVersionTracker * const objv_tracker, real_time * const pmtime, bool exclusive, - optional_yield y) override; + optional_yield y, + const DoutPrefixProvider *dpp) override; int read_info(RGWSI_MetaBackend::Context *ctx, - RGWRole *role, + const std::string& role_id, + rgw::sal::RGWRole *role, RGWObjVersionTracker * const objv_tracker, real_time * const pmtime, std::map * pattrs, - optional_yield y) override; + optional_yield y, + const DoutPrefixProvider *dpp) override; int read_name(RGWSI_MetaBackend::Context *ctx, std::string& name, RGWObjVersionTracker * const objv_tracker, real_time * const pmtime, - optional_yield y) override; + optional_yield y, + const DoutPrefixProvider *dpp) override; int read_path(RGWSI_MetaBackend::Context *ctx, std::string& path, RGWObjVersionTracker * const objv_tracker, real_time * const pmtime, - optional_yield y) override; + optional_yield y, + const DoutPrefixProvider *dpp) override; int delete_info(RGWSI_MetaBackend::Context *ctx, const std::string& name, RGWObjVersionTracker * const objv_tracker, - optional_yield y) override; + optional_yield y, + const DoutPrefixProvider *dpp) override; private: -- 2.39.5