feat: 增强 starssh 的 agent forwarding 与 tcp/unix 转发能力
- 为 LoginInput 增加 ForwardSSHAgent 配置,并在 Exec/PTTY 会话创建时按需自动请求 agent forwarding - 新增 agent_forward 运行时,封装本地 ssh-agent 建连、转发注册、显式请求与 unavailable/denied 语义 - 自动 agent forwarding 改为 best-effort:本地 agent 不可用、转发被拒绝或初始化失败时不再打断会话创建 - 为 StarSSH 增加 closing 状态与 agent forwarder 生命周期回收,避免 Close 与会话创建并发时泄漏资源 - 扩展 ForwardRequest 为带网络归一化的转发模型,支持 tcp/tcp4/tcp6/unix 端点组合 - 新增本地/远端 tcp<->unix、unix<->unix 及 detached helper,补齐 streamlocal 场景下的常用 API - 将显式网络地址编码收口为 tcp4://、tcp6://、unix://,消除 tcp:22 一类值的解析歧义 - 为本地 unix listener 增加 stale socket 探测、复用与关闭清理,避免遗留 socket 导致重启失败 - 补充 agent forwarding、关闭竞态、remote unix forward、local unix forward、stale socket 复用与端点解析等回归测试
This commit is contained in:
+29
-5
@@ -9,6 +9,14 @@ import (
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
var newSSHSession = func(client *ssh.Client) (*ssh.Session, error) {
|
||||
return client.NewSession()
|
||||
}
|
||||
|
||||
var requestSessionPTY = func(session *ssh.Session, config TerminalConfig) error {
|
||||
return session.RequestPty(config.Term, config.Rows, config.Columns, config.Modes)
|
||||
}
|
||||
|
||||
func (s *StarSSH) Close() error {
|
||||
return s.closeTransport(true)
|
||||
}
|
||||
@@ -22,7 +30,15 @@ func (s *StarSSH) NewExecSession() (*ssh.Session, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewExecSession(client)
|
||||
session, err := NewExecSession(client)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.maybeRequestAgentForwarding(session); err != nil {
|
||||
_ = session.Close()
|
||||
return nil, err
|
||||
}
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func (s *StarSSH) NewPTYSession(config *TerminalConfig) (*ssh.Session, error) {
|
||||
@@ -30,7 +46,15 @@ func (s *StarSSH) NewPTYSession(config *TerminalConfig) (*ssh.Session, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewPTYSession(client, config)
|
||||
session, err := NewPTYSession(client, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.maybeRequestAgentForwarding(session); err != nil {
|
||||
_ = session.Close()
|
||||
return nil, err
|
||||
}
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func NewTransferSession(client *ssh.Client) (*ssh.Session, error) {
|
||||
@@ -41,7 +65,7 @@ func NewExecSession(client *ssh.Client) (*ssh.Session, error) {
|
||||
if client == nil {
|
||||
return nil, errors.New("ssh client is nil")
|
||||
}
|
||||
return client.NewSession()
|
||||
return newSSHSession(client)
|
||||
}
|
||||
|
||||
func NewSession(client *ssh.Client) (*ssh.Session, error) {
|
||||
@@ -53,13 +77,13 @@ func NewPTYSession(client *ssh.Client, config *TerminalConfig) (*ssh.Session, er
|
||||
return nil, errors.New("ssh client is nil")
|
||||
}
|
||||
|
||||
session, err := client.NewSession()
|
||||
session, err := newSSHSession(client)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cfg := normalizeTerminalConfig(config)
|
||||
if err := session.RequestPty(cfg.Term, cfg.Rows, cfg.Columns, cfg.Modes); err != nil {
|
||||
if err := requestSessionPTY(session, cfg); err != nil {
|
||||
_ = session.Close()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user