secrets

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MPL-2.0 Imports: 20 Imported by: ? 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCacheable added in v0.9.0

func IsCacheable(expr string) bool

IsCacheable reports whether an expression is a standalone secret reference eligible for TF_VAR cache reuse.

func NormalizeExpression added in v0.9.0

func NormalizeExpression(expr string) (string, bool)

NormalizeExpression returns the secret("vault","item","field") call for a secret reference, for example "secret.op.vault.item.field", "op.vault.item.field", or "secret.sops.key.path". A "secrets." prefix is the same as "secret.". A sops reference becomes secret("sops","key.path",""). A canonical secret(...) call returns trimmed and false. A value that is not a reference returns "" and false.

func NormalizeLegacyBraces added in v0.9.0

func NormalizeLegacyBraces(value string) string

NormalizeLegacyBraces converts ${{ expr }} to ${ expr }.

Types

type Checker added in v0.10.0

type Checker interface {
	Account() string
	Check() error
}

Checker is the optional contract of a provider that can confirm its backend is reachable before any secret is read. Account names the backend in messages and groups the providers that share one account.

type DeferredError added in v0.9.0

type DeferredError struct {
	Expression string
	Message    string
}

DeferredError signals that a secret expression should be preserved for later evaluation. This is not an error condition but a control-flow signal.

func (*DeferredError) Error added in v0.9.0

func (e *DeferredError) Error() string

type MockProvider added in v0.9.0

type MockProvider struct {
	LoadSecretsFunc func() error
	ResolveFunc     func(ref SecretRef) (string, bool, error)
}

MockProvider is a mock implementation of the Provider interface for testing.

func NewMockProvider added in v0.9.0

func NewMockProvider() *MockProvider

NewMockProvider creates a new MockProvider instance.

func (*MockProvider) LoadSecrets added in v0.9.0

func (m *MockProvider) LoadSecrets() error

LoadSecrets calls the mock LoadSecretsFunc if set, otherwise returns nil.

func (*MockProvider) Resolve added in v0.9.0

func (m *MockProvider) Resolve(ref SecretRef) (string, bool, error)

Resolve calls the mock ResolveFunc if set, otherwise returns unhandled.

type OnePasswordCLIProvider added in v0.9.0

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

OnePasswordCLIProvider implements the Provider interface using the 1Password CLI.

func NewOnePasswordCLIProvider added in v0.9.0

func NewOnePasswordCLIProvider(vault OnePasswordVault) *OnePasswordCLIProvider

NewOnePasswordCLIProvider creates a new OnePasswordCLIProvider instance.

func (*OnePasswordCLIProvider) Account added in v0.10.0

func (s *OnePasswordCLIProvider) Account() string

Account returns the 1Password account this provider reads.

func (*OnePasswordCLIProvider) Check added in v0.10.0

func (s *OnePasswordCLIProvider) Check() error

Check confirms that the account is reachable and signed in. It runs op whoami for the account.

func (*OnePasswordCLIProvider) LoadSecrets added in v0.9.0

func (s *OnePasswordCLIProvider) LoadSecrets() error

LoadSecrets marks the provider as unlocked.

func (*OnePasswordCLIProvider) Resolve added in v0.9.0

func (s *OnePasswordCLIProvider) Resolve(ref SecretRef) (string, bool, error)

Resolve fetches a secret from 1Password CLI. ref.Item is config-controlled and positional; it's placed after "--" (end-of-options) in the op argv so an item name beginning with "-" is parsed as the operand op expects, not as an op flag. Returns handled=true only if the vault ID matches.

type OnePasswordSDKProvider added in v0.9.0

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

OnePasswordSDKProvider implements the Provider interface using the 1Password SDK.

func NewOnePasswordSDKProvider added in v0.9.0

func NewOnePasswordSDKProvider(vault OnePasswordVault) *OnePasswordSDKProvider

NewOnePasswordSDKProvider creates a new OnePasswordSDKProvider instance.

func (*OnePasswordSDKProvider) Account added in v0.10.0

func (s *OnePasswordSDKProvider) Account() string

Account returns the label of the service account that this provider authenticates with. Every SDK provider shares one token, so they all report the same label.

func (*OnePasswordSDKProvider) Check added in v0.10.0

func (s *OnePasswordSDKProvider) Check() error

Check confirms that the service account token authenticates. It lists the vaults the token can see.

func (*OnePasswordSDKProvider) LoadSecrets added in v0.9.0

func (s *OnePasswordSDKProvider) LoadSecrets() error

LoadSecrets marks the provider as unlocked.

func (*OnePasswordSDKProvider) Resolve added in v0.9.0

func (s *OnePasswordSDKProvider) Resolve(ref SecretRef) (string, bool, error)

Resolve fetches a secret from 1Password SDK. Returns handled=true only if the vault ID matches.

type OnePasswordVault added in v0.10.0

type OnePasswordVault struct {
	ID   string
	Name string
	URL  string
}

OnePasswordVault identifies the 1Password vault that a 1Password provider reads. ID is the alias that secret() references, Name is the vault name, and URL is the account.

type Provider added in v0.9.0

type Provider interface {
	// LoadSecrets loads/unlocks the secret store.
	LoadSecrets() error

	// Resolve fetches a secret value by reference.
	// Returns (value, handled, error). handled=false means this
	// provider doesn't own the requested vault.
	Resolve(ref SecretRef) (string, bool, error)
}

Provider is the minimal contract for secret backends.

type Resolver added in v0.9.0

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

Resolver dispatches secret references across configured providers and serves as the evaluator helper implementation.

func NewResolver added in v0.9.0

func NewResolver(providers []Provider, sh shell.Shell) *Resolver

NewResolver creates a Resolver from the given providers and shell.

func (*Resolver) CheckReachable added in v0.10.0

func (r *Resolver) CheckReachable(ctx context.Context) error

CheckReachable confirms that each 1Password account is reachable, with one check per account. Each check shows as a progress step under ctx. It checks every account and returns all failures joined, so one run reports every unreachable account.

func (*Resolver) EvaluateHelper added in v0.9.0

func (r *Resolver) EvaluateHelper(params []any, deferred bool) (any, error)

EvaluateHelper is the expr helper callback for secret(vault, item[, field]). On first pass (deferred=false), returns DeferredError. On second pass (deferred=true), resolves the secret.

func (*Resolver) LoadAll added in v0.9.0

func (r *Resolver) LoadAll() error

LoadAll calls LoadSecrets on every provider.

func (*Resolver) Resolve added in v0.9.0

func (r *Resolver) Resolve(ref SecretRef) (string, error)

Resolve finds the right provider and returns the secret value. Registers the value with shell for scrubbing.

type SecretRef added in v0.9.0

type SecretRef struct {
	Vault string // "sops" or a 1Password vault ID
	Item  string // item name or SOPS key path
	Field string // field name (empty for SOPS)
}

SecretRef is the canonical internal representation of a secret reference. All notation formats normalize to this before resolution.

type Shims

type Shims struct {
	shims.Shims
	DecryptFile          func(string, string) ([]byte, error)
	NewOnePasswordClient func(context.Context, ...onepassword.ClientOption) (*onepassword.Client, error)
	ResolveSecret        func(*onepassword.Client, context.Context, string) (string, error)
	Command              func(name string, arg ...string) *exec.Cmd
	CmdOutput            func(ctx context.Context, cmd *exec.Cmd) (stdout []byte, stderr []byte, err error)
	ListVaults           func(*onepassword.Client, context.Context) error
	WatchInterrupt       func() (<-chan struct{}, func())
	HintWriter           io.Writer
}

Shims holds the shared system call primitives and the secrets-specific provider shims.

func NewShims

func NewShims() *Shims

NewShims returns a Shims with every field set to its real implementation. DecryptFile runs sops and returns its stderr as the error text when sops exits with a failure. CmdOutput runs a command under a context and returns its stdout and stderr separately. WatchInterrupt reports an interrupt signal on its channel until its stop function runs.

type SopsProvider added in v0.9.0

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

SopsProvider implements the Provider interface using SOPS for decryption.

func NewSopsProvider added in v0.9.0

func NewSopsProvider(configPath string) *SopsProvider

NewSopsProvider creates a new SopsProvider instance.

func (*SopsProvider) LoadSecrets added in v0.9.0

func (s *SopsProvider) LoadSecrets() error

LoadSecrets loads and decrypts secrets from all existing secrets files, including the conventionally-unencrypted secrets.yaml/secrets.yml names: content decides whether a file is SOPS-encrypted, not its name, since an operator's own SOPS file can be named either way. A secrets.yaml/secrets.yml that fails to decrypt is refused with a clear error naming the path rather than the raw sops failure, since the far more likely cause is a genuinely plaintext file that was never encrypted (and, without a matching .gitignore entry, at risk of being committed).

func (*SopsProvider) Resolve added in v0.9.0

func (s *SopsProvider) Resolve(ref SecretRef) (string, bool, error)

Resolve fetches a SOPS secret by reference. Returns handled=true only if the vault is "sops" (case-insensitive).

Jump to

Keyboard shortcuts

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