secrets

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: GPL-3.0, LGPL-3.0 Imports: 20 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 decrypts the age encrypted files a site keeps beside its configuration.

Plaintext is returned in memory and streamed to wherever it is needed. It is never written to the workstation's disk, which is what the exec wrappers of the shell toolkit were careful about and what this package keeps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(path string, identities []age.Identity) ([]byte, error)

Decrypt reads an age encrypted file and returns its plaintext.

func DecryptSops

func DecryptSops(data []byte, keys SopsKeys, sections []string) (values map[string]map[string]string, err error)

DecryptSops decrypts a sops encrypted YAML file into memory and returns the values of the given top level mappings, by key.

A file encrypted to a kind of master key keys.Types does not trust is refused before any key is tried. The data key is recovered with the age identities of keys.Identities first, which are the ones workstation.identities names, and then, with keys.Discover, with whatever sops itself finds, age and PGP keys before any service. The integrity of the whole file is verified before anything is returned.

The values are read from the decrypted tree as sops holds it, never written out and parsed again, and no error says anything of them.

func DecryptString

func DecryptString(path string, identities []age.Identity) (string, error)

DecryptString decrypts a file whose content is one line, such as a password, and returns it without the trailing newline.

func DefaultSopsKeyTypes added in v0.3.0

func DefaultSopsKeyTypes() []string

DefaultSopsKeyTypes are the kinds of master key trusted when the workstation names none: age, which needs nothing but a local identity.

func Identities

func Identities(paths []string) ([]age.Identity, error)

Identities loads the age identities used to decrypt.

A file may hold age identities or an OpenSSH private key; both are accepted, because a site usually already has ssh keys and no reason to issue a second kind.

func SopsValueType added in v0.3.0

func SopsValueType(s string) (string, bool)

SopsValueType returns the type sops recorded for an encrypted value, and whether the value is one sops encrypted at all.

sops parses the plaintext as this type after decrypting it, but the type is outside what the encryption authenticates: anyone who can write the file can change it, and the parser's error then quotes the plaintext. Only "str" is read.

Types

type SopsInfo

type SopsInfo struct {
	// Keys are the master keys the data key is encrypted to, as sops names
	// their type ("age", "pgp", "kms", "gcp_kms", "azure_kv", "hc_vault")
	// and the key itself, for example an age recipient or a key ARN.
	Keys []SopsKey
	// Groups is the number of key groups, Threshold the number of them
	// needed to recover the data key when there are several.
	Groups    int
	Threshold int
	// LastModified is when sops last wrote the file.
	LastModified time.Time
	// EncryptedRegex is the rule that chose which values were encrypted.
	EncryptedRegex string
}

SopsInfo describes a sops encrypted document, read without decrypting it.

func InspectSops

func InspectSops(data []byte) (SopsInfo, error)

InspectSops reads the sops metadata of a YAML file without decrypting anything, so that a damaged or hand edited file is reported when the configuration loads rather than when a node is half way through a reinstall.

func (SopsInfo) CheckKeyTypes added in v0.3.0

func (i SopsInfo) CheckKeyTypes(trusted []string) error

CheckKeyTypes refuses a document encrypted to a kind of master key that is not trusted here. The metadata that names the keys is not covered by the message authentication code, so anyone who can write the file can add a Vault or a key management service there, and sops would send this machine's credentials to it.

func (SopsInfo) Summary

func (i SopsInfo) Summary() string

Summary counts the master keys per type, for example "2 age, 1 pgp".

type SopsKey

type SopsKey struct {
	Type string
	ID   string
}

SopsKey is one master key of a sops encrypted document.

type SopsKeys added in v0.3.0

type SopsKeys struct {
	// Identities are the age identities of workstation.identities. They
	// are tried first.
	Identities []age.Identity
	// Discover lets sops look for keys itself as well: SOPS_AGE_KEY_FILE
	// and its other variables, ~/.config/sops/age/keys.txt, a PGP agent,
	// the credentials of a cloud key management service or Vault. That can
	// run a program or ask for a passphrase, so it is for a terminal only.
	Discover bool
	// Types are the kinds of master key trusted, DefaultSopsKeyTypes when
	// empty. A file encrypted to any other kind is refused.
	Types []string
}

SopsKeys says which keys may open a sops file.

Directories

Path Synopsis
Package sopstest writes sops encrypted files for tests, the way "sops --encrypt --encrypted-regex '^(data|binaryData)$'" writes them, so that no test depends on a sops binary or on a private key kept in the repository.
Package sopstest writes sops encrypted files for tests, the way "sops --encrypt --encrypted-regex '^(data|binaryData)$'" writes them, so that no test depends on a sops binary or on a private key kept in the repository.

Jump to

Keyboard shortcuts

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