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

Add support for X11 forwarding #829

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
18 changes: 18 additions & 0 deletions pkg/ssh/server/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@

return true
},
X11ForwardingCallback: func(ctx ssh.Context, x11 ssh.X11) bool {

Check failure on line 67 in pkg/ssh/server/ssh.go

View workflow job for this annotation

GitHub Actions / lint

unknown field X11ForwardingCallback in struct literal of type "github.com/loft-sh/ssh".Server

Check failure on line 67 in pkg/ssh/server/ssh.go

View workflow job for this annotation

GitHub Actions / lint

undefined: ssh.X11

Check failure on line 67 in pkg/ssh/server/ssh.go

View workflow job for this annotation

GitHub Actions / lint

unknown field X11ForwardingCallback in struct literal of type "github.com/loft-sh/ssh".Server

Check failure on line 67 in pkg/ssh/server/ssh.go

View workflow job for this annotation

GitHub Actions / unit-tests

unknown field X11ForwardingCallback in struct literal of type "github.com/loft-sh/ssh".Server

Check failure on line 67 in pkg/ssh/server/ssh.go

View workflow job for this annotation

GitHub Actions / unit-tests

undefined: ssh.X11
return true
},
ChannelHandlers: map[string]ssh.ChannelHandler{
"direct-tcpip": ssh.DirectTCPIPHandler,
"direct-streamlocal@openssh.com": ssh.DirectStreamLocalHandler,
Expand Down Expand Up @@ -171,6 +174,7 @@

func (s *Server) handler(sess ssh.Session) {
ptyReq, winCh, isPty := sess.Pty()
x11Req, isX11 := sess.X11()

Check failure on line 177 in pkg/ssh/server/ssh.go

View workflow job for this annotation

GitHub Actions / lint

sess.X11 undefined (type "github.com/loft-sh/ssh".Session has no field or method X11)

Check failure on line 177 in pkg/ssh/server/ssh.go

View workflow job for this annotation

GitHub Actions / unit-tests

sess.X11 undefined (type "github.com/loft-sh/ssh".Session has no field or method X11)
cmd := s.getCommand(sess, isPty)
if ssh.AgentRequested(sess) {
// on some systems (like containers) /tmp may not exists, this ensures
Expand All @@ -191,6 +195,20 @@
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", "SSH_AUTH_SOCK", l.Addr().String()))
}

if isX11 {
l, xauth, err := ssh.NewX11Forwarder(x11Req)

Check failure on line 199 in pkg/ssh/server/ssh.go

View workflow job for this annotation

GitHub Actions / lint

undefined: ssh.NewX11Forwarder

Check failure on line 199 in pkg/ssh/server/ssh.go

View workflow job for this annotation

GitHub Actions / unit-tests

undefined: ssh.NewX11Forwarder
if err != nil {
s.exitWithError(sess, perrors.Wrap(err, "start X11 forwarder"))
return
}

defer l.Close()
defer os.Remove(xauth.Name())
go ssh.ForwardX11Connections(l, xauth, sess)

Check failure on line 207 in pkg/ssh/server/ssh.go

View workflow job for this annotation

GitHub Actions / lint

undefined: ssh.ForwardX11Connections

Check failure on line 207 in pkg/ssh/server/ssh.go

View workflow job for this annotation

GitHub Actions / unit-tests

undefined: ssh.ForwardX11Connections
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s:%d.0", "DISPLAY", ssh.X11DisplayHost, l.Addr().(*net.TCPAddr).Port - ssh.X11DisplayBasePort))

Check failure on line 208 in pkg/ssh/server/ssh.go

View workflow job for this annotation

GitHub Actions / lint

undefined: ssh.X11DisplayHost

Check failure on line 208 in pkg/ssh/server/ssh.go

View workflow job for this annotation

GitHub Actions / lint

undefined: ssh.X11DisplayBasePort (typecheck)

Check failure on line 208 in pkg/ssh/server/ssh.go

View workflow job for this annotation

GitHub Actions / unit-tests

undefined: ssh.X11DisplayHost

Check failure on line 208 in pkg/ssh/server/ssh.go

View workflow job for this annotation

GitHub Actions / unit-tests

undefined: ssh.X11DisplayBasePort
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", "XAUTHORITY", xauth.Name()))
}

// start shell session
var err error
if isPty {
Expand Down