ssh/tailssh: handle terminal opcodes

Updates #3802 #4146

Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
Maisem Ali
2022-03-12 17:40:40 -08:00
committed by Maisem Ali
parent da6ce27416
commit 6d61b7906e
2 changed files with 95 additions and 27 deletions

View File

@ -19,7 +19,6 @@ import (
"os"
"os/exec"
"os/user"
"reflect"
"strings"
"sync"
"time"
@ -353,6 +352,10 @@ func (srv *server) handleAcceptedSSH(ctx context.Context, s ssh.Session, ci *ssh
}
}
// Take control of the PTY so that we can configure it below.
// See https://github.com/tailscale/tailscale/issues/4146
s.DisablePTYEmulation()
cmd, stdin, stdout, stderr, err := srv.launchProcess(ctx, s, ci, lu)
if err != nil {
logf("start failed: %v", err.Error())
@ -376,14 +379,7 @@ func (srv *server) handleAcceptedSSH(ctx context.Context, s ssh.Session, ci *ssh
stdin.Close()
}()
go func() {
// Write to s.Channel directly, avoiding gliderlab/ssh's (*session).Write
// call that translates newline endings, which we don't need.
// See https://github.com/tailscale/tailscale/issues/4146.
// TODO(bradfitz,maisem): remove this reflect hackery once gliderlab/ssh changes
// are all in.
// s is an gliderlabs/ssh.(*session); write to its Channel field.
sshChan := reflect.ValueOf(s).Elem().FieldByName("Channel").Interface().(io.Writer)
_, err := io.Copy(sshChan, stdout)
_, err := io.Copy(s, stdout)
if err != nil {
// TODO: don't log in the success case.
logf("ssh: stdout copy: %v", err)