vault

package
v0.3.0-beta.9 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package vault owns encrypted daemon-managed secret material.

Index

Constants

View Source
const (
	// MCPGlobalScope identifies daemon-global MCP credentials.
	MCPGlobalScope = "global"
	// MCPWorkspaceScope identifies workspace-owned MCP credentials.
	MCPWorkspaceScope = "workspace"
	// MCPSharedRefPrefix identifies MCP secrets explicitly shared across owners.
	MCPSharedRefPrefix = "vault:mcp/shared/"
)

Variables

View Source
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")
)
View Source
var EnvNamePattern = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*$`)

EnvNamePattern is the daemon-wide grammar for environment variable names.

Functions

func EnvNameFromRef

func EnvNameFromRef(ref string) (string, error)

EnvNameFromRef returns the validated environment variable name in an env: ref.

func ExtensionSecretOwnerPrefix

func ExtensionSecretOwnerPrefix(extension, workspaceID string) string

ExtensionSecretOwnerPrefix returns the instance-qualified extension Vault prefix ending in a slash.

func ExtensionSecretRef

func ExtensionSecretRef(extension, workspaceID, envName string) string

ExtensionSecretRef returns the conventional Vault ref for one extension env binding.

func IsEnvRef

func IsEnvRef(ref string) bool

IsEnvRef reports whether a ref points at an operator-managed environment variable.

func IsSecretRef

func IsSecretRef(ref string) bool

IsSecretRef reports whether a ref points at Compozy-managed encrypted storage.

func MCPSecretOwnerPrefix

func MCPSecretOwnerPrefix(scope string, workspaceID string, serverName string) (string, error)

MCPSecretOwnerPrefix returns the canonical scope-qualified Vault prefix for one MCP server. The returned value always ends with a slash.

func MCPServerSegment

func MCPServerSegment(serverName string) (string, error)

MCPServerSegment returns a collision-safe Vault path segment for an MCP server name while preserving the exact server name as the runtime identity.

func MCPWorkspaceSegment

func MCPWorkspaceSegment(workspaceID string) (string, error)

MCPWorkspaceSegment returns a collision-safe Vault path segment for a workspace identifier. Grammar-safe identifiers remain readable; reserved or unsafe values use a deterministic hex encoding.

func NormalizeRef

func NormalizeRef(ref string) string

NormalizeRef returns the trimmed secret ref used by stores and resolvers.

func RefMatchesPrefix

func RefMatchesPrefix(ref string, prefix string) bool

RefMatchesPrefix reports whether ref is exactly prefix or is nested below it.

func SecretLikeEnvName

func SecretLikeEnvName(name string) bool

SecretLikeEnvName reports whether an environment variable name conventionally carries durable credential material and should be declared through secret_env.

func SecretRefNamespace

func SecretRefNamespace(ref string) (string, error)

SecretRefNamespace returns the first path segment for a validated vault ref.

func SecretRefPrefixNamespace

func SecretRefPrefixNamespace(prefix string) (string, error)

SecretRefPrefixNamespace returns the first path segment for a validated vault ref prefix.

func ValidateMCPSecretRefAccess

func ValidateMCPSecretRefAccess(ref string, scope string, workspaceID string, serverName string) error

ValidateMCPSecretRefAccess permits only the target server's owned refs or the explicit shared namespace.

func ValidateNamespace

func ValidateNamespace(namespace string) error

ValidateNamespace reports whether namespace is one of Compozy's durable vault namespaces.

func ValidateNonSecretEnvMap

func ValidateNonSecretEnvMap(path string, env map[string]string) error

ValidateNonSecretEnvMap rejects literal env maps that appear to carry secrets.

func ValidateRef

func ValidateRef(ref string) error

ValidateRef reports whether ref uses Compozy's supported env: or vault: grammar.

func ValidateRefNamespace

func ValidateRefNamespace(ref string, namespace string) error

ValidateRefNamespace reports whether ref uses env: or the requested vault namespace.

func ValidateSecretEnvMap

func ValidateSecretEnvMap(path string, namespace string, secretEnv map[string]string) error

ValidateSecretEnvMap validates env-name to secret-ref bindings for one vault namespace.

func ValidateSecretRef

func ValidateSecretRef(ref string) error

ValidateSecretRef reports whether ref belongs to one of Compozy's durable vault namespaces.

func ValidateSecretRefNamespace

func ValidateSecretRefNamespace(ref string, namespace string) error

ValidateSecretRefNamespace reports whether ref is a vault ref in the requested namespace.

func ValidateSecretRefPrefix

func ValidateSecretRefPrefix(prefix string) error

ValidateSecretRefPrefix reports whether prefix can safely filter Compozy vault refs.

Types

type KeyProvider

type KeyProvider interface {
	Key() ([]byte, error)
}

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.

type MCPDCRSecretRefs

type MCPDCRSecretRefs struct {
	ClientSecretRef            string
	RegistrationAccessTokenRef string
}

MCPDCRSecretRefs identifies the Vault locations for one MCP OAuth client registration.

func MCPDCRSecretRefsForTarget

func MCPDCRSecretRefsForTarget(scope string, workspaceID string, serverName string) (MCPDCRSecretRefs, error)

MCPDCRSecretRefsForTarget returns the canonical Vault refs for one MCP OAuth registration.

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

func WithLookupEnv(lookup func(string) (string, bool)) Option

WithLookupEnv injects env lookup for tests and daemon composition.

func WithNow

func WithNow(now func() time.Time) Option

WithNow injects the service clock.

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

func (s *Service) DeleteSecret(ctx context.Context, ref string) error

DeleteSecret removes one vault-backed ref.

func (*Service) GetMetadata

func (s *Service) GetMetadata(ctx context.Context, ref string) (Metadata, error)

GetMetadata returns redacted metadata for one vault-backed ref.

func (*Service) ListMetadata

func (s *Service) ListMetadata(ctx context.Context, prefix string) ([]Metadata, error)

ListMetadata returns redacted metadata for a ref prefix.

func (*Service) PutSecret

func (s *Service) PutSecret(ctx context.Context, ref string, kind string, plaintext string) (Metadata, error)

PutSecret encrypts and stores one vault-backed secret ref.

func (*Service) ResolveRef

func (s *Service) ResolveRef(ctx context.Context, ref string) (string, error)

ResolveRef resolves env: and vault: refs to plaintext for launch-time injection.

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.

Jump to

Keyboard shortcuts

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