Documentation
¶
Overview ¶
Package vault owns encrypted daemon-managed secret material.
Index ¶
- Constants
- Variables
- func EnvNameFromRef(ref string) (string, error)
- func ExtensionProfileSecretOwnerPrefix(extension, profileID, workspaceID string) string
- func ExtensionProfileSecretRef(extension, profileID, workspaceID, envName string) string
- func ExtensionSecretOwnerPrefix(extension, workspaceID string) string
- func ExtensionSecretRef(extension, workspaceID, envName string) string
- func IsEnvRef(ref string) bool
- func IsSecretRef(ref string) bool
- func ListProfileSecretPrefixes(ctx context.Context, q profileRefSQLQueryer, name string) ([]string, error)
- func MCPOwnerSegment(ownerID string) (string, error)
- func MCPSecretOwnerPrefix(target MCPSecretTarget) (string, error)
- func MCPServerSegment(serverName string) (string, error)
- func MigrateToKeyring(ctx context.Context, home string, store Store, ring Keyring, ...) (verified int, err error)
- func NormalizeMCPClientSecretRef(ref string, target MCPSecretTarget) (string, error)
- func NormalizeMCPOwner(owner string) string
- func NormalizeRef(ref string) string
- func ProfileSecretOwnerPrefix(profileName, ownerKind, owner string) (string, error)
- func RefMatchesPrefix(ref string, prefix string) bool
- func RenameProfileSecretRef(ref, oldName, newName string) string
- func RequireKeyringMigration(home string) error
- func SecretLikeEnvName(name string) bool
- func SecretRefNamespace(ref string) (string, error)
- func SecretRefPrefixNamespace(prefix string) (string, error)
- func ValidateExtensionSecretRefOwner(ref, extension string) error
- func ValidateMCPOwner(owner string) error
- func ValidateMCPSecretRefAccess(ref string, target MCPSecretTarget) error
- func ValidateNamespace(namespace string) error
- func ValidateNonSecretEnvMap(path string, env map[string]string) error
- func ValidateProfileScopedRef(ref, profileName string) error
- func ValidateProfileSecretRefAccess(ref, profileName string) error
- func ValidateRef(ref string) error
- func ValidateRefNamespace(ref string, namespace string) error
- func ValidateSecretEnvMap(path string, namespace string, secretEnv map[string]string) error
- func ValidateSecretRef(ref string) error
- func ValidateSecretRefNamespace(ref string, namespace string) error
- func ValidateSecretRefPrefix(prefix string) error
- type KeyProvider
- type Keyring
- type MCPDCRSecretRefs
- type MCPSecretTarget
- type Metadata
- type Option
- type ProfileRefRewrite
- type ProfileRefRewriter
- type ProfileSecretError
- type ProfileSecretRef
- type Record
- type Service
- func (s *Service) DeleteSecret(ctx context.Context, ref string) error
- func (s *Service) GetMetadata(ctx context.Context, ref string) (Metadata, error)
- func (s *Service) ListMetadata(ctx context.Context, prefix string) ([]Metadata, error)
- func (s *Service) PutSecret(ctx context.Context, ref string, kind string, plaintext string) (Metadata, error)
- func (s *Service) ResolveRef(ctx context.Context, ref string) (string, error)
- type Store
Constants ¶
const ( // MCPUserScope identifies user-owned MCP credentials. MCPUserScope = "user" // MCPProfileScope identifies profile-owned MCP credentials. MCPProfileScope = "profile" // MCPWorkspaceScope identifies workspace-owned MCP credentials. MCPWorkspaceScope = "workspace" // MCPWorkspaceProfileScope identifies a workspace and profile credential cell. MCPWorkspaceProfileScope = "workspace_profile" MCPSharedRefPrefix = "vault:mcp/shared/" )
const MCPManualOwner = "manual"
const (
// ProfileSecretRefPrefix is the root of profile-owned credential refs.
ProfileSecretRefPrefix = "vault:profiles/"
)
Variables ¶
var ( // ErrSecretNotFound reports that a secret reference has no stored value. ErrSecretNotFound = errors.New("vault: secret not found") // ErrUnsupportedSecretRef reports that a launch binding uses an unsupported reference scheme. ErrUnsupportedSecretRef = errors.New("vault: unsupported secret ref") // ErrMissingSecret reports that a required env or secret reference resolved to no value. ErrMissingSecret = errors.New("vault: secret value missing") )
var EnvNamePattern = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*$`)
EnvNamePattern is the daemon-wide grammar for environment variable names.
var ErrKeyringMigrationRequired = errors.New(
"vault: OS keyring has not been explicitly provisioned; run compozy vault key migrate",
)
var ( // ErrProfileSecretEnvForbidden marks process-environment refs rejected for profile-owned credentials. ErrProfileSecretEnvForbidden = errors.New("vault: profile secret env ref forbidden") )
Functions ¶
func EnvNameFromRef ¶
EnvNameFromRef returns the validated environment variable name in an env: ref.
func ExtensionProfileSecretOwnerPrefix ¶
ExtensionProfileSecretOwnerPrefix returns the profile-aware binding owner prefix. An empty profile keeps the shared user-layer namespace.
func ExtensionProfileSecretRef ¶
ExtensionProfileSecretRef returns the conventional ref for one profile-aware binding.
func ExtensionSecretOwnerPrefix ¶
ExtensionSecretOwnerPrefix returns the instance-qualified extension Vault prefix ending in a slash.
func ExtensionSecretRef ¶
ExtensionSecretRef returns the conventional Vault ref for one extension env binding.
func IsSecretRef ¶
IsSecretRef reports whether a ref points at Compozy-managed encrypted storage.
func ListProfileSecretPrefixes ¶
func ListProfileSecretPrefixes(ctx context.Context, q profileRefSQLQueryer, name string) ([]string, error)
ListProfileSecretPrefixes includes standalone credentials as well as refs used by live MCP authorization rows.
func MCPOwnerSegment ¶
MCPOwnerSegment returns a collision-safe Vault path segment for an MCP credential owner identifier. Grammar-safe identifiers remain readable; reserved or unsafe values use a deterministic hex encoding.
func MCPSecretOwnerPrefix ¶
func MCPSecretOwnerPrefix(target MCPSecretTarget) (string, error)
MCPSecretOwnerPrefix returns the canonical scope-qualified Vault prefix for one MCP server. The returned value always ends with a slash.
func MCPServerSegment ¶
MCPServerSegment returns a collision-safe Vault path segment for an MCP server name while preserving the exact server name as the runtime identity.
func MigrateToKeyring ¶
func MigrateToKeyring( ctx context.Context, home string, store Store, ring Keyring, activate func() error, ) (verified int, err error)
MigrateToKeyring imports the existing file key and verifies every ciphertext with the key read back from the OS store before activation. The caller owns the migration lock and an atomic activation callback, including file removal when requested. A failed activation removes only the new keyring entry.
func NormalizeMCPClientSecretRef ¶
func NormalizeMCPClientSecretRef(ref string, target MCPSecretTarget) (string, error)
NormalizeMCPClientSecretRef enforces configured client-secret ownership before resolution.
func NormalizeMCPOwner ¶
NormalizeMCPOwner treats an omitted owner as manual.
func NormalizeRef ¶
NormalizeRef returns the trimmed secret ref used by stores and resolvers.
func ProfileSecretOwnerPrefix ¶
ProfileSecretOwnerPrefix returns the canonical owner-qualified prefix ending in a slash.
func RefMatchesPrefix ¶
RefMatchesPrefix reports whether ref is exactly prefix or is nested below it.
func RenameProfileSecretRef ¶
RenameProfileSecretRef translates only references owned by the renamed profile.
func RequireKeyringMigration ¶
RequireKeyringMigration checks local opt-in evidence without querying the OS. Selecting os-keyring in config alone must never trigger a permission prompt.
func SecretLikeEnvName ¶
SecretLikeEnvName reports whether an environment variable name conventionally carries durable credential material and should be declared through secret_env.
func SecretRefNamespace ¶
SecretRefNamespace returns the first path segment for a validated vault ref.
func SecretRefPrefixNamespace ¶
SecretRefPrefixNamespace returns the first path segment for a validated vault ref prefix.
func ValidateExtensionSecretRefOwner ¶
ValidateExtensionSecretRefOwner checks the extension segment, without validating the workspace or profile instance.
func ValidateMCPOwner ¶
func ValidateMCPSecretRefAccess ¶
func ValidateMCPSecretRefAccess(ref string, target MCPSecretTarget) error
ValidateMCPSecretRefAccess permits only the target server's owned refs or the explicit shared namespace.
func ValidateNamespace ¶
ValidateNamespace reports whether namespace is one of Compozy's durable vault namespaces.
func ValidateNonSecretEnvMap ¶
ValidateNonSecretEnvMap rejects literal env maps that appear to carry secrets.
func ValidateProfileScopedRef ¶
ValidateProfileScopedRef rejects machine-wide env refs and enforces profile ownership for vault refs.
func ValidateProfileSecretRefAccess ¶
ValidateProfileSecretRefAccess permits only refs owned by the acting profile.
func ValidateRef ¶
ValidateRef reports whether ref uses Compozy's supported env: or vault: grammar.
func ValidateRefNamespace ¶
ValidateRefNamespace reports whether ref uses env: or the requested vault namespace.
func ValidateSecretEnvMap ¶
ValidateSecretEnvMap validates env-name to secret-ref bindings for one vault namespace.
func ValidateSecretRef ¶
ValidateSecretRef reports whether ref belongs to one of Compozy's durable vault namespaces.
func ValidateSecretRefNamespace ¶
ValidateSecretRefNamespace reports whether ref is a vault ref in the requested namespace.
func ValidateSecretRefPrefix ¶
ValidateSecretRefPrefix reports whether prefix can safely filter Compozy vault refs.
Types ¶
type KeyProvider ¶
KeyProvider loads the daemon-local vault encryption key.
func NewFileKeyProvider ¶
func NewFileKeyProvider(homeDir string, lookupEnv func(string) (string, bool)) KeyProvider
NewFileKeyProvider returns a non-interactive key provider backed by COMPOZY_VAULT_KEY or a 0600 key file.
func NewOSKeyProvider ¶
func NewOSKeyProvider(home string, ring Keyring) KeyProvider
NewOSKeyProvider reads an explicitly provisioned key. It never imports a file, creates a replacement key, or falls back when the OS keyring is unavailable. A nil ring selects the system keyring; tests inject only this I/O boundary.
type Keyring ¶
type Keyring interface {
Get(service, account string) (string, error)
Set(service, account, value string) error
Delete(service, account string) error
}
Keyring is the OS credential-store boundary used by vault key operations.
type MCPDCRSecretRefs ¶
MCPDCRSecretRefs identifies the Vault locations for one MCP OAuth client registration.
func MCPDCRSecretRefsForTarget ¶
func MCPDCRSecretRefsForTarget(target MCPSecretTarget) (MCPDCRSecretRefs, error)
MCPDCRSecretRefsForTarget returns the canonical Vault refs for one MCP OAuth registration.
type MCPSecretTarget ¶
MCPSecretTarget carries only the identity needed to address MCP credentials. It keeps the Vault boundary independent of the OAuth/config packages.
type Metadata ¶
type Metadata struct {
Ref string
Kind string
Present bool
CreatedAt time.Time
UpdatedAt time.Time
}
Metadata is a redacted vault row safe for operator-facing status surfaces.
type Option ¶
type Option func(*Service)
Option customizes the vault service.
func WithLookupEnv ¶
WithLookupEnv injects env lookup for tests and daemon composition.
type ProfileRefRewrite ¶
ProfileRefRewrite identifies one persisted ref mutation included in a profile rename.
func ListProfileRefRewrites ¶
func ListProfileRefRewrites( ctx context.Context, q profileRefSQLQueryer, oldName string, newName string, ) ([]ProfileRefRewrite, error)
ListProfileRefRewrites enumerates every persisted ref occurrence touched by a rename.
type ProfileRefRewriter ¶
type ProfileRefRewriter struct {
// contains filtered or unexported fields
}
ProfileRefRewriter rebinds profile-owned ciphertext and every daemon-owned ref atomically in a caller transaction.
func NewProfileRefRewriter ¶
func NewProfileRefRewriter(keys KeyProvider) (*ProfileRefRewriter, error)
NewProfileRefRewriter constructs the profile lifecycle ref rewriter.
func (*ProfileRefRewriter) RewriteProfileRefs ¶
func (r *ProfileRefRewriter) RewriteProfileRefs( ctx context.Context, exec profileRefSQLExecutor, oldName string, newName string, updatedAt string, ) error
RewriteProfileRefs re-encrypts vault rows under their new AAD identity and updates every stored ref occurrence.
type ProfileSecretError ¶
ProfileSecretError is a stable operator-facing validation error.
func (*ProfileSecretError) Error ¶
func (e *ProfileSecretError) Error() string
func (*ProfileSecretError) Unwrap ¶
func (e *ProfileSecretError) Unwrap() error
type ProfileSecretRef ¶
ProfileSecretRef is one parsed profile-owned credential reference.
func ParseProfileSecretRef ¶
func ParseProfileSecretRef(ref string) (ProfileSecretRef, error)
ParseProfileSecretRef parses the exact profile credential grammar.
type Record ¶
type Record struct {
Ref string
Kind string
EncryptedValue string
CreatedAt time.Time
UpdatedAt time.Time
}
Record is one encrypted vault row. EncryptedValue must never contain plaintext.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service resolves env-backed and vault-backed secret references.
func NewService ¶
func NewService(store Store, keys KeyProvider, opts ...Option) (*Service, error)
NewService constructs a vault service.
func (*Service) DeleteSecret ¶
DeleteSecret removes one vault-backed ref.
func (*Service) GetMetadata ¶
GetMetadata returns redacted metadata for one vault-backed ref.
func (*Service) ListMetadata ¶
ListMetadata returns redacted metadata for a ref prefix.
type Store ¶
type Store interface {
PutVaultSecret(ctx context.Context, record Record) error
GetVaultSecret(ctx context.Context, ref string) (Record, error)
ListVaultSecrets(ctx context.Context, prefix string) ([]Record, error)
DeleteVaultSecret(ctx context.Context, ref string) error
}
Store persists encrypted vault records.