Skip to content

GH-1526: [JDBC] Allow disabling connections to server-advertised endpoint locations - #1527

Merged
jbonofre merged 5 commits into
apache:mainfrom
fredjoonpark:GH-1526-follow-endpoint-locations
Nov 27, 2026
Merged

jbonofre merged 5 commits into
apache:mainfrom
fredjoonpark:GH-1526-follow-endpoint-locations

Conversation

@fredjoonpark

Copy link
Copy Markdown
Contributor

What's Changed

Adds a followEndpointLocations connection property, defaulting to true so nothing changes for existing users. With false, getStreams never opens a new connection for an endpoint, so the connection's credentials, client certificate and headers only go to the host the application connected to.

  • An endpoint is fetched over the existing connection if it has no locations, the arrow-flight-reuse-connection://? location, or a grpc, grpc+tcp or grpc+tls location on the connection's host and port. A grpc+tls location is only used when the connection uses TLS, and other schemes need another transport, such as an HTTP GET for https. A grpc or grpc+tcp location on a TLS connection is fetched over TLS. When TLS is enabled, a location on hostnameOverride also counts, on the connection's port unless the override includes one. Hosts are compared by name (case-insensitively, IPv6 brackets ignored), without DNS resolution.
  • Other locations are skipped through the per-location path that already refuses non-TLS locations on encrypted connections, so an endpoint's other locations are still tried. The query fails with an SQLException only if an endpoint has no location that can be used. The issue proposes failing on the first such location instead, but Flight.proto says an endpoint's locations are equivalent, so using an allowed one loses nothing.
  • The message for a skipped location only shows its scheme, host and port, since its other parts can hold credentials, such as a presigned URL's signature.
  • The handler keeps the setting it was built with, so changing the builder afterwards can't re-enable following.
  • Every result fetch (statements, prepared statements and DatabaseMetaData) goes through getStreams, so the check is only needed there. The host and port check is shared with getHostnameOverrideForEndpoint.
  • Documented in docs/source/flight_sql_jdbc_driver.rst.

Example:

jdbc:arrow-flight-sql://flight.example.com:443?followEndpointLocations=false

Notes:

  • The default stays true, since changing it would break servers that serve partitions from other hosts.
  • Drivers without this change ignore the property and send it to the server as a gRPC header, so applications that rely on it need a driver version that includes it. As for the other boolean properties, a blank or unrecognized value counts as false.
  • Locations on the connection's own host and port only reuse the connection when the property is false. By default they still get a new connection, as before (see the GH-38574 comment in getStreams).
  • There is no way to allow specific other hosts when the property is false. An allowlist could be added later if anyone needs it.
  • The existing message for non-TLS locations on encrypted connections still shows the whole location URI. That predates this change and could be redacted the same way separately.

Tests

  • ConnectionFollowEndpointLocationsTest (new). Its servers record the calls they receive:
    • by default, a server at another location is sent the connection's bearer token;
    • with followEndpointLocations=false, the query fails and that server receives no calls;
    • for a server that advertises its own location, the calls come from one client connection with false, and from two by default.
  • ArrowFlightSqlClientHandlerTest: locations on another host (over encrypted and plaintext connections), on another port of the connection's host, and on the connection's host and port but needing another transport (grpc+tls on a plaintext connection, https) are refused without using the client. The connection's own location (including grpc and grpc+tcp locations on an encrypted connection), a location on hostnameOverride, and [other host, arrow-flight-reuse-connection] are fetched over the existing client. The setting is kept after the builder changes, and the refusal message leaves out the location's user info, path, query and fragment.
  • ArrowFlightSqlClientHandlerBuilderTest: location matching for case, a different or missing port, Unix sockets, IPv6 hosts with and without brackets, an override with and without a port, and an override without TLS. Also the default, and that a builder copy keeps the setting.
  • ArrowFlightConnectionConfigImplTest: the default and parsing.

This change is additive and has no breaking changes.

The code, tests and docs were drafted with an AI assistant (Claude). The refusal and connection-reuse tests fail when getStreams ignores the property, and the full flight-sql-jdbc-core build passes.

Closes #1526.

Fred Park added 5 commits November 26, 2026 11:53
…d endpoint locations

Add a followEndpointLocations connection property, defaulting to true so
existing behavior is unchanged. When false, getStreams never opens a new
connection for an endpoint, so the connection's credentials are only sent
to the host the application connected to. Endpoints with no locations,
the arrow-flight-reuse-connection location, or a location on the
connection's own host (or hostnameOverride, when TLS is enabled) and port
are fetched over the existing connection. Other locations are refused
through the existing per-location error path, so an endpoint's remaining
locations are still tried, and the query fails with an SQLException if
none can be used.

Closes apache#1526.
An override that includes a port (flight.example.com:32010) never
matched, though the docs allow one; it now matches locations on that
host and port. Share the host and port check with
getHostnameOverrideForEndpoint. Note in the docs that the scheme is
ignored, that followed connections also get the client certificate and
headers, and that retainCookies and retainAuth have no effect when
false. Replace the fallback end-to-end test, which passed with the flag
ignored, with one where the server advertises its own location, and
cover bracketed IPv6 hosts.
Move the end-to-end tests into ConnectionFollowEndpointLocationsTest,
whose servers record the calls they receive. With credentials set, the
other server is sent the connection's bearer token by default and
receives no calls at all when followEndpointLocations is false. For a
server that advertises its own location, the calls come from one client
connection instead of two. Also check that a builder copy keeps the
setting, and document that hosts are compared without DNS resolution.
Move "whatever its scheme" to the location it applies to, and make the
test producer's location volatile, since it is set after the server
starts and read on server threads.
Snapshot followEndpointLocations when the handler is built, so changing
the builder afterwards can't re-enable following. Only fetch gRPC
locations over the existing connection, and grpc+tls ones only over an
encrypted connection, since other schemes need another transport, such
as an HTTP GET for https. Show only the scheme, host and port of a
refused location, since its other parts can hold credentials, such as a
presigned URL's signature.
@github-actions

This comment has been minimized.

@lidavidm lidavidm added the enhancement PRs that add or improve features. label Nov 27, 2026
@github-actions github-actions Bot added this to the 20.1.0 milestone Nov 27, 2026

@jbonofre jbonofre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this, LGTM.

With followEndpointLocations=false I wouldn't find a way for the server the make the driver open a connection to another host, and the default behaviour is unchanged.

@jbonofre
jbonofre merged commit 6f96cb1 into apache:main Nov 27, 2026
22 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement PRs that add or improve features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Java][FlightSQL][JDBC] Driver sends credentials to any host a server advertises, with no way to turn it off

3 participants