mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(dsql): refuse a connection that sends no TLS server name (#6282)
DSQL knows the cluster only by the TLS server name, and refuses a connection that sends none with FATAL 08P01 "unable to accept connection, sni was not received" once its password is in, whatever the password (measured). The endpoint fell back to the host in the token and let such a connection in. It now refuses it as DSQL does, and admit takes the cluster from the server name alone. The integration tests connected to 127.0.0.1 through pgjdbc's NonValidatingFactory and sent no server name; DsqlClusterFixture now gives pgjdbc a NonValidatingFactory that names the cluster, as the compatibility test's factory does.
This commit is contained in:
1 parent
a9ceee1de6
commit
d20084ade3
6 files changed
+61
-8
No files matched your search
@@ -69,13 +69,17 @@ public final class DsqlClusterFixture {
|
||||
return "jdbc:postgresql://127.0.0.1:" + endpoint.port() + "/postgres";
|
||||
}
|
||||
|
||||
/** What JDBC needs to sign in as {@code user}: TLS, without checking Floci's certificate. */
|
||||
/**
|
||||
* What JDBC needs to sign in as {@code user}: TLS naming the cluster as its server, as DSQL
|
||||
* requires, without checking Floci's certificate.
|
||||
*/
|
||||
public Properties properties(String user, String password) {
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("user", user);
|
||||
properties.setProperty("password", password);
|
||||
properties.setProperty("sslmode", "require");
|
||||
properties.setProperty("sslfactory", "org.postgresql.ssl.NonValidatingFactory");
|
||||
properties.setProperty("sslfactory", DsqlServerNameSocketFactory.class.getName());
|
||||
properties.setProperty(DsqlServerNameSocketFactory.SERVER_NAME, host);
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
||||
+13
@@ -116,6 +116,19 @@ class DsqlDataPlaneIntegrationTest {
|
||||
assertEquals("08P01", plain.getSQLState());
|
||||
assertTrue(plain.getServerErrorMessage().getDetail().startsWith("Session Id: "));
|
||||
|
||||
// Measured: a connection that names no server is refused once its password is in, whatever it is.
|
||||
for (String password : List.of(cluster.adminToken(), "not-a-token")) {
|
||||
PSQLException unnamed = assertThrows(PSQLException.class, () -> {
|
||||
Properties properties = cluster.properties("admin", password);
|
||||
properties.setProperty("sslfactory", "org.postgresql.ssl.NonValidatingFactory");
|
||||
DriverManager.getConnection(cluster.url(), properties).close();
|
||||
});
|
||||
assertEquals("unable to accept connection, sni was not received",
|
||||
unnamed.getServerErrorMessage().getMessage());
|
||||
assertEquals("08P01", unnamed.getSQLState());
|
||||
assertTrue(unnamed.getServerErrorMessage().getDetail().startsWith("Session Id: "));
|
||||
}
|
||||
|
||||
PSQLException wrongAction = assertThrows(PSQLException.class, () ->
|
||||
cluster.connect("admin", cluster.token("DbConnect", "test", "test", Instant.now(), 900, null)).close());
|
||||
assertEquals("unable to accept connection, access denied", wrongAction.getServerErrorMessage().getMessage());
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package io.github.hectorvent.floci.services.dsql;
|
||||
|
||||
import org.postgresql.ssl.NonValidatingFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* pgjdbc's {@link NonValidatingFactory}, naming a DSQL cluster as the TLS server whatever address
|
||||
* pgjdbc dialled, as a client that resolves the cluster's endpoint does. pgjdbc builds it from the
|
||||
* connection's properties, which carry the name in {@link #SERVER_NAME}.
|
||||
*/
|
||||
public final class DsqlServerNameSocketFactory extends NonValidatingFactory {
|
||||
|
||||
public static final String SERVER_NAME = "dsqlServerName";
|
||||
|
||||
private final String serverName;
|
||||
|
||||
public DsqlServerNameSocketFactory(Properties info) throws GeneralSecurityException {
|
||||
super(null);
|
||||
this.serverName = info.getProperty(SERVER_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException {
|
||||
return super.createSocket(socket, serverName, port, autoClose);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user