From e61bfe0d30a0c2ad687f0cdfc96f12e043decfae Mon Sep 17 00:00:00 2001 From: kchheda3 Date: Fri, 5 Sep 2025 14:12:05 -0400 Subject: [PATCH] rgw/create_bucket: for s3:createbucket calls return immediately if bucket already exists without updating the metadata. Signed-off-by: kchheda3 --- src/rgw/rgw_op.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 421c266b6d158..f7a8746f717e9 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -3798,6 +3798,24 @@ void RGWCreateBucket::execute(optional_yield y) return; } + // prevent re-creation with different index type or shard count + if ((createparams.index_type && *createparams.index_type != + info.layout.current_index.layout.type) || + (createparams.index_shards && *createparams.index_shards != + info.layout.current_index.layout.normal.num_shards)) { + s->err.message = + "Cannot modify existing bucket's index type or shard count"; + op_ret = -EEXIST; + return; + } + + // don't allow changes to object lock + if (createparams.obj_lock_enabled != info.obj_lock_enabled()) { + s->err.message = "Cannot modify existing bucket's object lock"; + op_ret = -EEXIST; + return; + } + // don't allow changes to the acl policy RGWAccessControlPolicy old_policy; int r = rgw_op_get_bucket_policy_from_attr(this, s->cct, driver, info.owner, @@ -3808,6 +3826,14 @@ void RGWCreateBucket::execute(optional_yield y) op_ret = -EEXIST; return; } + + // For s3::CreateBucket just return back if bucket exists, as we do not allow + // any changes in bucket config param. need_metadata_upload() is always false + // for S3, so use the check to decide if its s3 request and not swift request. + if (!need_metadata_upload()) { + op_ret = -ERR_BUCKET_EXISTS; + return; + } } s->bucket_owner = policy.get_owner(); -- 2.39.5