Skip to content

rgw: DoS when QuotaExceeded - #58378

Merged
cbodley merged 1 commit into
ceph:mainfrom
YaZasnyal:fix/discard_buffer_size
Jul 3, 2024
Merged

cbodley merged 1 commit into
ceph:mainfrom
YaZasnyal:fix/discard_buffer_size

Conversation

@YaZasnyal

@YaZasnyal YaZasnyal commented Jul 1, 2024 •

Copy link
Copy Markdown
Contributor

Hi, we have encountered a problem where one of our internal users reached their bucket quota. This caused a Denial of Service (DoS) on all RGW instances in the installation.

How to reproduce:

  1. Create a bucket and set a quota for it.
  2. Reach the quota by uploading objects (or set it to zero).
  3. Start uploading large (25+ MiB) objects to the bucket in parallel (50-100 workers).
  4. Observe how the RGW instance becomes completely unresponsive.

Why does it happens

When the quota is reached, the RGW quickly returns from the process_request method, but it still needs to dump all the data present in the socket. It does this in a loop, but only drains 1 KiB per read. The CPU starts spending all its time on context switches.

How to fix

We can increase the buffer size to a larger value. I have checked and found that a 1 MiB buffer is sufficient, and it works fine on a local machine with 65k packets.

This fix can be easily backported to older versions.

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard cephadm
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox
  • jenkins test windows
  • jenkins test rook e2e

@YaZasnyal
YaZasnyal requested a review from a team as a code owner July 1, 2024 16:52
@github-actions github-actions Bot added the rgw label Jul 1, 2024
// bytes before reading the next
while (!expect_continue && !parser.is_done()) {
static std::array<char, 1024> discard_buffer;
static std::array<char, 1024*1024> discard_buffer;

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.

since this is a static array, i think it's fine to make it larger without worrying about stack overflows 👍

but if there's a lot more data to transfer, it might be better to close the connection so the client won't have to send it all. there's a parser.content_length_remaining() function that may help us make that decision (unless the request is using chunked transfer encoding). what do you think? cc @mkogan1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I like this idea. I will try to make an update to this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Using the generic aws_sdk_s3 for rust I get a misleading error in this case:

2024-07-02T07:59:35.203879Z ERROR upload simple file failed __self.name="yyukgfvxrcutsuwqsgwnqvsmuxahvntt" __self.size=26214400 e=DispatchFailure(DispatchFailure { source: ConnectorError { kind: Io, source: hyper::Error(BodyWrite, Os { code: 32, kind: BrokenPipe, message: "Broken pipe" }), connection: Unknown } })

Probably not the best way to communicate with the user. Maybe this can be hidden behind the config option. With the increased buffer size RGW can discard 10Gb/s of data so I personally would leave this option disabled anyway.

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.

ok, i'd assumed that the disconnect would cause the client to retry instead of returning an error. but we've already responded with an http error, and we don't want the client to retry this request, so that makes sense. thanks for testing this! i think we should probably just drop that change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, reverted that commit.

@cbodley cbodley Jul 2, 2024 •

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.

thanks. i added the needs-qa label so we can get started with testing. but i'd prefer if you remove the second commit and its revert from this branch before we merge

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@YaZasnyal YaZasnyal changed the title rgw: DOS when QuotaExceeded rgw: DoS when QuotaExceeded Jul 2, 2024
@YaZasnyal
YaZasnyal force-pushed the fix/discard_buffer_size branch from c0508bf to 86b6567 Compare July 2, 2024 12:58
@YaZasnyal
YaZasnyal force-pushed the fix/discard_buffer_size branch from af13ac8 to d702c39 Compare July 2, 2024 19:32
@cbodley

cbodley commented Jul 3, 2024

Copy link
Copy Markdown
Contributor

jenkins test make check

@cbodley

cbodley commented Jul 3, 2024

Copy link
Copy Markdown
Contributor

@cbodley
cbodley merged commit be0e8e2 into ceph:main Jul 3, 2024
Moisi pushed a commit to Moisi/ceph that referenced this pull request Jun 30, 2025
…xceeded

Merge in STORAGEENG/ceph from bugfix/CEPH-377-upstream-fix-rgw-dos-when-quotaexceeded to aka_version_18.2.1

* commit '8545ef7a31f7e5d27303f99795d6389cc71e29d6':
  CEPH-377 Take upstream fix for QoS when QuotaExceeded 1. The upstream fix is ceph#58378 2. Also fix a build error after    https://git.source.akamai.com/projects/STORAGEENG/repos/ceph/pull-requests/147/overview
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants