Skip to content
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

release-24.1: [CC-28198] sqlproxy: fix ProxyProtocolListenAddr using wrong ACL. #123963

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions pkg/ccl/sqlproxyccl/proxy_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,15 @@ func newProxyHandler(

// handle is called by the proxy server to handle a single incoming client
// connection.
func (handler *proxyHandler) handle(ctx context.Context, incomingConn net.Conn) error {
func (handler *proxyHandler) handle(
ctx context.Context, incomingConn net.Conn, requireProxyProtocol bool,
) error {
connReceivedTime := timeutil.Now()

// Parse headers before admitting the connection since the connection may
// be upgraded to TLS.
var endpointID string
if handler.RequireProxyProtocol {
if requireProxyProtocol {
var err error
endpointID, err = acl.FindPrivateEndpointID(incomingConn)
if err != nil {
Expand Down
10 changes: 7 additions & 3 deletions pkg/ccl/sqlproxyccl/proxy_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1205,12 +1205,16 @@ func TestProxyHandler_handle(t *testing.T) {
defer stopper.Stop(ctx)
proxy, _ := newSecureProxyServer(ctx, t, stopper, &ProxyOptions{})

// Check that handle does not return any error if the incoming connection
// has no data packets.
p1, p2 := net.Pipe()
require.NoError(t, p1.Close())
require.Nil(t, proxy.handler.handle(ctx, p2, false /* requireProxyProtocol */))

// Check that handle does not return any error if the incoming connection
// has no data packets.
require.Nil(t, proxy.handler.handle(ctx, p2))
p1, p2 = net.Pipe()
require.NoError(t, p1.Close())
p2 = proxyproto.NewConn(p2)
require.Nil(t, proxy.handler.handle(ctx, p2, true /* requireProxyProtocol */))
}

func TestDenylistUpdate(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/ccl/sqlproxyccl/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (s *Server) ServeSQL(
}
log.Infof(ctx, "proxy server listening at %s", ln.Addr())
if err := s.Stopper.RunAsyncTask(ctx, "listener-serve", func(ctx context.Context) {
_ = s.serve(ctx, ln)
_ = s.serve(ctx, ln, s.handler.RequireProxyProtocol)
}); err != nil {
return err
}
Expand All @@ -242,7 +242,7 @@ func (s *Server) ServeSQL(
proxyProtocolLn = s.requireProxyProtocolOnListener(proxyProtocolLn)
log.Infof(ctx, "proxy with required proxy headers server listening at %s", proxyProtocolLn.Addr())
if err := s.Stopper.RunAsyncTask(ctx, "proxy-protocol-listener-serve", func(ctx context.Context) {
_ = s.serve(ctx, proxyProtocolLn)
_ = s.serve(ctx, proxyProtocolLn, true /* requireProxyProtocol */)
}); err != nil {
return err
}
Expand All @@ -251,7 +251,7 @@ func (s *Server) ServeSQL(
}

// serve is called by ServeSQL to serve a single listener.
func (s *Server) serve(ctx context.Context, ln net.Listener) error {
func (s *Server) serve(ctx context.Context, ln net.Listener, requireProxyProtocol bool) error {
err := s.Stopper.RunAsyncTask(ctx, "listen-quiesce", func(ctx context.Context) {
<-s.Stopper.ShouldQuiesce()
if err := ln.Close(); err != nil && !grpcutil.IsClosedConnection(err) {
Expand All @@ -275,7 +275,7 @@ func (s *Server) serve(ctx context.Context, ln net.Listener) error {
defer s.metrics.CurConnCount.Dec(1)
remoteAddr := conn.RemoteAddr()
ctxWithTag := logtags.AddTag(ctx, "client", log.SafeOperational(remoteAddr))
if err := s.handler.handle(ctxWithTag, conn); err != nil {
if err := s.handler.handle(ctxWithTag, conn, requireProxyProtocol); err != nil {
log.Infof(ctxWithTag, "connection error: %v", err)
}
})
Expand Down