Documentation
¶
Overview ¶
Package vaults owns Vaults and their Credentials: the resources, OAuth access-token refresh, and the MCP credential selection that Session creation freezes and execution resolves into a bearer token. Storage seals and opens the Credential secrets.
Index ¶
- Constants
- Variables
- type CreateOAuthCredential
- type CreateStaticCredential
- type CreateVault
- type Credential
- type CredentialKey
- type CredentialPage
- type DeleteCredential
- type DeleteVault
- type MCPBearerToken
- type MCPCredentialBinding
- type MCPCredentialMatch
- type MCPCredentialQuery
- type MCPCredentialRequest
- type MCPCredentialSelectionError
- type NewCredential
- type NewVault
- type OAuthGrant
- type OAuthMetadata
- type OAuthRefreshMetadata
- type OAuthRefreshUpdate
- type OAuthTx
- type PageQuery
- type Reader
- type ResolveMCPCredentials
- type Service
- func (s *Service) CreateOAuthCredential(ctx context.Context, command CreateOAuthCredential) (Credential, error)
- func (s *Service) CreateStaticCredential(ctx context.Context, command CreateStaticCredential) (Credential, error)
- func (s *Service) CreateVault(ctx context.Context, command CreateVault) (Vault, error)
- func (s *Service) DeleteCredential(ctx context.Context, command DeleteCredential) (string, error)
- func (s *Service) DeleteVault(ctx context.Context, command DeleteVault) (string, error)
- func (s *Service) MCPBearerToken(ctx context.Context, command MCPBearerToken) (string, error)
- func (s *Service) ResolveMCPCredentials(ctx context.Context, command ResolveMCPCredentials) ([]MCPCredentialBinding, error)
- func (s *Service) UpdateOAuthCredential(ctx context.Context, command UpdateOAuthCredential) (Credential, error)
- func (s *Service) UpdateStaticCredential(ctx context.Context, command UpdateStaticCredential) (Credential, error)
- type StaticTokenQuery
- type StaticTokenReplacement
- type Storage
- type UpdateOAuthCredential
- type UpdateStaticCredential
- type Vault
- type VaultPage
Constants ¶
const ( AuthStaticBearer = "static_bearer" AuthMCPOAuth = "mcp_oauth" )
Credential authentication types.
const ( StatusActive = "active" StatusArchived = "archived" )
Vault and Credential statuses.
Variables ¶
var ( // ErrNotFound reports a Vault or Credential that does not exist in the // caller's tenant, including one another tenant owns and an ID that cannot // name one. ErrNotFound = errors.New("vault resource not found") // ErrInvalidInput rejects a request the operation cannot accept. ErrInvalidInput = errors.New("invalid vault request") )
Functions ¶
This section is empty.
Types ¶
type CreateOAuthCredential ¶
type CreateOAuthCredential struct {
TenantID, VaultID string
Name, MCPServerURL, AccessToken string
OAuth OAuthMetadata
RefreshToken, ClientSecret string
}
CreateOAuthCredential keeps the write-only secrets apart from the metadata.
type CreateStaticCredential ¶
type CreateVault ¶
type Credential ¶
type Credential struct {
ID, VaultID, Name, AuthType, MCPServerURL string
CreatedAt, UpdatedAt time.Time
// OAuth is set for mcp_oauth Credentials only.
OAuth *OAuthMetadata
}
Credential contains only public metadata. Resource reads never select the sealed secret; only the bearer-token lookup for execution opens it.
type CredentialKey ¶
type CredentialKey struct {
TenantID, VaultID, CredentialID string
}
CredentialKey names one Credential of one Vault of one tenant.
type CredentialPage ¶
type CredentialPage struct {
Credentials []Credential
NextCursor string
}
type DeleteCredential ¶
type DeleteCredential struct{ TenantID, VaultID, CredentialID string }
type DeleteVault ¶
type DeleteVault struct{ TenantID, VaultID string }
type MCPBearerToken ¶
type MCPBearerToken struct {
TenantID string
VaultIDs []string
Binding MCPCredentialBinding
}
MCPBearerToken asks for the bearer token of a Session's frozen binding.
type MCPCredentialBinding ¶
type MCPCredentialBinding struct {
ServerLabel string `json:"server_label"`
ServerURL string `json:"server_url"`
VaultID string `json:"vault_id,omitempty"`
CredentialID string `json:"credential_id,omitempty"`
AuthType string `json:"auth_type,omitempty"`
}
MCPCredentialBinding freezes a non-secret selection, including anonymous servers. It is private execution configuration stored in the Session, not the public MCP tool shape, so its JSON names are stable.
type MCPCredentialMatch ¶
type MCPCredentialMatch struct {
VaultID, CredentialID, AuthType, MCPServerURL string
}
MCPCredentialMatch is the non-secret identity of a Credential that an MCP credential lookup found.
type MCPCredentialQuery ¶
type MCPCredentialQuery struct {
TenantID string
VaultIDs []string
ServerURL string
CredentialID string
}
MCPCredentialQuery selects a named Credential by ID alone, so its destination can be compared, and otherwise selects by exact destination.
type MCPCredentialRequest ¶
MCPCredentialRequest is one MCP server of a Session being created, with the Credential the caller named for it, if any.
type MCPCredentialSelectionError ¶
MCPCredentialSelectionError rejects a Session MCP credential selection with the observed official message (MV-03); the API reports a Conflict as 409 conflict_error and any other as 400 invalid_request_error. Selection searches only the attached Vaults, which the caller owns, so a missing, foreign-tenant, unattached or malformed reference produces the same error, and only a credential of an attached Vault can report a server_url mismatch.
func (*MCPCredentialSelectionError) Error ¶
func (e *MCPCredentialSelectionError) Error() string
type NewCredential ¶
type NewCredential struct {
CredentialKey
Name, AuthType, MCPServerURL string
Token string
OAuth OAuthGrant
}
NewCredential is a Credential with its new ID, ready to store. Storage seals its secret to the tenant, the Vault, that ID, the authentication type and the destination: Token for static_bearer, OAuth for mcp_oauth.
type OAuthGrant ¶
type OAuthGrant struct {
Metadata OAuthMetadata
AccessToken string
RefreshToken string
ClientSecret string
}
OAuthGrant is an mcp_oauth Credential's secret with the metadata it is refreshed by. Storage keeps the metadata readable and seals the whole grant, so the sealed copy authenticates every public setting used for refresh, including the token endpoint, and substituting stored metadata can never redirect a grant.
type OAuthMetadata ¶
type OAuthMetadata struct {
ExpiresAt *string `json:"expires_at"`
Refresh *OAuthRefreshMetadata `json:"refresh"`
}
OAuthMetadata is the safe projection of a stored OAuth grant.
type OAuthRefreshMetadata ¶
type OAuthRefreshUpdate ¶
type OAuthRefreshUpdate struct {
RefreshToken *string
Scope *string
ScopeSet bool
TokenEndpointAuthType string
ClientSecret *string
}
OAuthRefreshUpdate patches a stored refresh configuration. ScopeSet keeps omitted apart from null.
type OAuthTx ¶
type OAuthTx interface {
// LoadOAuthGrant locks the Credential until the transaction ends, so
// competing refreshes, replacements and deletions, including the parent
// Vault's, wait. A non-empty destination must match the stored one, or
// the Credential is ErrNotFound. Only then is the grant opened: stored
// metadata that differs from the sealed copy fails authentication.
LoadOAuthGrant(ctx context.Context, destination string) (OAuthGrant, error)
// ApplyOAuthRefresh seals and stores a refreshed grant for the loaded
// Credential. Execution refreshes are not caller writes and record no
// audit row.
ApplyOAuthRefresh(ctx context.Context, grant OAuthGrant) error
// ApplyOAuthReplacement seals and stores a caller's replacement for the
// loaded Credential and audits it.
ApplyOAuthReplacement(ctx context.Context, grant OAuthGrant) (Credential, error)
}
OAuthTx is one mcp_oauth Credential inside a WithOAuthCredential transaction.
type PageQuery ¶
type PageQuery struct {
// After is the last ID of the previous page, or empty for the first page.
// An After that names no resource of the list is ErrNotFound.
After string
Limit int
Ascending bool
// Statuses filters by status; empty selects every status.
Statuses []string
}
PageQuery selects one page of Vaults, or of one Vault's Credentials, ordered by creation time and then ID.
type Reader ¶
type Reader interface {
GetVault(ctx context.Context, tenantID, vaultID string) (Vault, error)
ListVaults(ctx context.Context, tenantID string, query PageQuery) (VaultPage, error)
GetCredential(ctx context.Context, tenantID, vaultID, credentialID string) (Credential, error)
// ListCredentials resolves the parent Vault first: an inaccessible parent
// is ErrNotFound, never an empty page.
ListCredentials(ctx context.Context, tenantID, vaultID string, query PageQuery) (CredentialPage, error)
}
Reader reads Vaults and Credential metadata within one tenant. A malformed tenant, Vault or Credential ID is ErrInvalidInput, except the parent Vault of ListCredentials, which is ErrNotFound; a missing or foreign resource is ErrNotFound.
type ResolveMCPCredentials ¶
type ResolveMCPCredentials struct {
TenantID string
VaultIDs []string
Requests []MCPCredentialRequest
}
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service runs the Vault and Credential operations. Storage seals and opens the secrets.
func NewService ¶
func NewService(storage Storage, refresher oauthrefresh.Refresher) (*Service, error)
NewService requires storage and the OAuth refresher.
func (*Service) CreateOAuthCredential ¶
func (s *Service) CreateOAuthCredential(ctx context.Context, command CreateOAuthCredential) (Credential, error)
CreateOAuthCredential stores a grant, with the metadata it is refreshed by, under a new Credential ID. Storage seals it to its tenant, Vault, that ID and destination.
func (*Service) CreateStaticCredential ¶
func (s *Service) CreateStaticCredential(ctx context.Context, command CreateStaticCredential) (Credential, error)
CreateStaticCredential stores a bearer token under a new Credential ID. Storage seals it to its tenant, Vault, that ID and destination.
func (*Service) CreateVault ¶
CreateVault stores a new Vault. Each call creates a distinct Vault.
func (*Service) DeleteCredential ¶
DeleteCredential removes the Credential without reading or opening its secret.
func (*Service) DeleteVault ¶
DeleteVault deletes a Vault with its Credentials. Sessions keep their frozen bindings, which then resolve to ErrNotFound.
func (*Service) MCPBearerToken ¶
MCPBearerToken is for execution only. It rechecks the complete frozen authorization before opening a secret, and refreshes an expired OAuth grant while holding its lock. Never persist or log the token, or downgrade a failure to an anonymous request.
func (*Service) ResolveMCPCredentials ¶
func (s *Service) ResolveMCPCredentials(ctx context.Context, command ResolveMCPCredentials) ([]MCPCredentialBinding, error)
ResolveMCPCredentials selects each MCP server's Credential from the attached Vaults, reading metadata only. Later resource changes do not reselect Credentials for an accepted Session or its creation retries.
func (*Service) UpdateOAuthCredential ¶
func (s *Service) UpdateOAuthCredential(ctx context.Context, command UpdateOAuthCredential) (Credential, error)
UpdateOAuthCredential applies the patch to the locked grant, so it serializes with refreshes.
func (*Service) UpdateStaticCredential ¶
func (s *Service) UpdateStaticCredential(ctx context.Context, command UpdateStaticCredential) (Credential, error)
UpdateStaticCredential replaces only the token and the update time. The stored destination is the seal's scope, which the write checks again, so the existing frozen bindings read the replacement.
type StaticTokenQuery ¶
type StaticTokenQuery struct {
TenantID string
VaultIDs []string
VaultID, CredentialID, MCPServerURL string
}
StaticTokenQuery is a frozen binding's complete scope.
type StaticTokenReplacement ¶
type StaticTokenReplacement struct {
CredentialKey
MCPServerURL string
Token string
}
StaticTokenReplacement is a new static_bearer token. The write matches the destination the token is sealed to.
type Storage ¶
type Storage interface {
Reader
// CreateVault stores a new Vault and allocates its ID.
CreateVault(ctx context.Context, vault NewVault) (Vault, error)
// DeleteVault deletes a Vault with all of its Credentials and returns its ID.
DeleteVault(ctx context.Context, tenantID, vaultID string) (string, error)
// CreateCredential seals the Credential's secret and stores it in a Vault
// of the tenant.
CreateCredential(ctx context.Context, credential NewCredential) (Credential, error)
// ReplaceStaticToken seals and replaces a static_bearer Credential's
// token.
ReplaceStaticToken(ctx context.Context, replacement StaticTokenReplacement) (Credential, error)
// DeleteCredential deletes a Credential and its sealed secret and returns its ID.
DeleteCredential(ctx context.Context, key CredentialKey) (string, error)
// WithOAuthCredential runs apply in one transaction and commits only when
// apply returns nil. It returns apply's error unchanged.
WithOAuthCredential(ctx context.Context, key CredentialKey, apply func(OAuthTx) error) error
// CountOwnedVaults counts how many of the given Vaults the tenant owns.
CountOwnedVaults(ctx context.Context, tenantID string, vaultIDs []string) (int, error)
// FindMCPCredentials returns at most two Credentials of the attached
// Vaults that the query selects, ordered by ID.
FindMCPCredentials(ctx context.Context, query MCPCredentialQuery) ([]MCPCredentialMatch, error)
// StaticToken opens a static_bearer Credential's token when the complete
// frozen scope still names it. A scope that names none is ErrNotFound.
StaticToken(ctx context.Context, query StaticTokenQuery) (string, error)
}
Storage persists Vaults and Credentials. Every operation is scoped to the tenant it names, and every caller-visible write records its audit row in the same transaction. In a write, a malformed ID of an existing resource names none and is ErrNotFound; a malformed tenant of a new Vault or a malformed new Credential ID is ErrInvalidInput.
type UpdateOAuthCredential ¶
type UpdateOAuthCredential struct {
TenantID, VaultID, CredentialID string
AccessToken *string
ExpiresAt *string
ExpiresAtSet bool
Refresh *OAuthRefreshUpdate
}
UpdateOAuthCredential patches an OAuth grant. ExpiresAtSet keeps omitted apart from null; a nil AccessToken keeps the stored one.