Start machine terminals at the su login prompt instead of tmux

A new terminal runs su -l for the server's own account in its PTY, so the
operator types the account password before getting a shell. Opening is
refused when su is missing, the server runs as root, or su opens a shell
without asking. The Pipelines-owned tmux backing, its reattach and its
persisted session names are removed: terminals end with the server and
are listed as ended. A starting server ends leftover pipelines-term_*
sessions on tmux -L pipelines only.
This commit is contained in:
2026-11-10 00:37:11 +00:00
parent 070f9e205e
commit 227c036aa5
16 changed files with 887 additions and 545 deletions
+27 -6
View File
@@ -14,21 +14,27 @@ import (
)
// terminalProcess is one terminal this server process holds: running (its
// attachment is the shell itself, or a tmux client showing the shell's
// session) or ended with its output still retained.
// attachment is the login, then the shell it becomes) or ended with its
// output still retained.
type terminalProcess struct {
mu sync.Mutex
record protocol.TerminalRecord
out *chatShellOutput
titles terminalTitles
// cmd and pty are the current attachment; a tmux client that exits while
// its session lives is replaced.
// login follows the output until the login completes; loginChanged is
// signalled when it changes.
login terminalLoginWatch
loginChanged chan struct{}
// cmd and pty are the running login or shell.
cmd *exec.Cmd
pty *os.File
input chan []byte
done chan struct{}
// closing is set by terminal_close: the end is a close, not an exit.
closing bool
// refused: the login never asked for a password; the terminal is
// forgotten without being listed.
refused bool
}
func newTerminalProcess(record protocol.TerminalRecord) *terminalProcess {
@@ -40,9 +46,19 @@ func newTerminalProcess(record protocol.TerminalRecord) *terminalProcess {
out: newChatShellOutput(protocol.TerminalRetained),
input: make(chan []byte, protocol.ChatShellInputQueue),
done: make(chan struct{}),
loginChanged: make(chan struct{}, 1),
}
}
// loginState is the login's progress and the output retained so far.
func (p *terminalProcess) loginState() (terminalLoginWatch, string) {
p.mu.Lock()
defer p.mu.Unlock()
text, _ := p.out.tail(terminalLoginScan)
return p.login, text
}
func (p *terminalProcess) running() bool {
p.mu.Lock()
defer p.mu.Unlock()
@@ -96,6 +112,12 @@ func (p *terminalProcess) read(terminal *os.File, titled func(string)) {
if n > 0 {
p.mu.Lock()
p.out.write(buffer[:n])
if p.login.feed(buffer[:n]) {
select {
case p.loginChanged <- struct{}{}:
default:
}
}
title, changed := p.titles.feed(buffer[:n])
changed = changed && title != p.record.Title
if changed {
@@ -112,8 +134,7 @@ func (p *terminalProcess) read(terminal *os.File, titled func(string)) {
}
}
// pumpInput writes queued input to the current attachment until the
// terminal ends. Input arriving while a tmux client is replaced is dropped.
// pumpInput writes queued input to the terminal until it ends.
func (p *terminalProcess) pumpInput() {
for {
select {