Skip to content

Cherry pick #112479 to 26.3: RabbitMQ related fix - #114439

Merged
robot-ch-test-poll merged 17 commits into
backport/26.3/112479from
cherrypick/26.3/112479
Sep 7, 2026
Merged

robot-ch-test-poll merged 17 commits into
backport/26.3/112479from
cherrypick/26.3/112479

Conversation

@robot-clickhouse-ci-1

Copy link
Copy Markdown
Contributor

Original pull-request #112479

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

kssenii and others added 16 commits July 29, 2026 20:38
`CREATE TABLE ... ENGINE = RabbitMQ` connects to the broker synchronously, so the whole
AMQP handshake runs while the statement is being executed. A broker can answer the
handshake with a `Connection.Tune` frame proposing a maximum frame size of zero, which
in AMQP means "no limit". `AMQP-CPP` stored that verbatim and uses the maximum frame
size both as the capacity of its receive buffer and as the bound that incoming frames
are validated against, so zero disabled the bound while the buffer stayed at its
initial 4096 bytes. The broker could then announce a frame with a payload of up to
`0xFFFFFFFF` bytes and have the client read that many bytes into the 4096-byte
allocation - a heap out-of-bounds write with remotely controlled length and content.

The fix is in the `contrib/AMQP-CPP` submodule: the negotiated maximum frame size is
never allowed below the protocol minimum, an oversized frame is rejected even when the
negotiated maximum is zero, and the receive buffer now clamps every read to the memory
it has actually allocated.

`remote_host_filter` is applied to `rabbitmq_address` as well. It used to be checked
only for `rabbitmq_host_port`, so an authenticated user could reach a host outside the
allowlist just by spelling the same address in the URI form.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ress

`RabbitMQConnection::connectImpl` connects to `rabbitmq_address` (the URI form)
whenever it is set, in preference to `rabbitmq_host_port`, and `connection_string`
is always filled from `rabbitmq_address`. The constructor, however, validated
`rabbitmq_host_port` first and only checked `rabbitmq_address` in the `else`
branch, so a user could pair an allowed `rabbitmq_host_port` with a disallowed
`rabbitmq_address` (both settings are accepted together) and still connect to the
unvalidated host, bypassing `remote_url_allow_hosts`.

Validate against `remote_host_filter` by keying off the same condition
`connectImpl` uses: check `rabbitmq_address` whenever it is set, falling back to
`rabbitmq_host_port` only when there is no address. `connection_string` now reuses
the exact validated string.

Regression test: an allowed `rabbitmq_host_port` plus a disallowed
`rabbitmq_address` is now rejected with `UNACCEPTABLE_URL`.

#112479 (comment)

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Follow-ups from review of the RabbitMQ malicious-broker fix:

* Bump contrib/AMQP-CPP to aba8fac: clamp the negotiated max frame size from
  above (a peer proposing frame_max close to 2^32-1 could otherwise make us
  allocate multiple gigabytes for the receive buffer), and stop TcpInBuffer
  from recording capacity for a buffer that malloc failed to allocate.

* Initialize OpenSSL when the connection is TLS because `rabbitmq_address` uses
  the `amqps` scheme, not only when the `rabbitmq_secure` setting is set.

* Strengthen the frame_max=0 test to assert that the library logs the
  `frame size exceeded` protocol error, a deterministic proof that the guard
  fired rather than the server merely surviving the overflow by luck on a
  non-sanitizer build.

* Add an `amqps` variant of the malicious-broker test that drives the same
  overflow through the previously unclamped TLS receive path.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
For the `rabbitmq_address` form, `RabbitMQConnection::connectImpl` takes the
transport from the URI scheme and never applies `configuration.secure`, so
`rabbitmq_address = 'amqp://...'` together with `rabbitmq_secure = 1` silently
connected in cleartext despite the user asking for TLS - a silent security
downgrade.

Reject that contradiction with `BAD_ARGUMENTS` instead of downgrading (rather
than trying to "upgrade" the URI, which is ambiguous: `amqp://host` with no
port would connect TLS to the plaintext default port 5672). TLS with the
address form must be expressed with an `amqps://` scheme.

Add a regression test and clarify the docs: `rabbitmq_secure` applies to the
`rabbitmq_host_port` form; the address form selects the transport via its
scheme.

#112479 (comment)

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…max-oob

# Conflicts:
#	docs/en/engines/table-engines/integrations/rabbitmq.md
The `SSL connection` section of `rabbitmq.mdx` sits inside the
`AUTOGENERATED` region of the generated documentation tree, so the
edit does not belong in this pull request.

Co-Authored-By: Claude Opus 5 <[email protected]>
… truth

- The autogenerated rabbitmq.mdx was edited during conflict resolution
  while its source of truth, the documentation block in
  StorageRabbitMQ.cpp, still described the old TLS contract. Update the
  embedded documentation so regeneration is idempotent and the Mintlify
  docs check passes, and apply the suggested wording for the
  `rabbitmq_address` description (URI form, precedence over
  `rabbitmq_host_port`, remote_url_allow_hosts check) and the SSL
  connection paragraph.
  #112479 (comment)
  #112479 (comment)
  #112479 (comment)
- The amqps regression only proved the server survived. Now it records
  the count of `frame size exceeded` log lines before connecting and
  requires the count to grow, proving the frame-size guard fired on the
  TLS receive path as well. Counting (not substring presence) because
  the plaintext test already logs the same line into the shared log.
  #112479 (comment)
- The malicious broker now parses the client's Connection.TuneOk reply
  and logs the negotiated frame_max, and the tests assert it against the
  expected clamp: a frame_max=0 proposal must be answered with 4096
  (checked on both the plaintext and TLS paths), and a new test with a
  broker proposing 2^32-1 checks the reply is capped at 128 MiB. The
  TuneOk reply is what bounds the receive buffer, so echoing a hostile
  proposal back would let the broker announce frames of arbitrary size.
  #112479 (comment)

Co-Authored-By: Claude Fable 5 <[email protected]>
The edited sections of rabbitmq.mdx sit inside the AUTOGENERATED region
of the generated documentation tree, which the Mintlify docs check
rejects when edited manually. The wording changes stay in the
documentation block of StorageRabbitMQ.cpp, the source of truth from
which the page is regenerated.

Co-Authored-By: Claude Fable 5 <[email protected]>
…allocated

Address review: with the initial 4 KiB TcpInBuffer allocation failed,
both receivefrom overloads computed a zero read size but still formed
`_data + _size` from a null buffer and passed it to read/SSL_read.
Short-circuit before forming the pointer and report the receive failure
explicitly (errno = ENOMEM, negative result).

#112479 (comment)

Co-Authored-By: Claude Fable 5 <[email protected]>
`conn.recv(65536)` is not frame-aware: on TCP/TLS it can return any positive
prefix of `Connection.StartOk`. When it returned only a prefix, the following
`recv_exactly(7)` for `Connection.TuneOk` started in the middle of `StartOk`,
the stream desynced, and the `client_frame_max` assertion became flaky.

Factor a `read_frame` helper (7-byte header + payload + end octet, all via
`recv_exactly`) and use it for both `StartOk` and `TuneOk` so the broker always
consumes exactly one whole frame and stays aligned.

Verified with a fragmented-`StartOk` client harness: the old broker fails to
parse the subsequent `TuneOk`, the new one parses it correctly.

#112479 (comment)

Co-Authored-By: Claude Opus 4.8 <[email protected]>
The `rabbitmq_secure = 1` vs plaintext `amqp://` `rabbitmq_address` contradiction
is rejected only for a fresh CREATE (`mode <= LoadingStrictnessLevel::CREATE`), so
an existing table that used this (previously accepted, silently plaintext)
combination still attaches after an upgrade instead of failing to load.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
`configuration.secure` was taken straight from the `rabbitmq_secure` setting, so
it disagreed with reality when `rabbitmq_secure = 0` but the `rabbitmq_address`
URI used the `amqps` scheme. Use `secure_connection`, which reflects the actual
transport (setting for the host/port form, URI scheme for the address form).

No behavioural change today - `connectImpl` derives the transport from the URI
for the address form and this field is only read on the host/port form, where
`secure_connection` equals the setting - but it keeps the field truthful.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Aug 12, 2026
@robot-ch-test-poll

Copy link
Copy Markdown
Contributor

Dear @kssenii, @arsenmuk, this cherry-pick PR has not been updated for 3d0h11m19s. Please resolve the conflicts to backport #112479, or close this PR if the backport is no longer needed. This PR will be automatically closed after 7 days of inactivity.

@robot-ch-test-poll

Copy link
Copy Markdown
Contributor

Dear @kssenii, @arsenmuk, this cherry-pick PR has not been updated for 7d0h14m54s. Closing automatically. If you still want to backport #112479, please resolve the conflicts and reopen this PR.

@robot-ch-test-poll

Copy link
Copy Markdown
Contributor

Dear @kssenii, @arsenmuk, this PR is opened while #112479 was marked as backported. The pr-backports-created is removed, so the original PR can be processed again.

If the cherry-pick is not needed anymore, then just close this PR.

…ypick-26.3-112479-local

# Conflicts:
#	src/Storages/RabbitMQ/StorageRabbitMQ.cpp
@robot-ch-test-poll
robot-ch-test-poll merged commit 93f4eac into backport/26.3/112479 Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants