Skip to content

Commit 3d021e9

Browse files
authored
Merge pull request ceph#57206 from clwluvw/restrict-public-buckets
rgw: implement RestrictPublicBuckets from PublicAccessBlock Reviewed-by: Adam Emerson <[email protected]> Reviewed-by: Casey Bodley <[email protected]>
2 parents dfb2134 + 07ad231 commit 3d021e9

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

PendingReleaseNotes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@
126126
ISA-L is recommended for new pools because the Jerasure library is
127127
no longer maintained.
128128

129+
* RGW: Added support for the `RestrictPublicBuckets` property of the S3 `PublicAccessBlock`
130+
configuration.
131+
129132
>=19.2.1
130133

131134
* CephFS: Command `fs subvolume create` now allows tagging subvolumes through option

src/rgw/rgw_common.cc

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,12 +1141,12 @@ struct perm_state_from_req_state : public perm_state_base {
11411141
};
11421142

11431143
Effect eval_or_pass(const DoutPrefixProvider* dpp,
1144-
const boost::optional<Policy>& policy,
1145-
const rgw::IAM::Environment& env,
1146-
boost::optional<const rgw::auth::Identity&> id,
1147-
const uint64_t op,
1148-
const ARN& resource,
1149-
boost::optional<rgw::IAM::PolicyPrincipal&> princ_type=boost::none) {
1144+
const boost::optional<Policy>& policy,
1145+
const rgw::IAM::Environment& env,
1146+
boost::optional<const rgw::auth::Identity&> id,
1147+
const uint64_t op,
1148+
const ARN& resource,
1149+
boost::optional<rgw::IAM::PolicyPrincipal&> princ_type=boost::none) {
11501150
if (!policy)
11511151
return Effect::Pass;
11521152
else
@@ -1336,7 +1336,7 @@ bool verify_requester_payer_permission(struct perm_state_base *s)
13361336

13371337
if (s->identity->is_owner_of(s->bucket_info.owner))
13381338
return true;
1339-
1339+
13401340
if (s->identity->is_anonymous()) {
13411341
return false;
13421342
}
@@ -1367,6 +1367,15 @@ bool verify_bucket_permission(const DoutPrefixProvider* dpp,
13671367
ldpp_dout(dpp, 16) << __func__ << ": policy: " << bucket_policy.get()
13681368
<< " resource: " << arn << dendl;
13691369
}
1370+
1371+
// If RestrictPublicBuckets is enabled and the bucket policy allows public access,
1372+
// deny the request if the requester is not in the bucket owner account
1373+
const bool restrict_public_buckets = s->bucket_access_conf && s->bucket_access_conf->restrict_public_buckets();
1374+
if (restrict_public_buckets && bucket_policy && rgw::IAM::is_public(*bucket_policy) && !s->identity->is_owner_of(s->bucket_info.owner)) {
1375+
ldpp_dout(dpp, 10) << __func__ << ": public policies are blocked by the RestrictPublicBuckets block public access setting" << dendl;
1376+
return false;
1377+
}
1378+
13701379
const auto effect = evaluate_iam_policies(
13711380
dpp, s->env, *s->identity, account_root, op, arn,
13721381
bucket_policy, identity_policies, session_policies);
@@ -1516,6 +1525,14 @@ bool verify_object_permission(const DoutPrefixProvider* dpp, struct perm_state_b
15161525
if (!verify_requester_payer_permission(s))
15171526
return false;
15181527

1528+
// If RestrictPublicBuckets is enabled and the bucket policy allows public access,
1529+
// deny the request if the requester is not in the bucket owner account
1530+
const bool restrict_public_buckets = s->bucket_access_conf && s->bucket_access_conf->restrict_public_buckets();
1531+
if (restrict_public_buckets && bucket_policy && rgw::IAM::is_public(*bucket_policy) && !s->identity->is_owner_of(s->bucket_info.owner)) {
1532+
ldpp_dout(dpp, 10) << __func__ << ": public policies are blocked by the RestrictPublicBuckets block public access setting" << dendl;
1533+
return false;
1534+
}
1535+
15191536
const auto effect = evaluate_iam_policies(
15201537
dpp, s->env, *s->identity, account_root, op, ARN(obj),
15211538
bucket_policy, identity_policies, session_policies);

0 commit comments

Comments
 (0)