Documentation
¶
Overview ¶
Package assembly 承担 core/engine 构造期(Engine.New)与运行期底层基础设施的组件装配与依赖接线职责: 包括主机密钥信任只读观测器(HostTrustObserver)、默认协议端口补齐(sshnet/*)、 拨号器适配链(ControlMaster 复用与可选 RemoteFS 覆写)、ControlMaster 活跃事件桥接(MuxActivityHub)、 入站原生 OpenSSH Mux 晚绑定门控授权桥接(NativeMuxAuthHub,ADR-019 D3)、 安全门控接线(BuildGate)、在途操作生命周期管理(OpLifecycle)以及 6 大用例服务装配。
本包属 LayerCoreEngine 装配与基础设施子包,生产源码严格零导入 core/ports/tck 与 core/internal/sim。
Index ¶
- func BuildGate(in GateWireInput) (*gate.Gate, error)
- type AssembledServices
- type DialContextFunc
- type GateWireInput
- type HostTrustObserver
- func (o *HostTrustObserver) Lookup(ep netaddr.Endpoint) (inventory.KeyFingerprint, bool)
- func (o *HostTrustObserver) PreferredAlgorithms(ctx context.Context, ep netaddr.Endpoint, kh option.KnownHostsList) ([]string, error)
- func (o *HostTrustObserver) PreferredAlgorithmsWithGlobal(ctx context.Context, ep netaddr.Endpoint, ...) ([]string, error)
- func (o *HostTrustObserver) RecordHostKey(ctx context.Context, ep netaddr.Endpoint, key ports.PublicKeyInfo, ...) error
- func (o *HostTrustObserver) RecordHostKeyWithHash(ctx context.Context, ep netaddr.Endpoint, key ports.PublicKeyInfo, ...) error
- func (o *HostTrustObserver) VerifyHostKey(ctx context.Context, req ports.HostTrustRequest) (ports.HostTrustCheck, error)
- func (o *HostTrustObserver) VerifyHostKeyWithPolicy(ctx context.Context, req ports.HostTrustRequest, ...) (ports.HostTrustCheck, error)
- type MuxActivityHub
- func (h *MuxActivityHub) Bind(svc *ucsess.Service)
- func (h *MuxActivityHub) Clear()
- func (h *MuxActivityHub) Notify(ctx context.Context, socketAddr string, kind mux.SocketActivityKind)
- func (h *MuxActivityHub) Register(socketPath string, handle plan.ManagedHandle[plan.KindMux], ...)
- func (h *MuxActivityHub) UnregisterHandle(handle plan.ManagedHandle[plan.KindMux])
- type NativeMuxAuthHub
- func (h *NativeMuxAuthHub) BindGate(g *gate.Gate)
- func (h *NativeMuxAuthHub) Clear()
- func (h *NativeMuxAuthHub) MarkMCPAttached()
- func (h *NativeMuxAuthHub) WithAuthorizedSession(ctx context.Context, req mux.NativeSessionRequest, ...) error
- func (h *NativeMuxAuthHub) WithAuthorizedStdioFwd(ctx context.Context, req mux.NativeStdioFwdRequest, ...) error
- type OpLifecycle
- func (l *OpLifecycle) BeginOp(ctx context.Context) (context.Context, func(), error)
- func (l *OpLifecycle) BeginShutdown(onClose func()) <-chan struct{}
- func (l *OpLifecycle) Cancel(cause error)
- func (l *OpLifecycle) IsClosed() bool
- func (l *OpLifecycle) WaitDrain(ctx context.Context, waitCh <-chan struct{}) error
- func (l *OpLifecycle) WithLock(fn func(closing bool) error) error
- type PortsWireInput
- type RemoteFSFunc
- type ResolvedPorts
- type ServicesWireInput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AssembledServices ¶
type AssembledServices struct {
Inventory *ucinv.Service
Credential *uccred.Service
Session *ucsess.Service
MCPSession *ucsess.Service
Transfer *uctrans.Service
MCPTransfer *uctrans.Service
Automation *ucauto.Service
MCPAutomation *ucauto.Service
Observability *ucobs.Service
}
AssembledServices 保存已完整接线的 6 大用例服务及物理沙箱隔离(0 OperatorReadFS / 0 ForwardAgent)的 MCP 视图。
func AssembleServices ¶
func AssembleServices(in ServicesWireInput) (AssembledServices, error)
AssembleServices 按依赖顺序装配 credential、inventory、session、transfer、automation 与 observability 全部用例服务。
type DialContextFunc ¶
DialContextFunc 与 RemoteFSFunc 与 core/engine 保持同构签名,用于构造底层拨号适配链。
type GateWireInput ¶
type GateWireInput struct {
Profile gate.PolicyProfileKind
Policy gate.GuardrailPolicy
AuditSink ports.AuditSink
Reconciler ports.AuditReconciler
Interaction ports.InteractionPort
Clock ports.Clock
Entropy ports.Entropy
SystemBus *events.SystemBus
Pool *pool.Pool
OnHalt func(gate.HaltInfo)
}
GateWireInput 封装构造 Engine 内部安全门控与连接池熔断联动所需的全部构造期参数。
type HostTrustObserver ¶
type HostTrustObserver struct {
// contains filtered or unexported fields
}
HostTrustObserver 在 ports.HostTrustPort 外层只读记录最近经校验通过或合法登记的 (Endpoint -> KeyFingerprint), 遇冲突或吊销立即驱逐旧记录,支撑 INV-F2 首连暂存探测返回真实服务端指纹(零伪造)。
func BuildDialerPort ¶
func BuildDialerPort(in PortsWireInput, rp ResolvedPorts) (ports.DialerPort, *HostTrustObserver, error)
BuildDialerPort 构造完整拨号器链(含主机信任观测器、透明 ControlMaster 客户端复用与可选 RemoteFS 覆写)。
func NewHostTrustObserver ¶
func NewHostTrustObserver(inner ports.HostTrustPort) *HostTrustObserver
NewHostTrustObserver 包装底层 HostTrustPort 并建立主机指纹只读观测表。
func (*HostTrustObserver) Lookup ¶
func (o *HostTrustObserver) Lookup(ep netaddr.Endpoint) (inventory.KeyFingerprint, bool)
Lookup 查询指定端点最近观测到的可信服务端主机密钥指纹。
func (*HostTrustObserver) PreferredAlgorithms ¶
func (o *HostTrustObserver) PreferredAlgorithms(ctx context.Context, ep netaddr.Endpoint, kh option.KnownHostsList) ([]string, error)
PreferredAlgorithms 透传至底层主机信任库。
func (*HostTrustObserver) PreferredAlgorithmsWithGlobal ¶
func (o *HostTrustObserver) PreferredAlgorithmsWithGlobal(ctx context.Context, ep netaddr.Endpoint, userKH, globalKH option.KnownHostsList) ([]string, error)
PreferredAlgorithmsWithGlobal 在底层主机信任库支持只读全局 known_hosts 时透传查询,否则回退用户 known_hosts 查询。
func (*HostTrustObserver) RecordHostKey ¶
func (o *HostTrustObserver) RecordHostKey(ctx context.Context, ep netaddr.Endpoint, key ports.PublicKeyInfo, kh option.KnownHostsList) error
RecordHostKey 透传记录已知主机密钥并在成功时缓存其指纹。
func (*HostTrustObserver) RecordHostKeyWithHash ¶
func (o *HostTrustObserver) RecordHostKeyWithHash(ctx context.Context, ep netaddr.Endpoint, key ports.PublicKeyInfo, kh option.KnownHostsList, hashHostnames bool) error
RecordHostKeyWithHash 在底层主机信任库支持单次 hash_known_hosts 策略时透传落盘并同步缓存其指纹。
func (*HostTrustObserver) VerifyHostKey ¶
func (o *HostTrustObserver) VerifyHostKey(ctx context.Context, req ports.HostTrustRequest) (ports.HostTrustCheck, error)
VerifyHostKey 透传校验并按结果更新或驱逐观测缓存。
func (*HostTrustObserver) VerifyHostKeyWithPolicy ¶
func (o *HostTrustObserver) VerifyHostKeyWithPolicy(ctx context.Context, req ports.HostTrustRequest, globalKH option.KnownHostsList, verifyDNS option.VerifyHostKeyDNSMode) (ports.HostTrustCheck, error)
VerifyHostKeyWithPolicy 在底层主机信任库支持全局 known_hosts 与 VerifyHostKeyDNS 策略时透传校验并同步更新观测缓存。
type MuxActivityHub ¶
type MuxActivityHub struct {
// contains filtered or unexported fields
}
MuxActivityHub 将默认 sshnet/mux 控制套接字上的客户端进入/活跃/离开与监听关闭事件 安全桥接至 session.Service.TouchControlMasterActivity,保活活跃会话并在监听退出时零泄漏清理索引。
func NewMuxActivityHub ¶
func NewMuxActivityHub() *MuxActivityHub
NewMuxActivityHub 构造初始为空的 ControlMaster 控制套接字活跃事件桥接器。
func (*MuxActivityHub) Bind ¶
func (h *MuxActivityHub) Bind(svc *ucsess.Service)
Bind 绑定负责接收保活续期通知的 session.Service 实例。
func (*MuxActivityHub) Notify ¶
func (h *MuxActivityHub) Notify(ctx context.Context, socketAddr string, kind mux.SocketActivityKind)
Notify 响应 sshnet/mux 回调:监听关闭时无条件清理索引,其余活跃事件转发至 session.Service 保活。
func (*MuxActivityHub) Register ¶
func (h *MuxActivityHub) Register(socketPath string, handle plan.ManagedHandle[plan.KindMux], doneCh <-chan struct{})
Register 登记套接字路径与 ManagedHandle[KindMux] 的映射;若 doneCh 已关闭则跳过登记以规避快速退出竞态残留。
func (*MuxActivityHub) UnregisterHandle ¶
func (h *MuxActivityHub) UnregisterHandle(handle plan.ManagedHandle[plan.KindMux])
UnregisterHandle 按句柄精确注销其关联的全部控制套接字映射条目。
type NativeMuxAuthHub ¶
type NativeMuxAuthHub struct {
// contains filtered or unexported fields
}
NativeMuxAuthHub 是入站原生 OpenSSH PROTOCOL.mux v4(NEW_SESSION / NEW_STDIO_FWD)的原子晚绑定作用域门控授权中心(ADR-019 v2.2 S3-Q3):
- 解决 ResolveDefaultPorts 早于 BuildGate 与 NewMCPServer 的构造顺序,且与 Engine 级 DisallowForwardAgent 解耦(由单实例 MuxServeOptions 独立管控 want_agent);
- 仅当 Engine 为 PolicyProfileDirectOperator、未附着任何 MCPServer 且 Gate 未熔断时放行;
- 每次放行强制经 //xops:syncclosure 同步作用域回调 gate.WithAuthorized[CapExecute|CapTunnel] 包裹完整执行生命周期, 携带单实例 (NodeID, Endpoint, PlanDigest) 强制生效 NodeOverrides 拒绝规则与 blocked_patterns 校验, 并在真实会话/转发退出后通过 auth.ReportOutcome 落盘终态审计与 .lock 注销(维持 O(1) 崩溃对账)。
func NewNativeMuxAuthHub ¶
func NewNativeMuxAuthHub(allowNative bool) *NativeMuxAuthHub
NewNativeMuxAuthHub 构造初始未绑定 Gate(默认失败关闭)的原生 Mux 授权晚绑定桥接器。
func (*NativeMuxAuthHub) BindGate ¶
func (h *NativeMuxAuthHub) BindGate(g *gate.Gate)
BindGate 在 BuildGate 完成后原子绑定权威 Gate 实例。
func (*NativeMuxAuthHub) Clear ¶
func (h *NativeMuxAuthHub) Clear()
Clear 在 Engine 停机阶段永久关闭并清空 Gate 引用,确保后续入站请求严格失败关闭。
func (*NativeMuxAuthHub) MarkMCPAttached ¶
func (h *NativeMuxAuthHub) MarkMCPAttached()
MarkMCPAttached 在 MCPServer 完成校验与登记后不可逆置位,立即对全部入站原生 OpenSSH Mux 请求失败关闭。
func (*NativeMuxAuthHub) WithAuthorizedSession ¶
func (h *NativeMuxAuthHub) WithAuthorizedSession( ctx context.Context, req mux.NativeSessionRequest, run func(authCtx context.Context) (execution.ExecutionOutcome, error), ) error
WithAuthorizedSession 以同步作用域闭包授权并包裹入站原生 OpenSSH MUX_C_NEW_SESSION 完整生命周期, 携带单实例 (NodeID, Endpoint, PlanDigest) 强制经 CapExecute、NodeOverrides 与 blocked_patterns 校验, 执行完毕后经 auth.ReportOutcome 上报真实 ExecutionOutcome 并在退出闭包时落盘 AuditPhaseFinalized。
func (*NativeMuxAuthHub) WithAuthorizedStdioFwd ¶
func (h *NativeMuxAuthHub) WithAuthorizedStdioFwd( ctx context.Context, req mux.NativeStdioFwdRequest, run func(authCtx context.Context) error, ) error
WithAuthorizedStdioFwd 以同步作用域闭包授权并包裹入站原生 OpenSSH MUX_C_NEW_STDIO_FWD 完整生命周期, 携带单实例 (NodeID, Endpoint, PlanDigest) 强制经 CapTunnel 与 NodeOverrides 校验, 执行完毕后方退出 gate.WithAuthorized 落盘 AuditPhaseFinalized 与 .lock 注销。
type OpLifecycle ¶
type OpLifecycle struct {
// contains filtered or unexported fields
}
OpLifecycle 管理 Engine 在途操作的取消桥接、并发排空计数与停机状态锁;零值恒失败关闭。
func (*OpLifecycle) BeginShutdown ¶
func (l *OpLifecycle) BeginShutdown(onClose func()) <-chan struct{}
BeginShutdown 原子置 closing=true、持锁执行 onClose 收集派生资源,并返回可选的在途排空通道。
func (*OpLifecycle) Cancel ¶
func (l *OpLifecycle) Cancel(cause error)
Cancel 触发生命周期根上下文取消,用于 Engine 停机或构造失败回滚。
type PortsWireInput ¶
type PortsWireInput struct {
Clock ports.Clock
Entropy ports.Entropy
ScopedFS ports.ScopedRootFS
OperatorReadFS ports.OperatorReadFS
HostTrust ports.HostTrustPort
KnownHostsDir algebraic.Option[pathalg.LocalDir]
HomeDir algebraic.Option[pathalg.LocalDir]
KnownHostsFileName string
KnownHostsMaxBytes int64
HashKnownHosts bool
SSHFPLookup ports.SSHFPLookupPort
Env ports.EnvPort
Terminal ports.TerminalPort
Process ports.ProcessPort
Interaction ports.InteractionPort
Vault ports.SecretVault
KeySigner ports.KeySignerPort
Agent ports.SSHAgentPort
DiagnosticSink ports.DiagnosticSink
DisallowForwardAgent bool
GlobalOptions option.OptionLayer
AllowNativeUncheckedSessions bool
NativeMuxAuth *NativeMuxAuthHub
PrivilegeEscalation ports.PrivilegeEscalationPort
ShellProbe ports.ShellProbePort
Forwarder ports.ForwarderPort
TUNDevice ports.TUNDevicePort
MuxSocket ports.MuxSocketPort
Dialer ports.DialerPort
RemoteFS RemoteFSFunc
DialContext DialContextFunc
ClientVersion string
ForwardAllowGatewayPorts bool
ForwardReplaceStaleUnix bool
OnMuxSocketActivity func(context.Context, string, mux.SocketActivityKind)
}
PortsWireInput 封装装配默认协议端口与真实拨号链所需的全量配置参数。
type RemoteFSFunc ¶
type RemoteFSFunc func(ctx context.Context, conn ports.TransportConn) (ports.RemoteFSPort, error)
DialContextFunc 与 RemoteFSFunc 与 core/engine 保持同构签名,用于构造底层拨号适配链。
type ResolvedPorts ¶
type ResolvedPorts struct {
KeySigner ports.KeySignerPort
Escalator ports.PrivilegeEscalationPort
ShellProbe ports.ShellProbePort
Forwarder ports.ForwarderPort
MCPForwarder ports.ForwarderPort
MuxSocket ports.MuxSocketPort
}
ResolvedPorts 保存经默认补齐后的全部协议出站端口实例(含物理隔离的 MCPForwarder)。
func ResolveDefaultPorts ¶
func ResolveDefaultPorts(in PortsWireInput) (rp ResolvedPorts, err error)
ResolveDefaultPorts 为未显式注入的可选协议端口装配真实 sshnet/* 生产默认实现。
type ServicesWireInput ¶
type ServicesWireInput struct {
Gate *gate.Gate
Pool *pool.Pool
Bus *events.SystemBus
Clock ports.Clock
Entropy ports.Entropy
ScopedFS ports.ScopedRootFS
OperatorReadFS ports.OperatorReadFS
Env ports.EnvPort
Terminal ports.TerminalPort
Process ports.ProcessPort
OpenSSH ports.OpenSSHConfigSource
CanonicalResolver ports.CanonicalResolverPort
DiagnosticSink ports.DiagnosticSink
DisallowForwardAgent bool
Interaction ports.InteractionPort
Vault ports.SecretVault
VaultControl ports.VaultControlPort
VaultControlRouter ports.VaultControlRouter
RequireExplicitVaultStore bool
InventoryStore ports.InventoryStore
JournalStore ports.JournalStore
Importers []ports.FormatImporter
KnownStores []string
DefaultEnrollTTL algebraic.Option[algebraic.Duration]
DefaultExecution algebraic.Option[execution.LaunchProfile]
LegacyConfigDetectedPath string
TUNDevice ports.TUNDevicePort
GlobalOptions option.OptionLayer
MaxJumpDepth int
TransferDefaultConcurrency int
TransferDefaultChunkSize int64
TransferDefaultMaxReadBytes int64
AutomationDefaultConcurrency int
AutomationMaxScriptBytes int64
AutomationMaxTemplateBytes int64
AutomationMaxCopyBytes int64
Ports ResolvedPorts
}
ServicesWireInput 封装装配 Engine 全部 6 大用例服务所需的运行期依赖与参数。