Skip to content

Commit efa8bb9

Browse files
authored
fix: Update the R2DBC connectors to work with Netty 4.2+ (#2240)
Netty 4.2 sets the default SSL host validation mode to HTTPS. Netty 4.1 did not set this. The R2DBC connector needs to clear the SSL host validation mode so that that Netty will use the connector's custom hostname validation logic instead of the default. Fixes #2227
1 parent 22137c8 commit efa8bb9

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed

pom.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -236,42 +236,42 @@
236236
<dependency>
237237
<groupId>io.projectreactor.netty</groupId>
238238
<artifactId>reactor-netty</artifactId>
239-
<version>1.2.8</version>
239+
<version>1.3.1</version>
240240
</dependency>
241241
<dependency>
242242
<groupId>io.netty</groupId>
243243
<artifactId>netty-handler</artifactId>
244-
<version>4.1.123.Final</version>
244+
<version>4.2.7.Final</version>
245245
</dependency>
246246
<dependency>
247247
<groupId>io.netty</groupId>
248248
<artifactId>netty-common</artifactId>
249-
<version>4.1.123.Final</version>
249+
<version>4.2.7.Final</version>
250250
</dependency>
251251
<dependency>
252252
<groupId>io.netty</groupId>
253253
<artifactId>netty-transport</artifactId>
254-
<version>4.1.123.Final</version>
254+
<version>4.2.7.Final</version>
255255
</dependency>
256256
<dependency>
257257
<groupId>io.netty</groupId>
258258
<artifactId>netty-transport-native-unix-common</artifactId>
259-
<version>4.1.123.Final</version>
259+
<version>4.2.7.Final</version>
260260
</dependency>
261261
<dependency>
262262
<groupId>io.netty</groupId>
263263
<artifactId>netty-buffer</artifactId>
264-
<version>4.1.123.Final</version>
264+
<version>4.2.7.Final</version>
265265
</dependency>
266266
<dependency>
267267
<groupId>io.netty</groupId>
268268
<artifactId>netty-codec</artifactId>
269-
<version>4.1.123.Final</version>
269+
<version>4.2.7.Final</version>
270270
</dependency>
271271
<dependency>
272272
<groupId>io.netty</groupId>
273273
<artifactId>netty-resolver</artifactId>
274-
<version>4.1.123.Final</version>
274+
<version>4.2.7.Final</version>
275275
</dependency>
276276
<!-- Logging -->
277277
<dependency>
@@ -396,11 +396,11 @@
396396
</ignoreVersion>
397397
</rule>
398398
<rule>
399-
<!-- Always Ignore netty versions > 4.1 -->
399+
<!-- Always Ignore netty versions > 4.2 -->
400400
<groupId>io.netty</groupId>
401401
<ignoreVersion>
402402
<type>range</type>
403-
<version>[4.2.0.Alpha,)</version>
403+
<version>[4.3.0.Alpha,)</version>
404404
</ignoreVersion>
405405
<ignoreVersion>
406406
<type>regex</type>

r2dbc/core/src/main/java/com/google/cloud/sql/core/CloudSqlConnectionFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public Publisher<? extends Connection> create() {
5555
.getConnectionMetadata(config)
5656
.getPreferredIpAddress();
5757
builder.option(HOST, hostIp).option(PORT, SERVER_PROXY_PORT);
58-
5958
return Mono.from(supplier.get().create(builder.build()).create())
6059
.map(c -> new CloudSqlConnection(config, c));
6160
}

r2dbc/core/src/main/java/com/google/cloud/sql/core/GcpConnectionFactoryProvider.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ public ConnectionFactory create(ConnectionFactoryOptions connectionFactoryOption
174174
sslContextBuilder.trustManager(connectionMetadata.getTrustManagerFactory());
175175
sslContextBuilder.protocols("TLSv1.2");
176176

177+
// Disable the default SSL hostname verification. Cloud SQL instances
178+
// require custom hostname checking logic, which is implemented in the
179+
// InstanceCheckingTrustManagerFactory.
180+
sslContextBuilder.endpointIdentificationAlgorithm("");
181+
177182
return sslContextBuilder;
178183
};
179184
return tcpSocketConnectionFactory(config, optionBuilder, sslFunction);

r2dbc/postgres/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<dependency>
5959
<groupId>org.postgresql</groupId>
6060
<artifactId>r2dbc-postgresql</artifactId>
61-
<version>1.0.7.RELEASE</version>
61+
<version>1.1.1.RELEASE</version>
6262
<scope>provided</scope>
6363
<exclusions>
6464
<exclusion>

r2dbc/postgres/src/main/java/com/google/cloud/sql/core/GcpConnectionFactoryProviderPostgres.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.netty.handler.ssl.SslContextBuilder;
2323
import io.r2dbc.postgresql.PostgresqlConnectionFactoryProvider;
2424
import io.r2dbc.postgresql.client.SSLMode;
25+
import io.r2dbc.postgresql.client.SSLNegotiation;
2526
import io.r2dbc.spi.ConnectionFactory;
2627
import io.r2dbc.spi.ConnectionFactoryOptions;
2728
import io.r2dbc.spi.ConnectionFactoryProvider;
@@ -51,7 +52,8 @@ ConnectionFactory tcpSocketConnectionFactory(
5152
Function<SslContextBuilder, SslContextBuilder> customizer) {
5253
builder
5354
.option(PostgresqlConnectionFactoryProvider.SSL_CONTEXT_BUILDER_CUSTOMIZER, customizer)
54-
.option(PostgresqlConnectionFactoryProvider.SSL_MODE, SSLMode.TUNNEL)
55+
.option(PostgresqlConnectionFactoryProvider.SSL_MODE, SSLMode.REQUIRE)
56+
.option(PostgresqlConnectionFactoryProvider.SSL_NEGOTIATION, SSLNegotiation.TUNNEL)
5557
.option(PostgresqlConnectionFactoryProvider.TCP_NODELAY, true)
5658
.option(PostgresqlConnectionFactoryProvider.TCP_KEEPALIVE, true);
5759

r2dbc/postgres/src/test/java/com/google/cloud/sql/core/R2dbcPostgresIamAuthIntegrationTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
2424
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
2525
import static io.r2dbc.spi.ConnectionFactoryOptions.HOST;
26-
import static io.r2dbc.spi.ConnectionFactoryOptions.PASSWORD;
2726
import static io.r2dbc.spi.ConnectionFactoryOptions.PROTOCOL;
2827
import static io.r2dbc.spi.ConnectionFactoryOptions.USER;
2928

@@ -46,7 +45,6 @@
4645

4746
@RunWith(JUnit4.class)
4847
public class R2dbcPostgresIamAuthIntegrationTests {
49-
5048
// [START cloud_sql_connector_postgres_r2dbc_iam_auth]
5149
private static final String CONNECTION_NAME = System.getenv("POSTGRES_CONNECTION_NAME");
5250
private static final String DB_NAME = System.getenv("POSTGRES_DB");
@@ -71,13 +69,13 @@ public void setUpPool() {
7169
.isNotEmpty());
7270

7371
// [START cloud_sql_connector_postgres_r2dbc_iam_auth]
72+
System.out.println("Using IAM user: " + DB_USER);
7473
// Set up ConnectionFactoryOptions
7574
ConnectionFactoryOptions options =
7675
ConnectionFactoryOptions.builder()
7776
.option(DRIVER, "gcp")
7877
.option(PROTOCOL, "postgresql")
7978
// Password must be set to a nonempty value to bypass driver validation errors
80-
.option(PASSWORD, "password")
8179
.option(USER, DB_USER)
8280
.option(DATABASE, DB_NAME)
8381
.option(HOST, CONNECTION_NAME)

0 commit comments

Comments
 (0)