Skip to content

GH-1499: [JDBC] Prefer an explicit trustStore over the system trust store - #1496

Merged
jbonofre merged 1 commit into
apache:mainfrom
Arawoof06:jdbc-truststore-precedence
Nov 18, 2026
Merged

jbonofre merged 1 commit into
apache:mainfrom
Arawoof06:jdbc-truststore-precedence

Conversation

@Arawoof06

@Arawoof06 Arawoof06 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What's Changed

ArrowFlightSqlClientHandler.Builder.build() picks the TLS trust source in the order tlsRootCerts, useSystemTrustStore, trustStore. useSystemTrustStore defaults to true, so a connection configured with trustStore and trustStorePassword but without useSystemTrustStore=false never reads that trust store. The server is validated against the system store instead, which is opened with the trust store's password. When that password matches the JDK cacerts (changeit), or on Windows and macOS where the system keychains need none, any certificate chaining to a system CA is accepted even though the user limited trust to their own CA, and the handshake then sends the credentials to that server. Otherwise the connection fails with "Keystore was tampered with, or password was incorrect", which is why every existing test sets useSystemTrustStore=false next to trustStore.

An explicit trustStore now takes precedence over the system store, the same way tlsRootCerts already does, and the docs say useSystemTrustStore is ignored when either is set. Configurations that already set useSystemTrustStore=false are unaffected. The new test in ConnectionTlsTest connects with trustStore and the default useSystemTrustStore and fails without this change. testGetAuthenticatedEncryptedConnectionWithKeyStoreBadPassword still passes, now failing on the configured trust store rather than on cacerts.

Closes #1499.

useSystemTrustStore defaults to true and was checked before trustStore, so a
configured trustStore was ignored unless useSystemTrustStore=false was also
set, and the server was validated against the system trust store instead.
Check trustStore first, as tlsRootCerts already is.
@github-actions

This comment has been minimized.

@lidavidm lidavidm added the bug-fix PRs that fix a big. label Nov 17, 2026
@github-actions github-actions Bot added this to the 20.0.0 milestone Nov 17, 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.

LGTM on the code, test, and documentation changes. Good catch on useSystemTrustStore shadowing an explicit trustStore by default.

One process item before merging: per CONTRIBUTING.md, functional/bug-fix changes should be linked to a GitHub issue rather than using the MINOR: prefix.

If you don't mind, I will create an issue and update PR title.

@jbonofre jbonofre changed the title MINOR: [JDBC] Prefer an explicit trustStore over the system trust store GH-1499: [JDBC] Prefer an explicit trustStore over the system trust store Nov 18, 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.

LGTM.

I opened #1499 and updated the PR title and description to link it per CONTRIBUTING.md.

@jbonofre
jbonofre merged commit 4fcf67e into apache:main Nov 18, 2026
23 of 25 checks passed
jbonofre added a commit that referenced this pull request Nov 19, 2026
… values and missing password (#1501)

## What's Changed

Follow-up to #1496 (#1499).

- Treat blank `trustStore` and `tlsRootCerts` values as unset (`null`)
in `ArrowFlightConnectionConfigImpl` and
`ArrowFlightSqlClientHandler.Builder` (consistent with
`hostnameOverride`), so empty query parameters or blank optional
properties (e.g., `?trustStore=&useSystemTrustStore=true` or
`?tlsRootCerts=&trustStore=...`) do not shadow fallback trust sources or
fail trying to open an empty path.
- Validate `trustStorePassword != null` in
`ArrowFlightSqlClientHandler.Builder#build()` before calling
`ClientAuthenticationUtils.getCertificateStream(...)`, so configuring
`trustStore` without `trustStorePassword` throws `SQLException`
(wrapping `IllegalArgumentException`) and closes the connection
allocator instead of leaking an uncaught `NullPointerException`.
- Sync Javadoc on
`ArrowFlightSqlClientHandler.Builder#withSystemTrustStore`,
`#withTrustStorePath`, and `#withTlsRootCertificates`, and clarify
precedence and blank-value handling in
`docs/source/flight_sql_jdbc_driver.rst`.
- Tighten
`ConnectionTlsTest#testGetAuthenticatedEncryptedConnectionWithKeyStoreBadPassword`
to assert the `IOException` -> `UnrecoverableKeyException` cause chain,
and add unit/connection tests for blank `trustStore`/`tlsRootCerts` and
missing `trustStorePassword`.

## Tests

- Ran `ConnectionTlsTest`, `ConnectionTlsRootCertsTest`,
`ConnectionTlsHostnameOverrideTest`, `ConnectionMutualTlsTest`,
`ArrowFlightSqlClientHandlerBuilderTest`, and
`ArrowFlightConnectionConfigImplTest` on JDK 17, 21, and 25, plus
`spotless:check` and `checkstyle:check`.

Closes #1500.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PRs that fix a big.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JDBC] Explicit trustStore is ignored unless useSystemTrustStore=false

3 participants