-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Postgres/MySQL Source Strict Encrypt: stop enforce SSL if ssl mode disabled #19025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
f6fbee6
3e2e3c4
b6d36d7
2bcd621
3fa7a64
3d2d0c8
3e198de
cb950f9
8d1527c
cca315c
221e76d
692ba6b
874dd03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,6 +210,42 @@ void testUssSslWithSslSetAndValueIntegerTrue() { | |
assertTrue(sslSet); | ||
} | ||
|
||
@Test | ||
void testUseSslWithEmptySslKeyAndSslModeVerifyFull() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests are good, let's also add an integration test for both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@ryankfu i added a couple of tests for postgres and mysql in order to cover such a case that the user encountered (when SSH tunnel was set and ssl_mode: disabled) |
||
final JsonNode config = Jsons.jsonNode(ImmutableMap.builder() | ||
.put("host", PSQL_DB.getHost()) | ||
.put("port", PSQL_DB.getFirstMappedPort()) | ||
.put("database", dbName) | ||
.put("username", PSQL_DB.getUsername()) | ||
.put("password", PSQL_DB.getPassword()) | ||
.put("ssl_mode", ImmutableMap.builder() | ||
.put("mode", "verify-full") | ||
.put("ca_certificate", "test_ca_cert") | ||
.put("client_certificate", "test_client_cert") | ||
.put("client_key", "test_client_key") | ||
.put("client_key_password", "test_pass") | ||
.build()) | ||
.build()); | ||
final boolean sslSet = JdbcUtils.useSsl(config); | ||
assertTrue(sslSet); | ||
} | ||
|
||
@Test | ||
void testUseSslWithEmptySslKeyAndSslModeDisable() { | ||
final JsonNode config = Jsons.jsonNode(ImmutableMap.builder() | ||
.put("host", PSQL_DB.getHost()) | ||
.put("port", PSQL_DB.getFirstMappedPort()) | ||
.put("database", dbName) | ||
.put("username", PSQL_DB.getUsername()) | ||
.put("password", PSQL_DB.getPassword()) | ||
.put("ssl_mode", ImmutableMap.builder() | ||
.put("mode", "disable") | ||
.build()) | ||
.build()); | ||
final boolean sslSet = JdbcUtils.useSsl(config); | ||
assertFalse(sslSet); | ||
} | ||
|
||
private static void createTableWithAllTypes(final Connection connection) throws SQLException { | ||
// jdbctype not included because they are not directly supported in postgres: TINYINT, LONGVARCHAR, | ||
// VARBINAR, LONGVARBINARY | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package io.airbyte.integrations.source.postgres; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.google.common.collect.ImmutableMap; | ||
import io.airbyte.db.jdbc.JdbcUtils; | ||
import io.airbyte.integrations.base.ssh.SshBastionContainer; | ||
import io.airbyte.integrations.base.ssh.SshTunnel; | ||
import io.airbyte.protocol.models.AirbyteConnectionStatus; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.Network; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class PostgresSourceStrictEncryptTest { | ||
private static final SshBastionContainer bastion = new SshBastionContainer(); | ||
private static final Network network = Network.newNetwork(); | ||
|
||
@Test | ||
void testCheckWithSSlModeDisable() throws Exception { | ||
|
||
try (PostgreSQLContainer<?> db = new PostgreSQLContainer<>("postgres:13-alpine").withNetwork(network)) { | ||
bastion.initAndStartBastion(network); | ||
db.start(); | ||
|
||
// stop to enforce ssl for ssl_mode disable | ||
final ImmutableMap.Builder<Object, Object> builderWithSSLModeDisable = getDatabaseConfigBuilderWithSSLMode(db, "disable"); | ||
final JsonNode configWithSSLModeDisable = bastion.getTunnelConfig(SshTunnel.TunnelMethod.SSH_PASSWORD_AUTH, builderWithSSLModeDisable); | ||
final AirbyteConnectionStatus connectionStatusForDisabledMode = new PostgresSourceStrictEncrypt().check(configWithSSLModeDisable); | ||
assertEquals(AirbyteConnectionStatus.Status.SUCCEEDED, connectionStatusForDisabledMode.getStatus()); | ||
|
||
} finally { | ||
bastion.stopAndClose(); | ||
} | ||
} | ||
|
||
@Test | ||
void testCheckWithSSlModePrefer() throws Exception { | ||
|
||
try (PostgreSQLContainer<?> db = new PostgreSQLContainer<>("postgres:13-alpine").withNetwork(network)) { | ||
bastion.initAndStartBastion(network); | ||
db.start(); | ||
//continue to enforce ssl because ssl mode is prefer | ||
final ImmutableMap.Builder<Object, Object> builderWithSSLModePrefer = getDatabaseConfigBuilderWithSSLMode(db, "prefer"); | ||
final JsonNode configWithSSLModePrefer = bastion.getTunnelConfig(SshTunnel.TunnelMethod.SSH_PASSWORD_AUTH, builderWithSSLModePrefer); | ||
final AirbyteConnectionStatus connectionStatusForPreferredMode = new PostgresSourceStrictEncrypt().check(configWithSSLModePrefer); | ||
assertEquals(AirbyteConnectionStatus.Status.FAILED, connectionStatusForPreferredMode.getStatus()); | ||
assertEquals("State code: 08004; Message: The server does not support SSL.", connectionStatusForPreferredMode.getMessage()); | ||
|
||
} finally { | ||
bastion.stopAndClose(); | ||
} | ||
} | ||
|
||
private ImmutableMap.Builder<Object, Object> getDatabaseConfigBuilderWithSSLMode(PostgreSQLContainer<?> db, String sslMode) { | ||
return ImmutableMap.builder() | ||
.put(JdbcUtils.HOST_KEY, Objects.requireNonNull(db.getContainerInfo() | ||
.getNetworkSettings() | ||
.getNetworks() | ||
.entrySet().stream() | ||
.findFirst() | ||
.get().getValue().getIpAddress())) | ||
.put(JdbcUtils.PORT_KEY, db.getExposedPorts().get(0)) | ||
.put(JdbcUtils.DATABASE_KEY, db.getDatabaseName()) | ||
.put(JdbcUtils.SCHEMAS_KEY, List.of("public")) | ||
.put(JdbcUtils.USERNAME_KEY, db.getUsername()) | ||
.put(JdbcUtils.PASSWORD_KEY, db.getPassword()) | ||
.put(JdbcUtils.SSL_MODE_KEY, Map.of(JdbcUtils.MODE_KEY, sslMode)); | ||
} | ||
|
||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we update the javadoc description to update what this method now does so it's not de-synced from what this method originally did?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated javadoc