feat: add enable_client_ip_attr_trust to stop trusting client-reported __client_ip - #60
Open
naughtyGitCat wants to merge 1 commit into
Open
naughtyGitCat wants to merge 1 commit into
naughtyGitCat wants to merge 1 commit into
Conversation
…d __client_ip When enable_client_ip_checkout is on, rewrite_handshake_response_packet first writes the peer address detected by obproxy into client_ip_buf_, then lets a __client_ip connect attribute sent by the client overwrite it unconditionally. OceanBase Connector/J (2.4.0 ~ 2.4.19) always reports socket.getLocalAddress() in __client_ip. For an application running inside a container that is the container address (e.g. 172.18.0.7), so observer applies ob_tcp_invited_nodes and the user@host match against an address that never reaches the proxy, and the login fails with ERROR 1227 Access denied although the TCP peer is in the whitelist. It also means any client can claim an arbitrary source ip. Add config item enable_client_ip_attr_trust (default true, behaviour unchanged). When set to false, obproxy forwards the detected peer address and only accepts __client_ip from an upstream obproxy, identified by __mysql_client_type=__ob_proxy in the login packet, so proxy chaining keeps working. Ignored self-reported values are logged at DEBUG level. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
naughtyGitCat
force-pushed
the
fix/client-ip-attr-trust
branch
from
September 11, 2026 08:18
4e55b5c to
941de2f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With
enable_client_ip_checkout=true(default),ObMysqlPacketRewriter::rewrite_handshake_response_packetfirst stores the peer address detected by obproxy (write_client_addr_buf), then scans the client's connect attributes and lets a client-supplied__client_ipoverwrite it unconditionally. The result is forwarded to observer as__client_ipand used there forob_tcp_invited_nodesand theuser@hostmatch.OceanBase Connector/J (every release on Maven Central, 2.4.0 through 2.4.19) sends
socket.getLocalAddress().getHostAddress()as__client_ipon every login. When the application runs inside a container the reported address is the container address.Observed on OceanBase CE 5.0.1.0 / obproxy 4.x:
ob_tcp_invited_nodeswas10.0.0.0/8,...and the user wasyoudata_mid@10.104.14.71; both would have matched the detected peer. Beyond the container case, this also means any client can claim an arbitrary source address, so the tenant whitelist and per-user host restriction are only as strong as the client's honesty.Turning
enable_client_ip_checkoutoff is not a workaround: it stops sending__client_ipentirely, observer then falls back to its own peer (the obproxy address), and every user created with a specific host fails to log in.Change
New config item
enable_client_ip_attr_trust(CFG_NO_NEED_REBOOT, global level).true(default): behaviour is unchanged.false: obproxy forwards the peer address it detected. A client-supplied__client_ipis only honoured when the login packet carries__mysql_client_type=__ob_proxy, i.e. the client is an upstream obproxy, so proxy chaining keeps working. Ignored values are logged at DEBUG.Only effective when
enable_client_ip_checkoutistrue.Files:
ob_proxy_config.h,ob_mysql_config_processor.{h,cpp},ob_mysql_packet_rewriter.{h,cpp},ob_mysql_transact.cpp.Notes
trueto avoid breaking deployments behind a NAT load balancer that rely on the driver-reported address. Maintainers may want to consider flipping the default in a future major release.enable_client_ip_checkoutplumbing and uses only constants and helpers already referenced in the same function (OB_MYSQL_CLIENT_MODE,OB_MYSQL_CLIENT_OBPROXY_MODE,ObString::compare). Happy to adjust if CI reports anything.defaultConnectionAttributesBanList=__client_ip(available since Connector/J 2.4.1), but the proxy should not have to trust a client-chosen address for an access-control decision.🤖 Generated with Claude Code