Skip to content

Commit 6e66389

Browse files
authored
Merge pull request ceph#53846 from cbodley/wip-62989-again
rgw: fix http error checks in keystone/barbican/vault clients Reviewed-by: Daniel Gryniewicz <[email protected]>
2 parents 0a193b0 + 36622e1 commit 6e66389

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

src/rgw/rgw_auth_keystone.cc

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ TokenEngine::get_from_keystone(const DoutPrefixProvider* dpp,
8383
validate.set_url(url);
8484

8585
int ret = validate.process(y);
86-
if (ret < 0) {
87-
throw ret;
88-
}
8986

9087
/* NULL terminate for debug output. */
9188
token_body_bl.append(static_cast<char>(0));
@@ -104,6 +101,10 @@ TokenEngine::get_from_keystone(const DoutPrefixProvider* dpp,
104101
<< validate.get_http_status() << dendl;
105102
return boost::none;
106103
}
104+
// throw any other http or connection errors
105+
if (ret < 0) {
106+
throw ret;
107+
}
107108

108109
ldpp_dout(dpp, 20) << "received response status=" << validate.get_http_status()
109110
<< ", body=" << token_body_bl.c_str() << dendl;
@@ -443,11 +444,6 @@ EC2Engine::get_from_keystone(const DoutPrefixProvider* dpp, const std::string_vi
443444

444445
/* send request */
445446
ret = validate.process(y);
446-
if (ret < 0) {
447-
ldpp_dout(dpp, 2) << "s3 keystone: token validation ERROR: "
448-
<< token_body_bl.c_str() << dendl;
449-
throw ret;
450-
}
451447

452448
/* if the supplied signature is wrong, we will get 401 from Keystone */
453449
if (validate.get_http_status() ==
@@ -457,6 +453,12 @@ EC2Engine::get_from_keystone(const DoutPrefixProvider* dpp, const std::string_vi
457453
decltype(validate)::HTTP_STATUS_NOTFOUND) {
458454
return std::make_pair(boost::none, -ERR_INVALID_ACCESS_KEY);
459455
}
456+
// throw any other http or connection errors
457+
if (ret < 0) {
458+
ldpp_dout(dpp, 2) << "s3 keystone: token validation ERROR: "
459+
<< token_body_bl.c_str() << dendl;
460+
throw ret;
461+
}
460462

461463
/* now parse response */
462464
rgw::keystone::TokenEnvelope token_envelope;
@@ -521,18 +523,19 @@ auto EC2Engine::get_secret_from_keystone(const DoutPrefixProvider* dpp,
521523

522524
/* send request */
523525
ret = secret.process(y);
526+
527+
/* if the supplied access key isn't found, we will get 404 from Keystone */
528+
if (secret.get_http_status() ==
529+
decltype(secret)::HTTP_STATUS_NOTFOUND) {
530+
return make_pair(boost::none, -ERR_INVALID_ACCESS_KEY);
531+
}
532+
// return any other http or connection errors
524533
if (ret < 0) {
525534
ldpp_dout(dpp, 2) << "s3 keystone: secret fetching error: "
526535
<< token_body_bl.c_str() << dendl;
527536
return make_pair(boost::none, ret);
528537
}
529538

530-
/* if the supplied signature is wrong, we will get 401 from Keystone */
531-
if (secret.get_http_status() ==
532-
decltype(secret)::HTTP_STATUS_NOTFOUND) {
533-
return make_pair(boost::none, -EINVAL);
534-
}
535-
536539
/* now parse response */
537540

538541
JSONParser parser;

src/rgw/rgw_kms.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,16 +307,17 @@ class VaultSecretEngine: public SecretEngine {
307307
}
308308

309309
res = secret_req.process(y);
310-
if (res < 0) {
311-
ldpp_dout(dpp, 0) << "ERROR: Request to Vault failed with error " << res << dendl;
312-
return res;
313-
}
314310

311+
// map 401 to EACCES instead of EPERM
315312
if (secret_req.get_http_status() ==
316313
RGWHTTPTransceiver::HTTP_STATUS_UNAUTHORIZED) {
317314
ldpp_dout(dpp, 0) << "ERROR: Vault request failed authorization" << dendl;
318315
return -EACCES;
319316
}
317+
if (res < 0) {
318+
ldpp_dout(dpp, 0) << "ERROR: Request to Vault failed with error " << res << dendl;
319+
return res;
320+
}
320321

321322
ldpp_dout(dpp, 20) << "Request to Vault returned " << res << " and HTTP status "
322323
<< secret_req.get_http_status() << dendl;
@@ -937,13 +938,14 @@ static int request_key_from_barbican(const DoutPrefixProvider *dpp,
937938
secret_req.append_header("X-Auth-Token", barbican_token);
938939

939940
res = secret_req.process(y);
940-
if (res < 0) {
941-
return res;
942-
}
941+
// map 401 to EACCES instead of EPERM
943942
if (secret_req.get_http_status() ==
944943
RGWHTTPTransceiver::HTTP_STATUS_UNAUTHORIZED) {
945944
return -EACCES;
946945
}
946+
if (res < 0) {
947+
return res;
948+
}
947949

948950
if (secret_req.get_http_status() >=200 &&
949951
secret_req.get_http_status() < 300 &&

0 commit comments

Comments
 (0)