priv

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package priv 实现 XOps v2 的远端提权执行适配器(ports.PrivilegeEscalationPort,P4-T1)。

核心安全、协议与并发不变量:

  • 随机化 `-p` 提权提示令牌与提权就绪帧(ready token)分离认证输入与命令输入: 口令仅在识别到合法提示帧后写入已验证的 (ports.RemoteSession).StdinPipe,普通 stdin 与脚本正文 在就绪帧抵达前绝不投递,防止口令混入命令流或命令输入误充口令;
  • 双输出流严格维持无环因果序(次流 -> 主控流,非 PTY 模式主控流为 stderr、PTY 模式主控流为 stdout): 仅主控流扫描提示帧与就绪帧,次流绝不扫描提示或就绪帧(阻断混淆代理口令泄露与输出串扰), 在主控流观测到 ready token 或到达 EOF 前有界暂存(<= 64 KiB)就绪前字节;一旦主控流触发 markReady, 独立的次流刷出协程立即无锁写入全部已暂存字节并关闭同步屏障,确保阻塞中的远端命令首包零滞留且与后续输出严格 FIFO;
  • 直接借用 (ports.RemoteSession).{StdoutPipe,StderrPipe}(由上游独立 io.Pipe 桥接驱动, 各流到达 EOF 独立关闭且不计入外层 MaxOutputBytes 配额,由本包 streamScanner 作为唯一精确截断权威), 在握手超时、就绪后取消或半开黑洞下通过 Session.Close O(1) 解阻; 一旦已越过就绪帧后发生中止或超时,恒返回不可重试的 *execution.OutcomeUnknown;
  • 完整兼容 POSIX sudo(含 sudo-rs 的 `[sudo: <token>] ...:` 封套、全角冒号与 `*` 回显抑制)、 su 与 doas,支持 NonInteractive(-n)失败关闭;
  • 隶属 LayerCoreSSHNetPriv 明文白名单,严格复用 secrettaint/sinks_narrow.go:isAllowedPrivEscalationWrite 正向白名单,并支持双层嵌套 primaryBox.Use -> secondaryBox.Use 组合口令写入(全包零行内 nolint 豁免);
  • *secret.SecretBox 仅在调用方同步协程内消费(零跨协程借用逃逸),全部输出/输入泵均由 core/conc.Nursery 监督(0 裸 go,0 协程泄漏)。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Entropy 可选注入显式随机字节源用于生成随机 -p 提示令牌与就绪帧;为空时回退 crypto/rand.Reader。
	Entropy ports.Entropy
	// Clock 可选注入时钟端口用于控制提权握手超时定时器;为空时回退系统时钟。
	Clock ports.Clock
	// HandshakeTimeout 可选覆盖等待提权认证完成的最长超时时长(<= 0 时默认 30s)。
	HandshakeTimeout time.Duration
}

Config 描述 Escalator 的显式运行期出站依赖配置(零全局单例与隐式状态)。

type Escalator

type Escalator struct {
	// contains filtered or unexported fields
}

Escalator 是基于随机化提示/就绪帧握手协议的 ports.PrivilegeEscalationPort 生产实现;零值恒失败关闭。

func NewEscalator

func NewEscalator(cfg Config) (*Escalator, error)

NewEscalator 校验配置并构造不可变 Escalator 实例。

func (*Escalator) RunPrivileged

func (e *Escalator) RunPrivileged(
	ctx context.Context,

	opener ports.SessionOpener,
	req ports.PrivilegeRequest,

	password *secret.SecretBox,
	streams ports.ExecStreams,
) (execution.ExecutionOutcome, error)

RunPrivileged 通过借用的 opener 打开远端会话并按 req 执行随机化 -p / 就绪帧提权握手, 实现 ports.PrivilegeEscalationPort;口令仅在调用方同步协程内写入经验证的 (ports.RemoteSession).StdinPipe。

func (*Escalator) RunPrivilegedWithCombinedSecret

func (e *Escalator) RunPrivilegedWithCombinedSecret(
	ctx context.Context,

	opener ports.SessionOpener,
	req ports.PrivilegeRequest,

	primary *secret.SecretBox,

	secondary *secret.SecretBox,
	streams ports.ExecStreams,
) (execution.ExecutionOutcome, error)

RunPrivilegedWithCombinedSecret 支持双因素提权(如口令 + 第二因子 PIN/OTP 拼接场景), 在同步调用方协程内以嵌套 primary.Use -> secondary.Use 方式将拼接明文写入经验证的 StdinPipe 并立即清零(0 nolint)。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL