T100.Extensions.Configuration.HashiCorpVault.Secrets 1.0.0

dotnet add package T100.Extensions.Configuration.HashiCorpVault.Secrets --version 1.0.0
                    
NuGet\Install-Package T100.Extensions.Configuration.HashiCorpVault.Secrets -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="T100.Extensions.Configuration.HashiCorpVault.Secrets" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="T100.Extensions.Configuration.HashiCorpVault.Secrets" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="T100.Extensions.Configuration.HashiCorpVault.Secrets" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add T100.Extensions.Configuration.HashiCorpVault.Secrets --version 1.0.0
                    
#r "nuget: T100.Extensions.Configuration.HashiCorpVault.Secrets, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package T100.Extensions.Configuration.HashiCorpVault.Secrets@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=T100.Extensions.Configuration.HashiCorpVault.Secrets&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=T100.Extensions.Configuration.HashiCorpVault.Secrets&version=1.0.0
                    
Install as a Cake Tool

T100.Extensions.Configuration.HashiCorpVault.Secrets

T100.Extensions.Configuration.HashiCorpVault.Secrets is a .NET library provides seamless integration with HashiCorp Vault for .NET configuration system, allowing secure retrieval of application secrets. This package streamlines the retrieval of sensitive information using the IConfiguration system and supports various Vault authentication methods.

Key Features

  • Integration with the IConfiguration system for fetching secrets directly as part of your .NET configuration.
  • Supports authentication with Token, AppRole, and Certificates.
  • Compatible with .NET 8.0 and .NET Standard 2.0, providing cross-platform availability.
  • Flexible configuration for accessing multiple secret paths.
  • Extended configuration options with support for logging.

Getting started

This package simplifies integrating HashiCorp Vault with your .NET application by providing a flexible configuration source. You can easily fetch secrets and configuration values from Vault securely and make them part of your application configuration.

Prerequisites

  • A running instance of HashiCorp Vault.
  • A valid method of authentication for Vault (for example, token, AppRole, or certificate).
  • Your project must target:
    • .NET 8.0 or
    • .NET Standard 2.0 for cross-platform compatibility.

Usage

To use the package, follow these steps:

  1. Install the package via NuGet:
dotnet add package T100.Extensions.Configuration.HashiCorpVault.Secrets
  1. Configure Vault integration in your application: Use AddVaultSecrets to connect your application's configuration system to Vault.

Example: Token Authentication

using Microsoft.Extensions.Configuration;
using T100.Extensions.Configuration.HashiCorpVault.Secrets;

const string host = "https://vault-server";
const string mountPoint = "kv.secrets";
const string prefix = string.Empty;
const string secretPath = "app/config";
const string token = "hvs...";

var builder = new ConfigurationBuilder() 
    .AddVaultSecrets(host, mountPoint, prefix, secretPath) 
    .UseTokenAuth(token);

var configuration = builder.Build();

// Fetch a secret value
var secretValue = configuration["my-secret-key"];
Console.WriteLine($"Secret value: {secretValue}");

Example: AppRole Authentication

using Microsoft.Extensions.Configuration;
using T100.Extensions.Configuration.HashiCorpVault.Secrets;

const string host = "https://vault-server";
const string mountPoint = "kv.secrets";
const string prefix = "brand:";
const string secretPath = "shared/config";
const string roleId = "572a0b1f-...";
const string secretId = "35708c97-...";

var builder = new ConfigurationBuilder() 
    .AddVaultSecrets(host, mountPoint, prefix, secretPath) 
    .UseAppRoleAuth(roleId, secretId);

var configuration = builder.Build();

// Fetch a secret value
var secretValue = configuration["connection"];
Console.WriteLine($"Secret value: {secretValue}");

Example: Certificate Authentication (certificate store)

using Microsoft.Extensions.Configuration;
using T100.Extensions.Configuration.HashiCorpVault.Secrets;

const string host = "https://vault-server";
const string mountPoint = "kv.secrets";
const string prefix = string.Empty; // optional
const string secretPath = "app/config";
const string secretPath1 = "shared/config";
const string thumbprint = "e642fa82...";

var builder = new ConfigurationBuilder() 
    .AddVaultSecrets(host, mountPoint, [secretPath, secretPath1])
    .UseCertificateAuth(thumbprint); // By default, the certificate will be searched in the personal store 
                                     // (StoreName.My) of the current user
var configuration = builder.Build();

// Fetch all secrets
foreach (var pair in configuration.AsEnumerable())
{
    Console.WriteLine(pair);
}

Example: Certificate Authentication (certificate file)

using Microsoft.Extensions.Configuration;
using T100.Extensions.Configuration.HashiCorpVault.Secrets;

const string host = "https://vault-server";
const string mountPoint = "kv.secrets";
const string prefix = string.Empty;
const string secretPath = "app/config";
const string secretPath1 = "shared/config";
const string certificateFile = "path-to-certificate.pfx";
const string certificatePassword = "<PASSWORD>";

using var certificate = new X509Certificate2(certificateFile, certificatePassword);

var builder = new ConfigurationBuilder() 
    .AddVaultSecrets(host, mountPoint, [secretPath, secretPath1]) 
    .UseCertificateAuth(certificate);

var configuration = builder.Build();

// Fetch all secrets
foreach (var pair in configuration.AsEnumerable())
{
    Console.WriteLine(pair);
}

Example: Complex Solution with troubleshooting

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using T100.Extensions.Configuration.HashiCorpVault.Secrets;

const string host = "https://vault-server";
const string mountPoint = "kv.secrets";
const string prefix = "brand:";
const string secretPath = "app/config";
const string secretPath1 = "shared/config";
const string secretPath2 = "other/config";
const string roleId = "572a0b1f-...";
const string secretId = "35708c97-...";
const string thumbprint = "e642fa82...";

using var factory = LoggerFactory.Create
(
    builder => builder.AddSystemdConsole(optional => optional.IncludeScopes = true) 
);

var logger = factory.CreateLogger<Program>();

var builder = new ConfigurationBuilder() 
    .AddVaultSecrets(host, mountPoint, [secretPath, secretPath1])
    .Configure(optional => optional.Logger = logger)
    .UseCertificateAuth(thumbprint)
    .AddVaultSecrets(host, mountPoint, prefix, secretPath3)
    .Configure(optional =>
    {
        optional.Logger = logger;
        optional.KeyDelimiter = "++";
    })
    .UseAppRoleAuth(roleId, secretId);

var configuration = builder.Build();

// Fetch all secrets
foreach (var pair in configuration.AsEnumerable())
{
    Console.WriteLine(pair);
}

Contributing and Feedback

This library is open source under the MIT license. Contributions, feedback, and issues are welcome!

  • Report issues on GitHub.
  • Fork the repository and submit a pull request to improve the functionality.

Happy coding, and efficiently retrieve your secrets with T100.Extensions.Configuration.HashiCorpVault.Secrets!

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 147 6/4/2025
1.0.0-beta.1 130 5/19/2025
0.1.0-alpha.4 146 5/16/2025
0.1.0-alpha.3 200 5/15/2025
0.1.0-alpha.2 212 5/14/2025
0.1.0-alpha.1 207 5/14/2025
0.1.0-alpha.0 265 5/14/2025