Documentation
¶
Index ¶
- Constants
- func Decrypt(masterIdentity *age.X25519Identity, encryptedPrivateKey string, ...) (string, error)
- func Dispatch(ctx context.Context, h Handler, action string, args map[string]any) (any, error)
- func Encrypt(publicKeyStr string, plaintext string) (string, error)
- func GenerateMasterIdentity() (string, error)
- func GenerateUserKeys(masterRecipient *age.X25519Recipient) (string, string, error)
- func InputSchema() map[string]any
- func InvalidateForScope(inv RunnerInvalidator, scope, userID, agentID string) error
- func IsAgentScope(scope string) bool
- func ParseMasterIdentity(identityStr string) (*age.X25519Identity, *age.X25519Recipient, error)
- func ValidateName(name string) error
- type Access
- func (a *Access) DeleteScoped(ctx context.Context, scope, agentID, name string) error
- func (a *Access) GetScoped(ctx context.Context, scope, agentID, name string) (string, error)
- func (a *Access) GetScopedMeta(ctx context.Context, scope, agentID, name string) (EntryMeta, error)
- func (a *Access) ListScoped(ctx context.Context, scope, agentID string) ([]EntryMeta, error)
- func (a *Access) SetScoped(ctx context.Context, scope, agentID, name, value string, opts SetOptions) error
- type AmbientSecretMeta
- type DB
- type DeleteInput
- type EntryMeta
- type Handler
- type ListInput
- type ResolvedScope
- type RunnerInvalidator
- type ScopeRequest
- type Service
- func (s *Service) AddSystemManagedNames(names ...string)
- func (s *Service) Begin(_ context.Context, authority authz.Authority) (*Access, error)
- func (s *Service) DecryptSystem(ciphertext string) (string, error)
- func (s *Service) Delete(ctx context.Context, userID string, name string) error
- func (s *Service) DeleteScoped(ctx context.Context, scope string, userID string, agentID string, name string) error
- func (s *Service) DeleteSystemScoped(ctx context.Context, scope string, agentID string, name string) error
- func (s *Service) EncryptSystem(plaintext string) (string, error)
- func (s *Service) Get(ctx context.Context, userID string, name string) (string, error)
- func (s *Service) GetScoped(ctx context.Context, scope string, userID string, agentID string, name string) (string, error)
- func (s *Service) GetScopedMeta(ctx context.Context, scope string, userID string, agentID string, name string) (EntryMeta, error)
- func (s *Service) List(ctx context.Context, userID string) ([]EntryMeta, error)
- func (s *Service) ListAmbientSecretMetas(ctx context.Context, userID string, agentID string) ([]AmbientSecretMeta, error)
- func (s *Service) ListScoped(ctx context.Context, scope string, userID string, agentID string) ([]EntryMeta, error)
- func (s *Service) ListSystemScoped(ctx context.Context, scope string, agentID string) ([]EntryMeta, error)
- func (s *Service) LoadEnvForAgent(ctx context.Context, userID string, agentID string) (map[string]string, error)
- func (s *Service) Lookup(ctx context.Context, userID string, name string) (string, bool, error)
- func (s *Service) MasterRecipient() *age.X25519Recipient
- func (s *Service) Set(ctx context.Context, userID string, name string, plaintext string) error
- func (s *Service) SetScoped(ctx context.Context, scope string, userID string, agentID string, name string, ...) error
- func (s *Service) SetScopedWithOptions(ctx context.Context, scope string, userID string, agentID string, name string, ...) error
- func (s *Service) SetSystemScoped(ctx context.Context, scope string, agentID string, name string, ...) error
- func (s *Service) SetSystemScopedWithOptions(ctx context.Context, scope string, agentID string, name string, ...) error
- func (s *Service) ValidateUserFacingName(name string) error
- type SetInput
- type SetOptions
- type Tool
Constants ¶
const ( ScopeUser = "user" ScopeUserAgent = "user_agent" ScopeSystem = "system" ScopeSystemAgent = "system_agent" )
const InputSchemaJSON = `` /* 1737-byte string literal not displayed */
const ToolName = "vault"
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 ¶
Encrypt encrypts plaintext using the given public key string. Returns armored ciphertext.
func GenerateMasterIdentity ¶ added in v0.35.2
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 InputSchema ¶ added in v0.60.0
func InvalidateForScope ¶ added in v0.60.0
func InvalidateForScope(inv RunnerInvalidator, scope, userID, agentID string) error
InvalidateForScope closes the live runners affected by a vault mutation so the next message rebuilds sandbox env from the updated secret snapshot.
func IsAgentScope ¶ added in v0.48.0
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 ¶
ValidateName checks that a vault entry name is a valid env var name and is not reserved.
Types ¶
type Access ¶ added in v0.60.0
type Access struct {
// contains filtered or unexported fields
}
Access captures one validated authority for a vault use case. Vault owns the direct rules for ResourceVault: the HTTP handlers and the agent tool pass a trusted authz.Authority and never a bare identity or an IsAdmin bool. The four durable scopes decide this way:
- user / user_agent are user-owned (is_owner is derived from the entry's owner column; an agent-scoped actor is confined to its own user_agent bucket, and every agent-scoped op folds an agent-read gate);
- system / system_agent are admin-managed and reachable only by an admin.
Trusted internal callers (MCP, connections/OAuth, email, channel config, sandbox env loader, key provisioning) keep using the raw Service methods; they are host-side credential plumbing, not user requests, and never open an Access.
func (*Access) DeleteScoped ¶ added in v0.60.0
DeleteScoped removes an entry after a delete decision.
func (*Access) GetScoped ¶ added in v0.60.0
GetScoped decrypts and returns one entry's plaintext value.
func (*Access) GetScopedMeta ¶ added in v0.60.0
GetScopedMeta returns non-sensitive metadata for one entry.
func (*Access) ListScoped ¶ added in v0.60.0
ListScoped lists entry metadata for one scope, or (scope == "") the caller's user and user_agent buckets aggregated, matching the pre-cutover tool default.
type AmbientSecretMeta ¶ added in v0.60.0
AmbientSecretMeta is prompt-safe ambient secret metadata: the env var name a tool reads plus the user's hint about what it holds. Never carries values.
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) (sqlc.VaultEntry, error)
DeleteVaultEntryByScope(ctx context.Context, arg sqlc.DeleteVaultEntryByScopeParams) error
}
DB is the minimal database interface the vault Service requires.
type DeleteInput ¶ added in v0.60.0
type EntryMeta ¶
type EntryMeta struct {
Scope string
UserID string
AgentID string
Name string
Description string
CreatedAt string
UpdatedAt string
}
EntryMeta holds non-sensitive metadata for a vault entry.
type ResolvedScope ¶ added in v0.60.0
func ResolveScope ¶ added in v0.60.0
func ResolveScope(req ScopeRequest) (ResolvedScope, error)
type RunnerInvalidator ¶ added in v0.60.0
type RunnerInvalidator interface {
InvalidateAll() error
InvalidateAgent(agentID string) error
InvalidateUser(userID string) error
}
RunnerInvalidator is the runner-cache surface vault mutations need. It is implemented by the credentials service at the composition boundary.
type ScopeRequest ¶ added in v0.60.0
type ScopeRequest struct {
Scope string
UserID string
AgentID string
IsAdmin bool
AgentScoped bool
BoundAgentID string
}
ScopeRequest / ResolvedScope / ResolveScope compute the durable owner columns for a vault-style scope. They are NOT the ResourceVault access rules (see access.go) — vault entries are authorized there. They remain here as a pure utility because unrelated resources that reuse the vault scope vocabulary (agent tool overrides, MCP connection tokens) still resolve their own columns this way. Their admin gate is a coarse structural check, not a policy decision.
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 ¶
NewService creates a vault Service. masterIdentityStr is the raw age secret key string (typically from the STELLA_VAULT_KEY environment variable). agents backs the ResourceVault access rules; pass nil only for trusted-only instances.
func NewServiceForPool ¶ added in v0.60.0
func NewServiceForPool(pool *pgxpool.Pool, masterIdentityStr string, agents *agentaccess.Service) (*Service, error)
NewServiceForPool creates a vault Service backed by the given connection pool, owning construction of its sqlc query set. masterIdentityStr is the raw age secret key string (typically from the STELLA_VAULT_KEY environment variable).
func (*Service) AddSystemManagedNames ¶ added in v0.60.0
AddSystemManagedNames reserves host-side credential names so they are never exposed as ambient sandbox env or accepted from user-facing vault writes. OAuth bundle keys come from the provider registry; hand-enumerating them in vault code drifts when manifest providers are added without Go changes (the X provider leak was exactly that failure mode). Defaults cover built-ins even if startup wiring is missed.
func (*Service) DecryptSystem ¶ added in v0.27.0
DecryptSystem decrypts ciphertext that was produced by EncryptSystem.
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
EncryptSystem encrypts plaintext with the master key for system-level storage (not tied to any user).
func (*Service) Get ¶
Get decrypts and returns the plaintext value of 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) ListAmbientSecretMetas ¶ added in v0.60.0
func (s *Service) ListAmbientSecretMetas(ctx context.Context, userID string, agentID string) ([]AmbientSecretMeta, error)
ListAmbientSecretMetas returns prompt-safe metadata for ambient secrets only.
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) 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. System-managed names stay internal-only.
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 ¶
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) 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) SetScopedWithOptions ¶ added in v0.60.0
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 for trusted host-side callers.
func (*Service) SetSystemScopedWithOptions ¶ added in v0.60.0
func (*Service) ValidateUserFacingName ¶ added in v0.60.0
ValidateUserFacingName applies core env-var rules plus host-managed credential reservations. System writers use Set directly so OAuth and MCP stores can keep writing their internal vault rows.
type SetOptions ¶ added in v0.60.0
type SetOptions struct {
Description *string
}
type Tool ¶ added in v0.60.0
type Tool struct {
// contains filtered or unexported fields
}
func NewTool ¶ added in v0.60.0
func NewTool(svc *Service, invalidator RunnerInvalidator) *Tool
func (*Tool) Definition ¶ added in v0.60.0
func (t *Tool) Definition() tools.Definition