Skip to content

Commit

Permalink
Merge pull request #50550 from cbodley/wip-58908
Browse files Browse the repository at this point in the history
rgw/keystone: use secret key from EC2 for sigv4 streaming mode

Reviewed-by: J. Eric Ivancich <ivancich@redhat.com>
  • Loading branch information
cbodley committed Apr 6, 2023
2 parents 7dd680a + 93eb1d7 commit 2d6d195
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
27 changes: 13 additions & 14 deletions src/rgw/rgw_auth_keystone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -556,15 +556,16 @@ std::pair<boost::optional<std::string>, int> EC2Engine::get_secret_from_keystone
/*
* Try to get a token for S3 authentication, using a secret cache if available
*/
std::pair<boost::optional<rgw::keystone::TokenEnvelope>, 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<rgw::keystone::TokenEnvelope> token;
boost::optional<std::string> secret;
int failure_reason;

/* Get a token from the cache if one has already been stored */
Expand All @@ -576,7 +577,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;
}
Expand All @@ -589,16 +590,16 @@ EC2Engine::get_access_token(const DoutPrefixProvider* dpp,

if (token) {
/* Fetch secret from keystone for the access_key_id */
boost::optional<std::string> 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 */
secret_cache.add(std::string(access_key_id), *token, *secret);
}
}

return std::make_pair(token, failure_reason);
return {token, secret, failure_reason};
}

EC2Engine::acl_strategy_t
Expand Down Expand Up @@ -669,9 +670,7 @@ rgw::auth::Engine::result_t EC2Engine::authenticate(
std::vector<std::string> admin;
} accepted_roles(cct);

boost::optional<token_envelope_t> 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) {
return result_t::deny(failure_reason);
Expand Down Expand Up @@ -707,7 +706,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));
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/rgw/rgw_auth_keystone.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,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<boost::optional<token_envelope_t>, int>

struct access_token_result {
boost::optional<token_envelope_t> token;
boost::optional<std::string> 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,
Expand Down

0 comments on commit 2d6d195

Please sign in to comment.