Skip to content

Commit 63bc738

Browse files
rgw/sts: by-passing authentication using temp creds
in case the request is forwarded from secondary in a multi-site setup. authenticating with the system user creds of which are used to sign the request. Permissions are still derived from the role. Signed-off-by: Pritha Srivastava <[email protected]>
1 parent 539b727 commit 63bc738

File tree

4 files changed

+48
-13
lines changed

4 files changed

+48
-13
lines changed

src/rgw/rgw_auth.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,9 @@ void rgw::auth::RoleApplier::modify_request_state(const DoutPrefixProvider *dpp,
12971297
for (auto& it : token_attrs.token_claims) {
12981298
s->token_claims.emplace_back(it);
12991299
}
1300+
if (is_system_request) {
1301+
s->system_request = true;
1302+
}
13001303
}
13011304

13021305
rgw::auth::Engine::result_t

src/rgw/rgw_auth.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -793,17 +793,20 @@ class RoleApplier : public IdentityApplier {
793793
rgw::sal::Driver* driver;
794794
Role role;
795795
TokenAttrs token_attrs;
796+
bool is_system_request;
796797

797798
public:
798799

799800
RoleApplier(CephContext* const cct,
800801
rgw::sal::Driver* driver,
801802
const Role& role,
802-
const TokenAttrs& token_attrs)
803+
const TokenAttrs& token_attrs,
804+
bool is_system_request)
803805
: cct(cct),
804806
driver(driver),
805807
role(role),
806-
token_attrs(token_attrs) {}
808+
token_attrs(token_attrs),
809+
is_system_request(is_system_request) {}
807810

808811
ACLOwner get_aclowner() const override;
809812
uint32_t get_perms_from_aclspec(const DoutPrefixProvider* dpp, const aclspec_t& aclspec) const override {
@@ -835,11 +838,12 @@ class RoleApplier : public IdentityApplier {
835838

836839
struct Factory {
837840
virtual ~Factory() {}
838-
virtual aplptr_t create_apl_role(CephContext* cct,
839-
const req_state* s,
840-
Role role,
841-
TokenAttrs token_attrs) const = 0;
842-
};
841+
virtual aplptr_t create_apl_role( CephContext* cct,
842+
const req_state* s,
843+
Role role,
844+
TokenAttrs token_attrs,
845+
bool is_system_request) const = 0;
846+
};
843847
};
844848

845849
class ServiceIdentity : public Identity {

src/rgw/rgw_auth_s3.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ class STSAuthStrategy : public rgw::auth::Strategy,
7070
aplptr_t create_apl_role(CephContext* const cct,
7171
const req_state* const s,
7272
RoleApplier::Role role,
73-
RoleApplier::TokenAttrs token_attrs) const override {
73+
RoleApplier::TokenAttrs token_attrs,
74+
bool is_system_request) const override {
7475
auto apl = rgw::auth::add_sysreq(cct, driver, s,
75-
rgw::auth::RoleApplier(cct, driver, std::move(role), std::move(token_attrs)));
76+
rgw::auth::RoleApplier(cct, driver, std::move(role), std::move(token_attrs), is_system_request));
7677
return aplptr_t(new decltype(apl)(std::move(apl)));
7778
}
7879

src/rgw/rgw_rest_s3.cc

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6960,6 +6960,7 @@ rgw::auth::s3::STSEngine::authenticate(
69606960
const req_state* const s,
69616961
optional_yield y) const
69626962
{
6963+
bool is_system_request{false};
69636964
if (! s->info.args.exists("x-amz-security-token") &&
69646965
! s->info.env->exists("HTTP_X_AMZ_SECURITY_TOKEN") &&
69656966
s->auth.s3_postobj_creds.x_amz_security_token.empty()) {
@@ -6971,10 +6972,36 @@ rgw::auth::s3::STSEngine::authenticate(
69716972
return result_t::reject(ret);
69726973
}
69736974
//Authentication
6975+
std::string secret_access_key;
69746976
//Check if access key is not the same passed in by client
69756977
if (token.access_key_id != _access_key_id) {
6976-
ldpp_dout(dpp, 0) << "Invalid access key" << dendl;
6977-
return result_t::reject(-EPERM);
6978+
/* In case the request is forwarded from secondary in case of multi-site,
6979+
we by-pass authentication using the session token credentials,
6980+
instead we use the system user's credentials that was used to sign
6981+
this request */
6982+
std::unique_ptr<rgw::sal::User> user;
6983+
const std::string access_key_id(_access_key_id);
6984+
if (driver->get_user_by_access_key(dpp, access_key_id, y, &user) < 0) {
6985+
ldpp_dout(dpp, 5) << "error reading user info, uid=" << access_key_id
6986+
<< " can't authenticate" << dendl;
6987+
return result_t::reject(-ERR_INVALID_ACCESS_KEY);
6988+
}
6989+
// only allow system users as this could be a forwarded request from secondary
6990+
if (user->get_info().system && driver->is_meta_master()) {
6991+
const auto iter = user->get_info().access_keys.find(access_key_id);
6992+
if (iter == std::end(user->get_info().access_keys)) {
6993+
ldpp_dout(dpp, 0) << "ERROR: access key not encoded in user info" << dendl;
6994+
return result_t::reject(-EPERM);
6995+
}
6996+
const RGWAccessKey& k = iter->second;
6997+
secret_access_key = k.key;
6998+
is_system_request = true;
6999+
} else {
7000+
ldpp_dout(dpp, 0) << "Invalid access key" << dendl;
7001+
return result_t::reject(-EPERM);
7002+
}
7003+
} else {
7004+
secret_access_key = token.secret_access_key;
69787005
}
69797006
//Check if the token has expired
69807007
if (! token.expiration.empty()) {
@@ -6995,7 +7022,7 @@ rgw::auth::s3::STSEngine::authenticate(
69957022
}
69967023
//Check for signature mismatch
69977024
const VersionAbstractor::server_signature_t server_signature = \
6998-
signature_factory(cct, token.secret_access_key, string_to_sign);
7025+
signature_factory(cct, secret_access_key, string_to_sign);
69997026
auto compare = signature.compare(server_signature);
70007027

70017028
ldpp_dout(dpp, 15) << "string_to_sign="
@@ -7059,7 +7086,7 @@ rgw::auth::s3::STSEngine::authenticate(
70597086
t_attrs.token_issued_at = std::move(token.issued_at);
70607087
t_attrs.principal_tags = std::move(token.principal_tags);
70617088
auto apl = role_apl_factory->create_apl_role(cct, s, std::move(r),
7062-
std::move(t_attrs));
7089+
std::move(t_attrs), is_system_request);
70637090
return result_t::grant(std::move(apl), completer_factory(token.secret_access_key));
70647091
} else { // This is for all local users of type TYPE_RGW|ROOT|NONE
70657092
if (token.user.empty()) {

0 commit comments

Comments
 (0)