Documentation
¶
Index ¶
- Constants
- func CheckSystemAvailability() error
- func DecodeSecretBytes(resp *Response) ([]byte, error)
- func EncodeRequest(w io.Writer, req *Request) error
- func MapErrorCode(code, message string) error
- func SanitizeDiagnostic(raw string, sensitive ...string) string
- type Action
- type HelperStore
- func (s *HelperStore) Delete(ctx context.Context, ref credential.Ref) error
- func (s *HelperStore) Get(ctx context.Context, ref credential.Ref) (credential.Secret, error)
- func (s *HelperStore) IsReadOnly() bool
- func (s *HelperStore) Put(ctx context.Context, ref credential.Ref, secret credential.Secret) error
- func (s *HelperStore) StoreID() string
- type PassStore
- func (p *PassStore) Delete(ctx context.Context, ref credential.Ref) error
- func (p *PassStore) Get(ctx context.Context, ref credential.Ref) (credential.Secret, error)
- func (p *PassStore) IsReadOnly() bool
- func (p *PassStore) Put(ctx context.Context, ref credential.Ref, secret credential.Secret) error
- func (p *PassStore) StoreID() string
- type PassStoreConfig
- type ProcessOptions
- type Request
- type Response
- type SystemStore
- func (s *SystemStore) Delete(ctx context.Context, ref credential.Ref) error
- func (s *SystemStore) Get(ctx context.Context, ref credential.Ref) (credential.Secret, error)
- func (s *SystemStore) IsReadOnly() bool
- func (s *SystemStore) Put(ctx context.Context, ref credential.Ref, secret credential.Secret) error
- func (s *SystemStore) StoreID() string
- type SystemStoreConfig
Constants ¶
const ( // DefaultPassPrefix 是 pass 存储项在 password-store 中的默认根路径前缀。 DefaultPassPrefix = "xops" // DefaultPassCommand 是原生 pass 命令行工具的二进制名称。 DefaultPassCommand = "pass" )
const ( // ProtocolVersion 是当前支持的 helper 协议主版本。 ProtocolVersion = 1 // MaxResponseBytes 是 helper 响应 stdout 允许读取的最大字节数(64KB)。 MaxResponseBytes = 64 * 1024 // MaxStderrBytes 是 helper 诊断 stderr 允许读取的最大字节数(4KB)。 MaxStderrBytes = 4 * 1024 )
const DefaultHelperTimeout = 30 * time.Second
DefaultHelperTimeout 是 credential helper 进程执行的默认超时时间。
const DefaultProcessWaitDelay = 50 * time.Millisecond
DefaultProcessWaitDelay 是主进程退出后等待继承管道的子孙进程排空的最大窗口。
const DefaultSystemHelperCommand = "xops-credential-system"
DefaultSystemHelperCommand 是系统密钥库 helper 的默认二进制名称。
Variables ¶
This section is empty.
Functions ¶
func CheckSystemAvailability ¶
func CheckSystemAvailability() error
CheckSystemAvailability 检查当前平台系统密钥库环境是否满足可用性前置要求。
func DecodeSecretBytes ¶
DecodeSecretBytes 从 Response 中提取并解码机密字节。调用方需负责清零。
func EncodeRequest ¶
EncodeRequest 将请求序列化为 JSON 并写入 writer。
func MapErrorCode ¶
MapErrorCode 将 helper 协议返回的错误代码映射为系统标准的凭据哨兵错误。 优先返回受控哨兵错误分类,避免将 helper 返回的任意非受控诊断文本拼接入错误导致已知请求机密泄漏。
func SanitizeDiagnostic ¶
SanitizeDiagnostic 对错误和诊断信息进行脱敏处理,屏蔽可疑 Base64 与长敏感字符串。
Types ¶
type HelperStore ¶
type HelperStore struct {
// contains filtered or unexported fields
}
HelperStore 基于外部 credential helper 进程实现 credential.Store 接口。
func NewHelperStore ¶
func NewHelperStore(storeID string, opts ProcessOptions, readOnly bool) (*HelperStore, error)
NewHelperStore 创建外部 credential helper 存储实例。
func (*HelperStore) Delete ¶
func (s *HelperStore) Delete(ctx context.Context, ref credential.Ref) error
Delete 从 helper 中删除凭据。只读模式下直接拒绝。
func (*HelperStore) Get ¶
func (s *HelperStore) Get(ctx context.Context, ref credential.Ref) (credential.Secret, error)
Get 从 helper 中获取凭据。
func (*HelperStore) Put ¶
func (s *HelperStore) Put(ctx context.Context, ref credential.Ref, secret credential.Secret) error
Put 向 helper 中写入凭据。只读模式下直接拒绝。
type PassStore ¶
type PassStore struct {
// contains filtered or unexported fields
}
PassStore 提供基于 pass 密码管理器的凭据存储实现。 支持原生 pass 命令行工具或遵循 Helper 协议 v1 的 pass helper 二进制。
func NewPassStore ¶
func NewPassStore(storeID string, cfg PassStoreConfig) (*PassStore, error)
NewPassStore 创建 pass 凭据存储实例。
func (*PassStore) Get ¶
func (p *PassStore) Get(ctx context.Context, ref credential.Ref) (credential.Secret, error)
Get 从 pass 中检索凭据。
func (*PassStore) Put ¶
func (p *PassStore) Put(ctx context.Context, ref credential.Ref, secret credential.Secret) error
Put 向 pass 中插入或更新凭据。机密通过 stdin 传递,严禁进入 argv。
type PassStoreConfig ¶
type PassStoreConfig struct {
NonInteractive bool
Prefix string
Command string
Args []string
Env []string
Timeout time.Duration
ReadOnly bool
IsHelperProtocol bool
}
PassStoreConfig 描述 pass 凭据存储配置。
type ProcessOptions ¶
type ProcessOptions struct {
// NonInteractive declares that the helper honors the nonInteractive request field.
NonInteractive bool
Command string
Args []string
Env []string
Timeout time.Duration
}
ProcessOptions 包含启动子进程 credential helper 的选项。
type Request ¶
type Request struct {
NonInteractive bool `json:"nonInteractive,omitempty"`
ProtocolVersion int `json:"protocolVersion"`
StoreID string `json:"storeID"`
ItemID string `json:"itemID"`
Secret string `json:"secret,omitempty"` // Base64 编码
}
Request 表示通过 stdin 传递给 helper 的请求 JSON 载荷。
type Response ¶
type Response struct {
Secret string `json:"secret,omitempty"` // Base64 编码
ExpiresAt *time.Time `json:"expiresAt,omitempty"`
Code string `json:"code,omitempty"`
Message string `json:"message,omitempty"`
}
Response 表示从 helper stdout 读取的响应 JSON 载荷。
func DecodeResponse ¶
DecodeResponse 从 reader 读取并反序列化响应 JSON,严格限制最大字节数、强制唯一响应并校验 Base64。
type SystemStore ¶
type SystemStore struct {
// contains filtered or unexported fields
}
SystemStore 封装操作系统原生密钥库或外部 helper 的凭据存储。
func NewSystemStore ¶
func NewSystemStore(storeID string, cfg SystemStoreConfig) (*SystemStore, error)
NewSystemStore 创建系统密钥库存储实例。
func (*SystemStore) Delete ¶
func (s *SystemStore) Delete(ctx context.Context, ref credential.Ref) error
Delete 从系统密钥库删除凭据。
func (*SystemStore) Get ¶
func (s *SystemStore) Get(ctx context.Context, ref credential.Ref) (credential.Secret, error)
Get 从系统密钥库检索凭据。
func (*SystemStore) Put ¶
func (s *SystemStore) Put(ctx context.Context, ref credential.Ref, secret credential.Secret) error
Put 向系统密钥库写入凭据。