Skip to content

Commit ebf3d63

Browse files
authored
transport-netty4 module set TLS SNI when server_name is provided (#20321)
* transport-netty4 module set TLS SNI when server_name is provided Signed-off-by: Orlando AGESOKO <orlando.agesoko@soheito.moe> * add buildSecureClientTransportEngine hook with serverName to handle SNI Signed-off-by: Orlando AGESOKO <orlando.agesoko@soheito.moe> * delegate SNI configuration to the secureTransportSettingsProvider Signed-off-by: Orlando AGESOKO <orlando.agesoko@soheito.moe> * update CHANGELOG.md Signed-off-by: Orlando AGESOKO <orlando.agesoko@soheito.moe> * fix Changelog.md entry pointed to Issue instead of PR Signed-off-by: Orlando AGESOKO <orlando.agesoko@soheito.moe> * fix format Signed-off-by: Orlando AGESOKO <orlando.agesoko@soheito.moe> --------- Signed-off-by: Orlando AGESOKO <orlando.agesoko@soheito.moe>
1 parent a5081f3 commit ebf3d63

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2828
- Fix Netty deprecation warnings in transport-netty4 module ([#20233](https://github.com/opensearch-project/OpenSearch/pull/20233))
2929
- Fix snapshot restore when an index sort is present ([#20284](https://github.com/opensearch-project/OpenSearch/pull/20284))
3030
- Fix SearchPhaseExecutionException to properly initCause ([#20320](https://github.com/opensearch-project/OpenSearch/pull/20320))
31+
- Fix `cluster.remote.<cluster_alias>.server_name` setting no populating SNI ([#20321](https://github.com/opensearch-project/OpenSearch/pull/20321))
3132

3233
### Dependencies
3334
- Bump `com.google.auth:google-auth-library-oauth2-http` from 1.38.0 to 1.41.0 ([#20183](https://github.com/opensearch-project/OpenSearch/pull/20183))

modules/transport-netty4/src/main/java/org/opensearch/transport/netty4/ssl/SecureNetty4Transport.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,29 @@ protected static class ClientSSLHandler extends ChannelOutboundHandlerAdapter {
181181
private final SecureTransportSettingsProvider secureTransportSettingsProvider;
182182
private final boolean hostnameVerificationEnabled;
183183
private final boolean hostnameVerificationResovleHostName;
184+
private final String serverName;
184185

185186
private ClientSSLHandler(
186187
final Settings settings,
187188
final SecureTransportSettingsProvider secureTransportSettingsProvider,
188189
final boolean hostnameVerificationEnabled,
189190
final boolean hostnameVerificationResovleHostName
191+
) {
192+
this(settings, secureTransportSettingsProvider, hostnameVerificationEnabled, hostnameVerificationResovleHostName, null);
193+
}
194+
195+
private ClientSSLHandler(
196+
final Settings settings,
197+
final SecureTransportSettingsProvider secureTransportSettingsProvider,
198+
final boolean hostnameVerificationEnabled,
199+
final boolean hostnameVerificationResovleHostName,
200+
final String serverName
190201
) {
191202
this.settings = settings;
192203
this.secureTransportSettingsProvider = secureTransportSettingsProvider;
193204
this.hostnameVerificationEnabled = hostnameVerificationEnabled;
194205
this.hostnameVerificationResovleHostName = hostnameVerificationResovleHostName;
206+
this.serverName = serverName;
195207
}
196208

197209
@Override
@@ -229,12 +241,14 @@ public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, Sock
229241

230242
sslEngine = secureTransportSettingsProvider.buildSecureClientTransportEngine(
231243
settings,
244+
serverName,
232245
hostname,
233246
inetSocketAddress.getPort()
234247
).orElse(null);
235248

236249
} else {
237-
sslEngine = secureTransportSettingsProvider.buildSecureClientTransportEngine(settings, null, -1).orElse(null);
250+
sslEngine = secureTransportSettingsProvider.buildSecureClientTransportEngine(settings, serverName, null, -1)
251+
.orElse(null);
238252
}
239253

240254
if (sslEngine == null) {
@@ -299,7 +313,8 @@ protected void initChannel(Channel ch) throws Exception {
299313
settings,
300314
secureTransportSettingsProvider,
301315
hostnameVerificationEnabled,
302-
hostnameVerificationResolveHostName
316+
hostnameVerificationResolveHostName,
317+
node.getAttributes().get("server_name")
303318
)
304319
);
305320
} else {

server/src/main/java/org/opensearch/plugins/SecureTransportSettingsProvider.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,18 @@ interface SecureTransportParameters {
122122
* @throws SSLException throws SSLException if the {@link SSLEngine} instance cannot be built
123123
*/
124124
Optional<SSLEngine> buildSecureClientTransportEngine(Settings settings, String hostname, int port) throws SSLException;
125+
126+
/**
127+
* If supported, builds the {@link SSLEngine} instance for client transport instance
128+
* @param settings settings
129+
* @param serverName the name to send in the TLS Server Name Indication (SNI) extension
130+
* @param hostname host name
131+
* @param port port
132+
* @return if supported, builds the {@link SSLEngine} instance
133+
* @throws SSLException throws SSLException if the {@link SSLEngine} instance cannot be built
134+
*/
135+
default Optional<SSLEngine> buildSecureClientTransportEngine(Settings settings, String serverName, String hostname, int port)
136+
throws SSLException {
137+
return buildSecureClientTransportEngine(settings, hostname, port);
138+
}
125139
}

0 commit comments

Comments
 (0)