Skip to content

Commit

Permalink
Merge pull request #55550 from cbodley/wip-64404-pacific
Browse files Browse the repository at this point in the history
pacific: rgw/auth: ignoring signatures for HTTP OPTIONS calls

Reviewed-by: Yuri Weinstein <yweinste@redhat.com>
  • Loading branch information
yuriw committed Feb 13, 2024
2 parents 2296495 + 34c71da commit 47af904
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
25 changes: 18 additions & 7 deletions src/rgw/rgw_auth_keystone.cc
Expand Up @@ -452,7 +452,8 @@ 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
const signature_factory_t& signature_factory,
bool ignore_signature) const
{
using server_signature_t = VersionAbstractor::server_signature_t;
boost::optional<rgw::keystone::TokenEnvelope> token;
Expand All @@ -464,12 +465,19 @@ EC2Engine::get_access_token(const DoutPrefixProvider* dpp,

/* Check that credentials can correctly be used to sign data */
if (t) {
std::string sig(signature);
server_signature_t server_signature = signature_factory(cct, t->get<1>(), string_to_sign);
if (sig.compare(server_signature) == 0) {
/* We should ignore checking signature in cache if caller tells us to which
* means we're handling a HTTP OPTIONS call. */
if (ignore_signature) {
ldpp_dout(dpp, 20) << "ignore_signature set and found in cache" << dendl;
return std::make_pair(t->get<0>(), 0);
} else {
ldpp_dout(dpp, 0) << "Secret string does not correctly sign payload, cache miss" << dendl;
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);
} else {
ldpp_dout(dpp, 0) << "Secret string does not correctly sign payload, cache miss" << dendl;
}
}
} else {
ldpp_dout(dpp, 0) << "No stored secret string, cache miss" << dendl;
Expand Down Expand Up @@ -541,7 +549,6 @@ rgw::auth::Engine::result_t EC2Engine::authenticate(
const string_to_sign_t& string_to_sign,
const signature_factory_t& signature_factory,
const completer_factory_t& completer_factory,
/* Passthorugh only! */
const req_state* s,
optional_yield y) const
{
Expand All @@ -560,10 +567,14 @@ rgw::auth::Engine::result_t EC2Engine::authenticate(
std::vector<std::string> admin;
} accepted_roles(cct);

/* When we handle a HTTP OPTIONS call we must ignore the signature */
bool ignore_signature = (s->op_type == RGW_OP_OPTIONS_CORS);

boost::optional<token_envelope_t> t;
int failure_reason;
std::tie(t, failure_reason) = \
get_access_token(dpp, access_key_id, string_to_sign, signature, signature_factory);
get_access_token(dpp, access_key_id, string_to_sign,
signature, signature_factory, ignore_signature);
if (! t) {
if (failure_reason == -ERR_SIGNATURE_NO_MATCH) {
// we looked up a secret but it didn't generate the same signature as
Expand Down
3 changes: 2 additions & 1 deletion src/rgw/rgw_auth_keystone.h
Expand Up @@ -151,7 +151,8 @@ 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 signature_factory_t& signature_factory) const;
const signature_factory_t& signature_factory,
bool ignore_signature) const;
result_t authenticate(const DoutPrefixProvider* dpp,
const std::string_view& access_key_id,
const std::string_view& signature,
Expand Down
7 changes: 7 additions & 0 deletions src/rgw/rgw_rest_s3.cc
Expand Up @@ -5774,6 +5774,13 @@ rgw::auth::s3::LocalEngine::authenticate(
}
const RGWAccessKey& k = iter->second;

/* Ignore signature for HTTP OPTIONS */
if (s->op_type == RGW_OP_OPTIONS_CORS) {
auto apl = apl_factory->create_apl_local(cct, s, user_info,
k.subuser, boost::none, access_key_id);
return result_t::grant(std::move(apl), completer_factory(k.key));
}

const VersionAbstractor::server_signature_t server_signature = \
signature_factory(cct, k.key, string_to_sign);
auto compare = signature.compare(server_signature);
Expand Down

0 comments on commit 47af904

Please sign in to comment.