secrets

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 19 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 an app's secrets (contract.md section 9.5): API tokens and anything else that may not sit in plain text. One file, `<Config>/secrets.enc`, holds every name and value, encrypted with AES-256-GCM under a key derived with HKDF-SHA256 from a random key file next to it (`<Config>/secrets.key`, made on the first Save), this machine's id (`/etc/machine-id` on Linux, `IOPlatformUUID` on macOS) and the app's pepper, a string in the app's source. Both files are 0600 and written through atomicfile, so a reader sees the old file or the new one. The two files copied to another machine do not open there: the user enters the secrets again.

What it protects against: secrets.enc alone is useless, and with the key file it opens only where the machine id matches, so a copy of the Config directory does not open elsewhere. What it does not: any process running as the user on that machine can decrypt if it also has the pepper, and so can anyone holding the key file, the machine id (a full-disk backup holds both) and the pepper. The pepper is a secret for a private repo, obscurity for a public one: a scanner that knows this scheme also needs the private app's source or its binary, while a public app's pepper is only a label that keeps one app's key apart from another's.

Open registers the doctor section "secrets" with the names only, never the values.

Index

Constants

View Source
const (
	FileName    = "secrets.enc"
	KeyFileName = "secrets.key"
)

The two files inside the Config directory.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

Store is the app's secrets file. Calls on one Store are serialized; two processes writing the same file both write a whole file, and the last one wins.

func Open

func Open(id identity.Identity, pepper string) *Store

Open gives the store of id's Config directory and registers its doctor section. It reads nothing until the first call. pepper is mixed into the key: any string is accepted, the empty one too, and a store saved with one pepper does not open with another.

func (*Store) Delete

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

Delete removes name. A name that is not stored is not an error.

func (*Store) Load

func (s *Store) Load(name string) (string, error)

Load returns the value stored under name; an unknown name is a not_found failure.

func (*Store) Names

func (s *Store) Names() ([]string, error)

Names lists the stored names, sorted.

func (*Store) Save

func (s *Store) Save(name, value string) error

Save stores value under name, replacing an older value. The first Save makes the key file. An empty name is a usage failure.

Jump to

Keyboard shortcuts

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