DockerSecrets.Configuration 1.2.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package DockerSecrets.Configuration --version 1.2.5
                    
NuGet\Install-Package DockerSecrets.Configuration -Version 1.2.5
                    
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="DockerSecrets.Configuration" Version="1.2.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DockerSecrets.Configuration" Version="1.2.5" />
                    
Directory.Packages.props
<PackageReference Include="DockerSecrets.Configuration" />
                    
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 DockerSecrets.Configuration --version 1.2.5
                    
#r "nuget: DockerSecrets.Configuration, 1.2.5"
                    
#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 DockerSecrets.Configuration@1.2.5
                    
#: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=DockerSecrets.Configuration&version=1.2.5
                    
Install as a Cake Addin
#tool nuget:?package=DockerSecrets.Configuration&version=1.2.5
                    
Install as a Cake Tool

DockerSecrets.Configuration

DockerSecrets.Configuration is a lightweight configuration provider that integrates Docker secrets seamlessly into your .NET applications. It leverages the Microsoft.Extensions.Configuration framework to load secrets from a specified directory (by default /run/secrets) and transform them into hierarchical configuration keys. This is especially useful when running your application in a Dockerized environment.

NuGet

Table of Contents

Features

  • Docker Secrets Integration: Load Docker secrets from a specified directory directly into your application configuration.
  • Namespace Filtering: Optionally filter secrets by a specified namespace to load only relevant secrets.
  • Customizable Delimiters: Easily define custom delimiters for namespace separation and key conversion.
  • Simple Integration: One-line extension method to add the secrets provider to your configuration pipeline.
  • Verbose Logging: Built-in console logging helps trace secret loading for easier debugging and monitoring.

Installation

Install the package via the .NET CLI:

dotnet add package DockerSecrets.Configuration

Or via the NuGet Package Manager:

Install-Package DockerSecrets.Configuration

For more details, check out the NuGet page.

Usage

ASP.NET Core Web Application

To integrate Docker secrets into an ASP.NET Core web application, modify your Program.cs as follows:

var builder = WebApplication.CreateBuilder(args);

// Add Docker secrets with an optional expected namespace filter.
builder.Configuration.AddDockerSecrets(
    expectedNamespace: "Namespace" // Replace "Namespace" with your desired namespace, or omit for no filtering.
);

var app = builder.Build();
app.Run();

Generic Host / Console Application

For generic host or console applications, add the secrets provider during configuration setup:

using Microsoft.Extensions.Hosting;
using DockerSecrets.Configuration;

IHost host = Host.CreateDefaultBuilder(args)
    .ConfigureAppConfiguration((context, config) =>
    {
        // Add Docker secrets with an optional expected namespace filter.
        config.AddDockerSecrets(
            expectedNamespace: "Namespace" // Replace with your desired namespace.
        );
    })
    .Build();

host.Run();

Configuration Options

When using the AddDockerSecrets extension method, you can customize the following parameters:

  • secretsPath:
    The directory where Docker secrets are mounted.
    Default: /run/secrets

  • expectedNamespace:
    If provided, only secrets that begin with this namespace (plus the delimiter) will be loaded.
    Example: "Test"

  • namespaceDelimiter:
    The character used to separate the namespace from the remainder of the file name.
    Default: "."
    Example: With an expected namespace of "Test" and a delimiter ".", a valid secret file name would be Test.ApplicationSettings__EncryptionKey.

  • keyDelimiter:
    The delimiter within the file name that will be replaced with a colon (:) to form hierarchical configuration keys.
    Default: "__"
    Example: A file named ApplicationSettings__EncryptionKey will be loaded as ApplicationSettings:EncryptionKey in the configuration.

How It Works

  1. The DockerSecretsConfigurationProvider reads all files from the configured secretsPath directory.
  2. If an expectedNamespace is set, only secrets prefixed with that namespace will be loaded.
  3. The namespace (if present) is stripped, and the file name is transformed into a hierarchical configuration key using the keyDelimiter.
  4. The contents of the file become the value of the configuration key.

For example, assuming the following files exist in /run/secrets:

/run/secrets/Test.Database__Password
/run/secrets/Test.Api__Key

With expectedNamespace set to "Test" and keyDelimiter set to "__", the resulting configuration keys will be:

{
  "Database:Password": "mysecretpassword",
  "Api:Key": "myapikey"
}

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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 was computed.  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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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.3.1 1,960 3/17/2025
1.3.0 202 3/17/2025
1.2.5 200 3/17/2025
1.2.4 205 3/17/2025
1.2.3 193 3/16/2025
1.2.2 188 3/16/2025
1.2.1 183 3/16/2025
1.2.0 224 3/16/2025