vault

package
v0.49.3 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScopeUser        = "user"
	ScopeUserAgent   = "user_agent"
	ScopeSystem      = "system"
	ScopeSystemAgent = "system_agent"
)
View Source
const StellaTokenName = "STELLA_TOKEN"

StellaTokenName is the per-user service token exposed to sandbox sessions.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(masterIdentity *age.X25519Identity, encryptedPrivateKey string, ciphertext string) (string, error)

Decrypt decrypts ciphertext that was encrypted with a user's public key. First decrypts the user's private key using the master identity, then uses that private key to decrypt the ciphertext. masterIdentity: the server's master age identity encryptedPrivateKey: the user's age private key, encrypted with master ciphertext: the age-encrypted secret value

func Encrypt

func Encrypt(publicKeyStr string, plaintext string) (string, error)

Encrypt encrypts plaintext using the given public key string. Returns armored ciphertext.

func GenerateMasterIdentity added in v0.35.2

func GenerateMasterIdentity() (string, error)

func GenerateUserKeys

func GenerateUserKeys(masterRecipient *age.X25519Recipient) (string, string, error)

GenerateUserKeys creates a new X25519 keypair for a user. The private key is encrypted with masterRecipient before returning. Returns (publicKeyString, encryptedPrivateKey, error). publicKeyString is the age public key string (age1...). encryptedPrivateKey is the armored age-encrypted private key.

func IsAgentScope added in v0.48.0

func IsAgentScope(scope string) bool

func ParseMasterIdentity

func ParseMasterIdentity(identityStr string) (*age.X25519Identity, *age.X25519Recipient, error)

ParseMasterIdentity parses an age identity string (e.g. "AGE-SECRET-KEY-1...") and returns both the identity (for decryption) and its recipient (for encryption).

func ValidateName

func ValidateName(name string) error

ValidateName checks that a vault entry name is a valid env var name and is not reserved.

Types

type DB

type DB interface {
	GetVaultUser(ctx context.Context, id string) (sqlc.VaultUser, error)
	GetVaultEntryByScope(ctx context.Context, arg sqlc.GetVaultEntryByScopeParams) (sqlc.VaultEntry, error)
	ListVaultEntriesByScope(ctx context.Context, arg sqlc.ListVaultEntriesByScopeParams) ([]sqlc.VaultEntry, error)
	ListVaultEntriesForRuntime(ctx context.Context, arg sqlc.ListVaultEntriesForRuntimeParams) ([]sqlc.VaultEntry, error)
	UpsertVaultEntryByScope(ctx context.Context, arg sqlc.UpsertVaultEntryByScopeParams) error
	DeleteVaultEntryByScope(ctx context.Context, arg sqlc.DeleteVaultEntryByScopeParams) error
}

DB is the minimal database interface the vault Service requires.

type EntryMeta

type EntryMeta struct {
	Scope     string
	UserID    string
	AgentID   string
	Name      string
	CreatedAt string
	UpdatedAt string
}

EntryMeta holds non-sensitive metadata for a vault entry.

type Service

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

Service provides vault operations: storing, retrieving, and decrypting secrets using user-level or system-level age encryption.

func NewService

func NewService(db DB, masterIdentityStr string) (*Service, error)

NewService creates a vault Service. masterIdentityStr is the raw age secret key string (typically from the STELLA_VAULT_KEY environment variable).

func (*Service) DecryptSystem added in v0.27.0

func (s *Service) DecryptSystem(ciphertext string) (string, error)

DecryptSystem decrypts ciphertext that was produced by EncryptSystem.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, userID string, name string) error

Delete removes a user-level vault entry by name for the given user.

func (*Service) DeleteScoped added in v0.48.0

func (s *Service) DeleteScoped(ctx context.Context, scope string, userID string, agentID string, name string) error

DeleteScoped removes a user-owned vault entry by name and scope.

func (*Service) DeleteSystemScoped added in v0.48.0

func (s *Service) DeleteSystemScoped(ctx context.Context, scope string, agentID string, name string) error

DeleteSystemScoped removes an admin-managed vault entry by name and scope.

func (*Service) EncryptSystem added in v0.27.0

func (s *Service) EncryptSystem(plaintext string) (string, error)

EncryptSystem encrypts plaintext with the master key for system-level storage (not tied to any user).

func (*Service) Get

func (s *Service) Get(ctx context.Context, userID string, name string) (string, error)

Get decrypts and returns the plaintext value of a single user-level vault entry by name.

func (*Service) GetMeta added in v0.38.0

func (s *Service) GetMeta(ctx context.Context, userID string, name string) (EntryMeta, error)

GetMeta returns non-sensitive metadata for a single user-level vault entry by name.

func (*Service) GetScoped added in v0.48.0

func (s *Service) GetScoped(ctx context.Context, scope string, userID string, agentID string, name string) (string, error)

GetScoped decrypts and returns one scoped vault entry by name.

func (*Service) GetScopedMeta added in v0.48.0

func (s *Service) GetScopedMeta(ctx context.Context, scope string, userID string, agentID string, name string) (EntryMeta, error)

GetScopedMeta returns non-sensitive metadata for a single scoped vault entry by name.

func (*Service) List

func (s *Service) List(ctx context.Context, userID string) ([]EntryMeta, error)

func (*Service) ListScoped added in v0.48.0

func (s *Service) ListScoped(ctx context.Context, scope string, userID string, agentID string) ([]EntryMeta, error)

ListScoped returns metadata for all user-owned vault entries in one effective scope.

func (*Service) ListSystemScoped added in v0.48.0

func (s *Service) ListSystemScoped(ctx context.Context, scope string, agentID string) ([]EntryMeta, error)

ListSystemScoped returns metadata for admin-managed vault entries in one effective scope.

func (*Service) LoadEnv

func (s *Service) LoadEnv(ctx context.Context, userID string) (map[string]string, error)

LoadEnv decrypts all user-level vault entries for userID and returns them as a name→plaintext map. Intended for backward-compatible callers.

func (*Service) LoadEnvForAgent added in v0.48.0

func (s *Service) LoadEnvForAgent(ctx context.Context, userID string, agentID string) (map[string]string, error)

LoadEnvForAgent resolves runtime env in the SQL precedence order; later scopes override earlier scopes.

func (*Service) MasterRecipient

func (s *Service) MasterRecipient() *age.X25519Recipient

MasterRecipient returns the master public key recipient. It is used when generating new user key pairs.

func (*Service) Set

func (s *Service) Set(ctx context.Context, userID string, name string, plaintext string) error

Set validates name, encrypts plaintext with the user's public key, and upserts the user-level vault entry. The user must already have age keys provisioned.

func (*Service) SetReserved added in v0.36.1

func (s *Service) SetReserved(ctx context.Context, userID string, name string, plaintext string) error

SetReserved stores an internal reserved env var. Callers must not pass user input.

func (*Service) SetScoped added in v0.48.0

func (s *Service) SetScoped(ctx context.Context, scope string, userID string, agentID string, name string, plaintext string) error

SetScoped stores a user-owned secret in the requested vault scope.

func (*Service) SetSystemScoped added in v0.48.0

func (s *Service) SetSystemScoped(ctx context.Context, scope string, agentID string, name string, plaintext string) error

SetSystemScoped stores an admin-managed secret. Call only after an explicit admin authorization check at the API boundary.

Jump to

Keyboard shortcuts

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