secrets

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 23 Imported by: 1 module, 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 CurrentEncryptionAlg = "aes-256-gcm-v1"

CurrentEncryptionAlg identifies the encryption scheme stored in Secret.Alg.

Variables

View Source
var (
	ErrSecretNotFound        = errors.New("secret not found")
	ErrDecryptionFailed      = errors.New("decryption failed")
	ErrEncryptionFailed      = errors.New("encryption failed")
	ErrInvalidConfig         = errors.New("invalid configuration")
	ErrInvalidSecretPath     = errors.New("invalid secret path")
	ErrEncryptFailed         = errors.New("encryption failed")
	ErrDecryptFailed         = errors.New("decryption failed")
	ErrDopplerNotConfigured  = errors.New("doppler integration not configured")
	ErrInvalidSecretFormat   = errors.New("invalid secret format")
	ErrUnsupportedPlatform   = errors.New("unsupported platform")
	ErrKeyGenerationFailed   = errors.New("key generation failed")
	ErrSecretAlreadyExists   = errors.New("secret already exists")
	ErrPermissionDenied      = errors.New("permission denied")
	ErrInvalidProvider       = errors.New("invalid secret provider")
	ErrProviderNotConfigured = errors.New("provider not configured")
	ErrConfigNotFound        = errors.New("configuration not found")
	ErrInvalidSecretName     = errors.New("invalid secret name")
	ErrReservedSecretName    = errors.New("reserved or system secret name")
)
View Source
var (
	SLogs = shared.PackageLogger("Secrets::", "🔐 Secrets Manager::")
)

Functions

func Decrypt

func Decrypt(ciphertext []byte, key []byte) ([]byte, error)

func DeriveKey

func DeriveKey(key string) ([]byte, error)

DeriveKey creates a SHA-256 hash of the provided key.

func Encrypt

func Encrypt(plaintext []byte, key []byte) ([]byte, error)

func ValidateSecretName added in v1.0.0

func ValidateSecretName(name string) error

ValidateSecretName enforces POSIX environment identifier rules and blocks reserved system, runtime, and internal NextDeploy secret keys.

Types

type ConfigFile

type ConfigFile struct {
	EncryptedPath string
	DecryptedPath string
	Content       []byte
}

type EnvFile

type EnvFile struct {
	EncryptedPath string
	DecryptedPath string
	Content       []byte
}

type Option

type Option func(*SecretManager)

func WithConfig

func WithConfig(cfg *config.NextDeployConfig) Option

func WithEnvFile added in v1.0.0

func WithEnvFile(path string) Option

WithEnvFile configures a dotenv file path to load when initializing SecretManager.

func WithKeyPath

func WithKeyPath(path string) Option

func WithProvider

func WithProvider(name string, provider SecretProvider) Option

type Secret

type Secret struct {
	Value       string `json:"value"`
	Version     int    `json:"version"`
	CreatedAt   int64  `json:"created_at"`
	ModifiedAt  int64  `json:"modified_at"`
	IsEncrypted bool   `json:"is_encrypted"`
	Alg         string `json:"alg,omitempty"`
	Salt        string `json:"salt,omitempty"`
	IV          string `json:"iv,omitempty"`
}

Secret represents a stored secret value and its encryption metadata.

type SecretManager

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

func NewSecretManager

func NewSecretManager(opts ...Option) (*SecretManager, error)

NewSecretManager creates and initializes a SecretManager with the given options.

func (*SecretManager) DecryptFile

func (sm *SecretManager) DecryptFile(filename string, key []byte) (string, error)

DecryptFile decrypts a .enc file produced by encryptToFile and returns the plaintext. A wrong key or any tampering surfaces as a decryption error (GCM authentication failure).

func (*SecretManager) EncryptEnvFile

func (sm *SecretManager) EncryptEnvFile(masterKey string) (map[string]string, error)

func (*SecretManager) EncryptFile

func (sm *SecretManager) EncryptFile(filename string, key []byte) error

func (*SecretManager) ExportSecrets

func (sm *SecretManager) ExportSecrets(filePath string) error

func (*SecretManager) FlattenSecrets

func (sm *SecretManager) FlattenSecrets() map[string]string

FlattenSecrets returns all secrets as a plain map[string]string, decrypting encrypted values in-place. Suitable for cloud injection.

func (*SecretManager) GenerateMasterKey

func (sm *SecretManager) GenerateMasterKey() ([]byte, error)

func (*SecretManager) GeneratePlatformKey

func (sm *SecretManager) GeneratePlatformKey() (string, error)

func (*SecretManager) GenerateWindowsKey

func (sm *SecretManager) GenerateWindowsKey() (string, error)

func (*SecretManager) GetAppName

func (sm *SecretManager) GetAppName() string

func (*SecretManager) GetDopplerProvider

func (sm *SecretManager) GetDopplerProvider() (SecretProvider, bool)

func (*SecretManager) GetKey

func (sm *SecretManager) GetKey() string

func (*SecretManager) GetKeyOsAgnosticPath

func (sm *SecretManager) GetKeyOsAgnosticPath() string

func (*SecretManager) GetSecret

func (sm *SecretManager) GetSecret(name string) (string, error)

GetSecret retrieves and decrypts a secret by name.

func (*SecretManager) ImportSecrets

func (sm *SecretManager) ImportSecrets(filePath string) error

func (*SecretManager) IsDopplerEnabled

func (sm *SecretManager) IsDopplerEnabled() bool

func (*SecretManager) IsKeyExist

func (sm *SecretManager) IsKeyExist() bool

func (*SecretManager) LoadEnvFile added in v1.0.0

func (sm *SecretManager) LoadEnvFile(path string) error

LoadEnvFile reads key/value pairs from a dotenv file and loads valid keys into the SecretManager without overwriting existing entries.

func (*SecretManager) MigrateToProvider

func (sm *SecretManager) MigrateToProvider(providerName string) error

MigrateToProvider exports all secrets into the named SecretProvider.

func (*SecretManager) PrepareSecretsContext

func (sm *SecretManager) PrepareSecretsContext() error

func (*SecretManager) RotateSecrets

func (sm *SecretManager) RotateSecrets() error

func (*SecretManager) SecureCompare

func (sm *SecretManager) SecureCompare(a, b string) bool

func (*SecretManager) SetSecret

func (sm *SecretManager) SetSecret(name, value string, encrypt bool) error

SetSecret validates the secret name and stores a new secret, optionally encrypting it at rest with per-secret encryption metadata.

func (*SecretManager) ValidateSecret

func (sm *SecretManager) ValidateSecret(name, value string) error

ValidateSecret validates a secret's name and minimum value length.

type SecretProvider

type SecretProvider interface {
	GetSecret(key string) (string, error)
	SetSecret(key, value string) error
	DeleteSecret(key string) error
	ListSecrets() ([]string, error)
	Encrypt(data []byte, key string) ([]byte, error)
	Decrypt(data []byte, key string) ([]byte, error)
	GenerateMasterKey() (string, error)
	DeriveKey(key string) ([]byte, error)
	ValidateSecretFormat(secret string) error
}

Jump to

Keyboard shortcuts

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