secrets

package
v0.9.13 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT 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 keeps the values services are given as environment variables (API keys and the like) out of their manifests, in a store an admin can rotate from the portal or the CLI.

A secret has a name, the environment variable it's handed over as, and a value. It reaches a service through a binding: to that service by name, or to every service. A service-bound secret wins over a global one for the same variable, so one app can be given its own key while the rest share one.

secrets.db is, like auth.db, authoritative: nothing can rebuild it, which is why it is its own file rather than part of state.db. Values are sealed with AES-256-GCM under a key kept beside it in secrets.key, so a copy of the database on its own (a stray backup, a file attached to a bug report) doesn't give them away. Anyone who can read both files as the operator can read every value, and so can every service, which runs as the operator too: this is for keeping keys out of manifests and making rotation easy, not a boundary between local processes.

Index

Constants

View Source
const (
	MaxValue = 64 << 10
)

Limits on what can be stored.

Variables

View Source
var (
	ErrNotFound = errors.New("no such secret")
	ErrExists   = errors.New("a secret with that name already exists")
)

Errors a caller may want to tell apart.

Functions

func DefaultEnv

func DefaultEnv(name string) string

DefaultEnv is the variable a secret is handed over as when none is given: its name in upper case, with '-' and '.' as '_'.

func ValidEnv

func ValidEnv(env string) error

ValidEnv checks the variable a secret is handed over as.

func ValidName

func ValidName(name string) error

ValidName checks a secret's name: lower case, as a service's is.

func ValidValue

func ValidValue(v string) error

ValidValue checks a secret's value. A NUL can't be passed in the environment at all.

Types

type Secret

type Secret struct {
	Name      string
	Env       string
	Revision  int64
	CreatedAt time.Time
	UpdatedAt time.Time
	// Global is whether it's bound to every service.
	Global bool
	// Services are the services it's bound to by name, sorted.
	Services []string
}

Secret is a secret as anyone outside this package sees it: never its value.

type Store

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

Store is the secrets database. It is safe for concurrent use. It keeps every secret in memory, decrypted, so the reconcile loop can ask about a service on every tick without touching the disk.

func Open

func Open(path, keyPath string) (*Store, error)

Open opens (creating if needed) the database at path and its key at keyPath. A database with sealed values and no key is refused rather than given a new key, which would lose them for good.

func (*Store) Bind

func (s *Store) Bind(name, service string) (Secret, error)

Bind hands the secret to service, or to every service when service is "". Two secrets for the same variable can't be bound at the same level: which one a service got would be a coin toss.

func (*Store) Close

func (s *Store) Close() error

Close closes the database.

func (*Store) Create

func (s *Store) Create(name, env, value string) (Secret, error)

Create adds a secret, bound to nothing yet.

func (*Store) Delete

func (s *Store) Delete(name string) (Secret, error)

Delete removes a secret and its bindings, and reports the services that had it, which lose it at their next restart (made at once by the supervisor).

func (*Store) Get

func (s *Store) Get(name string) (Secret, bool)

Get returns a secret by name, without its value.

func (*Store) List

func (s *Store) List() []Secret

List returns every secret, by name, without values.

func (*Store) Reaches

func (s *Store) Reaches(name string, services []string) []string

Reaches returns the services, among those given, that get the secret: the ones a change to it restarts. A service whose own secret shadows a global one for the same variable isn't counted.

func (*Store) Resolve

func (s *Store) Resolve(service string) (map[string]string, string)

Resolve returns the variables service is given, and a revision that changes whenever any of them would: a value rotated, a binding added or removed. The revision is a hash of names and counters, never of a value, so it can be logged or stored.

func (*Store) Rotate

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

Rotate replaces a secret's value. Every service it reaches is restarted with the new one by the supervisor, which sees the revision change.

func (*Store) Unbind

func (s *Store) Unbind(name, service string) (Secret, error)

Unbind takes the secret away from service, or from every service when service is "" (its by-name bindings stay).

func (*Store) Value added in v0.6.0

func (s *Store) Value(name string) (string, bool)

Value returns a secret's value, for the daemon's own use: the AI endpoint's keys for hosted providers, which it sends on each request and no app is given. Nothing on the control socket or the portal calls it, so a value still can't be read back out of the daemon.

Jump to

Keyboard shortcuts

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