Documentation
¶
Overview ¶
Package session 实现 XOps v2 全量会话、提权、探测、持久 PTY、隧道转发与多路复用控制面用例服务 (ADR-008 / ADR-009 / ADR-010 / ADR-011 / Plan P2.5-T2 & P3-T2)。
核心安全、并发与所有权不变量:
- 能力门控与连接池嵌套序恒为 gate.WithAuthorized[C] 包裹 pool.WithLease,严禁反序或绕过护栏, 并向 Authorized.ReportOutcome 上报强类型 ExecutionOutcome(确保 OutcomeUnknown 绝不降级);
- 提权执行(sudo/su/doas)经 PrivilegeEscalationPort 与 security.CanonicalScopeEscalated 校验, 口令仅经 SecretVault.WithSecret 或 InteractionPort.PromptSecret 借用透传(本包 0 SecretBox.Use);
- 两阶段远端 Shell 探针经 ShellProbePort 执行并严格失败关闭校验(拒绝非法/未知方言,零盲猜回退);
- 跨请求持久 PTY、-L/-R/-D/StreamLocal/TUN 转发与 ControlMaster 一律经 pool.RegisterLeaseHandleWith 绑定池钉选可撤销 TransportConn,杜绝失效 *pool.Lease 复用与 //xops:borrowed 逃逸,吊销即止、0 泄漏;
- ControlMaster 控制面门控一律消费 ControlPolicy.EffectiveMaster() / EffectivePersist() 失败关闭投影;
- 全部后台协程受 core/conc.Nursery 监督(0 裸 go、0 goleak、0 time.Sleep),禁导 core/osfs 与 sshnet。
Index ¶
- Variables
- func TryDialMuxClient(ctx context.Context, muxPort ports.MuxSocketPort, env ports.EnvPort, ...) (ports.TransportConn, bool, error)
- type ControlMasterInfo
- func (i ControlMasterInfo) Done() <-chan struct{}
- func (i ControlMasterInfo) EffectiveMaster() option.ControlMasterMode
- func (i ControlMasterInfo) EffectivePersist() option.ControlPersistSpec
- func (i ControlMasterInfo) Handle() algebraic.Option[plan.ManagedHandle[plan.KindMux]]
- func (i ControlMasterInfo) IsValid() bool
- func (i ControlMasterInfo) IsZero() bool
- func (i ControlMasterInfo) MasterPID() uint32
- func (i ControlMasterInfo) ReusedExisting() bool
- func (i ControlMasterInfo) SocketPath() pathalg.LocalSourcePath
- func (i ControlMasterInfo) Wait(ctx context.Context) error
- type ControlMasterRequest
- type ControlMasterStatus
- func (st ControlMasterStatus) Active() bool
- func (st ControlMasterStatus) EffectiveMaster() option.ControlMasterMode
- func (st ControlMasterStatus) EffectivePersist() option.ControlPersistSpec
- func (st ControlMasterStatus) Err() error
- func (st ControlMasterStatus) HandleStatus() pool.HandleStatus
- func (st ControlMasterStatus) IsValid() bool
- func (st ControlMasterStatus) IsZero() bool
- func (st ControlMasterStatus) SocketPath() pathalg.LocalSourcePath
- type ExecRequest
- type ForwardInfo
- func (i ForwardInfo) BoundAddr() string
- func (i ForwardInfo) Done() <-chan struct{}
- func (i ForwardInfo) Handle() plan.ManagedHandle[plan.KindTunnel]
- func (i ForwardInfo) IsValid() bool
- func (i ForwardInfo) IsZero() bool
- func (i ForwardInfo) Spec() ports.ForwardSpec
- func (i ForwardInfo) Wait(ctx context.Context) error
- type ForwardStatus
- type InteractiveRequest
- type MuxControlRequest
- type MuxRequest
- type OpenPTYRequest
- type PTYReadRequest
- type PTYReadResult
- type PTYStatus
- func (st PTYStatus) Active() bool
- func (st PTYStatus) BufferedBytes() int
- func (st PTYStatus) DroppedBytes() uint64
- func (st PTYStatus) EOF() bool
- func (st PTYStatus) HandleStatus() pool.HandleStatus
- func (st PTYStatus) IsValid() bool
- func (st PTYStatus) IsZero() bool
- func (st PTYStatus) Size() ports.TerminalSize
- func (st PTYStatus) Term() string
- type PrivilegeExecRequest
- type ProbeShellRequest
- type RequestTTYMode
- type Service
- func (s *Service) CanSuspendProcessGroup() (security.Verdict, error)
- func (s *Service) ClosePTY(ctx context.Context, handle plan.ManagedHandle[plan.KindPTY]) error
- func (s *Service) ControlMux(ctx context.Context, req MuxControlRequest) (ports.MuxControlResponse, error)
- func (s *Service) Exec(ctx context.Context, req ExecRequest) (execution.ExecutionOutcome, error)
- func (s *Service) ExecPrivileged(ctx context.Context, req PrivilegeExecRequest) (execution.ExecutionOutcome, error)
- func (s *Service) InspectControlMaster(ctx context.Context, handle plan.ManagedHandle[plan.KindMux]) (ControlMasterStatus, error)
- func (s *Service) InspectForward(ctx context.Context, handle plan.ManagedHandle[plan.KindTunnel]) (ForwardStatus, error)
- func (s *Service) InspectPTY(ctx context.Context, handle plan.ManagedHandle[plan.KindPTY]) (PTYStatus, error)
- func (s *Service) Interactive(ctx context.Context, req InteractiveRequest) (execution.ExecutionOutcome, error)
- func (s *Service) OpenPTY(ctx context.Context, req OpenPTYRequest) (plan.ManagedHandle[plan.KindPTY], error)
- func (s *Service) ProbeMux(ctx context.Context, req MuxRequest) (ports.MuxControlResponse, error)
- func (s *Service) ProbeShell(ctx context.Context, req ProbeShellRequest) (ports.ShellProbeResult, error)
- func (s *Service) ReadPTY(ctx context.Context, req PTYReadRequest) (res PTYReadResult, err error)
- func (s *Service) ResizePTY(ctx context.Context, handle plan.ManagedHandle[plan.KindPTY], ...) error
- func (s *Service) RunMuxProxy(ctx context.Context, req MuxRequest, stdin io.ReadCloser, stdout io.Writer) error
- func (s *Service) SignalPTY(ctx context.Context, handle plan.ManagedHandle[plan.KindPTY], sig string) error
- func (s *Service) StartControlMaster(ctx context.Context, req ControlMasterRequest) (ControlMasterInfo, error)
- func (s *Service) StartForward(ctx context.Context, req StartForwardRequest) (ForwardInfo, error)
- func (s *Service) StopControlMaster(ctx context.Context, handle plan.ManagedHandle[plan.KindMux]) error
- func (s *Service) StopForward(ctx context.Context, handle plan.ManagedHandle[plan.KindTunnel]) error
- func (s *Service) TouchControlMaster(ctx context.Context, handle plan.ManagedHandle[plan.KindMux]) error
- func (s *Service) TouchControlMasterActivity(ctx context.Context, handle plan.ManagedHandle[plan.KindMux], delta int) error
- func (s *Service) WithForwardHandle(ctx context.Context, handle plan.ManagedHandle[plan.KindTunnel], ...) error
- func (s *Service) WithMuxConn(ctx context.Context, req MuxRequest, ...) error
- func (s *Service) WithMuxProxy(ctx context.Context, req MuxRequest, ...) error
- func (s *Service) WritePTY(ctx context.Context, handle plan.ManagedHandle[plan.KindPTY], data []byte) (n int, err error)
- type ServiceConfig
- type StartForwardRequest
Constants ¶
This section is empty.
Variables ¶
var ( ErrNilContext = errors.New("usecase/session: context 不能为 nil") ErrInvalidConfig = errors.New("usecase/session: 无效的 ServiceConfig 配置") ErrServiceNotInitialized = errors.New("usecase/session: Service 未初始化") ErrInvalidRequest = errors.New("usecase/session: 无效的会话执行请求") ErrInvalidRequestTTY = errors.New("usecase/session: 无效的 RequestTTY 模式") ErrInvalidProbeResult = errors.New("usecase/session: 远端 Shell 探测结果无效") ErrEscalationScopeChanged = errors.New("usecase/session: 提权规范作用域校验失败或发生漂移") ErrPTYClosed = errors.New("usecase/session: 持久 PTY 会话已关闭或已吊销") ErrControlMasterDisabled = errors.New("usecase/session: ControlPolicy 生效投影已禁用多路复用") ErrMuxPersistExpired = errors.New("usecase/session: ControlPersist 驻留超时已过期") )
本包导出的规范化哨兵错误,供 core/engine 与上层测试以 errors.Is 精确区分故障类别。
Functions ¶
func TryDialMuxClient ¶
func TryDialMuxClient(ctx context.Context, muxPort ports.MuxSocketPort, env ports.EnvPort, interaction ports.InteractionPort, hop plan.HopSpec, dig plan.HopDigest) (ports.TransportConn, bool, error)
TryDialMuxClient 按 ControlPolicy 生效投影执行透明客户端 ControlMaster 附着(INV-C4,供 core/engine 拨号适配复用):
- 仅在 ControlPath 已启用且 EffectiveMaster 为 no/auto/autoask 时尝试附着(yes/ask 强制新建主连接不走客户端附着);
- autoask 模式先探测活跃套接字,存活时经 confirmMuxMasterWith 请求操作员确认(拒签/不可交互时失败关闭);
- 遇 ErrNotFound/ErrMuxUnavailable 透明返回 (nil, false, nil) 供拨号层回退底层新建连接;
- 严格核验 DialMux 返回连接的 IsAlive()、(HopDigest, Endpoint) 精确一致,失配即关闭并失败关闭报错。
Types ¶
type ControlMasterInfo ¶
type ControlMasterInfo struct {
// contains filtered or unexported fields
}
ControlMasterInfo 封装 ControlMaster 启动或复用已有主进程的不可变结果;零值恒无效并失败关闭。
func (ControlMasterInfo) Done ¶
func (i ControlMasterInfo) Done() <-chan struct{}
Done 返回只读完成信号通道:受管主进程退出并完成监听清理后关闭;复用外部主进程时返回已关闭通道;零值/无效返回 nil。
func (ControlMasterInfo) EffectiveMaster ¶
func (i ControlMasterInfo) EffectiveMaster() option.ControlMasterMode
func (ControlMasterInfo) EffectivePersist ¶
func (i ControlMasterInfo) EffectivePersist() option.ControlPersistSpec
func (ControlMasterInfo) Handle ¶
func (i ControlMasterInfo) Handle() algebraic.Option[plan.ManagedHandle[plan.KindMux]]
func (ControlMasterInfo) IsValid ¶
func (i ControlMasterInfo) IsValid() bool
ControlMasterInfo 零值安全只读访问器与响应式停机等待方法(供 entry/muxdaemon 零轮询阻塞等待)。
func (ControlMasterInfo) IsZero ¶
func (i ControlMasterInfo) IsZero() bool
func (ControlMasterInfo) MasterPID ¶
func (i ControlMasterInfo) MasterPID() uint32
func (ControlMasterInfo) ReusedExisting ¶
func (i ControlMasterInfo) ReusedExisting() bool
func (ControlMasterInfo) SocketPath ¶
func (i ControlMasterInfo) SocketPath() pathalg.LocalSourcePath
func (ControlMasterInfo) Wait ¶
func (i ControlMasterInfo) Wait(ctx context.Context) error
Wait 阻塞等待 ControlMaster 退出或 ctx 取消:
- 零值/无效时严格失败关闭返回 ErrInvalidRequest;ctx == nil 返回 ErrNilContext;
- 复用已有外部主进程时直接按 ctx 状态返回 nil / ctx.Err();
- 正常 -O exit / -O stop 与 ControlPersist 空闲到期(ErrMuxPersistExpired)映射为 nil,其余传输故障原样透传(即使句柄已自动回收)。
type ControlMasterRequest ¶
type ControlMasterRequest struct {
Plan plan.SealedConnectionPlan
NodeID string
Risk algebraic.Option[security.RiskLevel]
Approval algebraic.Option[gate.ApprovalSubmission]
OperationStream *events.OperationStream
}
ControlMasterRequest 描述启动或附着 ControlMaster(-M / ControlPersist)的强类型输入(P3-T2)。 所有多路复用门控严格从 Plan 末跳的 ControlPolicy.EffectiveMaster() / EffectivePersist() 投影求值。
type ControlMasterStatus ¶
type ControlMasterStatus struct {
// contains filtered or unexported fields
}
ControlMasterStatus 表示受管 ControlMaster 句柄的不可变只读状态快照;零值恒无效并失败关闭。
func (ControlMasterStatus) Active ¶
func (st ControlMasterStatus) Active() bool
func (ControlMasterStatus) EffectiveMaster ¶
func (st ControlMasterStatus) EffectiveMaster() option.ControlMasterMode
func (ControlMasterStatus) EffectivePersist ¶
func (st ControlMasterStatus) EffectivePersist() option.ControlPersistSpec
func (ControlMasterStatus) Err ¶
func (st ControlMasterStatus) Err() error
func (ControlMasterStatus) HandleStatus ¶
func (st ControlMasterStatus) HandleStatus() pool.HandleStatus
func (ControlMasterStatus) IsValid ¶
func (st ControlMasterStatus) IsValid() bool
func (ControlMasterStatus) IsZero ¶
func (st ControlMasterStatus) IsZero() bool
func (ControlMasterStatus) SocketPath ¶
func (st ControlMasterStatus) SocketPath() pathalg.LocalSourcePath
type ExecRequest ¶
type ExecRequest struct {
Plan plan.SealedConnectionPlan
Command execution.CommandPlan
NodeID, Term string
Stdin io.Reader
Stdout, Stderr io.Writer
RequestTTY RequestTTYMode
Risk algebraic.Option[security.RiskLevel]
Approval algebraic.Option[gate.ApprovalSubmission]
OperationStream *events.OperationStream
}
ExecRequest 描述单次远端命令执行用例的强类型输入。
type ForwardInfo ¶
type ForwardInfo struct {
// contains filtered or unexported fields
}
ForwardInfo 封装成功启动的受管长驻转发句柄与绑定地址元信息;零值恒无效并失败关闭。
func (ForwardInfo) BoundAddr ¶
func (i ForwardInfo) BoundAddr() string
func (ForwardInfo) Done ¶
func (i ForwardInfo) Done() <-chan struct{}
Done 返回只读完成信号通道:受管转发终止并释放本地监听/资源后关闭;零值/无效返回 nil。
func (ForwardInfo) Handle ¶
func (i ForwardInfo) Handle() plan.ManagedHandle[plan.KindTunnel]
func (ForwardInfo) IsValid ¶
func (i ForwardInfo) IsValid() bool
ForwardInfo 零值安全只读访问器与响应式停机等待方法(供 entry/cli -N 前台隧道零轮询阻塞等待)。
func (ForwardInfo) IsZero ¶
func (i ForwardInfo) IsZero() bool
func (ForwardInfo) Spec ¶
func (i ForwardInfo) Spec() ports.ForwardSpec
type ForwardStatus ¶
type ForwardStatus struct {
// contains filtered or unexported fields
}
ForwardStatus 表示受管隧道转发句柄的不可变只读状态快照;零值恒无效并失败关闭。
func (ForwardStatus) Active ¶
func (st ForwardStatus) Active() bool
func (ForwardStatus) BoundAddr ¶
func (st ForwardStatus) BoundAddr() string
func (ForwardStatus) Err ¶
func (st ForwardStatus) Err() error
func (ForwardStatus) HandleStatus ¶
func (st ForwardStatus) HandleStatus() pool.HandleStatus
func (ForwardStatus) IsValid ¶
func (st ForwardStatus) IsValid() bool
func (ForwardStatus) IsZero ¶
func (st ForwardStatus) IsZero() bool
func (ForwardStatus) Spec ¶
func (st ForwardStatus) Spec() ports.ForwardSpec
type InteractiveRequest ¶
type InteractiveRequest struct {
Plan plan.SealedConnectionPlan
NodeID, Term string
Stdin io.Reader
Stdout, Stderr io.Writer
RequestTTY RequestTTYMode
Risk algebraic.Option[security.RiskLevel]
Approval algebraic.Option[gate.ApprovalSubmission]
OperationStream *events.OperationStream
}
InteractiveRequest 描述交互式远端 Shell 会话用例的强类型输入。
type MuxControlRequest ¶
type MuxControlRequest struct {
Target MuxRequest
Action ports.MuxControlAction
Forward algebraic.Option[ports.ForwardSpec]
}
MuxControlRequest 描述向 ControlMaster 发送 `-O` 控制动作(check/forward/cancel/exit/stop)的强类型输入。
type MuxRequest ¶
type MuxRequest struct {
Plan plan.SealedConnectionPlan
NodeID string
SocketPath algebraic.Option[pathalg.LocalSourcePath]
Risk algebraic.Option[security.RiskLevel]
Approval algebraic.Option[gate.ApprovalSubmission]
OperationStream *events.OperationStream
}
MuxRequest 描述面向 ControlMaster 套接字执行探测(ProbeMux)、stdio 透传(WithMuxProxy/RunMuxProxy) 或共享连接复用(WithMuxConn)的通用强类型输入。
type OpenPTYRequest ¶
type OpenPTYRequest struct {
Plan plan.SealedConnectionPlan
NodeID, Term string
Size algebraic.Option[ports.TerminalSize]
MaxBufferBytes int
Risk algebraic.Option[security.RiskLevel]
Approval algebraic.Option[gate.ApprovalSubmission]
OperationStream *events.OperationStream
}
OpenPTYRequest 描述在连接池世代 SlotMap 上创建跨请求持久 PTY 会话的强类型输入(ADR-009 / P3-T2)。
type PTYReadRequest ¶
type PTYReadRequest struct {
Handle plan.ManagedHandle[plan.KindPTY]
MaxBytes int // 0 默认 64 KiB
Wait bool // true 时事件驱动等待新输出、EOF 或取消/吊销
}
PTYReadRequest 描述从指定世代 PTY 句柄读取缓冲输出的请求参数。
type PTYReadResult ¶
type PTYReadResult struct {
// contains filtered or unexported fields
}
PTYReadResult 封装单次 ReadPTY 的不可变输出快照;零值恒无效并失败关闭。
func (PTYReadResult) Data ¶
func (r PTYReadResult) Data() []byte
func (PTYReadResult) DroppedBytes ¶
func (r PTYReadResult) DroppedBytes() uint64
func (PTYReadResult) EOF ¶
func (r PTYReadResult) EOF() bool
func (PTYReadResult) IsValid ¶
func (r PTYReadResult) IsValid() bool
func (PTYReadResult) IsZero ¶
func (r PTYReadResult) IsZero() bool
type PTYStatus ¶
type PTYStatus struct {
// contains filtered or unexported fields
}
PTYStatus 表示持久 PTY 句柄的不可变只读状态快照;零值恒无效并失败关闭。
func (PTYStatus) BufferedBytes ¶
func (PTYStatus) DroppedBytes ¶
func (PTYStatus) HandleStatus ¶
func (st PTYStatus) HandleStatus() pool.HandleStatus
func (PTYStatus) Size ¶
func (st PTYStatus) Size() ports.TerminalSize
type PrivilegeExecRequest ¶
type PrivilegeExecRequest struct {
Plan plan.SealedConnectionPlan
Privilege ports.PrivilegeRequest
NodeID, Term string
PasswordRef algebraic.Option[secret.Ref]
PromptPassword bool
Paths, RecursivePaths []string
LexicalScope algebraic.Option[security.ScopeSnapshot]
Canonicalize gate.CanonicalizeFunc
Stdin io.Reader
Stdout, Stderr io.Writer
RequestTTY RequestTTYMode
Risk algebraic.Option[security.RiskLevel]
Approval algebraic.Option[gate.ApprovalSubmission]
OperationStream *events.OperationStream
}
PrivilegeExecRequest 描述远端提权执行(sudo/su/doas)用例的强类型输入(ADR-008 / ADR-011 / P3-T2)。 提权口令严禁以明文字节传递,仅允许经 Vault PasswordRef 或交互 PromptPassword 在同步闭包内借用传递。
type ProbeShellRequest ¶
type ProbeShellRequest struct {
Plan plan.SealedConnectionPlan
NodeID string
Timeout algebraic.Option[algebraic.Duration]
Risk algebraic.Option[security.RiskLevel]
Approval algebraic.Option[gate.ApprovalSubmission]
OperationStream *events.OperationStream
}
ProbeShellRequest 描述远端 2 阶段默认 Shell 方言与解释器探测用例的强类型输入(P3-T2)。
type RequestTTYMode ¶
type RequestTTYMode uint8
RequestTTYMode 标识 SSH 伪终端分配策略(对应 OpenSSH RequestTTY auto/yes/no/force 与 -t/-tt/-T); 零值 RequestTTYUnset 失败关闭于文本编解码,运行期按操作类型取确定性默认策略(交互 Shell=auto,单命令=no)。
const ( RequestTTYUnset RequestTTYMode = iota // 未显式设置(零值) RequestTTYAuto // 自动:交互 Shell 且本机为 TTY 时分配 PTY RequestTTYYes // 本机为 TTY 时分配 PTY(对应 -t) RequestTTYNo // 禁止分配 PTY(对应 -T) RequestTTYForce // 强制分配远端 PTY,即使本机非 TTY(对应 -tt) )
func ParseRequestTTYMode ¶
func ParseRequestTTYMode(raw string) (RequestTTYMode, error)
ParseRequestTTYMode 严格解析 RequestTTY 文本(auto/yes/no/force)。
func (RequestTTYMode) AppendText ¶
func (m RequestTTYMode) AppendText(b []byte) ([]byte, error)
func (RequestTTYMode) IsValid ¶
func (m RequestTTYMode) IsValid() bool
IsValid / IsZero / String / TextAppender / TextMarshaler / TextUnmarshaler 实现 RequestTTYMode 值语义。
func (RequestTTYMode) IsZero ¶
func (m RequestTTYMode) IsZero() bool
func (RequestTTYMode) MarshalText ¶
func (m RequestTTYMode) MarshalText() ([]byte, error)
func (RequestTTYMode) String ¶
func (m RequestTTYMode) String() string
func (*RequestTTYMode) UnmarshalText ¶
func (m *RequestTTYMode) UnmarshalText(text []byte) error
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service 是 XOps v2 全量会话、提权、探测、持久 PTY、隧道转发与多路复用控制面用例服务; 零值恒未初始化并严格失败关闭。
func NewService ¶
func NewService(cfg ServiceConfig) (*Service, error)
NewService 校验必填依赖(Gate、Pool、Clock)并构造会话执行 Service。
func (*Service) CanSuspendProcessGroup ¶
CanSuspendProcessGroup 委托 TerminalPort 执行 POSIX 孤儿进程组安全挂起判定(INV-E1); 未初始化、未配置 TerminalPort 或底层异常时严格失败关闭返回 (security.VerdictDeny, error)。
func (*Service) ControlMux ¶
func (s *Service) ControlMux(ctx context.Context, req MuxControlRequest) (ports.MuxControlResponse, error)
ControlMux 向活跃 ControlMaster 发送 -O 控制命令(check/forward/cancel/exit/stop)。
func (*Service) Exec ¶
func (s *Service) Exec(ctx context.Context, req ExecRequest) (execution.ExecutionOutcome, error)
Exec 执行单条远端命令(严格按 gate.WithAuthorized 包裹 pool.WithLease), 过滤 SendEnv、按策略决定 PTY/流模式并向可选 OperationStream 发射完整事件序列与确定性 EOF。
func (*Service) ExecPrivileged ¶
func (s *Service) ExecPrivileged(ctx context.Context, req PrivilegeExecRequest) (execution.ExecutionOutcome, error)
ExecPrivileged 执行远端提权命令(sudo/su/doas):经 security.CanonicalScopeEscalated 复核提权作用域, 强制 gate.WithAuthorized[security.CapExecute] 包裹 pool.WithLease,并经作用域借用透传提权口令(0 明文消费)。
func (*Service) InspectControlMaster ¶
func (s *Service) InspectControlMaster(ctx context.Context, handle plan.ManagedHandle[plan.KindMux]) (ControlMasterStatus, error)
InspectControlMaster / TouchControlMaster / StopControlMaster 提供受管 ControlMaster 句柄的状态快照、活跃续期与有序停机。
func (*Service) InspectForward ¶
func (s *Service) InspectForward(ctx context.Context, handle plan.ManagedHandle[plan.KindTunnel]) (ForwardStatus, error)
InspectForward / WithForwardHandle / StopForward 提供受管隧道句柄的状态查询、同步借用与显式释放。
func (*Service) InspectPTY ¶
func (*Service) Interactive ¶
func (s *Service) Interactive(ctx context.Context, req InteractiveRequest) (execution.ExecutionOutcome, error)
Interactive 启动远端交互式 Shell 会话(严格按 gate.WithAuthorized 包裹 pool.WithLease), 按 RequestTTY 策略经 TerminalPort.WithRawTerminal + TerminalHandle.Relay 中继交互流与窗口缩放。
func (*Service) OpenPTY ¶
func (s *Service) OpenPTY(ctx context.Context, req OpenPTYRequest) (plan.ManagedHandle[plan.KindPTY], error)
OpenPTY 在连接池世代 SlotMap 上创建跨请求持久 PTY 会话并返回强类型 ManagedHandle[plan.KindPTY]: 严格遵循 gate.WithAuthorized[security.CapExecute] 包裹 pool.WithLease 与 pool.RegisterLeaseHandleWith。
func (*Service) ProbeMux ¶
func (s *Service) ProbeMux(ctx context.Context, req MuxRequest) (ports.MuxControlResponse, error)
ProbeMux 经 CapInspect 门控探测指定 ControlMaster 套接字存活状态与主进程 PID。
func (*Service) ProbeShell ¶
func (s *Service) ProbeShell(ctx context.Context, req ProbeShellRequest) (ports.ShellProbeResult, error)
ProbeShell 通过冻结的 ports.ShellProbePort 执行规范化 2 阶段远端 Shell 探测: 严格经 gate.WithAuthorized[security.CapInspect] 包裹 pool.WithLease,并对探测快照实施二次失败关闭校验(零盲猜回退)。
func (*Service) ReadPTY ¶
func (s *Service) ReadPTY(ctx context.Context, req PTYReadRequest) (res PTYReadResult, err error)
ReadPTY / WritePTY / ResizePTY / SignalPTY / InspectPTY / ClosePTY 提供跨请求持久 PTY 句柄操作(陈旧世代/吊销/熔断均失败关闭)。
func (*Service) ResizePTY ¶
func (s *Service) ResizePTY(ctx context.Context, handle plan.ManagedHandle[plan.KindPTY], size ports.TerminalSize) error
func (*Service) RunMuxProxy ¶
func (s *Service) RunMuxProxy(ctx context.Context, req MuxRequest, stdin io.ReadCloser, stdout io.Writer) error
RunMuxProxy 打开 `-O proxy` 连接并在 conc.RunScoped 监督下完成可关闭 stdin 与 stdout 的双向中继; 在 Nursery 作用域内监听 wCtx 同步中止,确保 stdin 真实读错、远端先达 EOF、背压写阻塞或 ctx 取消 均即时关闭 conn 与 stdin 并忠实传播非关闭故障与取消错误(0 死锁、0 goleak,适配真实 *os.File 的 fs.ErrClosed)。
func (*Service) StartControlMaster ¶
func (s *Service) StartControlMaster(ctx context.Context, req ControlMasterRequest) (ControlMasterInfo, error)
StartControlMaster 启动受管 ControlMaster(-M / ControlPersist)或在 auto/autoask 模式下复用活跃主进程: 严格消费 ControlPolicy.EffectiveMaster() 与 EffectivePersist() 失败关闭投影,绝不绕过 Path 禁用校验。
func (*Service) StartForward ¶
func (s *Service) StartForward(ctx context.Context, req StartForwardRequest) (ForwardInfo, error)
StartForward 启动一条受管长驻 SSH 转发(支持 -L/-R/-D、TCP↔Unix StreamLocal 双向/混合与 TUN): 严格遵循 gate.WithAuthorized[security.CapTunnel] 包裹 pool.WithLease 与 pool.RegisterLeaseHandleWith。
func (*Service) StopControlMaster ¶
func (*Service) StopForward ¶
func (s *Service) StopForward(ctx context.Context, handle plan.ManagedHandle[plan.KindTunnel]) error
func (*Service) TouchControlMaster ¶
func (*Service) TouchControlMasterActivity ¶
func (*Service) WithForwardHandle ¶
func (s *Service) WithForwardHandle(ctx context.Context, handle plan.ManagedHandle[plan.KindTunnel], fn func(ctx context.Context, fh ports.ForwardHandle) error) error
func (*Service) WithMuxConn ¶
func (s *Service) WithMuxConn(ctx context.Context, req MuxRequest, fn func(ctx context.Context, conn ports.TransportConn) error) error
WithMuxConn 经 MuxSocketPort.DialMux 复用活跃 ControlMaster 并严格核验返回的 (HopDigest, Endpoint) 身份与计划末跳精确一致,在同步作用域闭包内借出 ports.TransportConn,退出时无条件关闭。
type ServiceConfig ¶
type ServiceConfig struct {
Gate gate.Authorizer // 必填:能力门控授权器(ADR-008:严禁 nil)
Pool *pool.Pool // 必填:双通道纯内存 Actor 连接池(ADR-009)
Clock ports.Clock // 必填:时钟端口(事件时间戳、ControlPersist 与耗时统计)
Env ports.EnvPort // 可选:只读环境变量与本机身份端口
Terminal ports.TerminalPort // 可选:本机原始终端端口
Escalator ports.PrivilegeEscalationPort // 可选:远端提权(sudo/su/doas)端口
Vault ports.SecretVault // 可选:全作用域凭据库端口
Interaction ports.InteractionPort // 可选:人工交互端口
ShellProbe ports.ShellProbePort // 可选:2 阶段远端 Shell 探测端口
Forwarder ports.ForwarderPort // 可选:-L/-R/-D/StreamLocal/TUN 转发端口
TUNDevice ports.TUNDevicePort // 可选:本机 TUN/TAP 虚拟网卡端口
MuxSocket ports.MuxSocketPort // 可选:ControlMaster AF_UNIX 控制面端口
}
ServiceConfig 定义会话执行用例服务 Service 的显式出站依赖配置。
type StartForwardRequest ¶
type StartForwardRequest struct {
Plan plan.SealedConnectionPlan
Spec ports.ForwardSpec
NodeID string
Risk algebraic.Option[security.RiskLevel]
Approval algebraic.Option[gate.ApprovalSubmission]
OperationStream *events.OperationStream
}
StartForwardRequest 描述启动 SSH 端口转发(-L/-R/-D)、StreamLocal(TCP↔Unix 双向/混合)或 TUN 隧道的强类型输入(P3-T2)。