Skip to content

API Reference parrot.security.vault_utils

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.security.vault_utils

View source

Vault CRUD helpers — shared encrypted-credential storage for handlers.

Provides store, retrieve, and delete operations on the user_credentials DocumentDB collection using the same AES-GCM encryption scheme as :class:~parrot.handlers.credentials.CredentialsHandler.

Any handler that needs to persist secrets in the Vault should import from here rather than duplicating this logic.

Usage::

from parrot.security.vault_utils import (
    store_vault_credential,
    retrieve_vault_credential,
    delete_vault_credential,
)

await store_vault_credential(user_id, "mcp_perplexity_agent-1", {"api_key": "sk-..."})

Alias DocumentDb

Re-exported from parrot.interfaces.documentdb.DocumentDb.

Attribute VAULT_CRED_COLLECTION

Type: str

Class VaultCredentialStore

Storage operations implemented by Redis and Postgres vault stores.

Method VaultCredentialStore.store

store(user_id: Any, vault_name: str, secret_params: Dict[str, Any]) -> None

Parameter Type Default Description
user_id Any
vault_name str
secret_params Dict[str, Any]

Method VaultCredentialStore.retrieve

retrieve(user_id: Any, vault_name: str) -> Dict[str, Any]

Parameter Type Default Description
user_id Any
vault_name str

Returns: Dict[str, Any]

Method VaultCredentialStore.delete

delete(user_id: Any, vault_name: str) -> None

Parameter Type Default Description
user_id Any
vault_name str

Method VaultCredentialStore.list_credentials

list_credentials(user_id: Any) -> Dict[str, Dict[str, Any]]

Parameter Type Default Description
user_id Any

Returns: Dict[str, Dict[str, Any]]

Method VaultCredentialStore.exists

exists(user_id: Any, vault_name: str) -> bool

Parameter Type Default Description
user_id Any
vault_name str

Returns: bool

Function create_vault_credential

Insert a credential only if (user_id, vault_name) does not exist yet.

Atomic when the configured store provides create (Redis); otherwise the existence check and write are serialized per key inside this process.

create_vault_credential(user_id: str, vault_name: str, secret_params: Dict[str, Any]) -> bool

Parameter Type Default Description
user_id str
vault_name str
secret_params Dict[str, Any]

Returns: bool — True when the credential was created, False when it already exists.

Alias credential_context

Re-exported from parrot.security.credentials_utils.credential_context.

Alias decrypt_credential

Re-exported from parrot.security.credentials_utils.decrypt_credential.

Function delete_vault_credential

Hard-delete a Vault credential from DocumentDB.

delete_vault_credential(user_id: str, vault_name: str) -> None

Parameter Type Default Description
user_id str Owner's user identifier.
vault_name str Vault credential name to remove.

Alias encrypt_credential

Re-exported from parrot.security.credentials_utils.encrypt_credential.

Function get_vault_credential_store

Resolve the configured vault store, preferring a registered Postgres store.

get_vault_credential_store() -> 'VaultCredentialStore | None'

Returns: 'VaultCredentialStore | None'

Function get_vault_keyring

Return the process-wide vault :class:KeyRing (built on first use).

get_vault_keyring() -> Any

Returns: Any — KeyRing built from VAULT_MASTER_KEY_v{N} / VAULT_ACTIVE_KEY_ID.

Raises:

  • RuntimeError — If navigator-session vault crypto is unavailable or the keys are not configured.

Function list_vault_credentials

Return all decryptable credentials belonging to a user.

list_vault_credentials(user_id: str) -> Dict[str, Dict[str, Any]]

Parameter Type Default Description
user_id str

Returns: Dict[str, Dict[str, Any]]

Attribute logger

Function oauth2_vault_name

Build the deterministic Vault credential name for an OAuth2 token.

Mirrors :data:parrot.auth.oauth2_base._VAULT_NAME_TEMPLATE so the namespace stays consistent across writers and readers.

oauth2_vault_name(provider_id: str, channel: str, user_id: str) -> str

Parameter Type Default Description
provider_id str
channel str
user_id str

Returns: str

Function reset_vault_keyring

Drop the cached key ring (tests, key reconfiguration).

reset_vault_keyring() -> None

Function retrieve_vault_credential

Decrypt and return a secret credential from the Vault.

retrieve_vault_credential(user_id: str, vault_name: str) -> Dict[str, Any]

Parameter Type Default Description
user_id str Owner's user identifier.
vault_name str Vault credential name.

Returns: Dict[str, Any] — Decrypted dict of secret parameters.

Raises:

  • KeyError — If the credential is not found in the Vault.
  • RuntimeError — If vault keys are unavailable.
  • navigator_session.vault.VaultCryptoError — If the stored credential does not belong to (user_id, vault_name) or fails integrity.

Function set_vault_credential_store

Server registers its Postgres store at startup (VAULT_STORE=postgres). Core never imports server code.

set_vault_credential_store(store: Any) -> None

Parameter Type Default Description
store Any

Function store_vault_credential

Encrypt and upsert secret parameters in the Vault.

Stores the credential under the compound key (user_id, vault_name) in the user_credentials collection. If a document with that key already exists it is updated; otherwise a new document is inserted.

store_vault_credential(user_id: str, vault_name: str, secret_params: Dict[str, Any]) -> None

Parameter Type Default Description
user_id str Owner's user identifier.
vault_name str Deterministic credential name (e.g. "mcp_perplexity_agent-1").
secret_params Dict[str, Any] Dict of secret values to encrypt (e.g. {"api_key": "sk-..."})

Raises:

  • RuntimeError — If vault keys are unavailable.
  • navigator_session.vault.VaultCryptoError — If the stored credential does not belong to (user_id, vault_name) or fails integrity.

Function vault_credential_exists

Return whether a credential exists without decrypting it.

vault_credential_exists(user_id: str, vault_name: str) -> bool

Parameter Type Default Description
user_id str
vault_name str

Returns: bool

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally