Skip to content

HashiCorp Vault Key Store

The Vault key store persists encryption keys in HashiCorp Vault using the KV v2 secrets engine. It is the recommended choice for organizations that already use Vault for centralized secrets management and need enterprise-grade audit trails.

Installation

shell
dotnet add package Tayra.KeyStore.Vault
powershell
Install-Package Tayra.KeyStore.Vault

Basic Setup

The simplest registration uses token authentication:

cs
var services = new ServiceCollection();

// Use HashiCorp Vault with token authentication
services.AddTayra(opts => opts.LicenseKey = licenseKey)
    .UseVaultKeyStore(
        vaultAddress: "https://vault.example.com:8200",
        token: "hvs.your-vault-token");
anchor

Configuration Options

Use the options overload to customize paths and retry behavior:

cs
var services = new ServiceCollection();

services.AddTayra(opts => opts.LicenseKey = licenseKey)
    .UseVaultKeyStore(
        vaultAddress: "https://vault.example.com:8200",
        token: "hvs.your-vault-token",
        options =>
        {
            // KV v2 mount point (default: "secret")
            options.MountPoint = "secret";

            // Path prefix within the KV mount (default: "tayra/keys")
            options.PathPrefix = "myapp/encryption-keys";

            // Maximum number of retries for transient errors (default: 3)
            options.MaxRetries = 5;

            // Base delay for exponential backoff on retries (default: 100ms)
            options.RetryBaseDelay = TimeSpan.FromMilliseconds(200);
        });
anchor

Options Reference

PropertyTypeDefaultDescription
VaultAddressstring?nullThe Vault server address (e.g., "https://vault.example.com:8200"). Required.
Tokenstring?nullAuthentication token. Used with token-based auth.
MountPointstring"secret"KV v2 mount point in Vault.
PathPrefixstring"tayra"Path prefix within the KV mount for storing keys.
MaxRetriesint3Maximum number of retries for transient errors.
RetryBaseDelayTimeSpan100msBase delay for exponential backoff on retries.

Pre-configured Vault Client

If you already have a VaultSharp.IVaultClient configured (e.g., with AppRole or Kubernetes auth), pass it directly:

cs
var services = new ServiceCollection();

// Pass a pre-configured IVaultClient with your preferred auth method
var existingVaultClient = new VaultSharp.VaultClient(
    new VaultSharp.VaultClientSettings(
        "https://vault.example.com:8200",
        new VaultSharp.V1.AuthMethods.Token.TokenAuthMethodInfo("hvs.your-vault-token")));

services.AddTayra(opts => opts.LicenseKey = licenseKey)
    .UseVaultKeyStore(existingVaultClient, options =>
    {
        options.PathPrefix = "myapp/encryption-keys";
    });
anchor

This is useful when your application uses a different Vault auth method or when you want to share a single client instance across services.

KV v2 Secrets Engine

Tayra stores each encryption key as a separate secret in the Vault KV v2 engine. The secret path follows this pattern:

{mount_point}/data/{path_prefix}/{key_id}
ComponentValueSource
mount_pointsecretMountPoint option (default: "secret")
datadataFixed — required by the Vault KV v2 API to distinguish data from metadata operations
path_prefixtayraPathPrefix option (default: "tayra")
key_iduser-123:personalThe Tayra key identifier

For example, with the default settings and a key ID of user-123:personal, the secret is stored at:

secret/data/tayra/user-123:personal

The secret contains a single field key with the Base64-encoded AES-256 key bytes.

KV v2 Versioning

Vault KV v2 maintains version history for secrets. When Tayra deletes a key (crypto-shredding), the entire secret is destroyed -- not just the latest version. This ensures that previous versions of the key cannot be recovered.

Vault Policy Requirements

The Vault token must have the following capabilities on the key path:

hcl
path "secret/data/tayra/*" {
  capabilities = ["create", "read", "delete"]
}

path "secret/metadata/tayra/*" {
  capabilities = ["list", "delete"]
}

Adjust the path to match your MountPoint and PathPrefix settings. The metadata path is needed for ListKeyIdsAsync and full secret destruction during crypto-shredding.

Least Privilege

Grant only the capabilities listed above. Tayra does not need update (keys are immutable once stored) or sudo capabilities.

Token Renewal

Vault tokens have a TTL and must be renewed periodically. Tayra does not manage token lifecycle -- if your token expires, key store operations will fail.

For production deployments, consider:

  • AppRole auth with periodic tokens that auto-renew via a Vault agent sidecar.
  • Kubernetes auth if running on Kubernetes, which handles token injection and renewal automatically.
  • Token wrapping for secure initial token delivery.

Pass a pre-configured IVaultClient with your preferred auth method rather than a raw token for long-running services.

Retry Logic

The Vault key store includes built-in retry logic with exponential backoff for transient HTTP errors. The backoff delay doubles on each attempt: for the default settings (base delay = 100ms, max retries = 3), the delays are approximately 100ms, 200ms, and 400ms.

See Also