Skip to content

[v25.1.x] cloud_storage_clients: check Content-Type header before parsing REST error responses in s3_client #25817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

vbotbuildovich
Copy link
Collaborator

Backport of PR #25738

`ss::httpd::function_handler` calls `rep->done(_type)` on the reply before
returning it. Because certain code paths in imposter services may want to
return a different `Content-Type` in their response, this impl's `handle()`
function allows for modifying the `type` set in the function handler's body
before the final call to `done(type)` is performed.

This class also handles an oversight in `mime_types.cc`, in which `xml` is
not handled as a possible `mime` type.

(cherry picked from commit 7477d92)
All S3 error codes should be returned using `application/xml`
as the `Content-Type` header.

(cherry picked from commit 0f6d14a)
There are code paths here that possibly return a `xml` body for their
response. They need to ensure the response will be properly marked with
`application/xml` in the `Content-Type` header.

(cherry picked from commit 8dd0922)
…ly_with()`

Sometimes we need to be able to set the headers and the body of a response.

Add a new overload that allows us to do so.

(cherry picked from commit a803a63)
…tor_test`

The `not_found_response` is XML encoded.

(cherry picked from commit 115bf81)
…t_test`

More XML encoded responses that need their `Content-Type` headers properly set.

(cherry picked from commit 366027f)
Future commits will add use of this function to the `s3_client`.
For that reason, move the `enum class response_content_type` to `types.h`,
and `get_response_content_type()` helper function to `util.cc/.h`.

(cherry picked from commit cc5b49f)
According to the S3 docs (`https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html`),
REST error responses _should_ have the Content-Type header set to
`application/xml`. However, response like `503 Service Unavailable` may
not be of this assumed `Content-Type`.

As seen in CI (abridged output):

```
WARN  s3 - s3_client.cc:841 - S3 PUT request failed for key "...": Service Unavailable [Content-Type: text/plain; charset=utf-8]; ...
ERROR s3 - util.cc:209 - !!parsing error boost::wrapexcept<boost::property_tree::xml_parser::xml_parser_error> (<unspecified file>(1): expected <)
ERROR s3 - s3_client.cc:441 - !!error parse error boost::wrapexcept<boost::property_tree::xml_parser::xml_parser_error> (<unspecified file>(1): expected <)
```

To fix this issue, read the `Content-Type` header in `s3_client` instead of
assuming `xml` as the `Content-Type` and attempting to parse it. If the
`Content-Type` is not `xml`, we will return a partially filled
`rest_error_response`.

(cherry picked from commit 1cc76c7)
@vbotbuildovich vbotbuildovich added this to the v25.1.x-next milestone Apr 15, 2025
@vbotbuildovich vbotbuildovich added the kind/backport PRs targeting a stable branch label Apr 15, 2025
@vbotbuildovich
Copy link
Collaborator Author

CI test results

test results on build#64559
test_id test_kind job_url test_status passed
rptest.tests.maintenance_test.MaintenanceTest.test_maintenance_sticky.use_rpk=True ducktape https://buildkite.com/redpanda/redpanda/builds/64559#019639f8-a5fc-42d0-8337-c51a0e1c24cd FLAKY 1/2

@WillemKauf WillemKauf merged commit ec8f905 into redpanda-data:v25.1.x Apr 15, 2025
17 checks passed
@piyushredpanda piyushredpanda modified the milestones: v25.1.x-next, v25.1.2 Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build area/redpanda kind/backport PRs targeting a stable branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants