in internal/sshd/session.go [155:213]
func (s *session) handleShell(ctx context.Context, req *ssh.Request) (context.Context, uint32, error) {
ctxlog := log.ContextLogger(ctx)
if req.WantReply {
if err := req.Reply(true, []byte{}); err != nil {
ctxlog.WithError(err).Debug("session: handleShell: Failed to reply")
}
}
env := sshenv.Env{
IsSSHConnection: true,
OriginalCommand: s.execCmd,
GitProtocolVersion: s.gitProtocolVersion,
RemoteAddr: s.remoteAddr,
NamespacePath: s.namespace,
}
countingWriter := &readwriter.CountingWriter{W: s.channel}
rw := &readwriter.ReadWriter{
Out: countingWriter,
In: s.channel,
ErrOut: s.channel.Stderr(),
}
cmd, err := s.getCommand(env, rw)
if err != nil {
return s.handleCommandError(ctx, err)
}
cmdName := reflect.TypeOf(cmd).String()
establishSessionDuration := time.Since(s.started).Seconds()
ctxlog.WithFields(log.Fields{
"env": env, "command": cmdName, "established_session_duration_s": establishSessionDuration,
}).Info("session: handleShell: executing command")
metrics.SshdSessionEstablishedDuration.Observe(establishSessionDuration)
ctxWithLogData, err := cmd.Execute(ctx)
logData := extractLogDataFromContext(ctxWithLogData)
logData.WrittenBytes = countingWriter.N
ctxWithLogData = context.WithValue(ctx, logInfo{}, logData)
if err != nil {
grpcStatus := grpcstatus.Convert(err)
if grpcStatus.Code() != grpccodes.Internal {
s.toStderr(ctx, "ERROR: %v\n", grpcStatus.Message())
}
return ctx, 1, err
}
ctxlog.Info("session: handleShell: command executed successfully")
return ctxWithLogData, 0, nil
}