vault

package
v1.286.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VaultSecretNamespace = "codesphere"
	VaultSecretName      = "cs-vault"
)

Variables

This section is empty.

Functions

func DecryptFileWithSOPS

func DecryptFileWithSOPS(src, keyPath string) ([]byte, error)

DecryptFileWithSOPS decrypts a SOPS-encrypted file and returns the plaintext bytes. If keyPath is non-empty, SOPS_AGE_KEY_FILE is set for the sops process.

func EncryptFileWithSOPS

func EncryptFileWithSOPS(src, target, recipient string) error

EncryptFileWithSOPS encrypts src with SOPS+age and writes ciphertext to target.

func IsSOPSEncryptedFile

func IsSOPSEncryptedFile(path string) (bool, error)

IsSOPSEncryptedFile checks whether the file at path is a SOPS-encrypted YAML document.

func LoadUnencryptedVaultData added in v1.261.1

func LoadUnencryptedVaultData(vaultPath string) (*files.InstallVault, error)

LoadUnencryptedVaultData reads parses an unencrypted vault at vaultPath returning the decoded install vault. This is only used for GCP Bootstrapping. All other features should force a decrypted vault.

func LoadVaultData

func LoadVaultData(vaultPath, ageKeyPath string) (*files.InstallVault, error)

LoadVaultData reads, SOPS-decrypts, and parses the vault at vaultPath using the age key at ageKeyPath, returning the decoded install vault.

func ResolveAgeKey

func ResolveAgeKey(explicitKeyFile, fallbackDir string) (recipient string, keyPath string, err error)

ResolveAgeKey resolves an existing age key or generates a new one.

When explicitKeyFile is non-empty it takes priority over everything else: the recipient is read directly from that file and it is returned as the key path. This lets callers thread an explicit --age-key-file through without mutating the process environment.

Otherwise it checks (in order):

  1. SOPS_AGE_KEY environment variable (raw key content)
  2. SOPS_AGE_KEY_FILE environment variable (path to key file)
  3. Default location: ~/.config/sops/age/keys.txt
  4. Generate a new key and write it to <fallbackDir>/age_key.txt

Returns the age public key (recipient) and the path to the key file (empty when the key was supplied via SOPS_AGE_KEY).

Types

type AgeKeyResolver added in v1.284.1

type AgeKeyResolver interface {
	Resolve(explicitKeyFile, fallbackDir string) (recipient, keyPath string, err error)
}

AgeKeyResolver finds the age recipient used to encrypt a vault.

type DefaultAgeKeyResolver added in v1.284.1

type DefaultAgeKeyResolver struct{}

DefaultAgeKeyResolver resolves age keys from the standard SOPS locations.

func (DefaultAgeKeyResolver) Resolve added in v1.284.1

func (DefaultAgeKeyResolver) Resolve(explicitKeyFile, fallbackDir string) (recipient, keyPath string, err error)

type Encryptor added in v1.284.1

type Encryptor interface {
	Encrypt(src, target, recipient string) error
}

Encryptor encrypts a plaintext vault for an age recipient.

type MockAgeKeyResolver added in v1.284.1

type MockAgeKeyResolver struct {
	mock.Mock
}

MockAgeKeyResolver is an autogenerated mock type for the AgeKeyResolver type

func NewMockAgeKeyResolver added in v1.284.1

func NewMockAgeKeyResolver(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockAgeKeyResolver

NewMockAgeKeyResolver creates a new instance of MockAgeKeyResolver. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockAgeKeyResolver) EXPECT added in v1.284.1

func (*MockAgeKeyResolver) Resolve added in v1.284.1

func (_mock *MockAgeKeyResolver) Resolve(explicitKeyFile string, fallbackDir string) (string, string, error)

Resolve provides a mock function for the type MockAgeKeyResolver

type MockAgeKeyResolver_Expecter added in v1.284.1

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

func (*MockAgeKeyResolver_Expecter) Resolve added in v1.284.1

func (_e *MockAgeKeyResolver_Expecter) Resolve(explicitKeyFile any, fallbackDir any) *MockAgeKeyResolver_Resolve_Call

Resolve is a helper method to define mock.On call

  • explicitKeyFile string
  • fallbackDir string

type MockAgeKeyResolver_Resolve_Call added in v1.284.1

type MockAgeKeyResolver_Resolve_Call struct {
	*mock.Call
}

MockAgeKeyResolver_Resolve_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Resolve'

func (*MockAgeKeyResolver_Resolve_Call) Return added in v1.284.1

func (*MockAgeKeyResolver_Resolve_Call) Run added in v1.284.1

func (_c *MockAgeKeyResolver_Resolve_Call) Run(run func(explicitKeyFile string, fallbackDir string)) *MockAgeKeyResolver_Resolve_Call

func (*MockAgeKeyResolver_Resolve_Call) RunAndReturn added in v1.284.1

func (_c *MockAgeKeyResolver_Resolve_Call) RunAndReturn(run func(explicitKeyFile string, fallbackDir string) (string, string, error)) *MockAgeKeyResolver_Resolve_Call

type MockEncryptor added in v1.284.1

type MockEncryptor struct {
	mock.Mock
}

MockEncryptor is an autogenerated mock type for the Encryptor type

func NewMockEncryptor added in v1.284.1

func NewMockEncryptor(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockEncryptor

NewMockEncryptor creates a new instance of MockEncryptor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockEncryptor) EXPECT added in v1.284.1

func (_m *MockEncryptor) EXPECT() *MockEncryptor_Expecter

func (*MockEncryptor) Encrypt added in v1.284.1

func (_mock *MockEncryptor) Encrypt(src string, target string, recipient string) error

Encrypt provides a mock function for the type MockEncryptor

type MockEncryptor_Encrypt_Call added in v1.284.1

type MockEncryptor_Encrypt_Call struct {
	*mock.Call
}

MockEncryptor_Encrypt_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Encrypt'

func (*MockEncryptor_Encrypt_Call) Return added in v1.284.1

func (*MockEncryptor_Encrypt_Call) Run added in v1.284.1

func (_c *MockEncryptor_Encrypt_Call) Run(run func(src string, target string, recipient string)) *MockEncryptor_Encrypt_Call

func (*MockEncryptor_Encrypt_Call) RunAndReturn added in v1.284.1

func (_c *MockEncryptor_Encrypt_Call) RunAndReturn(run func(src string, target string, recipient string) error) *MockEncryptor_Encrypt_Call

type MockEncryptor_Expecter added in v1.284.1

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

func (*MockEncryptor_Expecter) Encrypt added in v1.284.1

func (_e *MockEncryptor_Expecter) Encrypt(src any, target any, recipient any) *MockEncryptor_Encrypt_Call

Encrypt is a helper method to define mock.On call

  • src string
  • target string
  • recipient string

type SOPSEncryptor added in v1.284.1

type SOPSEncryptor struct{}

SOPSEncryptor encrypts vaults using SOPS and age.

func (SOPSEncryptor) Encrypt added in v1.284.1

func (SOPSEncryptor) Encrypt(src, target, recipient string) error

type VaultSecretCreator

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

func NewVaultSecretCreator

func NewVaultSecretCreator(c client.Client) *VaultSecretCreator

func (*VaultSecretCreator) CreateSecretFromFile

func (v *VaultSecretCreator) CreateSecretFromFile(ctx context.Context, vaultFile, ageKeyPath, namespace, secretName string) error

CreateSecretFromFile decrypts a SOPS-encrypted vault file and creates or updates a Kubernetes secret with its contents in the target cluster.

Each vault entry is mapped to one or more secret keys:

  • File entries produce a single key equal to the entry name.
  • Field entries produce "entryName.password" and, when present, "entryName.username".

func (*VaultSecretCreator) CreateSecretFromVault

func (v *VaultSecretCreator) CreateSecretFromVault(ctx context.Context, vault *files.InstallVault, namespace, secretName string) error

CreateSecretFromVault creates or updates a Kubernetes secret with the contents of a Vault in the target cluster.

Each vault entry is mapped to one or more secret keys:

  • File entries produce a single key equal to the entry name.
  • Field entries produce "entryName.password" and, when present, "entryName.username".

type VaultTemplatingSecretStore

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

VaultTemplatingSecretStore resolves secrets referenced from config templates against a SOPS-encrypted install vault. The vault can either be provided directly or loaded lazily from disk on first lookup.

func NewLazyVaultTemplatingSecretStore

func NewLazyVaultTemplatingSecretStore(vaultPath, ageKeyPath string) *VaultTemplatingSecretStore

NewLazyVaultTemplatingSecretStore returns a store that decrypts and loads the vault from vaultPath using ageKeyPath on the first secret lookup.

func NewVaultTemplatingSecretStore

func NewVaultTemplatingSecretStore(vault *files.InstallVault) *VaultTemplatingSecretStore

NewVaultTemplatingSecretStore returns a store backed by an already-decrypted vault.

func NewVaultTemplatingSecretStoreFromFile

func NewVaultTemplatingSecretStoreFromFile(vaultPath, ageKeyPath string) (*VaultTemplatingSecretStore, error)

NewVaultTemplatingSecretStoreFromFile decrypts and loads the vault from vaultPath using ageKeyPath and returns a store backed by it.

func (*VaultTemplatingSecretStore) LookupSecret

func (s *VaultTemplatingSecretStore) LookupSecret(name string, selector ...string) (string, error)

LookupSecret returns the value of the named secret, optionally narrowed by a field selector (e.g. "password", "file.content"). The vault is loaded lazily on first use when the store was created without a preloaded vault.

Jump to

Keyboard shortcuts

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