VaultSharp

Dosaic.Plugins.Persistence.VaultSharp is a Dosaic plugin that integrates HashiCorp Vaultarrow-up-right for secure secret storage. It provides a typed ISecretStorage<TBucket> abstraction backed either by a live Vault server (KV v2 + TOTP engines) or a local filesystem (useful for development and testing without a running Vault instance).

Installation

dotnet add package Dosaic.Plugins.Persistence.VaultSharp

or add as a package reference to your .csproj:

<PackageReference Include="Dosaic.Plugins.Persistence.VaultSharp" Version=""/>

Configuration

The plugin is configured via the vault section in appsettings.yml / appsettings.json. The section is bound to VaultConfiguration using the [Configuration("vault")] attribute.

Vault server mode

vault:
  url: "http://localhost:8200"
  token: "your-vault-token"
  totpIssuer: "MyApp"               # optional — default: Dosaic.Plugins.Persistence.VaultSharp
  totpPeriodInSeconds: 30            # optional — default: 30

Local filesystem mode (development / testing)

When useLocalFileSystem is true, secrets are stored as JSON files under localFileSystemPath. No Vault server is required. TOTP codes are generated locally using RFC 6238 (HMAC-SHA1).

VaultConfiguration properties

Property
Type
Default
Description

Url

string

""

Vault server base URL

Token

string

""

Token used to authenticate with Vault

TotpIssuer

string

"Dosaic.Plugins.Persistence.VaultSharp"

Issuer label stored in the TOTP key

TotpPeriodInSeconds

int

30

TOTP counter period in seconds

UseLocalFileSystem

bool

false

Store secrets on the local filesystem instead of Vault

LocalFileSystemPath

string

"./nodep-vault"

Root folder for local filesystem secrets

Vault mount points

The plugin uses two fixed Vault secret engine mount points:

Engine
Mount

KV v2

credentials

TOTP

totp

Both engines must exist in Vault before the application starts.

Registration

With Dosaic WebHost (automatic)

When using PluginWebHostBuilder, the plugin is discovered automatically and VaultConfiguration is resolved from IConfiguration. You only need to register your secret storage buckets — typically in your own plugin or startup code:

Without Dosaic WebHost (manual)

For local filesystem storage without a Vault server:

Usage

Defining a secret bucket

Buckets are plain enums that categorise secrets stored in Vault:

ISecretStorage<TBucket> interface

Inject it via the constructor:

SecretId<TBucket>

SecretId<TBucket> is a read-only struct that identifies a stored secret. It encodes the bucket, type and a unique key into a URL-safe Sqidarrow-up-right string via the Id property.

Secret types

All secret types derive from the abstract record Secret.

UsernamePasswordSecret

UsernamePasswordApiKeySecret

Extends UsernamePasswordSecret with an additional ApiKey field.

UsernamePasswordTotpSecret

Stores a username, password, and a TOTP key. On create / update the Totp must contain a TotpKey with the Base32-encoded seed. On read the Totp is populated with a TotpCode containing the current OTP, its expiry time and remaining seconds.

CertificateSecret

Updating and deleting secrets

Local TOTP code generation (TotpCodeGenerator)

TotpCodeGenerator is a static helper that generates TOTP codes locally (RFC 6238, HMAC-SHA1) without calling Vault. It is used internally by LocalFileSystemSecretStorage but is also available for direct use:

Features

  • Typed secret buckets — secrets are namespaced by a user-defined enum; different bucket enums compile to different ISecretStorage<T> registrations

  • Four secret typesUsernamePassword, UsernamePasswordApiKey, UsernamePasswordTotp, Certificate

  • Opaque secret IDs — bucket, type and key are encoded into a URL-safe Sqid string for safe external exposure

  • First-class TOTP support — creates/manages TOTP keys in Vault's TOTP engine; decodes live OTP codes on every read

  • Local filesystem backend — drop-in replacement for local development and testing; TOTP codes generated locally via RFC 6238

  • OpenTelemetry tracing — all storage operations are wrapped in ActivitySource spans with secret.bucket, secret.key, and secret.type tags

  • Readiness health checkvault (Vault HTTP health endpoint) or vault-local-filesystem (directory write probe) registered automatically as a readiness check

  • Dosaic WebHost integration — discovered and wired automatically by the source generator; no manual bootstrap required when using PluginWebHostBuilder

Health Checks

The plugin registers a readiness health check automatically:

Mode
Check name
Probe

Vault server

vault

GET /v1/sys/health via IVaultClient

Local filesystem

vault-local-filesystem

Creates and deletes a .health-probe file in LocalFileSystemPath

Both checks report Unhealthy on failure, preventing the application from receiving traffic until the backend is reachable.

Last updated