credentials

package
v0.0.0-...-10bf2d1 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package credentials defines the common contract for credential providers.

A resolved Secret owns its byte buffer. Callers must close it as soon as the child process has consumed the credential.

Index

Constants

View Source
const (
	ProviderOnePassword = "1password"
	ProviderCommand     = "command"
	ProviderEnvironment = "environment"
	ProviderNative      = "native"
)

Variables

View Source
var (
	ErrInvalidReference = errors.New("invalid credential reference")
	ErrUnavailable      = errors.New("credential provider unavailable")
	ErrNativeCredential = errors.New("credential is managed by the native client")
)

Functions

func Fingerprint

func Fingerprint(secret []byte) string

Fingerprint returns the first 96 bits of a domain-separated SHA-256 digest.

func Zero

func Zero(b []byte)

Zero overwrites every byte in b.

Types

type Metadata

type Metadata struct {
	Provider string
	Label    string
}

Metadata is safe to display or log. Label must never contain credential material or command arguments.

type Provider

type Provider interface {
	Available(context.Context, Reference) bool
	Resolve(context.Context, Reference) (*Secret, error)
	Metadata(Reference) Metadata
}

Provider resolves one kind of credential reference.

type Reference

type Reference struct {
	Identifier string
	Executable string
	Arguments  []string
}

Reference is the provider configuration stored in an environment manifest. Identifier is an opaque provider-specific reference (for example, an op URI or environment variable name). Executable and Arguments are used only by the command provider.

type Secret

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

Secret is a short-lived credential buffer. Secret is not safe for concurrent use. Close must be called exactly once by the owner when practical.

func NewSecret

func NewSecret(value []byte) (*Secret, error)

NewSecret takes ownership of value. The caller must not retain or mutate the slice after this call.

func RunSecretCommand

func RunSecretCommand(ctx context.Context, executable string, arguments, environment []string) (*Secret, error)

RunSecretCommand executes a credential helper without a shell. Its stdout is retained as the secret, while stderr and stdout are deliberately excluded from returned errors because either stream may contain credential material.

func (*Secret) Close

func (s *Secret) Close() error

Close overwrites the owned buffer and releases it. It is idempotent.

func (*Secret) Fingerprint

func (s *Secret) Fingerprint() (string, error)

Fingerprint returns a short, non-reversible identifier suitable for comparing two resolved credentials. It does not reveal the credential.

func (*Secret) Use

func (s *Secret) Use(fn func([]byte) error) error

Use exposes the owned buffer only for the duration of fn. The slice must not be retained by fn.

func (*Secret) WriteTo

func (s *Secret) WriteTo(w io.Writer) (int64, error)

WriteTo sends the secret to a writer without converting it to a string.

Jump to

Keyboard shortcuts

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