secrets

package
v0.0.0-...-ec0f628 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const CurrentSecretsSchemaVersion = 0

CurrentSecretsSchemaVersion is the highest secrets.yaml schema version this build understands. A store with no `schemaVersion` field is treated as version 0 (the original, current format). When a future format bumps this, OLDER binaries (which carry a lower CurrentSecretsSchemaVersion) refuse to read it — see the guard in unmarshalSecretsFile — instead of silently dropping the new fields on the next write. This reader must therefore ship and roll out fleet-wide BEFORE any higher-versioned store is ever written.

View Source
const EncryptedSecretFilesDataFileName = "secrets.yaml"

Variables

View Source
var ErrSecretsStoreVersionUnsupported = errors.New("unsupported secrets store version")

ErrSecretsStoreVersionUnsupported is returned when the on-disk store declares a schema version newer than CurrentSecretsSchemaVersion. It MUST stay fatal on every read path — including ones that otherwise tolerate a missing/uninitialized store (root_cmd's IgnoreConfigDirError) — because reading a too-new store as empty and then writing would clobber it. Detect it with errors.Is.

Functions

func IsUnsupportedStoreVersion

func IsUnsupportedStoreVersion(err error) bool

IsUnsupportedStoreVersion reports whether err indicates the on-disk secrets store declares a newer schema version than this build understands. Read paths that otherwise tolerate a missing/uninitialized store (the CLI's IgnoreConfigDirError, the GitHub Actions "no client secrets -> use parent" fallbacks) MUST treat a true result as FATAL and never swallow it as "no secrets" — ignoring a too-new store risks a later write clobbering it.

func TrimPrivKey

func TrimPrivKey(privKey string) string

func TrimPubKey

func TrimPubKey(pubKey string) string

TrimPubKey normalizes SSH public keys by ignoring aliases/comments SSH keys have format: <key-type> <key-data> optional-comment/alias We only keep the key-type and key-data parts to ensure keys with different aliases but same key data are treated identically for encryption/decryption

Types

type Cryptor

type Cryptor interface {
	GenerateKeyPairWithProfile(projectName, profile string) error
	GenerateEd25519KeyPairWithProfile(projectName, profile string) error
	ReadProfileConfig() error
	AddFile(path string) error
	RemoveFile(path string) error
	DecryptAll(forceChanged bool) error
	EncryptChanged(force bool, forceChanged bool) error
	ReadSecretFiles() error
	MarshalSecretsFile() error
	GetSecretFiles() EncryptedSecretFiles
	GetAndDecryptFileContent(relPath string) ([]byte, error)
	PublicKey() string
	PrivateKey() string
	Workdir() string
	// AddPublicKey allow another public key to encrypt secrets
	AddPublicKey(pubKey string) error
	// RemovePublicKey remove public key from encrypting secrets
	RemovePublicKey(pubKey string) error
	// GetKnownPublicKeys return all public keys
	GetKnownPublicKeys() []string

	Options() []Option
	GitRepo() git.Repo
}

func NewCryptor

func NewCryptor(workDir string, opts ...Option) (Cryptor, error)

type EncryptedSecretFile

type EncryptedSecretFile struct {
	Path          string   `json:"path" yaml:"path"`
	EncryptedData []string `json:"encryptedData" yaml:"encryptedData"`
}

type EncryptedSecretFiles

type EncryptedSecretFiles struct {
	// SchemaVersion is the secrets.yaml schema version. Absent/0 = the original
	// format. A reader refuses any value above CurrentSecretsSchemaVersion (fail-closed).
	SchemaVersion int                         `json:"schemaVersion,omitempty" yaml:"schemaVersion,omitempty"`
	Registry      Registry                    `json:"registry" yaml:"registry"`
	Secrets       map[string]EncryptedSecrets `json:"secrets" yaml:"secrets"`
}

type EncryptedSecrets

type EncryptedSecrets struct {
	Files     []EncryptedSecretFile `json:"secrets" yaml:"secrets"`
	PublicKey SshKey                `json:"publicKeys" yaml:"publicKeys"`

	// not to be serialized
	PrivateKey SshKey `json:"-" yaml:"-"`
}

func (*EncryptedSecrets) AddFileIfNotExist

func (es *EncryptedSecrets) AddFileIfNotExist(f EncryptedSecretFile)

func (*EncryptedSecrets) GetEncryptedContent

func (es *EncryptedSecrets) GetEncryptedContent(path string) []string

func (*EncryptedSecrets) RemoveFile

func (es *EncryptedSecrets) RemoveFile(f EncryptedSecretFile)

type Option

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

func WithConfirmationReader

func WithConfirmationReader(reader util.ConsoleReader) Option

func WithConsoleReader

func WithConsoleReader(reader util.ConsoleReader) Option

func WithConsoleWriter

func WithConsoleWriter(writer util.ConsoleWriter) Option

func WithDetectGitDir

func WithDetectGitDir() Option

func WithGeneratedEd25519Keys

func WithGeneratedEd25519Keys(projectName, profile string) Option

func WithGeneratedKeys

func WithGeneratedKeys(projectName, profile string) Option

func WithGitRepo

func WithGitRepo(gitRepo git.Repo) Option

func WithKeysFromCurrentProfile

func WithKeysFromCurrentProfile() Option

func WithKeysFromScConfig

func WithKeysFromScConfig(profile string) Option

func WithPrivateKey

func WithPrivateKey(key string) Option

func WithPrivateKeyPath

func WithPrivateKeyPath(filePath string) Option

func WithProfile

func WithProfile(profile string) Option

func WithPublicKey

func WithPublicKey(key string) Option

func WithPublicKeyPath

func WithPublicKeyPath(filePath string) Option

func WithWorkDir

func WithWorkDir(wd string) Option

type Registry

type Registry struct {
	Files []string `json:"files" yaml:"files"`
}

type SshKey

type SshKey struct {
	Data []byte `json:"data" yaml:"data"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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