Skip to content

Commit 3c90f0e

Browse files
committed
[+] updated TLS configuration to support TLS 1.2 and 1.3 versions
[+] added server cipher suite preference and session ticket management [+] set connection deadline for SSL handshake to improve timeout handling [*] reset connection deadline after successful handshake
1 parent 7e58d46 commit 3c90f0e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pkg/postgresql/proxy_server.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,14 @@ func (p *PostgresProxy) Start(port int, certFile, keyFile string) error {
347347
return fmt.Errorf("error loading TLS key pair from %s and %s: %v", certFile, keyFile, errLoad)
348348
}
349349
p.tlsConfig = &tls.Config{
350-
Certificates: []tls.Certificate{cert},
351-
InsecureSkipVerify: true,
352-
ClientAuth: tls.NoClientCert,
353-
ServerName: "localhost",
350+
Certificates: []tls.Certificate{cert},
351+
MinVersion: tls.VersionTLS12,
352+
MaxVersion: tls.VersionTLS13,
353+
PreferServerCipherSuites: true,
354+
SessionTicketsDisabled: false,
355+
ClientAuth: tls.NoClientCert,
354356
}
357+
355358
log.Printf("TLS enabled with certificate files")
356359
} else {
357360
certPEM, keyPEM, err := getSelfCertsFromK8s(p)
@@ -427,6 +430,7 @@ func (p *PostgresProxy) HandleConnection(initialConn net.Conn) {
427430
log.Printf("Error sending SSL response: %v", err)
428431
return
429432
}
433+
conn.SetDeadline(time.Now().Add(5 * time.Second)) // 💥 handshake timeout
430434
// Gereksiz "Performing TLS handshake" log kaldırıldı
431435
// Gereksiz "Using tls.Config with ServerName" log kaldırıldı
432436
tlsConn := tls.Server(conn, p.tlsConfig)
@@ -439,6 +443,7 @@ func (p *PostgresProxy) HandleConnection(initialConn net.Conn) {
439443
})
440444
return
441445
}
446+
conn.SetDeadline(time.Time{}) // deadline sıfırla
442447
// Gereksiz "TLS handshake successful" log kaldırıldı
443448
conn = tlsConn
444449
startupMessageReader = conn

0 commit comments

Comments
 (0)