secrets

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 18 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 secrets resolves provider-qualified secret references.

It deliberately provides a closed, explicitly constructed registry. It is an internal routing boundary, not a plugin or provider-extension API.

Index

Examples

Constants

View Source
const (
	// MaxPlaintextSize bounds one decrypted JSON document.
	MaxPlaintextSize int64 = 1 << 20
)

Variables

This section is empty.

Functions

func SnapshotStores

func SnapshotStores(stores []Store) (string, error)

SnapshotStores returns a deterministic ciphertext-only identity for a strongest-to-weakest candidate list. Missing candidates participate so a later appearance changes the snapshot. It retains no ciphertext or decoded values.

Types

type AgeProvider

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

AgeProvider decrypts JSON stores with the external age command. It retains no plaintext or decoded-document cache.

func NewAgeProvider

func NewAgeProvider(options AgeProviderOptions) (*AgeProvider, error)

NewAgeProvider validates effective age configuration. Identity paths must be absolute; their contents are never opened or inspected by Wirecmd.

func (*AgeProvider) Resolve

func (p *AgeProvider) Resolve(ctx context.Context, _ Scope, locators []string) (BatchResult, error)

Resolve decrypts each needed store at most once and applies first-store-wins precedence for each requested locator.

func (*AgeProvider) Scheme

func (*AgeProvider) Scheme() string

func (*AgeProvider) ValidateLocator

func (*AgeProvider) ValidateLocator(locator string) error

type AgeProviderOptions

type AgeProviderOptions struct {
	Command      string
	Identities   []string
	Stores       []Store
	Timeout      time.Duration
	MaxPlaintext int64
	Snapshot     *StoreSnapshot
}

AgeProviderOptions defines the fixed age command and effective store inputs for one configured scope. Command is primarily injectable for tests; normal construction leaves it empty to use age from PATH.

type BatchResult

type BatchResult struct {
	Values  map[string]string
	Missing []string
}

BatchResult is the result of resolving one provider's deduplicated locators. A locator appears in exactly one of Values or Missing.

type Code

type Code string

Code classifies a secret-resolution failure without requiring callers to parse an error string.

const (
	CodeInvalidReference  Code = "invalid_secret_reference"
	CodeUnknownProvider   Code = "unknown_secret_provider"
	CodeDuplicateProvider Code = "duplicate_secret_provider"
	CodeProviderInvalid   Code = "secret_provider_invalid"
	CodeProviderFailed    Code = "secret_provider_failed"
	CodeSecretUnavailable Code = "secret_not_available"

	CodeAgeUnavailable        Code = "age_unavailable"
	CodeAgeVersionUnsupported Code = "age_version_unsupported"
	CodeAgeDecryptionTimeout  Code = "age_decryption_timeout"
	CodeAgeDecryptionFailed   Code = "age_decryption_failed"
	CodeSecretStoreInvalid    Code = "secret_store_invalid"
)

type EnvProvider

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

EnvProvider resolves environment values through an injected lookup function. The function must preserve the difference between an unset variable and an explicitly empty variable, as os.LookupEnv does.

func NewEnvProvider

func NewEnvProvider(lookup func(string) (string, bool)) (*EnvProvider, error)

NewEnvProvider constructs an env provider. A nil lookup is invalid because it would make unset values indistinguishable from empty values.

func (*EnvProvider) Resolve

func (p *EnvProvider) Resolve(_ context.Context, _ Scope, locators []string) (BatchResult, error)

func (*EnvProvider) Scheme

func (*EnvProvider) Scheme() string

func (*EnvProvider) ValidateLocator

func (*EnvProvider) ValidateLocator(locator string) error

type Error

type Error struct {
	Code    Code
	Message string
	Missing []Reference
}

Error is a safe, structured secret-resolution error. Message never contains provider stderr, plaintext, or identity contents. Missing contains requested locators only, never their resolved values.

func (*Error) Error

func (e *Error) Error() string

type Provider

type Provider interface {
	Scheme() string
	ValidateLocator(string) error
	Resolve(context.Context, Scope, []string) (BatchResult, error)
}

Provider resolves opaque locators for one normalized scheme. Provider implementations own their locator grammar and never receive other schemes.

type Reference

type Reference struct {
	Scheme  string
	Locator string
}

Reference is a canonical provider-qualified secret reference. It is comparable so callers can use it as a map key without carrying plaintext.

func ParseReference

func ParseReference(raw string) (Reference, error)

ParseReference validates provider-independent SCHEME://LOCATOR syntax and returns its canonical representation. A Registry additionally verifies that the scheme exists and applies the provider's locator grammar.

func (Reference) String

func (r Reference) String() string
Example
fmt.Println(Reference{Scheme: "age", Locator: "TOKEN"})
Output:
age://TOKEN

type Registry

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

Registry holds the fixed provider set selected by the CLI or daemon.

func NewRegistry

func NewRegistry(providers ...Provider) (*Registry, error)

NewRegistry constructs a closed registry. Schemes are normalized to lower case and duplicate registrations are rejected.

func (*Registry) Parse

func (r *Registry) Parse(raw string) (Reference, error)

Parse validates raw SCHEME://LOCATOR input and returns its canonical form.

func (*Registry) Resolve

func (r *Registry) Resolve(ctx context.Context, scope Scope, references []Reference) (map[Reference]string, error)

Resolve batches references by provider in deterministic scheme order. It validates References again so manually constructed values cannot bypass a provider's locator rules.

type Scope

type Scope string

Scope identifies the lifecycle context for one batch of secret resolution. The registry does not interpret it; callers keep separate scopes separate.

type Store

type Store struct {
	Path                string
	RejectParentSymlink bool
}

Store is one encrypted age document. Stores are evaluated in the order supplied to NewAgeProvider, from strongest to weakest precedence.

type StoreSnapshot

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

StoreSnapshot binds a candidate-list identity to the exact ciphertext bytes that will be decrypted. It is operation-local and must not be retained as a daemon cache value.

func CaptureStores

func CaptureStores(stores []Store) (*StoreSnapshot, error)

CaptureStores safely reads each candidate once. The returned ciphertext is consumed by AgeProvider so cache identity and decryption cannot observe different file versions.

func (*StoreSnapshot) Identity

func (s *StoreSnapshot) Identity() string

Identity returns the ciphertext-only deterministic snapshot identity.

Jump to

Keyboard shortcuts

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