From: Casey Bodley Date: Wed, 15 Mar 2023 20:50:07 +0000 (-0400) Subject: rgw/keystone: use secret key from EC2 for sigv4 streaming mode X-Git-Tag: v17.2.8~155^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c2ba1acf28a1b03c74e23e5c259f1d60d2296b0c;p=ceph.git rgw/keystone: use secret key from EC2 for sigv4 streaming mode when the EC2Engine has a secret key from keystone, pass it to the Completer so it's available to AWSv4ComplMulti for STREAMING-AWS4-HMAC-SHA256-PAYLOAD support Fixes: https://tracker.ceph.com/issues/58908 Signed-off-by: Casey Bodley (cherry picked from commit 93eb1d7d47de98b558bfd9c11a1dc1c7bbc37bb7) --- diff --git a/src/rgw/rgw_auth_keystone.cc b/src/rgw/rgw_auth_keystone.cc index c99c9c1e43f..81588d50c4f 100644 --- a/src/rgw/rgw_auth_keystone.cc +++ b/src/rgw/rgw_auth_keystone.cc @@ -545,15 +545,16 @@ std::pair, int> EC2Engine::get_secret_from_keystone /* * Try to get a token for S3 authentication, using a secret cache if available */ -std::pair, int> -EC2Engine::get_access_token(const DoutPrefixProvider* dpp, - const std::string_view& access_key_id, - const std::string& string_to_sign, - const std::string_view& signature, - const signature_factory_t& signature_factory) const +auto EC2Engine::get_access_token(const DoutPrefixProvider* dpp, + const std::string_view& access_key_id, + const std::string& string_to_sign, + const std::string_view& signature, + const signature_factory_t& signature_factory) const + -> access_token_result { using server_signature_t = VersionAbstractor::server_signature_t; boost::optional token; + boost::optional secret; int failure_reason; /* Get a token from the cache if one has already been stored */ @@ -565,7 +566,7 @@ EC2Engine::get_access_token(const DoutPrefixProvider* dpp, std::string sig(signature); server_signature_t server_signature = signature_factory(cct, t->get<1>(), string_to_sign); if (sig.compare(server_signature) == 0) { - return std::make_pair(t->get<0>(), 0); + return {t->get<0>(), t->get<1>(), 0}; } else { ldpp_dout(dpp, 0) << "Secret string does not correctly sign payload, cache miss" << dendl; } @@ -578,8 +579,8 @@ EC2Engine::get_access_token(const DoutPrefixProvider* dpp, if (token) { /* Fetch secret from keystone for the access_key_id */ - boost::optional secret; - std::tie(secret, failure_reason) = get_secret_from_keystone(dpp, token->get_user_id(), access_key_id); + std::tie(secret, failure_reason) = + get_secret_from_keystone(dpp, token->get_user_id(), access_key_id); if (secret) { /* Add token, secret pair to cache, and set timeout */ @@ -587,7 +588,7 @@ EC2Engine::get_access_token(const DoutPrefixProvider* dpp, } } - return std::make_pair(token, failure_reason); + return {token, secret, failure_reason}; } EC2Engine::acl_strategy_t @@ -658,9 +659,7 @@ rgw::auth::Engine::result_t EC2Engine::authenticate( std::vector admin; } accepted_roles(cct); - boost::optional t; - int failure_reason; - std::tie(t, failure_reason) = \ + auto [t, secret_key, failure_reason] = get_access_token(dpp, access_key_id, string_to_sign, signature, signature_factory); if (! t) { if (failure_reason == -ERR_SIGNATURE_NO_MATCH) { @@ -702,7 +701,7 @@ rgw::auth::Engine::result_t EC2Engine::authenticate( auto apl = apl_factory->create_apl_remote(cct, s, get_acl_strategy(*t), get_creds_info(*t, accepted_roles.admin, std::string(access_key_id))); - return result_t::grant(std::move(apl), completer_factory(boost::none)); + return result_t::grant(std::move(apl), completer_factory(secret_key)); } } diff --git a/src/rgw/rgw_auth_keystone.h b/src/rgw/rgw_auth_keystone.h index 31a4388080a..de1a108747c 100644 --- a/src/rgw/rgw_auth_keystone.h +++ b/src/rgw/rgw_auth_keystone.h @@ -150,7 +150,13 @@ class EC2Engine : public rgw::auth::s3::AWSEngine { const std::string_view& access_key_id, const std::string& string_to_sign, const std::string_view& signature) const; - std::pair, int> + + struct access_token_result { + boost::optional token; + boost::optional secret_key; + int failure_reason = 0; + }; + access_token_result get_access_token(const DoutPrefixProvider* dpp, const std::string_view& access_key_id, const std::string& string_to_sign,