Skip to content

HDDS-15608. Return BucketAlreadyOwnedByYou when the same S3 owner recreates an existing bucket#10814

Open
Gargi-jais11 wants to merge 1 commit into
apache:masterfrom
Gargi-jais11:HDDS-15608
Open

HDDS-15608. Return BucketAlreadyOwnedByYou when the same S3 owner recreates an existing bucket#10814
Gargi-jais11 wants to merge 1 commit into
apache:masterfrom
Gargi-jais11:HDDS-15608

Conversation

@Gargi-jais11

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

s3-tests test_bucket_create_exists fails when the same S3 client creates a bucket twice. Ozone S3 Gateway always returns 409 with error code BucketAlreadyExists.

AWS S3 expects:

Scenario                                                         |      HTTP      | Error code
--                                                               |        --      | --
Same S3 owner creates a bucket that already exists               |     409        | BucketAlreadyOwnedByYou
Different S3 owner creates a bucket with an existing global name |    409         | BucketAlreadyExists

Add BUCKET_ALREADY_OWNED_BY_YOU to S3ErrorTable (BucketAlreadyOwnedByYou, HTTP 409) and return when same S3 owner creates a bucket that already exists

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-15608

How was this patch tested?

Added IT and UT.
Manual Testing:
Before Fix:

// wrong behaviour: same owner creating a bucket already existing --> throws BucketAlreadyExists error

 BUCKET="duplicate-test-$$"
bash-5.1$ aws s3api create-bucket \
  --bucket "$BUCKET" \
  --endpoint-url http://s3g:9878/
{
    "Location": "http://s3g:9878/duplicate-test-117"
}
bash-5.1$ aws s3api create-bucket \
  --bucket "$BUCKET" \
  --endpoint-url http://s3g:9878/

// Different owner of bucket getting BucketAlreadyExists error is okay
An error occurred (BucketAlreadyExists) when calling the CreateBucket operation: The requested bucket name is not available as it already exists.

bash-5.1$ BUCKET="duplicate-other-owner-$$"
bash-5.1$ ozone sh bucket create "/s3v/${BUCKET}" --user other-s3-owner
bash-5.1$ aws s3api create-bucket \
  --bucket "$BUCKET" \
  --endpoint-url http://s3g:9878/

An error occurred (BucketAlreadyExists) when calling the CreateBucket operation: The requested bucket name is not available as it already exists.

After Fix:

// Same owner creating already existing bucket ---> Throw BUCKET_ALREADY_OWNED_BY_YOU

BUCKET="duplicate-test-$$"
bash-5.1$ aws s3api create-bucket \
  --bucket "$BUCKET" \
  --endpoint-url http://s3g:9878/
{
    "Location": "http://s3g:9878/duplicate-test-119"
}
bash-5.1$ aws s3api create-bucket \
  --bucket "$BUCKET" \
  --endpoint-url http://s3g:9878/

An error occurred (BucketAlreadyOwnedByYou) when calling the CreateBucket operation: Your previous request to create the named bucket succeeded and you already own it.

// Bucket owned by other user ---> Throws BUCKET_ALREADY_EXISTS

bash-5.1$ BUCKET="duplicate-other-owner-$$"
bash-5.1$ ozone sh bucket create "/s3v/${BUCKET}" --user other-s3-owner
bash-5.1$ aws s3api create-bucket \
  --bucket "$BUCKET" \
  --endpoint-url http://s3g:9878/

An error occurred (BucketAlreadyExists) when calling the CreateBucket operation: The requested bucket name is not available as it already exists.

@Gargi-jais11
Gargi-jais11 marked this pull request as ready for review July 20, 2026 07:03
@Gargi-jais11 Gargi-jais11 added the s3 S3 Gateway label Jul 20, 2026

@Test
public void testCreateBucketAndFailOnDuplicate() throws Exception {
public void testCreateBucketAndFailOnDuplicateWithSameOWNER() throws Exception {

@rich7420 rich7420 Jul 21, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small non-blocking nits: the same-owner case here passes via null == null (the stub bucket has no owner and no principal is set), so it doesn't quite exercise a real owner match. Setting a principal and a matching bucket owner would cover getRequestOwner(). Thanks!

@rich7420 rich7420 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gargi-jais11 thanks for the patch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

s3 S3 Gateway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants