@@ -8500,6 +8500,14 @@ void RGWPutBucketPolicy::send_response()
85008500
85018501int RGWPutBucketPolicy::verify_permission (optional_yield y)
85028502{
8503+ // If the user is the root account of the bucket owner,
8504+ // and x-amz-confirm-remove-self-bucket-access was not set,
8505+ // then the user can put bucket policy.
8506+ if (s->auth .identity ->is_root_of (s->bucket_owner .id ) &&
8507+ s->bucket_attrs .find (RGW_ATTR_IAM_POLICY_REMOVE_SELF_ACCESS) == s->bucket_attrs .end ()) {
8508+ return 0 ;
8509+ }
8510+
85038511 auto [has_s3_existing_tag, has_s3_resource_tag] = rgw_check_policy_condition (this , s, false );
85048512 if (has_s3_resource_tag)
85058513 rgw_iam_add_buckettags (this , s);
@@ -8549,10 +8557,15 @@ void RGWPutBucketPolicy::execute(optional_yield y)
85498557 }
85508558
85518559 op_ret = retry_raced_bucket_write (this , s->bucket .get (), [&p, this , &attrs] {
8552- attrs[RGW_ATTR_IAM_POLICY].clear ();
8553- attrs[RGW_ATTR_IAM_POLICY].append (p.text );
8554- op_ret = s->bucket ->merge_and_store_attrs (this , attrs, s->yield );
8555- return op_ret;
8560+ attrs[RGW_ATTR_IAM_POLICY].clear ();
8561+ attrs[RGW_ATTR_IAM_POLICY].append (p.text );
8562+ if (s->info .env ->exists (" HTTP_X_AMZ_CONFIRM_REMOVE_SELF_BUCKET_ACCESS" )) {
8563+ attrs[RGW_ATTR_IAM_POLICY_REMOVE_SELF_ACCESS].clear ();
8564+ } else {
8565+ attrs.erase (RGW_ATTR_IAM_POLICY_REMOVE_SELF_ACCESS);
8566+ }
8567+ op_ret = s->bucket ->merge_and_store_attrs (this , attrs, s->yield );
8568+ return op_ret;
85568569 }, y);
85578570 } catch (rgw::IAM::PolicyParseException& e) {
85588571 ldpp_dout (this , 5 ) << " failed to parse policy: " << e.what () << dendl;
@@ -8573,6 +8586,14 @@ void RGWGetBucketPolicy::send_response()
85738586
85748587int RGWGetBucketPolicy::verify_permission (optional_yield y)
85758588{
8589+ // If the user is the root account of the bucket owner,
8590+ // and x-amz-confirm-remove-self-bucket-access was not set,
8591+ // then the user can put bucket policy.
8592+ if (s->auth .identity ->is_root_of (s->bucket_owner .id ) &&
8593+ s->bucket_attrs .find (RGW_ATTR_IAM_POLICY_REMOVE_SELF_ACCESS) == s->bucket_attrs .end ()) {
8594+ return 0 ;
8595+ }
8596+
85768597 auto [has_s3_existing_tag, has_s3_resource_tag] = rgw_check_policy_condition (this , s, false );
85778598 if (has_s3_resource_tag)
85788599 rgw_iam_add_buckettags (this , s);
@@ -8622,6 +8643,14 @@ void RGWDeleteBucketPolicy::send_response()
86228643
86238644int RGWDeleteBucketPolicy::verify_permission (optional_yield y)
86248645{
8646+ // If the user is the root account of the bucket owner,
8647+ // and x-amz-confirm-remove-self-bucket-access was not set,
8648+ // then the user can put bucket policy.
8649+ if (s->auth .identity ->is_root_of (s->bucket_owner .id ) &&
8650+ s->bucket_attrs .find (RGW_ATTR_IAM_POLICY_REMOVE_SELF_ACCESS) == s->bucket_attrs .end ()) {
8651+ return 0 ;
8652+ }
8653+
86258654 auto [has_s3_existing_tag, has_s3_resource_tag] = rgw_check_policy_condition (this , s, false );
86268655 if (has_s3_resource_tag)
86278656 rgw_iam_add_buckettags (this , s);
@@ -8645,6 +8674,7 @@ void RGWDeleteBucketPolicy::execute(optional_yield y)
86458674 op_ret = retry_raced_bucket_write (this , s->bucket .get (), [this ] {
86468675 rgw::sal::Attrs& attrs = s->bucket ->get_attrs ();
86478676 attrs.erase (RGW_ATTR_IAM_POLICY);
8677+ attrs.erase (RGW_ATTR_IAM_POLICY_REMOVE_SELF_ACCESS);
86488678 op_ret = s->bucket ->put_info (this , false , real_time (), s->yield );
86498679 return op_ret;
86508680 }, y);
0 commit comments