refactor(rds): split PostgresProtocolHandler into authenticate and bridge primitives (#2913)

Extract handleAuth into authenticate(...), which returns the post-startup
client Socket (or null when the handshake ended early), and a public
bridge(...) that relays. RdsAuthProxy and RedshiftAuthProxy now call
authenticate then bridge in sequence; RDS and Redshift relay behaviour is
unchanged. This lets a later change replace the Redshift relay with an
intercepting bridge without touching the handshake.
This commit is contained in:
Vũ Thế Huy authored and GitHub committed 2026-09-02 10:09:55 -04:00
1 parent 660e7613bf
commit 5b3c0e01e3
4 files changed
+51 -27

No files matched your search

@@ -81,11 +81,14 @@ class PostgresProtocolHandlerTest {
Thread authThread = Thread.ofVirtual().start(() -> {
try {
PostgresProtocolHandler.handleAuth(
Socket activeClient = PostgresProtocolHandler.authenticate(
proxyClient, backend,
"dbadmin", "adminpass", "postgres",
false, testSigV4Validator(), testTlsCertificates(),
(user, pass) -> true);
if (activeClient != null) {
PostgresProtocolHandler.bridge(activeClient, backend);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -135,11 +138,14 @@ class PostgresProtocolHandlerTest {
Thread authThread = Thread.ofVirtual().start(() -> {
try {
PostgresProtocolHandler.handleAuth(
Socket activeClient = PostgresProtocolHandler.authenticate(
proxyClient, backend,
"dbadmin", "adminpass", "postgres",
false, testSigV4Validator(), testTlsCertificates(),
(user, pass) -> true);
if (activeClient != null) {
PostgresProtocolHandler.bridge(activeClient, backend);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -189,11 +195,14 @@ class PostgresProtocolHandlerTest {
Thread authThread = Thread.ofVirtual().start(() -> {
try {
PostgresProtocolHandler.handleAuth(
Socket activeClient = PostgresProtocolHandler.authenticate(
proxyClient, backend,
"dbadmin", "adminpass", "postgres",
false, testSigV4Validator(), testTlsCertificates(),
(user, pass) -> true);
if (activeClient != null) {
PostgresProtocolHandler.bridge(activeClient, backend);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -252,11 +261,14 @@ class PostgresProtocolHandlerTest {
Thread authThread = Thread.ofVirtual().start(() -> {
try {
PostgresProtocolHandler.handleAuth(
Socket activeClient = PostgresProtocolHandler.authenticate(
proxyClient, backend,
"dbadmin", "adminpass", "postgres",
false, testSigV4Validator(), tlsCertificates,
(user, pass) -> true);
if (activeClient != null) {
PostgresProtocolHandler.bridge(activeClient, backend);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -302,11 +314,14 @@ class PostgresProtocolHandlerTest {
Thread authThread = Thread.ofVirtual().start(() -> {
try {
PostgresProtocolHandler.handleAuth(
Socket activeClient = PostgresProtocolHandler.authenticate(
proxyClient, backend,
"dbadmin", "adminpass", "postgres",
false, testSigV4Validator(), tlsCertificates,
(user, pass) -> true);
if (activeClient != null) {
PostgresProtocolHandler.bridge(activeClient, backend);
}
} catch (IOException ignored) {
// Client aborts the handshake below — the handler observing that is expected.
}
@@ -348,11 +363,14 @@ class PostgresProtocolHandlerTest {
Thread authThread = Thread.ofVirtual().start(() -> {
try {
PostgresProtocolHandler.handleAuth(
Socket activeClient = PostgresProtocolHandler.authenticate(
proxyClient, backend,
"dbadmin", "adminpass", "postgres",
false, testSigV4Validator(), testTlsCertificates(),
(user, pass) -> true);
if (activeClient != null) {
PostgresProtocolHandler.bridge(activeClient, backend);
}
} catch (IOException e) {
throw new RuntimeException(e);
}