credentialhelper

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPassPrefix 是 pass 存储项在 password-store 中的默认根路径前缀。
	DefaultPassPrefix = "xops"

	// DefaultPassCommand 是原生 pass 命令行工具的二进制名称。
	DefaultPassCommand = "pass"
)
View Source
const (
	// ProtocolVersion 是当前支持的 helper 协议主版本。
	ProtocolVersion = 1

	// MaxResponseBytes 是 helper 响应 stdout 允许读取的最大字节数(64KB)。
	MaxResponseBytes = 64 * 1024

	// MaxStderrBytes 是 helper 诊断 stderr 允许读取的最大字节数(4KB)。
	MaxStderrBytes = 4 * 1024
)
View Source
const DefaultHelperTimeout = 30 * time.Second

DefaultHelperTimeout 是 credential helper 进程执行的默认超时时间。

View Source
const DefaultProcessWaitDelay = 50 * time.Millisecond

DefaultProcessWaitDelay 是主进程退出后等待继承管道的子孙进程排空的最大窗口。

View Source
const DefaultSystemHelperCommand = "xops-credential-system"

DefaultSystemHelperCommand 是系统密钥库 helper 的默认二进制名称。

Variables

This section is empty.

Functions

func CheckSystemAvailability

func CheckSystemAvailability() error

CheckSystemAvailability 检查当前平台系统密钥库环境是否满足可用性前置要求。

func DecodeSecretBytes

func DecodeSecretBytes(resp *Response) ([]byte, error)

DecodeSecretBytes 从 Response 中提取并解码机密字节。调用方需负责清零。

func EncodeRequest

func EncodeRequest(w io.Writer, req *Request) error

EncodeRequest 将请求序列化为 JSON 并写入 writer。

func MapErrorCode

func MapErrorCode(code, message string) error

MapErrorCode 将 helper 协议返回的错误代码映射为系统标准的凭据哨兵错误。 优先返回受控哨兵错误分类,避免将 helper 返回的任意非受控诊断文本拼接入错误导致已知请求机密泄漏。

func SanitizeDiagnostic

func SanitizeDiagnostic(raw string, sensitive ...string) string

SanitizeDiagnostic 对错误和诊断信息进行脱敏处理,屏蔽可疑 Base64 与长敏感字符串。

Types

type Action

type Action string

Action 表示向 helper 发起的操作动作。

const (
	// ActionGet 获取指定引用的凭据。
	ActionGet Action = "get"
	// ActionStore 存储凭据。
	ActionStore Action = "store"
	// ActionErase 擦除凭据。
	ActionErase Action = "erase"
)

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

Get 从 helper 中获取凭据。

func (*HelperStore) IsReadOnly

func (s *HelperStore) IsReadOnly() bool

IsReadOnly 返回该存储是否为只读模式。

func (*HelperStore) Put

func (s *HelperStore) Put(ctx context.Context, ref credential.Ref, secret credential.Secret) error

Put 向 helper 中写入凭据。只读模式下直接拒绝。

func (*HelperStore) StoreID

func (s *HelperStore) StoreID() string

StoreID 返回该存储的注册标识。

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) Delete

func (p *PassStore) Delete(ctx context.Context, ref credential.Ref) error

Delete 从 pass 中删除指定凭据项。

func (*PassStore) Get

Get 从 pass 中检索凭据。

func (*PassStore) IsReadOnly

func (p *PassStore) IsReadOnly() bool

IsReadOnly 返回该存储是否为只读。

func (*PassStore) Put

func (p *PassStore) Put(ctx context.Context, ref credential.Ref, secret credential.Secret) error

Put 向 pass 中插入或更新凭据。机密通过 stdin 传递,严禁进入 argv。

func (*PassStore) StoreID

func (p *PassStore) StoreID() string

StoreID 返回该存储的注册标识。

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

func DecodeResponse(r io.Reader) (*Response, error)

DecodeResponse 从 reader 读取并反序列化响应 JSON,严格限制最大字节数、强制唯一响应并校验 Base64。

func Run

func Run(ctx context.Context, opts ProcessOptions, action Action, req *Request) (*Response, error)

Run 启动 credential helper 子进程,传递 stdin 并解析 stdout 响应。

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

Get 从系统密钥库检索凭据。

func (*SystemStore) IsReadOnly

func (s *SystemStore) IsReadOnly() bool

IsReadOnly 返回该存储是否为只读。

func (*SystemStore) Put

func (s *SystemStore) Put(ctx context.Context, ref credential.Ref, secret credential.Secret) error

Put 向系统密钥库写入凭据。

func (*SystemStore) StoreID

func (s *SystemStore) StoreID() string

StoreID 返回该存储的注册标识。

type SystemStoreConfig

type SystemStoreConfig struct {
	NonInteractive bool
	Command        string
	Args           []string
	Env            []string
	Timeout        time.Duration
	ReadOnly       bool
}

SystemStoreConfig 包含系统密钥库后端的配置选项。

Jump to

Keyboard shortcuts

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