sops

package
v0.32.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 17 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

Index

Constants

View Source
const (
	AnnotationLab       = "claims.stuttgart-things.com/lab"
	AnnotationVaultPath = "claims.stuttgart-things.com/vault-path"
)

Annotations claims sets on the Secrets below secrets/ (plain metadata, not encrypted: encrypted_regex covers data/stringData only).

View Source
const ConfigFile = ".sops.yaml"

ConfigFile is the name of the sops config at the repository root.

View Source
const HashPrefixLen = 12

HashPrefixLen is how much of a hash claims prints.

Variables

View Source
var Binary = "sops"

Binary is the sops executable; a variable for tests.

View Source
var MinVersion = [3]int{3, 9, 0}

MinVersion is the oldest sops claims secret works with (--filename-override).

Functions

func CheckEncrypted added in v0.32.0

func CheckEncrypted(ciphertext []byte) error

CheckEncrypted verifies that every value under data and stringData of ciphertext is a sops ENC[...] value, so a .sops.yaml whose encrypted_regex misses them can never put plaintext into git.

func CheckSOPSAvailable

func CheckSOPSAvailable() (string, error)

CheckSOPSAvailable verifies that the sops binary is installed and the SOPS_AGE_RECIPIENTS environment variable is set. It returns the recipients string on success.

func CheckSOPSInstalled

func CheckSOPSInstalled() bool

CheckSOPSInstalled returns true if the sops binary is on PATH.

func Decrypt added in v0.32.0

func Decrypt(ctx context.Context, repoRoot, rel string) ([]byte, error)

Decrypt decrypts rel (relative to repoRoot) into memory.

func Encrypt

func Encrypt(plaintext []byte, recipients string) ([]byte, error)

Encrypt encrypts plaintext YAML using sops with age encryption. It writes the plaintext to a temporary file, runs sops --encrypt, and returns the encrypted output.

func EncryptFor added in v0.32.0

func EncryptFor(ctx context.Context, repoRoot, rel string, plaintext []byte, redact []string) ([]byte, error)

EncryptFor encrypts plaintext (YAML) for rel: sops reads it from stdin and takes the recipients from the creation rule of repoRoot's .sops.yaml that matches rel. redact lists the values in plaintext (kept out of errors).

func FileRecipients added in v0.32.0

func FileRecipients(encrypted []byte) []string

FileRecipients returns the age recipients in the sops metadata of an encrypted file (public keys, safe to print).

func GenerateSecretYAML

func GenerateSecretYAML(data SecretData) ([]byte, error)

GenerateSecretYAML produces a Kubernetes Secret manifest in YAML format.

func Hash added in v0.32.0

func Hash(v string) string

Hash is the hex sha256 of v.

func IsEncrypted added in v0.32.0

func IsEncrypted(data []byte) bool

IsEncrypted reports whether data carries sops metadata.

func Keys added in v0.32.0

func Keys(values map[string]string) []string

Keys returns the sorted keys of values.

func Rotate added in v0.32.0

func Rotate(ctx context.Context, repoRoot, rel string) error

Rotate generates a new data key for rel and re-encrypts it in place (sops rotate --in-place); the file never exists as plaintext.

func SameValues added in v0.32.0

func SameValues(a, b map[string]string) bool

SameValues reports whether a and b hold the same keys with the same values.

func ShortHash added in v0.32.0

func ShortHash(v string) string

ShortHash is the printed prefix of Hash(v).

func ShortRecipient added in v0.32.0

func ShortRecipient(r string) string

ShortRecipient abbreviates an age recipient for display: age1abcd…wxyz.

func UpdateKeys added in v0.32.0

func UpdateKeys(ctx context.Context, repoRoot, rel string) error

UpdateKeys re-wraps the data key of rel for the recipients .sops.yaml names now (sops updatekeys); it needs a key that can decrypt rel.

func ValidKey added in v0.32.0

func ValidKey(k string) error

ValidKey reports whether k may be a key of a Secret.

func Version added in v0.32.0

func Version(ctx context.Context) (string, error)

Version returns the version of the sops binary, e.g. "3.10.2".

func VersionAtLeast added in v0.32.0

func VersionAtLeast(v string, min [3]int) bool

VersionAtLeast reports whether v (x.y.z) is at least min.

func WriteFileAtomic added in v0.32.0

func WriteFileAtomic(path string, data []byte) error

WriteFileAtomic writes data (ciphertext) to path via a temporary file in the same directory and a rename.

Types

type AgeKeys added in v0.32.0

type AgeKeys struct {
	Source     string   // where they come from (an env var or a file), never the key
	Recipients []string // the public keys of the identities ("" when unknown)
	Opaque     bool     // SOPS_AGE_KEY_CMD: the keys cannot be inspected
}

AgeKeys describes the age identities sops would use to decrypt.

func FindAgeKeys added in v0.32.0

func FindAgeKeys() (*AgeKeys, error)

FindAgeKeys looks for the age identities the way sops does: SOPS_AGE_KEY, SOPS_AGE_KEY_FILE, SOPS_AGE_KEY_CMD, then the default key file. It returns their public keys so callers can check them against the recipients of a rule; the private keys stay in this function.

func (*AgeKeys) CanDecrypt added in v0.32.0

func (k *AgeKeys) CanDecrypt(recipients []string) (ok, known bool)

CanDecrypt reports whether one of the keys is among recipients; unknown (true, false) for SOPS_AGE_KEY_CMD.

type Config added in v0.32.0

type Config struct {
	Path  string
	Rules []Rule
}

Config is a parsed .sops.yaml.

func LoadConfig added in v0.32.0

func LoadConfig(repoRoot string) (*Config, error)

LoadConfig reads <repoRoot>/.sops.yaml. claims does not walk up from the file like sops can: the rules for secrets/ belong at the repository root, where sops (run there) finds them too.

func (*Config) RuleFor added in v0.32.0

func (c *Config) RuleFor(rel string) (*Rule, error)

RuleFor returns the rule sops applies to rel (slash-separated, relative to the repository root): the first one whose path_regex matches. A rule without path_regex matches everything, as in sops. No match is an error: claims never guesses recipients.

func (*Config) SharedRecipients added in v0.32.0

func (c *Config) SharedRecipients() []string

SharedRecipients returns the recipients common to every per-lab rule (path_regex secrets/<lab>/...): with two or more lab rules, these are the offline recovery recipient(s). Catch-all rules for other files below secrets/ do not count. nil when there are fewer than two lab rules.

type Manifest added in v0.32.0

type Manifest struct {
	Metadata map[string]any
	Type     string
	Values   map[string]string
}

Manifest is a Kubernetes Secret as claims secret reads and writes it. Values are kept as strings; data (base64) is decoded on read and written back as stringData, the canonical form of files below secrets/.

func NewManifest added in v0.32.0

func NewManifest(name, namespace string, annotations map[string]string) *Manifest

NewManifest returns an Opaque Secret name/namespace with annotations.

func ParseManifest added in v0.32.0

func ParseManifest(plaintext []byte) (*Manifest, error)

ParseManifest parses decrypted YAML of a Secret.

func (*Manifest) Marshal added in v0.32.0

func (m *Manifest) Marshal() ([]byte, error)

Marshal renders the Secret with all values as stringData.

func (*Manifest) Name added in v0.32.0

func (m *Manifest) Name() string

Name is metadata.name.

func (*Manifest) Namespace added in v0.32.0

func (m *Manifest) Namespace() string

Namespace is metadata.namespace.

func (*Manifest) SecretValues added in v0.32.0

func (m *Manifest) SecretValues() []string

SecretValues lists the values (for redaction).

type Rule added in v0.32.0

type Rule struct {
	Index          int // position in creation_rules
	PathRegex      string
	EncryptedRegex string
	Age            []string // recipients, from age: or key_groups[].age
	// contains filtered or unexported fields
}

Rule is one creation rule of .sops.yaml (the parts claims reads).

func (*Rule) Has added in v0.32.0

func (r *Rule) Has(recipient string) bool

Has reports whether r encrypts for recipient.

type SecretData

type SecretData struct {
	Name       string
	Namespace  string
	StringData map[string]string
}

SecretData holds the data needed to generate a Kubernetes Secret YAML.

Directories

Path Synopsis
Package sopstest sets up throwaway age keys and a .sops.yaml for tests.
Package sopstest sets up throwaway age keys and a .sops.yaml for tests.

Jump to

Keyboard shortcuts

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