Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dhananjaykrutika
Copy link
Contributor

Community Contribution License

All community contributions in this pull request are licensed to the project maintainers
under the terms of the Apache 2 license.
By creating this pull request I represent that I have the right to license the
contributions to the project maintainers under the Apache 2 license.

Description

Attempts to create a lifecycle rule using cURL when the xml has no prefix fails with errXMLNotWellFormed error:

$ curl -X PUT "http://localhost:9001/bucket-1?lifecycle" -H "Content-Type: application/xml" -H "Content-MD5: is0WM2LlKTzQECbf4PMRrQ==" --data '<LifecycleConfiguration><Rule><Expiration><Days>6</Days></Expiration><ID>Expiration-rule</ID><Status>Enabled</Status></Rule></LifecycleConfiguration>'
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>InvalidArgument</Code><Message>The XML you provided was not well-formed or did not validate against our published schema</Message><BucketName>bucket-1</BucketName><Resource>/bucket-1</Resource><RequestId>180B2C661117A385</RequestId><HostId>7987905dee74cdeb212432486a178e511309594cee7cb75f892cd53e35f09ea4</HostId></Error>

Motivation and Context

In the now deprecated PutBucketLifecycle API, Rule had a mandatory Prefix element and there existed no Filter field.
(See https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketLifecycle.html)
In the newer PutBucketLifecycleConfiguration API, Rule has a prefix field that is deprecated, and there exists an optional Filter field, and within it, an optional Prefix field.
(See https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketLifecycleConfiguration.html)

Existing prefix validation fails if Rule.Prefix does not exist and there are no Filters. This behavior is incorrect since Prefix itself is not mandatory in PutBucketLifecycleConfiguration API.

A valid rule could be a pre-existing one created using the now deprecated PutBucketLifecycle.
Or, a valid rule could also be either a pre-existing or a new rule that is created using PutBucketLifecycleConfiguration.

Prefix validation has been modified to check that either Rule.Prefix or Rule.Filter.Prefix exist but not both.
In doing so, we are assuming that any pre-existing rule created using PutBucketLifecycle API is already valid; so validation won't fail if Rule.Prefix is empty.

How to test this PR?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Optimization (provides speedup with no functional changes)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • Fixes a regression (If yes, please add commit-id or PR # here)
  • Unit tests added/updated
  • Internal documentation updated
  • Create a documentation update request here

@dhananjaykrutika
Copy link
Contributor Author

This PR attempts to fix #20580

Copy link
Contributor

@klauspost klauspost left a comment

Choose a reason for hiding this comment

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

If feasible add tests for these set/unset, AFAICT it shouldn't be too crazy to add.

@harshavardhana harshavardhana merged commit 366876e into master Nov 25, 2024
21 checks passed
@harshavardhana harshavardhana deleted the prefix-validation-fix branch November 25, 2024 20:12
dhananjaykrutika added a commit that referenced this pull request Nov 26, 2024
The test fails without the change.
Also, removed a duplicate test case involving lifecycle config with no rules.
harshavardhana pushed a commit that referenced this pull request Nov 28, 2024
The test fails without the change.
Also, removed a duplicate test case involving lifecycle config with no rules.
harshavardhana pushed a commit that referenced this pull request Mar 17, 2025
The test fails without the change.
Also, removed a duplicate test case involving lifecycle config with no rules.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants