SSH Proxy support (#2736)

* initial commit
This commit is contained in:
Irena Rindos authored and GitHub committed 2023-01-09 13:43:02 -05:00
1 parent 1fb960575f
commit beb97ac9f2
9 files changed
+70 -36

No files matched your search

+7 -9
View File
@@ -12,20 +12,18 @@ import (
)
func init() {
err := proxy.RegisterHandler("tcp", handleProxy)
err := proxy.RegisterHandler(proxy.TcpHandlerName, handleProxy)
if err != nil {
panic(err)
}
}
// handleProxy creates a tcp proxy between the incoming websocket conn and the
// connection it creates with the remote endpoint. handleTcpProxyV1 sets the connectionId
// as connected in the repository.
// handleProxy creates a tcp proxy between the incoming conn and the
// connection created by the ProxyDialer.
//
// handleProxy blocks until an error (EOF on happy path) is received on either
// connection.
//
// All options are ignored.
// handleProxy returns a ProxyConnFn which starts the copy between the
// connections and blocks until an error (EOF on happy path) is received on
// either connection.
func handleProxy(ctx context.Context, conn net.Conn, out *proxy.ProxyDialer, connId string, _ *anypb.Any) (proxy.ProxyConnFn, error) {
const op = "tcp.HandleProxy"
switch {
@@ -41,7 +39,7 @@ func handleProxy(ctx context.Context, conn net.Conn, out *proxy.ProxyDialer, con
return nil, err
}
return func() {
return func(ctx context.Context) {
connWg := new(sync.WaitGroup)
connWg.Add(2)
go func() {
+3 -3
View File
@@ -29,7 +29,7 @@ func TestHandleProxy_Errors(t *testing.T) {
t.Cleanup(func() {
l.Close()
})
dialer, err := proxy.NewProxyDialer(context.Background(), func() (net.Conn, error) {
dialer, err := proxy.NewProxyDialer(context.Background(), func(...proxy.Option) (net.Conn, error) {
return net.Dial("tcp", l.Addr().String())
})
require.NoError(t, err)
@@ -156,7 +156,7 @@ func TestHandleTcpProxyV1(t *testing.T) {
resp, _, err := s.RequestAuthorizeConnection(ctx, "workerid", connCancelFn)
require.NoError(err)
tDial, err := proxy.NewProxyDialer(ctx, func() (net.Conn, error) {
tDial, err := proxy.NewProxyDialer(ctx, func(...proxy.Option) (net.Conn, error) {
return net.Dial("tcp", l.Addr().String())
})
require.NoError(err)
@@ -170,7 +170,7 @@ func TestHandleTcpProxyV1(t *testing.T) {
// https://pkg.go.dev/testing#T.FailNow
require.NoError(err)
})
fn()
fn(context.Background())
}()
// wait for HandleTcpProxyV1 to dial endpoint