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
- Variables
- func DefaultEnv(name string) string
- func ValidEnv(env string) error
- func ValidName(name string) error
- func ValidValue(v string) error
- type Secret
- type Store
- func (s *Store) Bind(name, service string) (Secret, error)
- func (s *Store) Close() error
- func (s *Store) Create(name, env, value string) (Secret, error)
- func (s *Store) Delete(name string) (Secret, error)
- func (s *Store) Get(name string) (Secret, bool)
- func (s *Store) List() []Secret
- func (s *Store) Reaches(name string, services []string) []string
- func (s *Store) Resolve(service string) (map[string]string, string)
- func (s *Store) Rotate(name, value string) (Secret, error)
- func (s *Store) Unbind(name, service string) (Secret, error)
- func (s *Store) Value(name string) (string, bool)
Constants ¶
const (
MaxValue = 64 << 10
)
Limits on what can be stored.
Variables ¶
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 ¶
DefaultEnv is the variable a secret is handed over as when none is given: its name in upper case, with '-' and '.' as '_'.
func ValidValue ¶
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 ¶
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 ¶
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) Delete ¶
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) Reaches ¶
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 ¶
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 ¶
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 ¶
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
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.