Documentation
¶
Index ¶
- Constants
- func NewConnector(cfgProvider config.ConfigProvider, opts ...ssh.Option) *ssh.Connector
- func NewConnectorWithAdapterOptions(cfgProvider config.ConfigProvider, adpOpts []Option, sshOpts ...ssh.Option) *ssh.Connector
- func NewConnectorWithInteraction(cfgProvider config.ConfigProvider, interaction ssh.InteractionHandler, ...) *ssh.Connector
- func NewNonInteractiveConnector(cfgProvider config.ConfigProvider, opts ...ssh.Option) *ssh.Connector
- func VerifyConnection(ctx context.Context, preview *config.Provider, nodeID string, ...) error
- type ConnectionVerification
- type CredentialResolver
- type Option
- func WithControlMultiplexing(enabled bool) Option
- func WithCredentialRecording(enabled bool) Option
- func WithCredentialService(service *credential.Service) Option
- func WithCredentialSource(source CredentialResolver) Option
- func WithEnrollmentProbeExclusions(nodeIDs ...string) Option
- func WithEnrollmentProbing(report func(string, error)) Option
- func WithGlobalSessionAuth(auth SessionAuth) Option
- func WithGlobalSessionControl(opts SessionControlOptions) Option
- func WithHostTrustOverrides(enabled bool) Option
- func WithNonInteractive(nonInteractive bool) Option
- func WithOpenSSHParser(parser *config.OpenSSHParser) Option
- func WithRememberConfirmation(confirm func(context.Context, string) (bool, error)) Option
- func WithSessionAuthOverride(nodeID string, auth SessionAuth) Option
- func WithSessionControlOverride(nodeID string, opts SessionControlOptions) Option
- type SSHAdapter
- func (a *SSHAdapter) ConfirmAuthenticatedConnection(ctx context.Context, nodeID string, client *ssh.Client) (*ssh.ExecutionConfig, error)
- func (a *SSHAdapter) ConfirmConnection(ctx context.Context, nodeID string) error
- func (a *SSHAdapter) DisableSessionControlSharing(nodeID string)
- func (a *SSHAdapter) ExpandControlPath(nodeID string, rawPath string) (string, error)
- func (a *SSHAdapter) GetConfig(nodeID string) (*ssh.ClientConfig, error)
- func (a *SSHAdapter) GetControlConfig(nodeID string) (*ssh.ControlConfig, error)
- func (a *SSHAdapter) ResolveControl(nodeName string, sessionOpts SessionControlOptions) (*ssh.ControlConfig, error)
- func (a *SSHAdapter) ResolveSSHOptions(nodeName string, sessionOpts SessionControlOptions) (*ssh.Options, error)
- func (a *SSHAdapter) ResolveSecret(ctx context.Context, req ssh.SecretRequest) ([]byte, error)
- func (a *SSHAdapter) UpdateAuth(ctx context.Context, ...) (string, error)
- func (a *SSHAdapter) UpdateSudo(ctx context.Context, nodeID, sudoUpdateToken string, mode ssh.SudoMode, ...) (string, error)
- type SessionAuth
- type SessionControlOptions
Constants ¶
const VerificationTimeout = 15 * time.Second
VerificationTimeout bounds the entire inventory connection check.
Variables ¶
This section is empty.
Functions ¶
func NewConnector ¶
NewConnector 是一个辅助方法,快速创建组装好 Adapter 的 ssh.Connector,支持传入 Option 进行显式注入配置。
func NewConnectorWithAdapterOptions ¶ added in v0.12.0
func NewConnectorWithAdapterOptions(cfgProvider config.ConfigProvider, adpOpts []Option, sshOpts ...ssh.Option) *ssh.Connector
NewConnectorWithAdapterOptions 创建组装好 Adapter 选项和 SSH 选项的 Connector
func NewConnectorWithInteraction ¶ added in v0.12.0
func NewConnectorWithInteraction(cfgProvider config.ConfigProvider, interaction ssh.InteractionHandler, opts ...ssh.Option) *ssh.Connector
NewConnectorWithInteraction creates a connector with a presentation-layer interaction handler supplied by the composition root.
func NewNonInteractiveConnector ¶ added in v0.10.0
func NewNonInteractiveConnector(cfgProvider config.ConfigProvider, opts ...ssh.Option) *ssh.Connector
NewNonInteractiveConnector 创建一个非交互式的 Connector,避免在批量操作中阻塞等待输入,支持传入 Option。
func VerifyConnection ¶ added in v0.13.0
func VerifyConnection(ctx context.Context, preview *config.Provider, nodeID string, resolver CredentialResolver) error
VerifyConnection authenticates an inventory preview without opening a shell or recording credentials. New host keys follow the existing import policy; changed host keys are still rejected. The caller decides whether to save.
Types ¶
type ConnectionVerification ¶ added in v0.14.0
type ConnectionVerification struct {
Probe *ssh.ProbeResult
ProbeErr error
}
ConnectionVerification separates authentication failures from optional, non-fatal execution probing. No inventory or credential data is persisted.
func VerifyConnectionWithProbe ¶ added in v0.14.0
func VerifyConnectionWithProbe(ctx context.Context, preview *config.Provider, nodeID string, resolver CredentialResolver) (ConnectionVerification, error)
VerifyConnectionWithProbe reuses the authenticated verification connection for one bounded execution probe. ProbeErr never turns successful authentication into a verification failure; transport cleanup failures remain fatal. The connection uses server/unknown independently of node/global command settings.
type CredentialResolver ¶ added in v0.12.0
type CredentialResolver interface {
Resolve(ctx context.Context, ref credential.Ref) (credential.Secret, error)
}
CredentialResolver 描述能够根据 Ref 解析 Secret 的契约(如 *credential.Registry)
type Option ¶ added in v0.12.0
type Option func(*SSHAdapter)
Option 定义 SSHAdapter 的配置选项
func WithControlMultiplexing ¶ added in v0.16.0
WithControlMultiplexing controls whether this adapter exposes a ControlProvider to the underlying ssh.Connector. Credential verification and MCP hosts disable it so they never attach to or create external control sockets on disk.
func WithCredentialRecording ¶ added in v0.12.0
WithCredentialRecording controls persistence of secrets discovered during a connection. Composition roots apply remember policy and terminal ownership; explicit credential form actions use the service independently.
func WithCredentialService ¶ added in v0.12.0
func WithCredentialService(service *credential.Service) Option
WithCredentialService injects the transactional writer used when an interactive connection is explicitly allowed to remember a discovered secret. Secrets must never be written through the legacy configuration fields.
func WithCredentialSource ¶ added in v0.12.0
func WithCredentialSource(source CredentialResolver) Option
WithCredentialSource 注入凭据解析器(如 credential.Registry),用于解析 Ref 引用
func WithEnrollmentProbeExclusions ¶ added in v0.14.0
WithEnrollmentProbeExclusions skips enrollment probing for nodes with explicit session execution choices. Other nodes, including jumps, retain their policy.
func WithEnrollmentProbing ¶ added in v0.14.0
WithEnrollmentProbing enables read-only probing before a new authenticated node is saved. It still requires interactive credential remembering to be enabled for that node. The optional reporter belongs to the CLI layer.
func WithGlobalSessionAuth ¶ added in v0.12.0
func WithGlobalSessionAuth(auth SessionAuth) Option
WithGlobalSessionAuth 注入会话级全局默认机密覆盖(当特定节点未显式指定 override 时生效)
func WithGlobalSessionControl ¶ added in v0.16.0
func WithGlobalSessionControl(opts SessionControlOptions) Option
WithGlobalSessionControl registers session multiplexing overrides for all nodes in the session.
func WithHostTrustOverrides ¶ added in v0.16.0
WithHostTrustOverrides controls whether this adapter forwards trust-class SSH options (StrictHostKeyChecking, UserKnownHostsFile) from configuration or session overrides to the underlying ssh.Connector. MCP and verification paths disable it to enforce fail-closed host key verification.
func WithNonInteractive ¶ added in v0.12.0
WithNonInteractive 标记该适配器为非交互式环境(如批处理、MCP、Playbook)
func WithOpenSSHParser ¶ added in v0.16.0
func WithOpenSSHParser(parser *config.OpenSSHParser) Option
WithOpenSSHParser injects an explicit OpenSSHParser for Tier 4 resolution (e.g. in tests).
func WithRememberConfirmation ¶ added in v0.12.0
WithRememberConfirmation injects a presentation-owned decision made only after authentication succeeds and before a newly discovered secret is saved.
func WithSessionAuthOverride ¶ added in v0.12.0
func WithSessionAuthOverride(nodeID string, auth SessionAuth) Option
WithSessionAuthOverride 注入特定节点的会话级临时机密覆盖
func WithSessionControlOverride ¶ added in v0.16.0
func WithSessionControlOverride(nodeID string, opts SessionControlOptions) Option
WithSessionControlOverride registers session multiplexing overrides for a specific node.
type SSHAdapter ¶
type SSHAdapter struct {
// contains filtered or unexported fields
}
SSHAdapter 实现 ssh.ConnectionProvider, ssh.SecretResolver, ssh.CredentialRecorder 接口,作为业务模型与底层 SSH 的防腐层
func NewNonInteractiveSSHAdapter ¶ added in v0.10.0
func NewNonInteractiveSSHAdapter(cfgProvider config.ConfigProvider, opts ...Option) *SSHAdapter
NewNonInteractiveSSHAdapter 创建非交互式的 SSH 适配器
func NewSSHAdapter ¶
func NewSSHAdapter(cfgProvider config.ConfigProvider, opts ...Option) *SSHAdapter
NewSSHAdapter 创建 SSH 适配器
func (*SSHAdapter) ConfirmAuthenticatedConnection ¶ added in v0.14.0
func (a *SSHAdapter) ConfirmAuthenticatedConnection(ctx context.Context, nodeID string, client *ssh.Client) (*ssh.ExecutionConfig, error)
ConfirmAuthenticatedConnection probes only pending, remembered connections. A failed probe preserves authentication success and normal node enrollment.
func (*SSHAdapter) ConfirmConnection ¶ added in v0.13.0
func (a *SSHAdapter) ConfirmConnection(ctx context.Context, nodeID string) error
ConfirmConnection publishes a prepared node before credentials are recorded. Providers without pending connections require no additional mutation.
func (*SSHAdapter) DisableSessionControlSharing ¶ added in v0.16.0
func (a *SSHAdapter) DisableSessionControlSharing(nodeID string)
DisableSessionControlSharing forces ControlPath=none for the session (both globally and on nodeID) while preserving any non-multiplexing session SSH options already registered for nodeID or globally.
func (*SSHAdapter) ExpandControlPath ¶ added in v0.16.0
func (a *SSHAdapter) ExpandControlPath(nodeID string, rawPath string) (string, error)
ExpandControlPath expands tokens in rawPath for nodeID using node snapshot context. Useful for CLI control commands (-O check/exit/stop) that directly connect to sockets.
func (*SSHAdapter) GetConfig ¶
func (a *SSHAdapter) GetConfig(nodeID string) (*ssh.ClientConfig, error)
GetConfig 获取底层 SSH 客户端需要的配置
func (*SSHAdapter) GetControlConfig ¶ added in v0.16.0
func (a *SSHAdapter) GetControlConfig(nodeID string) (*ssh.ControlConfig, error)
GetControlConfig implements ssh.ControlProvider.
func (*SSHAdapter) ResolveControl ¶ added in v0.16.0
func (a *SSHAdapter) ResolveControl(nodeName string, sessionOpts SessionControlOptions) (*ssh.ControlConfig, error)
ResolveControl resolves the effective ControlConfig for nodeID given session options, strictly enforcing the 4-tier precedence hierarchy and field-by-field merging semantics.
func (*SSHAdapter) ResolveSSHOptions ¶ added in v0.16.0
func (a *SSHAdapter) ResolveSSHOptions(nodeName string, sessionOpts SessionControlOptions) (*ssh.Options, error)
ResolveSSHOptions resolves the effective ssh.Options for nodeName given session options, enforcing the 4-tier precedence hierarchy (Tier 1 CLI > Tier 2 Node > Tier 3 Global > Tier 4 ~/.ssh/config).
func (*SSHAdapter) ResolveSecret ¶ added in v0.12.0
func (a *SSHAdapter) ResolveSecret(ctx context.Context, req ssh.SecretRequest) ([]byte, error)
ResolveSecret 从当前配置模型解析认证或提权所需机密,并严格校验与连接快照的一致性
func (*SSHAdapter) UpdateAuth ¶
func (a *SSHAdapter) UpdateAuth(ctx context.Context, nodeID, authUpdateToken, password, keyPath, passphrase string) (string, error)
UpdateAuth 处理密码或私钥密码的回写并返回本次提交后的新认证令牌
type SessionAuth ¶ added in v0.12.0
type SessionAuth struct {
Password string
Passphrase string
KeyPath string
SuPwd string
OTP string
ProxyJump string
Remember bool
}
SessionAuth 描述单个连接会话的临时认证机密与跳板覆盖
type SessionControlOptions ¶ added in v0.16.0
type SessionControlOptions struct {
Master *ssh.ControlMasterMode
Path *string
Persist *string
Options *ssh.Options
}
SessionControlOptions specifies session-level OpenSSH option overrides (Tier 1). Pointers indicate whether a multiplexing flag was explicitly specified on the CLI.
func ParseOptionStrings ¶ added in v0.16.0
func ParseOptionStrings(options []string) (SessionControlOptions, error)
ParseOptionStrings parses OpenSSH -o Key=Value strings into SessionControlOptions. Unknown keys are rejected instead of ignored so a typo cannot silently disable the requested behavior.
func (SessionControlOptions) IsEmpty ¶ added in v0.16.0
func (s SessionControlOptions) IsEmpty() bool
IsEmpty returns true if no session control or SSH option flags were provided.
func (*SessionControlOptions) SetMaster ¶ added in v0.16.0
func (s *SessionControlOptions) SetMaster(m ssh.ControlMasterMode)
SetMaster sets the ControlMaster override.
func (*SessionControlOptions) SetPath ¶ added in v0.16.0
func (s *SessionControlOptions) SetPath(p string)
SetPath sets the ControlPath override.
func (*SessionControlOptions) SetPersist ¶ added in v0.16.0
func (s *SessionControlOptions) SetPersist(p string)
SetPersist sets the ControlPersist override.
func (SessionControlOptions) ToSSHOptions ¶ added in v0.16.0
func (s SessionControlOptions) ToSSHOptions() *ssh.Options
ToSSHOptions returns the session-level ssh.Options representation (including Master/Path/Persist fields).