Documentation
¶
Overview ¶
Package security 提供 XOps v2 纯函数数学安全内核。
本包及无环内部叶包 internal/secutil 恪守 100% 纯数学与零副作用铁律(零 sync/sync/atomic/context/os/net/reflect/crypto/rand/time.Now):
- 有界安全格:Verdict 交半格、RiskLevel 并半格(零值 RiskUnknown 失败关闭)、 GuardrailDecision 封闭和类型及 NodeOverrides 顺序无关格折叠;
- 幻影能力封闭类型集:Capability(CapInspect..CapMutate)及序列化枚举 CapabilityKind;
- 操作与链路身份、规范绑定与审批信封:TraceID、OperationID、SHA-256 Digest、经 digestcover 静态校验的 OperationBinding 与 ApprovalEnvelope,以及双阶段路径规范化升级判定 CanonicalScopeEscalated。
架构隔离铁律(ADR-008):运行期能力证明 Authorized[C] 物理独占定义于 core/internal/gate,严禁在本包定义。
Index ¶
- Variables
- func CanonicalScopeEscalated(lexical, canonical ScopeSnapshot) bool
- func EqualDecision(a, b GuardrailDecision) bool
- func MarshalDecisionTo(enc *jsontext.Encoder, d GuardrailDecision) error
- func MatchGlob(pattern, target string) (bool, error)
- func NewApprovalNonceFrom(entropy io.Reader) ([secutil.ApprovalNonceBytes]byte, error)
- func SanitizePromptText(raw string) string
- func ValidateGlob(pattern string) error
- type ApprovalEnvelope
- func (e ApprovalEnvelope) Binding() OperationBinding
- func (e ApprovalEnvelope) CanApprove() bool
- func (e ApprovalEnvelope) CanonicalJSON() ([]byte, error)
- func (e ApprovalEnvelope) Decision() GuardrailDecision
- func (e ApprovalEnvelope) Digest() (Digest, error)
- func (e ApprovalEnvelope) Equal(other ApprovalEnvelope) bool
- func (e ApprovalEnvelope) ExpiresAt() (time.Time, bool)
- func (e ApprovalEnvelope) IsActiveAt(now time.Time) bool
- func (e ApprovalEnvelope) IsExpiredAt(now time.Time) bool
- func (e ApprovalEnvelope) IsValid() bool
- func (e ApprovalEnvelope) IsZero() bool
- func (e ApprovalEnvelope) IssuedAt() time.Time
- func (e ApprovalEnvelope) MarshalJSONTo(enc *jsontext.Encoder) error
- func (e ApprovalEnvelope) MatchesBinding(binding OperationBinding) bool
- func (e ApprovalEnvelope) MatchesDigest(expected Digest) (bool, error)
- func (e ApprovalEnvelope) Nonce() ([secutil.ApprovalNonceBytes]byte, bool)
- func (e ApprovalEnvelope) NonceHex() string
- func (e ApprovalEnvelope) OperationID() OperationID
- func (e ApprovalEnvelope) PolicyDigest() algebraic.Option[Digest]
- func (e ApprovalEnvelope) Risk() RiskLevel
- func (e ApprovalEnvelope) ScopeSummary() string
- func (e ApprovalEnvelope) TTL() algebraic.Duration
- func (e *ApprovalEnvelope) UnmarshalJSONFrom(dec *jsontext.Decoder) error
- func (e ApprovalEnvelope) WriteCanonical(w io.Writer) error
- type ApprovalEnvelopeSpec
- type BlockedCommandMatcher
- func (m BlockedCommandMatcher) Digest() (Digest, error)
- func (m BlockedCommandMatcher) Equal(other BlockedCommandMatcher) bool
- func (m BlockedCommandMatcher) IsValid() bool
- func (m BlockedCommandMatcher) IsZero() bool
- func (m BlockedCommandMatcher) Join(other BlockedCommandMatcher) BlockedCommandMatcher
- func (m BlockedCommandMatcher) Len() int
- func (m BlockedCommandMatcher) MarshalJSONTo(enc *jsontext.Encoder) error
- func (m BlockedCommandMatcher) Matches(text string) bool
- func (m BlockedCommandMatcher) Patterns() []string
- func (m *BlockedCommandMatcher) UnmarshalJSONFrom(dec *jsontext.Decoder) error
- func (m BlockedCommandMatcher) WriteCanonical(w io.Writer) error
- type CapExecute
- type CapFileMut
- type CapFileRead
- type CapInspect
- type CapMutate
- type CapTransfer
- type CapTunnel
- type Capability
- type CapabilityKind
- func (k CapabilityKind) AppendText(b []byte) ([]byte, error)
- func (k CapabilityKind) Compare(other CapabilityKind) int
- func (k CapabilityKind) IsValid() bool
- func (k CapabilityKind) IsZero() bool
- func (k CapabilityKind) MarshalText() ([]byte, error)
- func (k CapabilityKind) String() string
- func (k *CapabilityKind) UnmarshalText(text []byte) error
- type DecisionAllow
- type DecisionDeny
- type DecisionKind
- func (k DecisionKind) AppendText(b []byte) ([]byte, error)
- func (k DecisionKind) CompareStrictness(other DecisionKind) int
- func (k DecisionKind) IsValid() bool
- func (k DecisionKind) IsZero() bool
- func (k DecisionKind) Join(other DecisionKind) DecisionKind
- func (k DecisionKind) MarshalText() ([]byte, error)
- func (k DecisionKind) StrictnessRank() uint8
- func (k DecisionKind) String() string
- func (k DecisionKind) ToVerdict() Verdict
- func (k *DecisionKind) UnmarshalText(text []byte) error
- type DecisionNeedApproval
- func (d *DecisionNeedApproval) IsValid() bool
- func (d *DecisionNeedApproval) Kind() DecisionKind
- func (d DecisionNeedApproval) MarshalJSONTo(enc *jsontext.Encoder) error
- func (d *DecisionNeedApproval) Reason() string
- func (d *DecisionNeedApproval) Risk() RiskLevel
- func (*DecisionNeedApproval) ToVerdict() Verdict
- type Digest
- func (d Digest) AppendText(b []byte) ([]byte, error)
- func (d Digest) Bytes() ([sha256.Size]byte, bool)
- func (d Digest) Compare(other Digest) int
- func (d Digest) Equal(other Digest) bool
- func (d Digest) Hex() string
- func (d Digest) IsValid() bool
- func (d Digest) IsZero() bool
- func (d Digest) MarshalText() ([]byte, error)
- func (d Digest) String() string
- func (d *Digest) UnmarshalText(text []byte) error
- type EscalationReason
- type GuardrailDecision
- func EvaluateThreshold(opRisk, threshold RiskLevel) GuardrailDecision
- func FoldDecisions(decisions ...GuardrailDecision) GuardrailDecision
- func JoinDecisions(a, b GuardrailDecision) GuardrailDecision
- func NormalizeDecision(d GuardrailDecision) GuardrailDecision
- func UnmarshalDecisionFrom(dec *jsontext.Decoder) (GuardrailDecision, error)
- type NodeOverrideRule
- func (r NodeOverrideRule) ApprovalThreshold() RiskLevel
- func (r NodeOverrideRule) CombineSamePattern(other NodeOverrideRule) NodeOverrideRule
- func (r NodeOverrideRule) DecisionFloor() DecisionKind
- func (r NodeOverrideRule) Equal(other NodeOverrideRule) bool
- func (r NodeOverrideRule) IsValid() bool
- func (r NodeOverrideRule) IsZero() bool
- func (r NodeOverrideRule) MarshalJSONTo(enc *jsontext.Encoder) error
- func (r NodeOverrideRule) Pattern() string
- func (r *NodeOverrideRule) UnmarshalJSONFrom(dec *jsontext.Decoder) error
- type NodeOverrides
- func (o NodeOverrides) Equal(other NodeOverrides) bool
- func (o NodeOverrides) EvaluateBatch(baseThreshold, opRisk RiskLevel, nodeIDs ...string) GuardrailDecision
- func (o NodeOverrides) EvaluateNode(baseThreshold, opRisk RiskLevel, nodeID string) GuardrailDecision
- func (o NodeOverrides) IsValid() bool
- func (o NodeOverrides) IsZero() bool
- func (o NodeOverrides) Join(other NodeOverrides) NodeOverrides
- func (o NodeOverrides) Len() int
- func (o NodeOverrides) MarshalJSONTo(enc *jsontext.Encoder) error
- func (o NodeOverrides) ResolveBatchThreshold(baseThreshold RiskLevel, nodeIDs ...string) (RiskLevel, error)
- func (o NodeOverrides) ResolveThreshold(baseThreshold RiskLevel, nodeID string) (RiskLevel, error)
- func (o NodeOverrides) Rules() []NodeOverrideRule
- func (o *NodeOverrides) UnmarshalJSONFrom(dec *jsontext.Decoder) error
- type OperationBinding
- func (b OperationBinding) Action() string
- func (b OperationBinding) CanonicalPaths() []string
- func (b OperationBinding) Capability() CapabilityKind
- func (b OperationBinding) CommandDigest() algebraic.Option[Digest]
- func (b OperationBinding) Digest() (Digest, error)
- func (b OperationBinding) Endpoint() algebraic.Option[netaddr.Endpoint]
- func (b OperationBinding) Equal(other OperationBinding) bool
- func (b OperationBinding) IsValid() bool
- func (b OperationBinding) IsZero() bool
- func (b OperationBinding) MarshalJSONTo(enc *jsontext.Encoder) error
- func (b OperationBinding) NodeID() string
- func (b OperationBinding) NodeIDs() []string
- func (b OperationBinding) Param(key string) (string, bool)
- func (b OperationBinding) Parameters() map[string]string
- func (b OperationBinding) PlanDigest() algebraic.Option[Digest]
- func (b OperationBinding) RecursivePaths() []string
- func (b OperationBinding) Tool() string
- func (b *OperationBinding) UnmarshalJSONFrom(dec *jsontext.Decoder) error
- func (b OperationBinding) WriteCanonical(w io.Writer) error
- type OperationBindingSpec
- type OperationID
- func (id OperationID) AppendText(b []byte) ([]byte, error)
- func (id OperationID) Compare(other OperationID) int
- func (id OperationID) Equal(other OperationID) bool
- func (id OperationID) IsValid() bool
- func (id OperationID) IsZero() bool
- func (id OperationID) MarshalText() ([]byte, error)
- func (id OperationID) String() string
- func (id *OperationID) UnmarshalText(text []byte) error
- type RiskLevel
- func (r RiskLevel) AppendText(b []byte) ([]byte, error)
- func (r RiskLevel) CompareSeverity(other RiskLevel) int
- func (r RiskLevel) CompareThresholdStrictness(other RiskLevel) int
- func (r RiskLevel) IsValid() bool
- func (r RiskLevel) IsZero() bool
- func (r RiskLevel) Join(other RiskLevel) RiskLevel
- func (r RiskLevel) MarshalText() ([]byte, error)
- func (r RiskLevel) Normalize() RiskLevel
- func (r RiskLevel) SeverityRank() uint8
- func (r RiskLevel) StrictestThreshold(other RiskLevel) RiskLevel
- func (r RiskLevel) String() string
- func (r RiskLevel) ThresholdStrictnessRank() uint8
- func (r *RiskLevel) UnmarshalText(text []byte) error
- type ScopeEscalationResult
- func (r ScopeEscalationResult) AddedProtectedPaths() []string
- func (r ScopeEscalationResult) Equal(other ScopeEscalationResult) bool
- func (r ScopeEscalationResult) Escalated() bool
- func (r ScopeEscalationResult) HasReason(target EscalationReason) bool
- func (r ScopeEscalationResult) IsValid() bool
- func (r ScopeEscalationResult) IsZero() bool
- func (r ScopeEscalationResult) MarshalJSONTo(enc *jsontext.Encoder) error
- func (r ScopeEscalationResult) Reasons() []EscalationReason
- func (r *ScopeEscalationResult) UnmarshalJSONFrom(dec *jsontext.Decoder) error
- type ScopeSnapshot
- func (s ScopeSnapshot) Capability() CapabilityKind
- func (s ScopeSnapshot) Decision() GuardrailDecision
- func (s ScopeSnapshot) Endpoint() algebraic.Option[netaddr.Endpoint]
- func (s ScopeSnapshot) Equal(other ScopeSnapshot) bool
- func (s ScopeSnapshot) HasProtectedPath() bool
- func (s ScopeSnapshot) IsValid() bool
- func (s ScopeSnapshot) IsZero() bool
- func (s ScopeSnapshot) Join(other ScopeSnapshot) ScopeSnapshot
- func (s ScopeSnapshot) MarshalJSONTo(enc *jsontext.Encoder) error
- func (s ScopeSnapshot) Paths() []ScopedPath
- func (s ScopeSnapshot) Risk() RiskLevel
- func (s ScopeSnapshot) TargetNode() string
- func (s *ScopeSnapshot) UnmarshalJSONFrom(dec *jsontext.Decoder) error
- func (s ScopeSnapshot) Verdict() Verdict
- type ScopeSnapshotSpec
- type ScopedPath
- func (p ScopedPath) Equal(other ScopedPath) bool
- func (p ScopedPath) IsProtected() bool
- func (p ScopedPath) IsRecursive() bool
- func (p ScopedPath) IsValid() bool
- func (p ScopedPath) IsZero() bool
- func (p ScopedPath) JoinSamePath(other ScopedPath) ScopedPath
- func (p ScopedPath) MarshalJSONTo(enc *jsontext.Encoder) error
- func (p ScopedPath) Path() string
- func (p ScopedPath) ProtectedZones() []string
- func (p *ScopedPath) UnmarshalJSONFrom(dec *jsontext.Decoder) error
- type TraceID
- func (id TraceID) AppendText(b []byte) ([]byte, error)
- func (id TraceID) Compare(other TraceID) int
- func (id TraceID) Equal(other TraceID) bool
- func (id TraceID) IsValid() bool
- func (id TraceID) IsZero() bool
- func (id TraceID) MarshalText() ([]byte, error)
- func (id TraceID) String() string
- func (id *TraceID) UnmarshalText(text []byte) error
- type Verdict
- func (v Verdict) Allowed() bool
- func (v Verdict) AppendText(b []byte) ([]byte, error)
- func (v Verdict) Compare(other Verdict) int
- func (v Verdict) Denied() bool
- func (v Verdict) IsValid() bool
- func (v Verdict) IsZero() bool
- func (v Verdict) MarshalText() ([]byte, error)
- func (v Verdict) Meet(other Verdict) Verdict
- func (v Verdict) Normalize() Verdict
- func (v Verdict) String() string
- func (v *Verdict) UnmarshalText(text []byte) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidVerdict = domi18n.Sentinel(domi18n.KeySecurityInvalidVerdict) ErrInvalidRiskLevel = domi18n.Sentinel(domi18n.KeySecurityInvalidRiskLevel) ErrInvalidDecision = domi18n.Sentinel(domi18n.KeySecurityInvalidDecision) ErrInvalidCapability = domi18n.Sentinel(domi18n.KeySecurityInvalidCapability) ErrInvalidGlob = domi18n.Sentinel(domi18n.KeySecurityInvalidGlob) ErrInvalidNodeOverride = domi18n.Sentinel(domi18n.KeySecurityInvalidNodeOverride) ErrInvalidTraceID = domi18n.Sentinel(domi18n.KeySecurityInvalidTraceID) ErrInvalidOperationID = domi18n.Sentinel(domi18n.KeySecurityInvalidOperationID) ErrNilEntropy = domi18n.Sentinel(domi18n.KeySecurityNilEntropy) ErrInvalidDigest = domi18n.Sentinel(domi18n.KeySecurityInvalidDigest) ErrInvalidOperationBinding = domi18n.Sentinel(domi18n.KeySecurityInvalidBinding) ErrInvalidApprovalEnvelope = domi18n.Sentinel(domi18n.KeySecurityInvalidEnvelope) ErrInvalidScopeSnapshot = domi18n.Sentinel(domi18n.KeySecurityInvalidScope) ErrNilWriter = domi18n.Sentinel(domi18n.KeySecurityNilWriter) ErrNilReceiver = domi18n.Sentinel(domi18n.KeySecurityNilReceiver) )
本包导出的规范化哨兵错误集合,均由失败关闭路径显式返回以便调用方使用 errors.Is 判定。
Functions ¶
func CanonicalScopeEscalated ¶
func CanonicalScopeEscalated(lexical, canonical ScopeSnapshot) bool
CanonicalScopeEscalated 纯数学判定词法预检快照 lexical 与规范化解析快照 canonical 之间 是否发生安全作用域升级、受保护分区重定向(含同风险同决策的 Protected-A -> Protected-B)或目标漂移(INV-E5)。 遵循严格失败关闭原则:任一快照无效或为零值时恒返回 true。
func EqualDecision ¶
func EqualDecision(a, b GuardrailDecision) bool
EqualDecision 按值严格比较两个 GuardrailDecision 是否均有效且完全一致(nil 或无效零值恒返回 false)。
func MarshalDecisionTo ¶
func MarshalDecisionTo(enc *jsontext.Encoder, d GuardrailDecision) error
MarshalDecisionTo 将任意有效 GuardrailDecision 编码至 Go 1.27 JSON/v2 流; 对 nil、typed-nil 或未初始化零值变体一律失败关闭返回 ErrInvalidDecision。
func MatchGlob ¶
MatchGlob 使用操作系统无关的 O(|P|*|S|) UTF-8 码点引擎执行通配符匹配(INV-E3): '*' 跨 '/'、'\' 与换行匹配任意序列,'?' 匹配单码点,'[...]' 支持取反与范围,'\' 恒为字面字符。
func NewApprovalNonceFrom ¶
NewApprovalNonceFrom 从显式注入熵源读取 16 字节非全零审批防重放 Nonce(零隐式 crypto/rand)。
func SanitizePromptText ¶
SanitizePromptText 将 C0/DEL/C1 控制字符、Unicode 行/段分隔符(U+2028/U+2029)、 Unicode Cf 格式字符(含 Bidi 覆写/隔离与零宽字符)转义为可打印 ASCII 序列, 并将非法 UTF-8 原始字节显式转义为 \xHH,抵御审批提示伪造与 Trojan-Source 视觉欺骗。
func ValidateGlob ¶
ValidateGlob 校验操作系统无关的护栏 UTF-8 通配符模式语法, 拒绝空串、非法 UTF-8、控制字符、Unicode Cf(含 Bidi 双向控制与零宽字符)以及畸形字符类。
Types ¶
type ApprovalEnvelope ¶
type ApprovalEnvelope struct {
// contains filtered or unexported fields
}
ApprovalEnvelope 是密码学锚定操作标识、规范绑定、风险等级、护栏决策、作用域摘要、签发时刻、 有效期与防重放 Nonce 的不可变审批挑战信封(INV-E5 / RFC §3.5–3.6); 零值恒无效,且经 //xops:canonicalhash 由 xopsvet/digestcover 校验 WriteCanonical 全字段覆盖(零 reflect)。
func NewApprovalEnvelope ¶
func NewApprovalEnvelope(spec ApprovalEnvelopeSpec) (ApprovalEnvelope, error)
NewApprovalEnvelope 校验全部安全字段、RFC 3339 时间窗口与决策风险一致性并构造不可变 ApprovalEnvelope。
func (ApprovalEnvelope) Binding ¶
func (e ApprovalEnvelope) Binding() OperationBinding
Binding 返回信封绑定的不可变操作绑定快照。
func (ApprovalEnvelope) CanApprove ¶
func (e ApprovalEnvelope) CanApprove() bool
CanApprove 报告该信封是否代表可进入用户确认流程的待审批挑战(仅 DecisionNeedApproval 返回 true)。
func (ApprovalEnvelope) CanonicalJSON ¶
func (e ApprovalEnvelope) CanonicalJSON() ([]byte, error)
CanonicalJSON 使用 Go 1.27 encoding/json/v2 的 Deterministic(true) 编码确定性 JSON 字节流。
func (ApprovalEnvelope) Decision ¶
func (e ApprovalEnvelope) Decision() GuardrailDecision
Decision 返回信封锁定的护栏决策副本;无效零值失败关闭返回 *DecisionDeny。
func (ApprovalEnvelope) Digest ¶
func (e ApprovalEnvelope) Digest() (Digest, error)
Digest 计算并返回 ApprovalEnvelope 的确定性 SHA-256 规范摘要。
func (ApprovalEnvelope) Equal ¶
func (e ApprovalEnvelope) Equal(other ApprovalEnvelope) bool
Equal 严格比对两个 ApprovalEnvelope 是否均有效且全部字段一致(Nonce 采用常量时间比对)。
func (ApprovalEnvelope) ExpiresAt ¶
func (e ApprovalEnvelope) ExpiresAt() (time.Time, bool)
ExpiresAt 返回信封到期 UTC 时刻(issuedAt + ttl)与有效性标志。
func (ApprovalEnvelope) IsActiveAt ¶
func (e ApprovalEnvelope) IsActiveAt(now time.Time) bool
IsActiveAt 报告信封在显式观测时刻 now 是否处于有效窗口 [issuedAt, issuedAt+ttl) 内。
func (ApprovalEnvelope) IsExpiredAt ¶
func (e ApprovalEnvelope) IsExpiredAt(now time.Time) bool
IsExpiredAt 在显式观测时刻 now 判断信封是否已过期(零 time.Now);无效或零时刻失败关闭返回 true。
func (ApprovalEnvelope) IsValid ¶
func (e ApprovalEnvelope) IsValid() bool
IsValid 报告审批信封是否经构造器完整校验且所有不变量成立。
func (ApprovalEnvelope) IssuedAt ¶
func (e ApprovalEnvelope) IssuedAt() time.Time
IssuedAt 返回规范化的 UTC 签发时刻。
func (ApprovalEnvelope) MarshalJSONTo ¶
func (e ApprovalEnvelope) MarshalJSONTo(enc *jsontext.Encoder) error
MarshalJSONTo 实现 encoding/json/v2.MarshalerTo(值接收者);对零值信封失败关闭。
func (ApprovalEnvelope) MatchesBinding ¶
func (e ApprovalEnvelope) MatchesBinding(binding OperationBinding) bool
MatchesBinding 校验给定 OperationBinding 是否与信封锁定绑定完全一致(无效零值恒返回 false)。
func (ApprovalEnvelope) MatchesDigest ¶
func (e ApprovalEnvelope) MatchesDigest(expected Digest) (bool, error)
MatchesDigest 计算本信封的规范 SHA-256 摘要并以常量时间与 expected 比对。
func (ApprovalEnvelope) Nonce ¶
func (e ApprovalEnvelope) Nonce() ([secutil.ApprovalNonceBytes]byte, bool)
Nonce 返回 16 字节防重放 Nonce 副本与有效性标志。
func (ApprovalEnvelope) NonceHex ¶
func (e ApprovalEnvelope) NonceHex() string
NonceHex 返回 32 位小写十六进制防重放 Nonce;无效零值返回空串。
func (ApprovalEnvelope) OperationID ¶
func (e ApprovalEnvelope) OperationID() OperationID
OperationID 返回信封绑定的操作唯一标识。
func (ApprovalEnvelope) PolicyDigest ¶
func (e ApprovalEnvelope) PolicyDigest() algebraic.Option[Digest]
PolicyDigest 返回可选活跃策略快照摘要。
func (ApprovalEnvelope) Risk ¶
func (e ApprovalEnvelope) Risk() RiskLevel
Risk 返回信封锁定的操作风险等级;无效零值返回 RiskUnknown。
func (ApprovalEnvelope) ScopeSummary ¶
func (e ApprovalEnvelope) ScopeSummary() string
ScopeSummary 返回已脱敏的审批范围摘要文本。
func (ApprovalEnvelope) TTL ¶
func (e ApprovalEnvelope) TTL() algebraic.Duration
TTL 返回信封有效期(algebraic.Duration)。
func (*ApprovalEnvelope) UnmarshalJSONFrom ¶
func (e *ApprovalEnvelope) UnmarshalJSONFrom(dec *jsontext.Decoder) error
UnmarshalJSONFrom 实现 encoding/json/v2.UnmarshalerFrom;对 JSON null、缺失必需字段或篡改值失败关闭并重置零值。
func (ApprovalEnvelope) WriteCanonical ¶
func (e ApprovalEnvelope) WriteCanonical(w io.Writer) error
WriteCanonical 以零反射、长度前缀与域分离方式将 ApprovalEnvelope 全部字段写入 w(受 digestcover 校验)。
type ApprovalEnvelopeSpec ¶
type ApprovalEnvelopeSpec struct {
OperationID OperationID
Binding OperationBinding
Risk RiskLevel
Decision GuardrailDecision
ScopeSummary string
IssuedAt time.Time
TTL algebraic.Duration
Nonce [secutil.ApprovalNonceBytes]byte
PolicyDigest algebraic.Option[Digest]
}
ApprovalEnvelopeSpec 是构造不可变 ApprovalEnvelope 的显式入参规格; IssuedAt 与 IssuedAt+TTL 均须落在 RFC 3339 合法年份 [1, 9999] 且无溢出,TTL 统一使用 algebraic.Duration, Nonce 须非全零 16 字节,且当 Decision 为 *DecisionNeedApproval 时 spec.Risk 必须与审批决策风险严格一致。
type BlockedCommandMatcher ¶ added in v1.3.0
type BlockedCommandMatcher struct {
// contains filtered or unexported fields
}
BlockedCommandMatcher 表示不可变、按字典序规范排序并去重的命令黑名单 UTF-8 Glob 匹配器(ADR-018)。
核心不变量:
- 严格复用 security.ValidateGlob / security.MatchGlob 的 OS 无关 UTF-8 码点引擎(绝不使用 RE2), 保留 "*.sh"、"curl*" 等旧版黑名单模式精确语义;
- 零值恒无效并严格失败关闭(IsValid() == false 且 Matches 恒返回 true 视作阻断), 空黑名单须经 EmptyBlockedCommandMatcher 显式构造;
- 经 //xops:canonicalhash 由 xopsvet/digestcover 校验 WriteCanonical 全字段覆盖(零 reflect), 供 gate.computePolicyDigest 密码学锚定以防策略收紧后旧审批信封重放。
func EmptyBlockedCommandMatcher ¶ added in v1.3.0
func EmptyBlockedCommandMatcher() BlockedCommandMatcher
EmptyBlockedCommandMatcher 返回显式为空且有效的命令黑名单匹配器(Join 运算单位元)。
func NewBlockedCommandMatcher ¶ added in v1.3.0
func NewBlockedCommandMatcher(patterns []string) (BlockedCommandMatcher, error)
NewBlockedCommandMatcher 校验全部 UTF-8 Glob 模式并按字典序规范排序去重,构造不可变 BlockedCommandMatcher。 任意非法模式(空串、非法 UTF-8、控制/Bidi 字符或未闭合字符类)均在构造期严格失败关闭返回包装 ErrInvalidGlob 的错误。
func (BlockedCommandMatcher) Digest ¶ added in v1.3.0
func (m BlockedCommandMatcher) Digest() (Digest, error)
Digest 计算并返回 BlockedCommandMatcher 的确定性 SHA-256 规范摘要。
func (BlockedCommandMatcher) Equal ¶ added in v1.3.0
func (m BlockedCommandMatcher) Equal(other BlockedCommandMatcher) bool
Equal 比较两个 BlockedCommandMatcher 是否均有效且规范模式集完全一致(零值永不相等)。
func (BlockedCommandMatcher) IsValid ¶ added in v1.3.0
func (m BlockedCommandMatcher) IsValid() bool
IsValid 报告匹配器是否已通过构造器有效初始化。
func (BlockedCommandMatcher) IsZero ¶ added in v1.3.0
func (m BlockedCommandMatcher) IsZero() bool
IsZero 报告匹配器是否为无效零值。
func (BlockedCommandMatcher) Join ¶ added in v1.3.0
func (m BlockedCommandMatcher) Join(other BlockedCommandMatcher) BlockedCommandMatcher
Join 按集合并半格单调收紧合并两个黑名单匹配器;任一侧无效返回零值,满足交换/结合/幂等律。
func (BlockedCommandMatcher) Len ¶ added in v1.3.0
func (m BlockedCommandMatcher) Len() int
Len 返回已规范去重后的黑名单模式条数;无效零值返回 0。
func (BlockedCommandMatcher) MarshalJSONTo ¶ added in v1.3.0
func (m BlockedCommandMatcher) MarshalJSONTo(enc *jsontext.Encoder) error
MarshalJSONTo 实现 encoding/json/v2.MarshalerTo(值接收者),以规范排序数组编码;零值失败关闭。
func (BlockedCommandMatcher) Matches ¶ added in v1.3.0
func (m BlockedCommandMatcher) Matches(text string) bool
Matches 判定命令文本 text 是否命中任一黑名单 UTF-8 Glob 模式。 失败关闭语义:未初始化零值恒返回 true(视作阻断);当存在活跃黑名单模式且 text 含非法 UTF-8 时同样返回 true 防止编码绕过。
func (BlockedCommandMatcher) Patterns ¶ added in v1.3.0
func (m BlockedCommandMatcher) Patterns() []string
Patterns 返回按字典序排列的黑名单模式防御性拷贝;无效零值或空匹配器返回 nil。
func (*BlockedCommandMatcher) UnmarshalJSONFrom ¶ added in v1.3.0
func (m *BlockedCommandMatcher) UnmarshalJSONFrom(dec *jsontext.Decoder) error
UnmarshalJSONFrom 实现 encoding/json/v2.UnmarshalerFrom;对 JSON null 或非法模式失败关闭并重置零值。
func (BlockedCommandMatcher) WriteCanonical ¶ added in v1.3.0
func (m BlockedCommandMatcher) WriteCanonical(w io.Writer) error
WriteCanonical 以零反射、长度前缀与域分离方式将 BlockedCommandMatcher 全部字段写入 w(受 digestcover 校验)。
type CapExecute ¶
type CapExecute struct {
// contains filtered or unexported fields
}
CapExecute 表示远端命令执行或交互式 Shell/PTY 会话能力。
type CapFileMut ¶
type CapFileMut struct {
// contains filtered or unexported fields
}
CapFileMut 表示远端文件写入、补丁修改或目录结构变更能力。
type CapFileRead ¶
type CapFileRead struct {
// contains filtered or unexported fields
}
CapFileRead 表示远端文件读取或元信息查询能力。
type CapInspect ¶
type CapInspect struct {
// contains filtered or unexported fields
}
CapInspect 表示只读探测、节点/会话列举或状态查询能力。
type CapMutate ¶
type CapMutate struct {
// contains filtered or unexported fields
}
CapMutate 表示本机配置、凭据 Vault 或已知主机信任库变更能力。
type CapTransfer ¶
type CapTransfer struct {
// contains filtered or unexported fields
}
CapTransfer 表示跨主机文件传输(SCP、SFTP、MCP HTTP 分片流)能力。
type CapTunnel ¶
type CapTunnel struct {
// contains filtered or unexported fields
}
CapTunnel 表示 SSH 端口转发(-L/-R/-D/StreamLocal/TUN)能力。
type Capability ¶
type Capability interface {
// contains filtered or unexported methods
}
Capability 是 XOps v2 编译期幻影能力封闭类型集(RFC §3.1),仅用于 core/internal/gate.Authorized[C] 等泛型能力证明的类型约束,100% 纯数学且零同步原语。
type CapabilityKind ¶
type CapabilityKind uint8
CapabilityKind 是幻影类型集 Capability 对应的可序列化能力枚举;零值恒为 CapabilityInvalid。
const ( CapabilityInvalid CapabilityKind = iota // 零值无效能力(失败关闭默认值) CapabilityInspect // 对应幻影类型 CapInspect CapabilityExecute // 对应幻影类型 CapExecute CapabilityFileRead // 对应幻影类型 CapFileRead CapabilityFileMut // 对应幻影类型 CapFileMut CapabilityTransfer // 对应幻影类型 CapTransfer CapabilityTunnel // 对应幻影类型 CapTunnel CapabilityMutate // 对应幻影类型 CapMutate )
func CapabilityKindOf ¶
func CapabilityKindOf[C Capability]() CapabilityKind
CapabilityKindOf 在编译期类型参数 C 与运行期 CapabilityKind 间建立穷尽映射;接口零值 nil 返回 CapabilityInvalid。
func ParseCapabilityKind ¶
func ParseCapabilityKind(raw string) (CapabilityKind, error)
ParseCapabilityKind 严格解析规范小写能力类别文本。
func (CapabilityKind) AppendText ¶
func (k CapabilityKind) AppendText(b []byte) ([]byte, error)
AppendText 实现 encoding.TextAppender(值接收者);对无效值严格失败关闭。
func (CapabilityKind) Compare ¶
func (k CapabilityKind) Compare(other CapabilityKind) int
Compare 定义 CapabilityKind 上的确定性全序(无效值排在最前)。
func (CapabilityKind) IsValid ¶
func (k CapabilityKind) IsValid() bool
IsValid 报告 k 是否为 7 种合法能力类别之一。
func (CapabilityKind) MarshalText ¶
func (k CapabilityKind) MarshalText() ([]byte, error)
MarshalText 实现 encoding.TextMarshaler(值接收者)。
func (CapabilityKind) String ¶
func (k CapabilityKind) String() string
String 返回能力类别的规范小写文本;无效值返回 "invalid"。
func (*CapabilityKind) UnmarshalText ¶
func (k *CapabilityKind) UnmarshalText(text []byte) error
UnmarshalText 实现 encoding.TextUnmarshaler;失败时重置为 CapabilityInvalid 并失败关闭。
type DecisionAllow ¶
type DecisionAllow struct {
// contains filtered or unexported fields
}
DecisionAllow 表示策略在当前上下文下显式允许执行; 内置正向门控 valid bool,未初始化零值与 typed-nil 均失败关闭为拒绝。
func NewDecisionAllow ¶
func NewDecisionAllow(reason string) *DecisionAllow
NewDecisionAllow 构造经显式策略核准的不可变放行决策。
func (*DecisionAllow) IsValid ¶
func (d *DecisionAllow) IsValid() bool
IsValid 报告放行决策是否非 nil 且经合法构造器签发。
func (*DecisionAllow) Kind ¶
func (d *DecisionAllow) Kind() DecisionKind
Kind 有效时返回 DecisionKindAllow;无效时失败关闭返回 DecisionKindDeny。
func (DecisionAllow) MarshalJSONTo ¶
func (d DecisionAllow) MarshalJSONTo(enc *jsontext.Encoder) error
MarshalJSONTo 实现 encoding/json/v2.MarshalerTo(值接收者);对零值/无效实例失败关闭。
func (*DecisionAllow) ToVerdict ¶
func (d *DecisionAllow) ToVerdict() Verdict
ToVerdict 有效时返回 VerdictAllow;无效时失败关闭返回 VerdictDeny。
type DecisionDeny ¶
type DecisionDeny struct {
// contains filtered or unexported fields
}
DecisionDeny 表示无条件拒绝执行该操作(限制支配格吸收顶元;零值语义仍为拒绝)。
func NewDecisionDeny ¶
func NewDecisionDeny(reason string) *DecisionDeny
NewDecisionDeny 构造携带脱敏原因文本的不可变拒绝决策。
func NewDecisionDenyWithCode ¶
func NewDecisionDenyWithCode(code, reason string) *DecisionDeny
NewDecisionDenyWithCode 构造携带机器可读拒绝码与原因文本的不可变拒绝决策。
func (DecisionDeny) MarshalJSONTo ¶
func (d DecisionDeny) MarshalJSONTo(enc *jsontext.Encoder) error
MarshalJSONTo 实现 encoding/json/v2.MarshalerTo(值接收者),输出规范拒绝变体对象。
func (*DecisionDeny) ToVerdict ¶
func (*DecisionDeny) ToVerdict() Verdict
ToVerdict 恒返回 VerdictDeny。
type DecisionKind ¶
type DecisionKind uint8
DecisionKind 表示 GuardrailDecision 的三态判别枚举,零值恒为 DecisionKindDeny(限制支配吸收元)。
const ( DecisionKindDeny DecisionKind = DecisionKind(secutil.DecisionDenyCode) // 零值失败关闭判定类别(最严,吸收 NeedApproval 与 Allow) DecisionKindNeedApproval DecisionKind = DecisionKind(secutil.DecisionNeedApprovalCode) // 需用户显式审批挑战(次严,吸收 Allow) DecisionKindAllow DecisionKind = DecisionKind(secutil.DecisionAllowCode) // 策略显式允许执行(最宽,限制支配并半格单位元) )
func ParseDecisionKind ¶
func ParseDecisionKind(raw string) (DecisionKind, error)
ParseDecisionKind 严格解析规范小写决策类别("deny"、"need_approval"、"allow")。
func (DecisionKind) AppendText ¶
func (k DecisionKind) AppendText(b []byte) ([]byte, error)
AppendText 实现 encoding.TextAppender(值接收者);对非法越界值失败关闭。
func (DecisionKind) CompareStrictness ¶
func (k DecisionKind) CompareStrictness(other DecisionKind) int
CompareStrictness 按限制严苛度顺序比较两个 DecisionKind。
func (DecisionKind) IsValid ¶
func (k DecisionKind) IsValid() bool
IsValid 报告 k 是否为合法的 DecisionKind。
func (DecisionKind) IsZero ¶
func (k DecisionKind) IsZero() bool
IsZero 报告 k 是否处于零值拒绝态(DecisionKindDeny)。
func (DecisionKind) Join ¶
func (k DecisionKind) Join(other DecisionKind) DecisionKind
Join 按限制支配规则合并两个 DecisionKind(Deny 吸收 NeedApproval 吸收 Allow;非法值折叠为 Deny)。
func (DecisionKind) MarshalText ¶
func (k DecisionKind) MarshalText() ([]byte, error)
MarshalText 实现 encoding.TextMarshaler(值接收者)。
func (DecisionKind) StrictnessRank ¶
func (k DecisionKind) StrictnessRank() uint8
StrictnessRank 返回决策限制严苛度全序秩(Allow=1 < NeedApproval=2 < Deny/非法=3)。
func (DecisionKind) String ¶
func (k DecisionKind) String() string
String 返回规范小写文本;非法值返回 "deny(invalid)"。
func (DecisionKind) ToVerdict ¶
func (k DecisionKind) ToVerdict() Verdict
ToVerdict 将 DecisionKind 投影到二值 Verdict:仅显式 DecisionKindAllow 映射为 VerdictAllow。
func (*DecisionKind) UnmarshalText ¶
func (k *DecisionKind) UnmarshalText(text []byte) error
UnmarshalText 实现 encoding.TextUnmarshaler;失败时重置为 DecisionKindDeny 并失败关闭。
type DecisionNeedApproval ¶
type DecisionNeedApproval struct {
// contains filtered or unexported fields
}
DecisionNeedApproval 表示操作必须经用户显式审批挑战方可放行; 内置正向门控 valid bool,未初始化零值与 typed-nil 均失败关闭为 DecisionDeny。
func NewDecisionNeedApproval ¶
func NewDecisionNeedApproval(risk RiskLevel, reason string) (*DecisionNeedApproval, error)
NewDecisionNeedApproval 校验风险等级并构造不可变需审批决策。
func (*DecisionNeedApproval) IsValid ¶
func (d *DecisionNeedApproval) IsValid() bool
IsValid 报告审批决策是否有效且携带合法风险等级。
func (*DecisionNeedApproval) Kind ¶
func (d *DecisionNeedApproval) Kind() DecisionKind
Kind 有效时返回 DecisionKindNeedApproval,无效时失败关闭返回 DecisionKindDeny。
func (DecisionNeedApproval) MarshalJSONTo ¶
func (d DecisionNeedApproval) MarshalJSONTo(enc *jsontext.Encoder) error
MarshalJSONTo 实现 encoding/json/v2.MarshalerTo(值接收者);对零值/无效实例失败关闭。
func (*DecisionNeedApproval) Reason ¶
func (d *DecisionNeedApproval) Reason() string
Reason 返回脱敏审批提示原因;无效时返回空串。
func (*DecisionNeedApproval) Risk ¶
func (d *DecisionNeedApproval) Risk() RiskLevel
Risk 返回触发审批的风险等级;无效时返回 RiskUnknown。
func (*DecisionNeedApproval) ToVerdict ¶
func (*DecisionNeedApproval) ToVerdict() Verdict
ToVerdict 恒返回 VerdictDeny(获批前严禁放行)。
type Digest ¶
type Digest struct {
// contains filtered or unexported fields
}
Digest 表示规范化的不可变 SHA-256 密码学摘要值对象("sha256:<64位小写十六进制>"); 零值恒无效,Equal 使用 crypto/subtle.ConstantTimeCompare 抵御时序侧信道。
func DigestFromSHA256 ¶
DigestFromSHA256 将 32 字节 SHA-256 摘要封装为不可变 Digest。
func ParseDigest ¶
ParseDigest 严格解析规范 SHA-256 摘要文本("sha256:<64位小写十六进制>")。
func (Digest) AppendText ¶
AppendText、MarshalText 与 UnmarshalText 实现 Digest 的值接收者文本编解码(零值与非法输入失败关闭)。
func (Digest) IsValid ¶
IsValid、IsZero、Bytes、Hex、String、Equal 与 Compare 实现 Digest 的失败关闭语义、常量时间比对与确定性全序。
func (Digest) MarshalText ¶
func (*Digest) UnmarshalText ¶
type EscalationReason ¶
type EscalationReason uint8
EscalationReason 表示 CanonicalScopeEscalated 触发重提示或拒绝的结构化升级原因枚举;零值恒为 EscalationUnknown。
const ( EscalationUnknown EscalationReason = EscalationReason(secutil.EscalationUnknownCode) // 未知或未分类升级原因(零值失败关闭) EscalationInvalidInput EscalationReason = EscalationReason(secutil.EscalationInvalidInputCode) // 词法或规范快照之一为零值/无效,失败关闭判定升级 EscalationCapabilityDrift EscalationReason = EscalationReason(secutil.EscalationCapabilityDriftCode) // 操作能力类别发生跨界漂移 EscalationTargetNodeDrift EscalationReason = EscalationReason(secutil.EscalationTargetNodeDriftCode) // 目标节点身份发生漂移 EscalationEndpointDrift EscalationReason = EscalationReason(secutil.EscalationEndpointDriftCode) // 目标 SSH 端点(主机或端口)发生漂移 EscalationVerdictTightened EscalationReason = EscalationReason(secutil.EscalationVerdictTightenedCode) // 二值安全判定由 Allow 收紧为 Deny EscalationRiskIncreased EscalationReason = EscalationReason(secutil.EscalationRiskIncreasedCode) // 操作风险等级升高 EscalationDecisionTightened EscalationReason = EscalationReason(secutil.EscalationDecisionTightenedCode) // 护栏决策收紧 EscalationDecisionRiskIncreased EscalationReason = EscalationReason(secutil.EscalationDecisionRiskIncrCode) // 同为 NeedApproval 决策但内部审批风险等级升高 EscalationProtectedTransition EscalationReason = EscalationReason(secutil.EscalationProtectedTransitionCode) // 路径由非受保护区进入受保护区 EscalationProtectedRedirect EscalationReason = EscalationReason(secutil.EscalationProtectedRedirectCode) // 受保护路径发生软链重定向或新增受保护分区(含 Protected-A -> Protected-B) EscalationRecursiveExpanded EscalationReason = EscalationReason(secutil.EscalationRecursiveExpandedCode) // 同路径由非递归翻转为递归,或未匹配规范递归根数量净增 EscalationPathPresenceDrift EscalationReason = EscalationReason(secutil.EscalationPathPresenceDriftCode) // 路径集合在空集与非空集之间发生结构性漂移 )
func ParseEscalationReason ¶
func ParseEscalationReason(raw string) (EscalationReason, error)
ParseEscalationReason 解析规范小写升级原因标识。
func (EscalationReason) AppendText ¶
func (r EscalationReason) AppendText(b []byte) ([]byte, error)
AppendText 实现 encoding.TextAppender(值接收者);对零值 EscalationUnknown 失败关闭。
func (EscalationReason) IsValid ¶
func (r EscalationReason) IsValid() bool
IsValid 报告 r 是否为明确的已定义升级原因(不含零值 EscalationUnknown)。
func (EscalationReason) MarshalText ¶
func (r EscalationReason) MarshalText() ([]byte, error)
MarshalText 实现 encoding.TextMarshaler(值接收者)。
func (*EscalationReason) UnmarshalText ¶
func (r *EscalationReason) UnmarshalText(text []byte) error
UnmarshalText 实现 encoding.TextUnmarshaler;失败时重置为 EscalationUnknown。
type GuardrailDecision ¶
type GuardrailDecision interface {
Kind() DecisionKind
Reason() string
IsValid() bool
ToVerdict() Verdict
// contains filtered or unexported methods
}
GuardrailDecision 是护栏策略判定的封闭代数和类型(RFC §3.6),仅含三个不可变具体变体: *DecisionDeny、*DecisionNeedApproval 与 *DecisionAllow;由 xopsvet/sumexhaust 强制穷尽与 fail-closed default。
func EvaluateThreshold ¶
func EvaluateThreshold(opRisk, threshold RiskLevel) GuardrailDecision
EvaluateThreshold 按单调安全格规则将 (opRisk, threshold) 映射为 GuardrailDecision: 任一侧无效返回 *DecisionDeny;opRisk >= threshold 返回 *DecisionNeedApproval;否则返回 *DecisionAllow。
func FoldDecisions ¶
func FoldDecisions(decisions ...GuardrailDecision) GuardrailDecision
FoldDecisions 对一组护栏决策执行顺序无关的限制支配并半格折叠;空输入严格失败关闭返回 *DecisionDeny。
func JoinDecisions ¶
func JoinDecisions(a, b GuardrailDecision) GuardrailDecision
JoinDecisions 按限制支配有界格合并两个护栏决策(Deny 吸收 NeedApproval 吸收 Allow)。 同类别 *DecisionNeedApproval 按 (SeverityRank DESC, reason ASC) 全序选取,确保高风险原因绝不被低风险原因遮蔽, 同时完整满足交换律、结合律、幂等律与单调律。
func NormalizeDecision ¶
func NormalizeDecision(d GuardrailDecision) GuardrailDecision
NormalizeDecision 将任意 GuardrailDecision 归一化为有效不可变副本;nil/无效零值失败关闭为 *DecisionDeny。
func UnmarshalDecisionFrom ¶
func UnmarshalDecisionFrom(dec *jsontext.Decoder) (GuardrailDecision, error)
UnmarshalDecisionFrom 从 Go 1.27 JSON/v2 流严格解码多态 GuardrailDecision; 对 JSON null、缺失 kind、非法变体字段组合均严格失败关闭返回 ErrInvalidDecision。
type NodeOverrideRule ¶
type NodeOverrideRule struct {
// contains filtered or unexported fields
}
NodeOverrideRule 表示单条经过语法与阈值校验的不可变节点护栏覆盖规则;零值恒无效并严格失败关闭。
func NewNodeOverrideRule ¶
func NewNodeOverrideRule(pattern string, approvalThreshold RiskLevel) (NodeOverrideRule, error)
NewNodeOverrideRule 校验模式与风险阈值,构造一条仅收紧审批阈值的节点覆盖规则。
func NewNodeOverrideRuleWithFloor ¶
func NewNodeOverrideRuleWithFloor(pattern string, approvalThreshold RiskLevel, decisionFloor DecisionKind) (NodeOverrideRule, error)
NewNodeOverrideRuleWithFloor 校验模式、审批阈值与强制决策下限,构造完整节点覆盖规则。
func (NodeOverrideRule) ApprovalThreshold ¶
func (r NodeOverrideRule) ApprovalThreshold() RiskLevel
ApprovalThreshold 返回规则指定的审批阈值;无效时返回 RiskUnknown。
func (NodeOverrideRule) CombineSamePattern ¶
func (r NodeOverrideRule) CombineSamePattern(other NodeOverrideRule) NodeOverrideRule
CombineSamePattern 对同模式的两条规则执行并半格收紧(最严阈值 + 最严决策下限);非法或异模式返回零值。
func (NodeOverrideRule) DecisionFloor ¶
func (r NodeOverrideRule) DecisionFloor() DecisionKind
DecisionFloor 返回规则指定的最低限制决策类别;无效时失败关闭返回 DecisionKindDeny。
func (NodeOverrideRule) Equal ¶
func (r NodeOverrideRule) Equal(other NodeOverrideRule) bool
Equal 比较两条覆盖规则是否均有效且完全一致(零值永不相等)。
func (NodeOverrideRule) MarshalJSONTo ¶
func (r NodeOverrideRule) MarshalJSONTo(enc *jsontext.Encoder) error
MarshalJSONTo 实现 encoding/json/v2.MarshalerTo(值接收者);对零值规则失败关闭。
func (*NodeOverrideRule) UnmarshalJSONFrom ¶
func (r *NodeOverrideRule) UnmarshalJSONFrom(dec *jsontext.Decoder) error
UnmarshalJSONFrom 实现 encoding/json/v2.UnmarshalerFrom;对 JSON null 或缺失必需字段失败关闭并重置零值。
type NodeOverrides ¶
type NodeOverrides struct {
// contains filtered or unexported fields
}
NodeOverrides 表示按 pattern 排序并自动合并同模式冲突的不可变节点覆盖规则格集合(INV-E3 / RFC §3.6); 彻底消除 Go map 迭代序依赖,零值恒无效并失败关闭,空集合须经 EmptyNodeOverrides 显式构造。
func EmptyNodeOverrides ¶
func EmptyNodeOverrides() NodeOverrides
EmptyNodeOverrides 返回显式为空且有效的 NodeOverrides(Join 运算单位元)。
func NewNodeOverrides ¶
func NewNodeOverrides(rules ...NodeOverrideRule) (NodeOverrides, error)
NewNodeOverrides 校验并按规范顺序折叠一组规则为不可变 NodeOverrides,保证任意输入排列结果一致。
func NewNodeOverridesFromMap ¶
func NewNodeOverridesFromMap(entries map[string]RiskLevel) (NodeOverrides, error)
NewNodeOverridesFromMap 将配置中的 map[pattern]RiskLevel 按确定性键序规范化为顺序无关的 NodeOverrides。
func (NodeOverrides) Equal ¶
func (o NodeOverrides) Equal(other NodeOverrides) bool
Equal 比较两个 NodeOverrides 是否均有效且规则集完全相同。
func (NodeOverrides) EvaluateBatch ¶
func (o NodeOverrides) EvaluateBatch(baseThreshold, opRisk RiskLevel, nodeIDs ...string) GuardrailDecision
EvaluateBatch 在全局基准阈值、操作风险与批量目标节点集合上执行严格单调且顺序无关的限制支配折叠(INV-E3): 始终从全局 EvaluateThreshold(opRisk, baseThreshold) 起步折叠,确保任意新增目标节点只会维持或收紧决策。
func (NodeOverrides) EvaluateNode ¶
func (o NodeOverrides) EvaluateNode(baseThreshold, opRisk RiskLevel, nodeID string) GuardrailDecision
EvaluateNode 在基准阈值与操作风险下对单个目标节点求值(空 nodeID 走全局基准阈值,非法 nodeID 失败关闭为 Deny)。
func (NodeOverrides) Join ¶
func (o NodeOverrides) Join(other NodeOverrides) NodeOverrides
Join 按严苛度并半格合并两个 NodeOverrides;任一侧无效返回零值,满足交换/结合/幂等/单调律。
func (NodeOverrides) MarshalJSONTo ¶
func (o NodeOverrides) MarshalJSONTo(enc *jsontext.Encoder) error
MarshalJSONTo 实现 encoding/json/v2.MarshalerTo(值接收者),以规范排序数组编码;零值失败关闭。
func (NodeOverrides) ResolveBatchThreshold ¶
func (o NodeOverrides) ResolveBatchThreshold(baseThreshold RiskLevel, nodeIDs ...string) (RiskLevel, error)
ResolveBatchThreshold 对批量目标节点执行单调严苛阈值折叠(INV-E3): 始终以全局 baseThreshold 初始化折叠,确保批量操作绝不因单个宽松节点覆盖而弱化全局策略。
func (NodeOverrides) ResolveThreshold ¶
func (o NodeOverrides) ResolveThreshold(baseThreshold RiskLevel, nodeID string) (RiskLevel, error)
ResolveThreshold 计算单节点 nodeID 的有效审批阈值(INV-E3):空 nodeID 走全局 baseThreshold, 非空时前置校验 nodeID 并遍历全部命中规则按 StrictestThreshold 折叠,彻底消除规则顺序依赖。
func (NodeOverrides) Rules ¶
func (o NodeOverrides) Rules() []NodeOverrideRule
Rules 返回按 pattern 升序排列的规则防御性拷贝。
func (*NodeOverrides) UnmarshalJSONFrom ¶
func (o *NodeOverrides) UnmarshalJSONFrom(dec *jsontext.Decoder) error
UnmarshalJSONFrom 实现 encoding/json/v2.UnmarshalerFrom;失败时重置为零值并失败关闭。
type OperationBinding ¶
type OperationBinding struct {
// contains filtered or unexported fields
}
OperationBinding 是不可变的操作规范绑定快照(INV-E4 / INV-E5),锁定能力、工具/动作、目标、 规范路径、命令/计划摘要与排序参数,并经 //xops:canonicalhash 由 xopsvet/digestcover 校验全字段覆盖。
func NewOperationBinding ¶
func NewOperationBinding(spec OperationBindingSpec) (OperationBinding, error)
NewOperationBinding 校验并构造规范排序去重后的不可变 OperationBinding。
func (OperationBinding) CanonicalPaths ¶
func (b OperationBinding) CanonicalPaths() []string
CanonicalPaths 返回排序去重后的规范路径防御性拷贝。
func (OperationBinding) Capability ¶
func (b OperationBinding) Capability() CapabilityKind
Capability 返回绑定的能力类别;无效零值返回 CapabilityInvalid。
func (OperationBinding) CommandDigest ¶
func (b OperationBinding) CommandDigest() algebraic.Option[Digest]
CommandDigest 返回可选命令计划 SHA-256 摘要。
func (OperationBinding) Digest ¶
func (b OperationBinding) Digest() (Digest, error)
Digest 计算并返回 OperationBinding 的确定性 SHA-256 规范摘要。
func (OperationBinding) Endpoint ¶
func (b OperationBinding) Endpoint() algebraic.Option[netaddr.Endpoint]
Endpoint 返回可选强类型目标 SSH 端点。
func (OperationBinding) Equal ¶
func (b OperationBinding) Equal(other OperationBinding) bool
Equal 严格比对两个 OperationBinding 是否均有效且全部字段完全一致(无效零值永不相等)。
func (OperationBinding) IsValid ¶
func (b OperationBinding) IsValid() bool
IsValid 报告 OperationBinding 是否经构造器有效初始化。
func (OperationBinding) IsZero ¶
func (b OperationBinding) IsZero() bool
IsZero 报告 OperationBinding 是否为无效零值。
func (OperationBinding) MarshalJSONTo ¶
func (b OperationBinding) MarshalJSONTo(enc *jsontext.Encoder) error
MarshalJSONTo 实现 encoding/json/v2.MarshalerTo(值接收者);配合 Deterministic(true) 产出确定性 JSON,零值失败关闭。
func (OperationBinding) NodeID ¶
func (b OperationBinding) NodeID() string
NodeID 返回主目标节点标识(全局操作为空串)。
func (OperationBinding) NodeIDs ¶
func (b OperationBinding) NodeIDs() []string
NodeIDs 返回排序去重后的多目标节点防御性拷贝。
func (OperationBinding) Param ¶
func (b OperationBinding) Param(key string) (string, bool)
Param 按键查询单个绑定参数;无效绑定或键不存在返回 ("", false)。
func (OperationBinding) Parameters ¶
func (b OperationBinding) Parameters() map[string]string
Parameters 返回规范参数映射的全新拷贝,隔离外部修改。
func (OperationBinding) PlanDigest ¶
func (b OperationBinding) PlanDigest() algebraic.Option[Digest]
PlanDigest 返回可选连接计划 Merkle SHA-256 摘要。
func (OperationBinding) RecursivePaths ¶
func (b OperationBinding) RecursivePaths() []string
RecursivePaths 返回排序去重后的递归目录路径防御性拷贝。
func (*OperationBinding) UnmarshalJSONFrom ¶
func (b *OperationBinding) UnmarshalJSONFrom(dec *jsontext.Decoder) error
UnmarshalJSONFrom 实现 encoding/json/v2.UnmarshalerFrom;对 JSON null、缺失必需字段或非法值失败关闭并重置零值。
func (OperationBinding) WriteCanonical ¶
func (b OperationBinding) WriteCanonical(w io.Writer) error
WriteCanonical 以零反射、长度前缀与域分离方式将 OperationBinding 全部字段写入 w(受 digestcover 校验)。
type OperationBindingSpec ¶
type OperationBindingSpec struct {
Capability CapabilityKind
Tool string
Action string
NodeID string
NodeIDs []string
Endpoint algebraic.Option[netaddr.Endpoint]
CanonicalPaths []string
RecursivePaths []string
CommandDigest algebraic.Option[Digest]
PlanDigest algebraic.Option[Digest]
Parameters map[string]string
}
OperationBindingSpec 是构造不可变 OperationBinding 的显式入参规格。
type OperationID ¶
type OperationID struct {
// contains filtered or unexported fields
}
OperationID 表示单次安全授权、审批挑战与审计闭环的不可变操作唯一标识, 由 core/internal/foundation/trace.OpID 别名复用;零值恒无效并严格失败关闭。
func NewOperationIDFrom ¶
func NewOperationIDFrom(entropy io.Reader) (OperationID, error)
NewOperationIDFrom 从调用方显式注入的熵源读取 16 字节并构造 OperationID(零隐式 crypto/rand)。
func OperationIDFromBytes ¶
func OperationIDFromBytes(raw [secutil.OperationIDEntropyBytes]byte) OperationID
OperationIDFromBytes 将 16 字节原始熵确定性编码为 32 位小写十六进制 OperationID。
func ParseOperationID ¶
func ParseOperationID(raw string) (OperationID, error)
ParseOperationID 校验并构造 OperationID;仅接受长度 1..128 的可打印非空白 ASCII(0x21..0x7E)。
func (OperationID) AppendText ¶
func (id OperationID) AppendText(b []byte) ([]byte, error)
AppendText、MarshalText 与 UnmarshalText 实现 OperationID 的值接收者文本编解码(零值与非法输入失败关闭)。
func (OperationID) Compare ¶
func (id OperationID) Compare(other OperationID) int
func (OperationID) Equal ¶
func (id OperationID) Equal(other OperationID) bool
func (OperationID) IsValid ¶
func (id OperationID) IsValid() bool
IsValid、IsZero、String、Equal 与 Compare 实现 OperationID 的失败关闭语义与确定性全序(无效零值永不相等)。
func (OperationID) IsZero ¶
func (id OperationID) IsZero() bool
func (OperationID) MarshalText ¶
func (id OperationID) MarshalText() ([]byte, error)
func (OperationID) String ¶
func (id OperationID) String() string
func (*OperationID) UnmarshalText ¶
func (id *OperationID) UnmarshalText(text []byte) error
type RiskLevel ¶
type RiskLevel uint8
RiskLevel 表示操作风险等级与审批阈值使用的有界安全格(RFC §3.6): 零值恒为 RiskUnknown(0),在操作风险并半格 Join 与阈值严苛度并半格 StrictestThreshold 中均充当最高吸收顶元, 绝不静默视作低风险,且序列化边界严格拒绝 RiskUnknown。
const ( RiskUnknown RiskLevel = RiskLevel(secutil.RiskUnknownCode) // 零值未设置/未知风险(全格吸收态,严禁视作低风险) RiskSafe RiskLevel = RiskLevel(secutil.RiskSafeCode) // 只读无副作用低风险(操作风险并半格单位底元) RiskModerate RiskLevel = RiskLevel(secutil.RiskModerateCode) // 可恢复写操作或受保护路径读取(中等风险) RiskDangerous RiskLevel = RiskLevel(secutil.RiskDangerousCode) // 破坏性写、任意命令执行、盘符根或高危隧道(最高有效风险) )
func FoldThresholds ¶
FoldThresholds 对一组审批阈值执行顺序无关的严苛度并半格折叠;空输入严格失败关闭返回 RiskUnknown。
func ParseRiskLevel ¶
ParseRiskLevel 严格解析规范小写风险等级文本("safe"、"moderate"、"dangerous")。
func (RiskLevel) AppendText ¶
AppendText 实现 encoding.TextAppender(值接收者);对 RiskUnknown 及越界值失败关闭。
func (RiskLevel) CompareSeverity ¶
CompareSeverity 按操作严重度顺序比较两个 RiskLevel。
func (RiskLevel) CompareThresholdStrictness ¶
CompareThresholdStrictness 按审批阈值严苛度顺序比较两个 RiskLevel。
func (RiskLevel) MarshalText ¶
MarshalText 实现 encoding.TextMarshaler(值接收者)。
func (RiskLevel) SeverityRank ¶
SeverityRank 返回操作风险严重度全序秩(Safe=1 < Moderate=2 < Dangerous=3 < Unknown/非法=4)。
func (RiskLevel) StrictestThreshold ¶
StrictestThreshold 计算审批阈值严苛度并半格上确界(有效阈值取 min,RiskUnknown 吸收)。
func (RiskLevel) ThresholdStrictnessRank ¶
ThresholdStrictnessRank 返回审批阈值严苛度全序秩(Dangerous=1 < Moderate=2 < Safe=3 < Unknown/非法=4)。
func (*RiskLevel) UnmarshalText ¶
UnmarshalText 实现 encoding.TextUnmarshaler;失败时重置为 RiskUnknown 并失败关闭。
type ScopeEscalationResult ¶
type ScopeEscalationResult struct {
// contains filtered or unexported fields
}
ScopeEscalationResult 保存 InspectScopeEscalation 的纯函数判定结论与审计诊断详情; 内置正向有效门控 valid bool,未初始化零值调用 Escalated() 时严格失败关闭返回 true。
func InspectScopeEscalation ¶
func InspectScopeEscalation(lexical, canonical ScopeSnapshot) ScopeEscalationResult
InspectScopeEscalation 对 lexical 与 canonical 快照执行完整多维升级检测,返回确定性诊断结果。
func (ScopeEscalationResult) AddedProtectedPaths ¶
func (r ScopeEscalationResult) AddedProtectedPaths() []string
AddedProtectedPaths 返回规范化阶段新增或重定向命中的受保护路径列表防御性拷贝。
func (ScopeEscalationResult) Equal ¶
func (r ScopeEscalationResult) Equal(other ScopeEscalationResult) bool
Equal 严格比对两个 ScopeEscalationResult 是否均有效且全部结论字段一致(无效零值永不相等)。
func (ScopeEscalationResult) Escalated ¶
func (r ScopeEscalationResult) Escalated() bool
Escalated 报告规范化后的作用域相较词法预检是否发生升级、受保护重定向或输入异常;零值失败关闭返回 true。
func (ScopeEscalationResult) HasReason ¶
func (r ScopeEscalationResult) HasReason(target EscalationReason) bool
HasReason 报告结果中是否包含指定的升级原因。
func (ScopeEscalationResult) IsValid ¶
func (r ScopeEscalationResult) IsValid() bool
IsValid 报告 ScopeEscalationResult 是否由有效判定或反序列化产生。
func (ScopeEscalationResult) IsZero ¶
func (r ScopeEscalationResult) IsZero() bool
IsZero 报告 ScopeEscalationResult 是否为未初始化无效零值。
func (ScopeEscalationResult) MarshalJSONTo ¶
func (r ScopeEscalationResult) MarshalJSONTo(enc *jsontext.Encoder) error
func (ScopeEscalationResult) Reasons ¶
func (r ScopeEscalationResult) Reasons() []EscalationReason
Reasons 返回按固定顺序排列的升级原因防御性拷贝;零值返回 EscalationInvalidInput。
func (*ScopeEscalationResult) UnmarshalJSONFrom ¶
func (r *ScopeEscalationResult) UnmarshalJSONFrom(dec *jsontext.Decoder) error
type ScopeSnapshot ¶
type ScopeSnapshot struct {
// contains filtered or unexported fields
}
ScopeSnapshot 表示词法预检(Round 1)或远端软链规范化(Round 2)阶段的不可变安全作用域快照; 内部路径按字典序规范排序并折叠重复项,零值恒无效并在 CanonicalScopeEscalated 中无条件失败关闭返回 true。
func FoldScopeSnapshots ¶
func FoldScopeSnapshots(snaps ...ScopeSnapshot) ScopeSnapshot
FoldScopeSnapshots 对一组 ScopeSnapshot 执行顺序无关的代数格折叠;空输入失败关闭返回零值。
func NewScopeSnapshot ¶
func NewScopeSnapshot(spec ScopeSnapshotSpec) (ScopeSnapshot, error)
NewScopeSnapshot 校验并构造不可变 ScopeSnapshot。
func (ScopeSnapshot) Capability ¶
func (s ScopeSnapshot) Capability() CapabilityKind
Capability 返回快照绑定的能力类别。
func (ScopeSnapshot) Decision ¶
func (s ScopeSnapshot) Decision() GuardrailDecision
Decision 返回快照对应的护栏决策副本;无效时失败关闭返回 *DecisionDeny。
func (ScopeSnapshot) Endpoint ¶
func (s ScopeSnapshot) Endpoint() algebraic.Option[netaddr.Endpoint]
Endpoint 返回可选目标端点。
func (ScopeSnapshot) Equal ¶
func (s ScopeSnapshot) Equal(other ScopeSnapshot) bool
Equal 严格比对两个 ScopeSnapshot 是否均有效且所有字段完全一致(无效零值永不相等)。
func (ScopeSnapshot) HasProtectedPath ¶
func (s ScopeSnapshot) HasProtectedPath() bool
HasProtectedPath 报告快照中是否存在任意命中受保护分区的路径。
func (ScopeSnapshot) IsValid ¶
func (s ScopeSnapshot) IsValid() bool
IsValid 报告 ScopeSnapshot 是否完整有效。
func (ScopeSnapshot) Join ¶
func (s ScopeSnapshot) Join(other ScopeSnapshot) ScopeSnapshot
Join 将同身份两份作用域快照按有界格折叠(Verdict Meet、Risk Join、Decision Join、Paths 并集折叠)。 任一快照无效或身份漂移时失败关闭返回零值;严格满足交换/结合/幂等律。
func (ScopeSnapshot) MarshalJSONTo ¶
func (s ScopeSnapshot) MarshalJSONTo(enc *jsontext.Encoder) error
func (ScopeSnapshot) Paths ¶
func (s ScopeSnapshot) Paths() []ScopedPath
Paths 返回规范排序去重后的作用域路径防御性拷贝。
func (ScopeSnapshot) Risk ¶
func (s ScopeSnapshot) Risk() RiskLevel
Risk 返回快照对应的风险等级;无效时失败关闭返回 RiskUnknown。
func (ScopeSnapshot) TargetNode ¶
func (s ScopeSnapshot) TargetNode() string
TargetNode 返回快照绑定的目标节点标识。
func (*ScopeSnapshot) UnmarshalJSONFrom ¶
func (s *ScopeSnapshot) UnmarshalJSONFrom(dec *jsontext.Decoder) error
func (ScopeSnapshot) Verdict ¶
func (s ScopeSnapshot) Verdict() Verdict
Verdict 返回快照对应的二值判定;无效时失败关闭返回 VerdictDeny。
type ScopeSnapshotSpec ¶
type ScopeSnapshotSpec struct {
Capability CapabilityKind
TargetNode string
Endpoint algebraic.Option[netaddr.Endpoint]
Verdict Verdict
Risk RiskLevel
Decision GuardrailDecision
Paths []ScopedPath
}
ScopeSnapshotSpec 是构造不可变 ScopeSnapshot 的显式入参规格。
type ScopedPath ¶
type ScopedPath struct {
// contains filtered or unexported fields
}
ScopedPath 表示单条进入安全作用域判定的不可变路径条目及其受保护分区集合; 同路径按 recursive 逻辑或与受保护分区集合并集折叠,零值恒无效并失败关闭。
func NewScopedPath ¶
func NewScopedPath(path string, recursive bool, protectedZones ...string) (ScopedPath, error)
NewScopedPath 校验路径与受保护分区标签并构造不可变 ScopedPath。
func (ScopedPath) Equal ¶
func (p ScopedPath) Equal(other ScopedPath) bool
Equal 严格比对两个 ScopedPath 是否均有效且完全一致(无效零值永不相等)。
func (ScopedPath) IsProtected ¶
func (p ScopedPath) IsProtected() bool
IsProtected 报告该路径条目是否命中至少一个受保护分区。
func (ScopedPath) IsRecursive ¶
func (p ScopedPath) IsRecursive() bool
IsRecursive 报告该路径条目是否覆盖递归后代目录。
func (ScopedPath) JoinSamePath ¶
func (p ScopedPath) JoinSamePath(other ScopedPath) ScopedPath
JoinSamePath 对同路径的两条记录执行并半格合并(recursive || 与受保护分区并集);非法或异路径返回零值。
func (ScopedPath) MarshalJSONTo ¶
func (p ScopedPath) MarshalJSONTo(enc *jsontext.Encoder) error
MarshalJSONTo 与 UnmarshalJSONFrom 实现 ScopedPath、ScopeSnapshot 与 ScopeEscalationResult 的严格 json/v2 编解码(拒绝零值、null、未知字段与缺失必需字段)。
func (ScopedPath) ProtectedZones ¶
func (p ScopedPath) ProtectedZones() []string
ProtectedZones 返回按字典序排列去重后的受保护分区防御性拷贝。
func (*ScopedPath) UnmarshalJSONFrom ¶
func (p *ScopedPath) UnmarshalJSONFrom(dec *jsontext.Decoder) error
type TraceID ¶
type TraceID struct {
// contains filtered or unexported fields
}
TraceID 表示单次请求链路的不可变全局追踪唯一标识, 由 core/internal/foundation/trace 别名复用(零拷贝互通),供 core/ports 与 core/events 公开使用; 零值恒无效并严格失败关闭。
func NewTraceIDFrom ¶
NewTraceIDFrom 从调用方显式注入的熵源读取 16 字节并构造 TraceID(零隐式 crypto/rand)。
func ParseTraceID ¶
ParseTraceID 校验并构造 TraceID;仅接受长度 1..128 的可打印非空白 ASCII(0x21..0x7E)。
func TraceIDFromBytes ¶
func TraceIDFromBytes(raw [secutil.OperationIDEntropyBytes]byte) TraceID
TraceIDFromBytes 将 16 字节原始熵确定性编码为 32 位小写十六进制 TraceID。
func (TraceID) AppendText ¶
AppendText、MarshalText 与 UnmarshalText 实现 TraceID 的值接收者文本编解码(零值与非法输入失败关闭)。
func (TraceID) MarshalText ¶
func (*TraceID) UnmarshalText ¶
type Verdict ¶
type Verdict uint8
Verdict 表示失败关闭的二值安全判定交半格(INV-E1 / RFC §3.6): 零值恒为 VerdictDeny(0,吸收底元);仅显式 VerdictAllow(1)代表放行(单位顶元);越界值一律视为拒绝。
func FoldVerdicts ¶
FoldVerdicts 对一组判定执行顺序无关的交半格折叠;空输入严格失败关闭返回 VerdictDeny。
func ParseVerdict ¶
ParseVerdict 严格解析规范小写判定文本("deny" 或 "allow");其余输入一律失败关闭。
func VerdictFromError ¶
VerdictFromError 将 (Verdict, error) 折叠为纯 Verdict:任意非 nil 错误或非 VerdictAllow 值均返回 VerdictDeny。
func (Verdict) AppendText ¶
AppendText 实现 encoding.TextAppender(值接收者);对非法越界值失败关闭。
func (Verdict) MarshalText ¶
MarshalText 实现 encoding.TextMarshaler(值接收者)。
func (*Verdict) UnmarshalText ¶
UnmarshalText 实现 encoding.TextUnmarshaler;解析失败时重置为 VerdictDeny 并失败关闭。
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
secutil
Package secutil 为 core/domain/security 提供无环叶级纯函数计算辅助: 涵盖操作系统无关 UTF-8 Glob 匹配引擎与审批提示文本清洗、节点/令牌/摘要/Nonce/时间窗口校验、 受保护路径作用域差分对比、规范二进制写入原语以及通用排序合并与编解码辅助。
|
Package secutil 为 core/domain/security 提供无环叶级纯函数计算辅助: 涵盖操作系统无关 UTF-8 Glob 匹配引擎与审批提示文本清洗、节点/令牌/摘要/Nonce/时间窗口校验、 受保护路径作用域差分对比、规范二进制写入原语以及通用排序合并与编解码辅助。 |