Skip to main content
The palyra-vault crate provides a secure, platform-integrated mechanism for storing sensitive credentials such as API keys, tokens, and encryption keys. It abstracts away the complexities of OS-specific secret stores while providing a unified “Vault Reference” system used throughout the Palyra ecosystem to avoid persisting plaintext secrets in configuration files.

Vault Architecture and Backends

The Vault operates as a blob storage system where secrets are organized by Scopes and Keys. Access is managed through the Vault struct, which delegates persistence to a BlobBackend crates/palyra-vault/src/backend.rs#88-93.

Backend Selection

Palyra supports multiple backends, defaulting to the most secure option available for the host operating system crates/palyra-vault/src/backend.rs#135-158:
Backend KindPlatformImplementation
MacosKeychainmacOSUses the system Keychain via security CLI crates/palyra-vault/src/backend.rs#29-29.
LinuxSecretServiceLinuxUses libsecret / secret-tool crates/palyra-vault/src/backend.rs#31-35.
WindowsDpapiWindowsUses Data Protection API (DPAPI) to encrypt blobs for the current user crates/palyra-vault/src/backend.rs#16-16.
EncryptedFileAllEncrypted SQLite-style file backend (fallback or explicit preference) crates/palyra-vault/src/backend.rs#42-42.
The BackendKind is persisted in a backend.kind marker file within the vault root to ensure consistency across sessions crates/palyra-vault/src/backend.rs#24-24.

Logical Data Flow

The following diagram illustrates how the Vault API interacts with the platform-specific backends. Vault Backend Dispatch Sources: crates/palyra-vault/src/backend.rs#88-191, crates/palyra-vault/src/api.rs#12-12

Vault Scopes and References

Scoping

Secrets are addressed using a VaultScope, which is a hierarchical identifier (e.g., global, plugins/github). Scopes prevent key collisions between different components of the system crates/palyra-vault/src/scope.rs#16-16.

Vault Refs (vault://)

A Vault Ref is a URI-like string formatted as vault://scope/key. Instead of storing an API key directly in palyra.toml, the configuration stores the reference.
  • Daemon Resolution: When the daemon encounters a vault_ref in its config, it uses the Vault instance to fetch the SensitiveBytes at runtime.
  • CLI Integration: The CLI command secrets configure automates the process of setting a secret in the vault and updating the configuration file with the corresponding reference crates/palyra-cli/src/commands/secrets.rs#144-184.

Filesystem Layout and Security

The vault enforces strict filesystem permissions to ensure that only the owner of the process can read the secret metadata or the encrypted blobs.
  • Root Directory: Typically located at $PALYRA_VAULT_DIR or within the state root.
  • Permissions: The system uses ensure_owner_only_dir and ensure_owner_only_file to set 0700 and 0600 permissions respectively on Unix-like systems crates/palyra-vault/src/filesystem.rs#15-15.
  • Object Storage: In the EncryptedFile backend, objects are stored in an objects/ directory, with filenames derived from a hash of the scope and key crates/palyra-vault/src/backend.rs#25-27.

CLI Secret Management

The palyra CLI provides a suite of commands for managing the vault via run_secrets crates/palyra-cli/src/commands/secrets.rs#61-61.

Common Operations

Secret Management Data Flow

This diagram bridges the CLI command space to the internal Vault logic. CLI Secret Operation Flow Sources: crates/palyra-cli/src/commands/secrets.rs#61-78, crates/palyra-vault/src/api.rs#12-12, crates/palyra-vault/src/backend.rs#90-90

Implementation Details

Envelope Format

When using the EncryptedFile backend, secrets are stored in an envelope that includes:
  1. Version: Protocol versioning for future-proofing.
  2. Nonce: Unique cryptographic nonce for AES-GCM.
  3. AAD (Additional Authenticated Data): Includes the scope and key to prevent “secret swapping” attacks where an attacker moves an encrypted blob from one key to another.
  4. Ciphertext: The actual secret data.

Key Functions

Sources: crates/palyra-vault/src/backend.rs#1-191, crates/palyra-vault/src/lib.rs#1-20, crates/palyra-cli/src/commands/secrets.rs#1-180, crates/palyra-common/src/lib.rs#31-32.