Fix per-endpoint TLS/cleartext switching for xDS clusters with mixed transport_socket_matches - #6850
Fix per-endpoint TLS/cleartext switching for xDS clusters with mixed transport_socket_matches#6850jrhee17 wants to merge 1 commit into
transport_socket_matches#6850Conversation
📝 WalkthroughWalkthroughThe xDS client now derives session protocols from HTTP protocol options and clears TLS settings for plaintext endpoints. New integration tests cover mixed TLS/plaintext endpoint selection during round-robin requests and retries. ChangesxDS mixed transport session protocol handling
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
it/xds-client/src/test/java/com/linecorp/armeria/xds/it/MixedTransportSocketRetryTest.java (1)
195-197: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider extracting
base64Certto a shared utility.The
base64Certmethod is duplicated verbatim inMixedTransportSocketSessionProtocolTest. Consider extracting it (andXdsCertificateExtensionif co-located) to a shared test helper in the same package to reduce duplication.🤖 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 `@it/xds-client/src/test/java/com/linecorp/armeria/xds/it/MixedTransportSocketRetryTest.java` around lines 195 - 197, The `base64Cert` helper is duplicated in `MixedTransportSocketRetryTest` and `MixedTransportSocketSessionProtocolTest`; move it into a shared test utility in the same package and update both tests to call that shared helper. If `XdsCertificateExtension` belongs with it, co-locate that logic in the same helper so the duplicated certificate-loading code is centralized and easier to maintain.core/src/test/java/com/linecorp/armeria/internal/client/DefaultClientRequestContextTest.java (1)
447-552: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winLGTM on the new
setSessionProtocoltests — they're logically consistent with the implementation. One gap: this file doesn't directly testsetClientTlsSpec()/clearClientTlsSpec()driving the sessionProtocol TLS/cleartext switch (lines 1112-1126 inDefaultClientRequestContext.java), onlysetSessionProtocol()itself. Consider adding a test mirroring the existing pattern to cover that path directly.🤖 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/test/java/com/linecorp/armeria/internal/client/DefaultClientRequestContextTest.java` around lines 447 - 552, The new tests cover setSessionProtocol() directly, but they do not exercise the TLS/cleartext transition triggered by setClientTlsSpec() and clearClientTlsSpec(). Add a test in DefaultClientRequestContextTest that follows the existing init/update assertions and verifies that calling setClientTlsSpec() switches sessionProtocol() and URI/header scheme to HTTPS, and clearClientTlsSpec() switches them back to HTTP. Use the existing DefaultClientRequestContext, sessionProtocol(), uri(), and internalRequestHeaders() patterns to keep the coverage aligned with the current tests.
🤖 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.
Nitpick comments:
In
`@core/src/test/java/com/linecorp/armeria/internal/client/DefaultClientRequestContextTest.java`:
- Around line 447-552: The new tests cover setSessionProtocol() directly, but
they do not exercise the TLS/cleartext transition triggered by
setClientTlsSpec() and clearClientTlsSpec(). Add a test in
DefaultClientRequestContextTest that follows the existing init/update assertions
and verifies that calling setClientTlsSpec() switches sessionProtocol() and
URI/header scheme to HTTPS, and clearClientTlsSpec() switches them back to HTTP.
Use the existing DefaultClientRequestContext, sessionProtocol(), uri(), and
internalRequestHeaders() patterns to keep the coverage aligned with the current
tests.
In
`@it/xds-client/src/test/java/com/linecorp/armeria/xds/it/MixedTransportSocketRetryTest.java`:
- Around line 195-197: The `base64Cert` helper is duplicated in
`MixedTransportSocketRetryTest` and `MixedTransportSocketSessionProtocolTest`;
move it into a shared test utility in the same package and update both tests to
call that shared helper. If `XdsCertificateExtension` belongs with it, co-locate
that logic in the same helper so the duplicated certificate-loading code is
centralized and easier to maintain.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 8870940b-b434-4f1e-96ba-66b192801121
📒 Files selected for processing (9)
core/src/main/java/com/linecorp/armeria/client/ClientRequestContext.javacore/src/main/java/com/linecorp/armeria/client/ClientRequestContextWrapper.javacore/src/main/java/com/linecorp/armeria/common/SessionProtocol.javacore/src/main/java/com/linecorp/armeria/internal/client/DefaultClientRequestContext.javacore/src/test/java/com/linecorp/armeria/internal/client/DefaultClientRequestContextTest.javait/xds-client/src/test/java/com/linecorp/armeria/xds/it/MixedTransportSocketRetryTest.javait/xds-client/src/test/java/com/linecorp/armeria/xds/it/MixedTransportSocketSessionProtocolTest.javaxds/src/main/java/com/linecorp/armeria/xds/ClusterFilterFactory.javaxds/src/main/java/com/linecorp/armeria/xds/ClusterStream.java
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6850 +/- ##
============================================
- Coverage 74.46% 0 -74.47%
============================================
Files 1963 0 -1963
Lines 82437 0 -82437
Branches 10764 0 -10764
============================================
- Hits 61385 0 -61385
+ Misses 15918 0 -15918
+ Partials 5134 0 -5134 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Tick the box to add this pull request to the merge queue (same as
|
60c0406 to
1bdd051
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
SessionProtocol.withTls()/withoutTls() and per-endpoint TLS/cleartext switchingtransport_socket_matches
Motivation:
When an xDS cluster has mixed TLS and plaintext endpoints (via
transport_socket_matches), the session protocol must switch dynamically per endpoint. Previously,ClusterFilterFactorypicked a fixed session protocol at cluster level based on whether a defaulttransport_socketwas present. This meant all endpoints in a cluster used the same TLS/cleartext setting, which broke mixed clusters where some endpoints useUpstreamTlsContextand others useraw_buffer.Modifications:
ClusterFilterFactoryto always default to a TLS session protocol (based onHttpProtocolOptions), and defer per-endpoint TLS decisions to theapplyClusterSettingsdecorator. When the endpoint'sTransportSocketSnapshothas noClientTlsSpec(i.e.,raw_buffer),clearClientTlsSpec()is called to switch the protocol to cleartext.transportSocketparameter from theClusterFilterFactoryconstructor since TLS is no longer decided at cluster level.ClusterStreamaccordingly to stop passingtransportSocketto the constructor.MixedTransportSocketSessionProtocolTestverifying that a round-robin cluster with one TLS endpoint and one plaintext endpoint uses the correct session protocol for each.MixedTransportSocketRetryTestverifying that retry-created derived contexts also get the correct per-endpoint session protocol when retrying across mixed endpoints through real server connections.Result:
transport_socket_matchescontaining both TLS andraw_bufferentries now correctly switch between TLS and cleartext per endpoint.