From 5ec01848d942d27d19ed8cf23475dceb713c3e0b Mon Sep 17 00:00:00 2001 From: Pritha Srivastava Date: Wed, 8 Aug 2018 15:10:51 +0530 Subject: [PATCH] rgw: Code to make S3 and STS co-exist in same namespace. Signed-off-by: Pritha Srivastava --- src/rgw/CMakeLists.txt | 5 ++++- src/rgw/rgw_main.cc | 8 ++------ src/rgw/rgw_rest_s3.cc | 8 +++++++- src/rgw/rgw_rest_s3.h | 13 +++++++++---- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/rgw/CMakeLists.txt b/src/rgw/CMakeLists.txt index 8efd43bd63d..a7abc8bc8ec 100644 --- a/src/rgw/CMakeLists.txt +++ b/src/rgw/CMakeLists.txt @@ -108,7 +108,10 @@ set(librgw_common_srcs rgw_crypt.cc rgw_crypt_sanitize.cc rgw_iam_policy.cc - rgw_rest_user_policy.cc) + rgw_rest_user_policy.cc + rgw_sts.cc + rgw_rest_sts.cc) + add_library(rgw_common OBJECT ${librgw_common_srcs}) if(WITH_LTTNG) diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index abbeaade68f..82f9708ebf8 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -341,12 +341,13 @@ int main(int argc, const char **argv) // S3 website mode is a specialization of S3 const bool s3website_enabled = apis_map.count("s3website") > 0; + const bool sts_enabled = apis_map.count("sts") > 0; // Swift API entrypoint could placed in the root instead of S3 const bool swift_at_root = g_conf()->rgw_swift_url_prefix == "/"; if (apis_map.count("s3") > 0 || s3website_enabled) { if (! swift_at_root) { rest.register_default_mgr(set_logging(rest_filter(store, RGW_REST_S3, - new RGWRESTMgr_S3(s3website_enabled)))); + new RGWRESTMgr_S3(s3website_enabled, sts_enabled)))); } else { derr << "Cannot have the S3 or S3 Website enabled together with " << "Swift API placed in the root of hierarchy" << dendl; @@ -402,11 +403,6 @@ int main(int argc, const char **argv) rest.register_resource(g_conf()->rgw_admin_entry, admin_resource); } - if (apis_map.count("sts") > 0) { - auto *sts = new RGWRESTMgr_STS; - rest.register_resource(g_conf()->rgw_sts_entry, set_logging(sts)); - } - /* Initialize the registry of auth strategies which will coordinate * the dynamic reconfiguration. */ auto auth_registry = \ diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index f9ec11c0325..e80cc3ff17c 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -48,6 +48,7 @@ #include "include/ceph_assert.h" #include "include/assert.h" #include "rgw_role.h" +#include "rgw_rest_sts.h" #include "rgw_sts.h" #define dout_context g_ceph_context @@ -3026,6 +3027,11 @@ RGWOp *RGWHandler_REST_Service_S3::op_post() if (action.compare("DeleteUserPolicy") == 0) return new RGWDeleteUserPolicy; } + if (this->isSTSenabled) { + RGWHandler_REST_STS sts_handler(auth_registry); + sts_handler.init(store, s, s->cio); + return sts_handler.get_op(store); + } return NULL; } @@ -3522,7 +3528,7 @@ RGWHandler_REST* RGWRESTMgr_S3::get_handler(struct req_state* const s, } } else { if (s->init_state.url_bucket.empty()) { - handler = new RGWHandler_REST_Service_S3(auth_registry); + handler = new RGWHandler_REST_Service_S3(auth_registry, enable_sts); } else if (s->object.empty()) { handler = new RGWHandler_REST_Bucket_S3(auth_registry); } else { diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index 97181b29185..f535ad82fb1 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -499,7 +499,7 @@ public: class RGWHandler_REST_S3 : public RGWHandler_REST { friend class RGWRESTMgr_S3; - +protected: const rgw::auth::StrategyRegistry& auth_registry; public: static int init_from_header(struct req_state *s, int default_formatter, bool configurable_format); @@ -521,6 +521,7 @@ public: class RGWHandler_REST_Service_S3 : public RGWHandler_REST_S3 { protected: + bool isSTSenabled; bool is_usage_op() { return s->info.args.exists("usage"); } @@ -528,7 +529,9 @@ protected: RGWOp *op_head() override; RGWOp *op_post() override; public: - using RGWHandler_REST_S3::RGWHandler_REST_S3; + RGWHandler_REST_Service_S3(const rgw::auth::StrategyRegistry& auth_registry, + bool isSTSenabled) : + RGWHandler_REST_S3(auth_registry), isSTSenabled(isSTSenabled) {} ~RGWHandler_REST_Service_S3() override = default; }; @@ -592,9 +595,11 @@ public: class RGWRESTMgr_S3 : public RGWRESTMgr { private: bool enable_s3website; + bool enable_sts; public: - explicit RGWRESTMgr_S3(bool enable_s3website = false) - : enable_s3website(enable_s3website) { + explicit RGWRESTMgr_S3(bool enable_s3website = false, bool enable_sts = false) + : enable_s3website(enable_s3website), + enable_sts(enable_sts) { } ~RGWRESTMgr_S3() override = default; -- 2.39.5