Help us shape the future of Go! Take the 2026 Go Developer Survey

secrets

package
v0.4.0-beta.12 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package secrets keeps secret values encrypted at rest and fetches secrets from external managers such as Infisical, Vault, Doppler and 1Password.

Index

Constants

View Source
const (
	CharsetAlphanumeric = "alphanumeric"
	CharsetHex          = "hex"
	CharsetSymbols      = "symbols"
)
View Source
const ReferenceName = "secret"

ReferenceName is the reference target that reads secrets, as in ${{ secret.DB_PASSWORD }}.

Variables

View Source
var (
	ErrNotFound    = errors.New("secret not found")
	ErrInvalidName = errors.New("secret names use letters, digits and underscores, and do not start with a digit")
)
View Source
var ErrNotSealed = errors.New("value is not sealed")

Functions

func CheckFields

func CheckFields(fields []Field, values map[string]string) error

CheckFields reports the first required field missing from values.

func IsSealed

func IsSealed(value string) bool

Types

type Binding

type Binding struct {
	ID           string            `json:"id"`
	Scope        Scope             `json:"scope"`
	Provider     string            `json:"provider"`
	ConnectionID string            `json:"connection_id"`
	Options      map[string]string `json:"options,omitempty"`
	CreatedAt    time.Time         `json:"created_at"`
}

Binding connects a scope to a secret manager. Every key the manager returns becomes readable as ${{ secret.KEY }} in that scope.

type Connections

type Connections func(id string) (provider string, settings map[string]string, err error)

Connections looks up the stored settings of a provider connection.

type Doppler

type Doppler struct{ Client *http.Client }

Doppler downloads a config's secrets. A service token already names its project and config, so those are only needed with other token types.

func (Doppler) BindingFields

func (Doppler) BindingFields() []Field

func (Doppler) ConnectionFields

func (Doppler) ConnectionFields() []Field

func (Doppler) Fetch

func (p Doppler) Fetch(ctx context.Context, creds, opts map[string]string) (map[string]string, error)

func (Doppler) Label

func (Doppler) Label() string

func (Doppler) Type

func (Doppler) Type() string

type Field

type Field struct {
	Key      string `json:"key"`
	Label    string `json:"label"`
	Secret   bool   `json:"secret,omitempty"`
	Required bool   `json:"required,omitempty"`
	Default  string `json:"default,omitempty"`
}

Field describes one setting a provider needs, either on its connection (credentials) or on a binding (where to read from).

type Generator

type Generator struct {
	Length  int    `json:"length"`
	Charset string `json:"charset"`
}

Generator describes how a rotated value is produced.

func (Generator) Generate

func (g Generator) Generate() (string, error)

type Infisical

type Infisical struct{ Client *http.Client }

Infisical reads one folder of a project environment with a machine identity's universal auth credentials.

func (Infisical) BindingFields

func (Infisical) BindingFields() []Field

func (Infisical) ConnectionFields

func (Infisical) ConnectionFields() []Field

func (Infisical) Fetch

func (p Infisical) Fetch(ctx context.Context, creds, opts map[string]string) (map[string]string, error)

func (Infisical) Label

func (Infisical) Label() string

func (Infisical) Type

func (Infisical) Type() string

type Keyring

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

Keyring seals values with AES-256-GCM under a key kept in its own file.

func LoadKeyring

func LoadKeyring(path string) (*Keyring, error)

LoadKeyring reads the key at path, creating a new random key when the file does not exist.

func NewKeyring

func NewKeyring(key []byte) (*Keyring, error)

func (*Keyring) Open

func (k *Keyring) Open(sealed string) (string, error)

func (*Keyring) Seal

func (k *Keyring) Seal(plain string) (string, error)

type OnePassword

type OnePassword struct{ Client *http.Client }

OnePassword reads one item's fields through a 1Password Connect server. Each field's label becomes a key.

func (OnePassword) BindingFields

func (OnePassword) BindingFields() []Field

func (OnePassword) ConnectionFields

func (OnePassword) ConnectionFields() []Field

func (OnePassword) Fetch

func (p OnePassword) Fetch(ctx context.Context, creds, opts map[string]string) (map[string]string, error)

func (OnePassword) Label

func (OnePassword) Label() string

func (OnePassword) Type

func (OnePassword) Type() string

type Provider

type Provider interface {
	Type() string
	Label() string
	ConnectionFields() []Field
	BindingFields() []Field
	Fetch(ctx context.Context, credentials, options map[string]string) (map[string]string, error)
}

Provider reads secrets from an external manager. Credentials hold the connection's settings; options say which secrets the binding reads.

type Registry

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

func DefaultRegistry

func DefaultRegistry(client *http.Client) *Registry

DefaultRegistry holds every built-in provider.

func NewRegistry

func NewRegistry(providers ...Provider) *Registry

func (*Registry) All

func (r *Registry) All() []Provider

func (*Registry) Get

func (r *Registry) Get(typ string) (Provider, bool)

type Resolver

type Resolver struct {
	Store       *Store
	Registry    *Registry
	Connections Connections
}

Resolver merges stored secrets with what bound managers return.

func (Resolver) FetchBinding

func (r Resolver) FetchBinding(ctx context.Context, b Binding) (map[string]string, error)

FetchBinding reads every key a binding's manager returns.

func (Resolver) Values

func (r Resolver) Values(ctx context.Context, chain []Scope) (map[string]string, error)

Values returns the secrets visible through a chain of scopes ordered from broadest to narrowest. A narrower scope overrides a broader one, and within a scope a stored secret overrides a bound manager.

type Rotation

type Rotation struct {
	Schedule string `json:"schedule"`
	Generator
}

Rotation regenerates a secret on a cron schedule.

type Scope

type Scope struct {
	Type ScopeType `json:"type"`
	ID   string    `json:"id"`
}

Scope is what a secret or binding belongs to. A service scope is written as deployment/service.

func ParseScope

func ParseScope(s string) (Scope, error)

func (Scope) Deployment

func (s Scope) Deployment() string

Deployment is the deployment a deployment or service scope belongs to.

func (Scope) String

func (s Scope) String() string

func (Scope) Validate

func (s Scope) Validate() error

type ScopeType

type ScopeType string
const (
	ScopeWorkspace  ScopeType = "workspace"
	ScopeDeployment ScopeType = "deployment"
	ScopeService    ScopeType = "service"
)

type Secret

type Secret struct {
	Name          string     `json:"name"`
	Scope         Scope      `json:"scope"`
	Version       int        `json:"version"`
	Rotation      *Rotation  `json:"rotation,omitempty"`
	LastRotatedAt *time.Time `json:"last_rotated_at,omitempty"`
	CreatedAt     time.Time  `json:"created_at"`
	UpdatedAt     time.Time  `json:"updated_at"`
}

Secret is a stored secret without its value. Values only leave the store through Value.

type Store

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

Store keeps secrets and bindings in one JSON file, with every value sealed by the keyring.

func NewStore

func NewStore(path string, keyring *Keyring) *Store

func (*Store) AddBinding

func (s *Store) AddBinding(b Binding) (*Binding, error)

func (*Store) Binding

func (s *Store) Binding(id string) (*Binding, error)

func (*Store) Bindings

func (s *Store) Bindings(scope Scope) ([]Binding, error)

func (*Store) ConnectionInUse

func (s *Store) ConnectionInUse(connectionID string) (bool, error)

ConnectionInUse reports whether any binding uses a connection.

func (*Store) Delete

func (s *Store) Delete(scope Scope, name string) error

func (*Store) DeleteBinding

func (s *Store) DeleteBinding(id string) error

func (*Store) DropScope

func (s *Store) DropScope(scope Scope) error

DropScope removes every secret and binding of a scope, for a deleted deployment or workspace.

func (*Store) Get

func (s *Store) Get(scope Scope, name string) (*Secret, error)

func (*Store) List

func (s *Store) List(scope Scope) ([]Secret, error)

func (*Store) Rotate

func (s *Store) Rotate(scope Scope, name string) (*Secret, error)

Rotate replaces a secret's value with a generated one, using its rotation settings or the default generator.

func (*Store) Rotating

func (s *Store) Rotating() ([]Secret, error)

Rotating lists every secret that has a rotation schedule.

func (*Store) Set

func (s *Store) Set(scope Scope, name, value string) (*Secret, error)

Set stores a value, creating the secret or raising its version.

func (*Store) SetRotation

func (s *Store) SetRotation(scope Scope, name string, rotation *Rotation) (*Secret, error)

SetRotation sets or clears how a secret rotates.

func (*Store) Values

func (s *Store) Values(scope Scope) (map[string]string, error)

Values returns the plain values of every secret in a scope.

type Vault

type Vault struct{ Client *http.Client }

Vault reads one secret from a KV version 2 engine. OpenBao serves the same API.

func (Vault) BindingFields

func (Vault) BindingFields() []Field

func (Vault) ConnectionFields

func (Vault) ConnectionFields() []Field

func (Vault) Fetch

func (p Vault) Fetch(ctx context.Context, creds, opts map[string]string) (map[string]string, error)

func (Vault) Label

func (Vault) Label() string

func (Vault) Type

func (Vault) Type() string

Jump to

Keyboard shortcuts

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