Skip to content

Commit f1b1196

Browse files
authored
chore(core): switch ent to modern pg authenticator (#5955)
1 parent 7db9598 commit f1b1196

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

core/src/main/java/io/questdb/cutlass/pgwire/modern/CleartextPasswordPgWireAuthenticatorModern.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import io.questdb.BuildInformation;
2828
import io.questdb.cairo.CairoException;
29-
import io.questdb.cairo.SecurityContext;
3029
import io.questdb.cairo.sql.NetworkSqlExecutionCircuitBreaker;
3130
import io.questdb.cutlass.auth.AuthenticatorException;
3231
import io.questdb.cutlass.auth.SocketAuthenticator;
@@ -79,6 +78,7 @@ public class CleartextPasswordPgWireAuthenticatorModern implements SocketAuthent
7978
private final CircuitBreakerRegistry registry;
8079
private final String serverVersion;
8180
private final ResponseSink sink;
81+
private byte authType = AUTH_TYPE_NONE;
8282
private UsernamePasswordMatcher matcher;
8383
private long recvBufEnd;
8484
private long recvBufReadPos;
@@ -119,6 +119,7 @@ public CleartextPasswordPgWireAuthenticatorModern(
119119

120120
@Override
121121
public void clear() {
122+
authType = AUTH_TYPE_NONE;
122123
circuitBreaker.setSecret(-1);
123124
circuitBreaker.resetMaxTimeToDefault();
124125
circuitBreaker.unsetTimer();
@@ -143,7 +144,7 @@ public int denyAccess(CharSequence message) throws AuthenticatorException {
143144

144145
@Override
145146
public byte getAuthType() {
146-
return SecurityContext.AUTH_TYPE_CREDENTIALS;
147+
return authType;
147148
}
148149

149150
public CharSequence getPrincipal() {
@@ -292,6 +293,8 @@ private void compactSendBuf() {
292293
private void prepareBackendKeyData(ResponseSink responseSink) {
293294
responseSink.put('K');
294295
responseSink.putInt(Integer.BYTES * 3); // length of this message
296+
297+
// the below 8 bytes will not match when dumping PG traffic!
295298
responseSink.putInt(circuitBreakerId);
296299
responseSink.putInt(circuitBreaker.getSecret());
297300
}
@@ -426,7 +429,8 @@ private int processPasswordMessage() throws BadProtocolException {
426429
recvBufReadPos += 1 + Integer.BYTES; // first move beyond the msgType and msgLen
427430

428431
long hi = PGConnectionContextModern.getUtf8StrSize(recvBufReadPos, msgLimit, "bad password length", null);
429-
if (matcher.verifyPassword(username, recvBufReadPos, (int) (hi - recvBufReadPos)) != AUTH_TYPE_NONE) {
432+
authType = verifyPassword(username, recvBufReadPos, (int) (hi - recvBufReadPos));
433+
if (authType != AUTH_TYPE_NONE) {
430434
recvBufReadPos = msgLimit;
431435
state = State.AUTH_SUCCESS;
432436
} else {
@@ -515,6 +519,10 @@ private int writeToSocketAndAdvance(State nextState) {
515519
return SocketAuthenticator.NEEDS_WRITE;
516520
}
517521

522+
// kept protected for enterprise
523+
protected byte verifyPassword(CharSequence username, long passwordPtr, int passwordLen) {
524+
return matcher.verifyPassword(username, passwordPtr, passwordLen);
525+
}
518526

519527
private enum State {
520528
EXPECT_INIT_MESSAGE,

core/src/main/java/io/questdb/cutlass/pgwire/modern/DefaultPgWireAuthenticatorFactoryModern.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public SocketAuthenticator getPgWireAuthenticator(
6767
final UsernamePasswordMatcher matcher = new DynamicUsernamePasswordMatcher(serverConfiguration, configuration);
6868

6969
// HexTestsCircuitBreakRegistry implies we are either recording or replaying a hex test.
70-
// In this case, we don't sends build information to the client. Build informations are volatile by nature, we
70+
// In this case, we don't send build information to the client. Build information is volatile by nature, we
7171
// only record what does not change over time.
7272
BuildInformation buildInformationToUse = (registry == HexTestsCircuitBreakRegistry.INSTANCE ? null : buildInformation);
7373

0 commit comments

Comments
 (0)