pico

created pr with pico/pgs-ssh-proxy.1 on 2026-11-27T14:17:47Z · by c8ef7d19
added pico/pgs-ssh-proxy.2 on 2026-11-27T14:20:09Z · by c8ef7d19
1: b200a43 = 1: b200a43 feat(pgs): ability to proxy ssh conns to a separate service
-: ------- > 2: 667f0fc refactor(pssh): remove the handled bool
cmds
checkout latest patchset:
ssh pr.pico.sh pull pico:pgs-ssh-proxy | git am -3
checkout specific patchset revision:
ssh pr.pico.sh pull pico:pgs-ssh-proxy [rev] | git am -3
add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pico:pgs-ssh-proxy
add comment to patch request:
ssh pr.pico.sh comment pico:pgs-ssh-proxy "lgtm!"

Patchset pico/pgs-ssh-proxy.2 on 2026-11-27T14:20:09Z · commit b200a43

With pssh.Config.RawConnHandler we can proxy raw tcp data from one ssh service
to another.  This allows us to proxy ssh connections from pgs.sh to a separate
service where we might store all static files.

Essentially we have a hook to perform an io.Copy(client, proxy) between the user
and the backend ssh service
Diff stat
pkg/apps/pgs/ssh.go | 42 ++++++++++++++++++++++++++++++
pkg/pssh/server.go | 8 ++++++
2 files changed, 50 insertions(+)
Semantic diff summary
1 added, 2 modified, 0 signature changed, 0 removed across 2 analyzed files
+42 -0 pkg/apps/pgs/ssh.go #
......@@ -2,9 +2,13 @@ package pgs
22
33 import (
44 "context"
5+ "errors"
6+ "io"
7+ "net"
58 "os"
69 "os/signal"
710 "syscall"
11+ "time"
812
913 "github.com/picosh/pico/pkg/pssh"
1014 "github.com/picosh/pico/pkg/send/auth"
......@@ -22,6 +26,7 @@ func createSshServer(cfg *Config, ctx context.Context, cacheClearingQueue chan s
2226 host := shared.GetEnv("PGS_HOST", "0.0.0.0")
2327 port := shared.GetEnv("PGS_SSH_PORT", "2222")
2428 promPort := shared.GetEnv("PGS_PROM_PORT", "9222")
29+ proxyAddr := shared.GetEnv("PGS_SSH_PROXY_ADDR", "")
2530 logger := cfg.Logger
2631
2732 handler := NewUploadAssetHandler(
......@@ -65,6 +70,13 @@ func createSshServer(cfg *Config, ctx context.Context, cacheClearingQueue chan s
6570 "direct-tcpip": tunkit.LocalForwardHandler(webTunnel),
6671 },
6772 )
73+ if err != nil {
74+ return nil, err
75+ }
76+
77+ if proxyAddr != "" {
78+ server.Config.RawConnHandler = createRawProxyHandler(proxyAddr)
79+ }
6880
6981 return server, err
7082 }
......@@ -108,3 +120,33 @@ func StartSshServer(cfg *Config, killCh chan error) {
108120 exit()
109121 }
110122 }
123+
124+func createRawProxyHandler(targetAddr string) func(context.Context, net.Conn) (bool, error) {
125+ return func(ctx context.Context, client net.Conn) (bool, error) {
126+ dialer := &net.Dialer{Timeout: 10 * time.Second}
127+ upstream, err := dialer.DialContext(ctx, "tcp", targetAddr)
128+ if err != nil {
129+ return true, err
130+ }
131+
132+ defer func() {
133+ _ = upstream.Close()
134+ }()
135+
136+ errCh := make(chan error, 2)
137+ go func() {
138+ _, err := io.Copy(upstream, client)
139+ errCh <- err
140+ }()
141+ go func() {
142+ _, err := io.Copy(client, upstream)
143+ errCh <- err
144+ }()
145+
146+ err = <-errCh
147+ if errors.Is(err, io.EOF) {
148+ return true, nil
149+ }
150+ return true, err
151+ }
152+}
+8 -0 pkg/pssh/server.go #
......@@ -578,6 +578,7 @@ type SSHServerConfig struct {
578578 // HandshakeTimeout bounds the handshake and auth. Zero means
579579 // DefaultHandshakeTimeout and a negative value means no limit.
580580 HandshakeTimeout time.Duration
581+ RawConnHandler func(ctx context.Context, conn net.Conn) (handled bool, err error)
581582 }
582583
583584 // DefaultHandshakeTimeout keeps a client that never finishes its handshake
......@@ -721,6 +722,13 @@ func (s *SSHServer) HandleConn(conn net.Conn) error {
721722 _ = conn.Close()
722723 }()
723724
725+ if s.Config.RawConnHandler != nil {
726+ handled, err := s.Config.RawConnHandler(s.Ctx, conn)
727+ if handled {
728+ return err
729+ }
730+ }
731+
724732 timeout := s.Config.HandshakeTimeout
725733 if timeout == 0 {
726734 timeout = DefaultHandshakeTimeout
Back to top