Documentation
¶
Overview ¶
Package remotesess 实现 XOps v2 基于 *ssh.Session 的远端命令与交互式 Shell 会话适配器 (ports.RemoteSession,ADR-009 / ADR-015)。
核心安全与并发不变量:
- 构造期预绑定 StdinPipe / StdoutPipe / StderrPipe,绝不给 ssh.Session.Stdin/Stdout/Stderr 赋值, 彻底规避 golang.org/x/crypto/ssh 内部孤儿拷贝协程泄漏;
- 所有 env / pty-req / exec / shell 控制请求、输入输出流泵与 Wait 均受上游 lifeNursery 统一监督, 全包 0 裸 go 语句与零行内 nolint 豁免;
- 输出泵在达到 CommandPlan.MaxOutputBytes 或 dst.Write 失败后继续排空至 EOF,防 SSH 窗口反压死锁。
Index ¶
- type Session
- func (s *Session) Close() error
- func (s *Session) ResizePTY(ctx context.Context, size ports.TerminalSize) error
- func (s *Session) Signal(ctx context.Context, signal string) error
- func (s *Session) Start(ctx context.Context, cmd execution.CommandPlan, streams ports.ExecStreams) error
- func (s *Session) StartShell(ctx context.Context, streams ports.ExecStreams) error
- func (s *Session) StartSubsystem(ctx context.Context, subsystem string, streams ports.ExecStreams) error
- func (s *Session) StderrPipe() (io.Reader, error)
- func (s *Session) StdinPipe() (io.WriteCloser, error)
- func (s *Session) StdoutPipe() (io.Reader, error)
- func (s *Session) Wait(ctx context.Context) (execution.ExecutionOutcome, error)
- type SessionHooks
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session 封装单条 SSH 会话通道,实现 ports.RemoteSession 与 ports.SubsystemRemoteSession;零值恒失败关闭。
func NewFromChannel ¶ added in v1.3.0
func NewFromChannel( lifeNursery *conc.Nursery, isAlive func() bool, ch ssh.Channel, reqs <-chan *ssh.Request, hooks SessionHooks, ) (*Session, error)
NewFromChannel 基于原始 "session" ssh.Channel 与请求流构造受 lifeNursery 监督的 Session, 统一支持 Start / StartShell / StartSubsystem 与完整 RFC 4254 exit-status/exit-signal 采集(零未托管协程)。
func (*Session) ResizePTY ¶
ResizePTY 在 lifeNursery 监督下向远端会话发送 RFC 4254 window-change 窗口尺寸更新请求(防黑洞阻塞)。
func (*Session) Signal ¶
Signal 在 lifeNursery 监督下向远端进程发送规范化 POSIX 信号(如 "INT"、"TERM"、"KILL",兼容可选 "SIG" 前缀)。
func (*Session) Start ¶
func (s *Session) Start(ctx context.Context, cmd execution.CommandPlan, streams ports.ExecStreams) error
Start 在远端会话通道上渲染并启动不可变 CommandPlan(含可选 ForwardAgent、PTY、环境变量与输出上限截断)。
func (*Session) StartShell ¶
StartShell 在远端会话通道上启动交互式 Shell(可选 ForwardAgent、PTY 与环境变量统一由 streams 承载)。
func (*Session) StartSubsystem ¶ added in v1.3.0
func (s *Session) StartSubsystem(ctx context.Context, subsystem string, streams ports.ExecStreams) error
StartSubsystem 在远端会话通道上按 RFC 4254 subsystem 请求启动命名子系统(如 netconf / sftp,ADR-019 C1)。
func (*Session) StderrPipe ¶
StderrPipe 在 Start/StartShell/StartSubsystem 前借出远端标准错误读取管道(与非空 ExecStreams.Stderr 互斥)。
func (*Session) StdinPipe ¶
func (s *Session) StdinPipe() (io.WriteCloser, error)
StdinPipe 在 Start/StartShell/StartSubsystem 前借出远端标准输入写入管道(与非空 ExecStreams.Stdin 及 PlanKindScript 互斥)。
func (*Session) StdoutPipe ¶
StdoutPipe 在 Start/StartShell/StartSubsystem 前借出远端标准输出读取管道(与非空 ExecStreams.Stdout 互斥)。
type SessionHooks ¶ added in v1.3.0
type SessionHooks struct {
// ActivateAgentForward 在会话启动前激活父连接上的 ForwardAgent 会话 epoch,
// 返回幂等撤权回调、是否允许发送 auth-agent-req@openssh.com 及硬错误(如目标冲突或上下文取消)。
ActivateAgentForward func(ctx context.Context, spec inventory.AgentSpec) (revoke func(), allowed bool, err error)
// OnClose 在会话关闭时恰好在锁外触发一次,用于维护父连接活跃会话快照。
OnClose func()
// OnDiag 在锁外发送脱敏诊断记录。
OnDiag func(ctx context.Context, level uint8, msg string)
}
SessionHooks 为 remotesess.Session 注入来自父 TransportConn 的可选生命周期、ForwardAgent 与诊断回调。