Skip to content

fix: report hostname validation from active SSL engine - #999

Open
dkropachev wants to merge 2 commits into
scylladb:scylla-4.xfrom
dkropachev:fix/report-active-hostname-validation
Open

fix: report hostname validation from active SSL engine#999
dkropachev wants to merge 2 commits into
scylladb:scylla-4.xfrom
dkropachev:fix/report-active-hostname-validation

Conversation

@dkropachev

@dkropachev dkropachev commented Aug 12, 2026

Copy link
Copy Markdown

Follow-up to #968.

Removes the newly added hostname-validation accessors and derives the reported value from the active JDK SSLEngine instead. Unknown custom factories remain omitted.

Unrelated changes were extracted into:

Tests:

  • mvn -pl core -DskipITs -Dtest=DefaultDriverConfigReporterTest,ProtocolInitHandlerTest,CloudConfigFactoryTest test
  • full GitHub Actions matrix

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: QUIET

Plan: Pro Plus

Run ID: e79baa61-7858-4eb5-a2e0-d9e0239e8890

📥 Commits

Reviewing files that changed from the base of the PR and between dcfd2d2 and 38b3d57.

📒 Files selected for processing (2)
  • core/src/main/java/com/datastax/oss/driver/internal/core/context/DefaultDriverConfigReporter.java
  • core/src/test/java/com/datastax/oss/driver/internal/core/channel/ProtocolInitHandlerTest.java
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • scylladb/github-automation (auto-detected)
  • scylladb/scylladb (auto-detected)

Included review availability: Your plan includes up to 3 reviews per rolling hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The change removes hostname-validation accessors from SSL engine factories. JdkSslHandlerFactory records validation state from each created SSLEngine. DefaultDriverConfigReporter reads this state from the active channel and omits unknown values. The reporter API now accepts a channel. Tests cover overridden engines, SNI endpoints, unknown factories, removed handlers, and control-channel state.

Sequence Diagram(s)

sequenceDiagram
  participant ProtocolInitHandler
  participant DriverConfigReporter
  participant JdkSslHandlerFactory
  participant SSLEngine
  ProtocolInitHandler->>DriverConfigReporter: pass control channel
  DriverConfigReporter->>JdkSslHandlerFactory: read channel validation state
  JdkSslHandlerFactory->>SSLEngine: inspect SSL parameters
  DriverConfigReporter-->>ProtocolInitHandler: build configuration report
Loading

Suggested reviewers: nikagra

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.59% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly describes the main change: reporting hostname validation from the active SSL engine.
Description check ✅ Passed The description accurately explains the accessor removal, active SSLEngine inspection, unknown-factory behavior, and test coverage.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Note

Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.

🟡 Other comments (1)
core/src/main/java/com/datastax/oss/driver/internal/core/ssl/JdkSslHandlerFactory.java-47-53 (1)

47-53: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Treat subclasses as custom factories when the algorithm is absent.

instanceof ProgrammaticSslEngineFactory includes user subclasses. A subclass can implement hostname validation without setting an endpoint-identification algorithm. This branch then reports false instead of omitting an unknown value. Use exact-class checks for the built-in fallback.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@core/src/main/java/com/datastax/oss/driver/internal/core/ssl/JdkSslHandlerFactory.java`
around lines 47 - 53, Update the hostnameValidationRequired fallback in
JdkSslHandlerFactory to use exact-class checks for DefaultSslEngineFactory,
ProgrammaticSslEngineFactory, and SniSslEngineFactory rather than instanceof
checks. Ensure subclasses are treated as arbitrary custom factories, leaving the
value unknown when no endpoint-identification algorithm is configured.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@core/src/main/java/com/datastax/oss/driver/internal/core/ssl/JdkSslHandlerFactory.java`:
- Around line 33-55: Make hostname-validation state connection-specific instead
of storing it in the shared JdkSslHandlerFactory.hostnameValidationRequired
field. In newSslHandler, attach the computed value to the created SslHandler or
channel, then ensure the DRIVER_CONFIG/reporting path reads that per-connection
state for the same channel rather than the factory field.

---

Other comments:
In
`@core/src/main/java/com/datastax/oss/driver/internal/core/ssl/JdkSslHandlerFactory.java`:
- Around line 47-53: Update the hostnameValidationRequired fallback in
JdkSslHandlerFactory to use exact-class checks for DefaultSslEngineFactory,
ProgrammaticSslEngineFactory, and SniSslEngineFactory rather than instanceof
checks. Ensure subclasses are treated as arbitrary custom factories, leaving the
value unknown when no endpoint-identification algorithm is configured.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: QUIET

Plan: Pro Plus

Run ID: 9b308576-cae4-46e5-88fb-c10cd5bbd93c

📥 Commits

Reviewing files that changed from the base of the PR and between a3d7be6 and c99cd1b.

📒 Files selected for processing (5)
  • core/src/main/java/com/datastax/oss/driver/api/core/ssl/ProgrammaticSslEngineFactory.java
  • core/src/main/java/com/datastax/oss/driver/internal/core/context/DefaultDriverConfigReporter.java
  • core/src/main/java/com/datastax/oss/driver/internal/core/ssl/DefaultSslEngineFactory.java
  • core/src/main/java/com/datastax/oss/driver/internal/core/ssl/JdkSslHandlerFactory.java
  • core/src/test/java/com/datastax/oss/driver/internal/core/context/DefaultDriverConfigReporterTest.java
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • scylladb/github-automation (auto-detected)
  • scylladb/scylladb (auto-detected)
💤 Files with no reviewable changes (2)
  • core/src/main/java/com/datastax/oss/driver/api/core/ssl/ProgrammaticSslEngineFactory.java
  • core/src/main/java/com/datastax/oss/driver/internal/core/ssl/DefaultSslEngineFactory.java

@dkropachev
dkropachev force-pushed the fix/report-active-hostname-validation branch 2 times, most recently from 6dd1b17 to b9096d0 Compare August 12, 2026 22:06
@coderabbitai coderabbitai Bot added P1 and removed P3 labels Aug 12, 2026
Pass the control channel to the configuration reporter and retain the driver-installed JDK SSL handler on that channel. Read the endpoint-identification algorithm from the exact engine used for the connection instead of exposing diagnostic accessors on SSL engine factories.

Omit hostname verification when the driver-installed handler is unavailable or a disabled state cannot be determined safely.
Treat endpoint-identification parameters as authoritative only when the driver built the trust-manager path that interprets them. Mark configured truststore or keystore contexts and standard cloud bundles as known.

Omit hostname verification for process-wide, programmatic, subclassed, and arbitrary SSL contexts, whose trust managers may enforce or ignore hostname checks independently. Keep only a weak reference to the recorded handler.
@dkropachev
dkropachev force-pushed the fix/report-active-hostname-validation branch from 29fe44b to c53ad68 Compare August 19, 2026 23:53
if (!isHostnameValidationKnown()) {
return null;
}
String endpointIdentificationAlgorithm =

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

After the second commit this read can no longer differ from what the factory already knows: isHostnameValidationKnown() passes only for exact-class DefaultSslEngineFactory (sets HTTPS iff requireHostnameValidation) and SniSslEngineFactory (always sets it). The only thing the channel attribute, weak reference and pipeline walk still distinguish is a NettyOptions hook that replaced the driver's handler — paid for on every connection, plus the Channel parameter now threaded through DriverConfigReporter, NoopDriverConfigReporter and ProtocolInitHandler. Asking the two built-ins for the boolean collapses all of it.

/** Builds a new instance from the driver configuration. */
public DefaultSslEngineFactory(DriverContext driverContext) {
DriverExecutionProfile config = driverContext.getConfig().getDefaultProfile();
this.hostnameValidationKnown =

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This makes the field absent for the most common TLS setup — no keystore or truststore, server cert chaining to cacerts — where it used to be reported. If the reason is that SSLContext.getDefault() can be swapped process-wide via SSLContext.setDefault, that belongs here as a comment: the javadoc on isHostnameValidationKnown ("this factory built the trust-manager path") doesn't describe the keystore-only branch either, where context.init(km, null, …) leaves the JDK's default trust managers in place. It is also a verbatim copy of buildContext's condition below, with nothing keeping the two in step.

/* programmaticLocalDc= */ null);
Map<String, String> options = new HashMap<>();
r.populateControlConnectionOptions(options, reportingChannel); // must not throw
assertThat(options).isEmpty();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This pins more than the name says: one throwing getSSLParameters() drops the whole DRIVER_CONFIG blob — reconnection, timeouts, node location — through populateControlConnectionOptions's blanket catch, not just the optional field. A try/catch around the single getHostnameValidationRequired call would omit only hostname-verification, which the schema already allows.

}

/** Builds the factory for a cloud-bundle context whose trust managers the driver created. */
public static SniSslEngineFactory forCloudBundle(SSLContext sslContext) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Public and takes any SSLContext, so any caller can mint the "the driver built these trust managers" claim for a context it didn't build — the false positive this PR exists to remove. Package-private, with a package-private entry point for CloudConfigFactory, would keep the guarantee tied to the provenance. Nothing covers the getClass() == CloudConfigFactory.class branch either, so a subclass on the production path would silently drop the field for every cloud session with the suite green.

@Test
public void should_report_tls_enabled_with_hostname_verification() throws Exception {
// hostname-verification comes from the factory's own state, not the config option.
public void should_treat_a_programmatic_ssl_context_with_an_algorithm_as_unknown()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These four …_as_unknown tests now stop at the same return false in isHostnameValidationKnown() without ever reaching getSSLParameters(), so the anonymous subclasses that set or omit the algorithm are inert setup and imply the algorithm still decides something. should_report_only_built_in_factories_with_known_validators already covers the branch.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants