@@ -1141,12 +1141,12 @@ struct perm_state_from_req_state : public perm_state_base {
11411141};
11421142
11431143Effect 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