pvNugsSecretManagerNc10ProviderEnvironment 10.0.0

dotnet add package pvNugsSecretManagerNc10ProviderEnvironment --version 10.0.0
                    
NuGet\Install-Package pvNugsSecretManagerNc10ProviderEnvironment -Version 10.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="pvNugsSecretManagerNc10ProviderEnvironment" Version="10.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="pvNugsSecretManagerNc10ProviderEnvironment" Version="10.0.0" />
                    
Directory.Packages.props
<PackageReference Include="pvNugsSecretManagerNc10ProviderEnvironment" />
                    
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 pvNugsSecretManagerNc10ProviderEnvironment --version 10.0.0
                    
#r "nuget: pvNugsSecretManagerNc10ProviderEnvironment, 10.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 pvNugsSecretManagerNc10ProviderEnvironment@10.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=pvNugsSecretManagerNc10ProviderEnvironment&version=10.0.0
                    
Install as a Cake Addin
#tool nuget:?package=pvNugsSecretManagerNc10ProviderEnvironment&version=10.0.0
                    
Install as a Cake Tool

๐Ÿ” pvNugsSecretManagerNc10ProviderEnvironment

NuGet Version NuGet Downloads License .NET Environment Variable and Configuration provider for the pvWay Secret Manager stack on .NET 10. ๐Ÿš€

This package implements IPvNugsSecretProvider and retrieves secrets from any source supported by Microsoft.Extensions.Configuration, including environment variables, appsettings.json, user secrets, and command-line arguments.

This package is intended to be used together with:

  • pvNugsSecretManagerNc10 for orchestration, caching, and exception normalization
  • an application-defined IPvNugsSecretManager consumer such as a callerService

๐Ÿ—๏ธ Architecture

The current design is intentionally split into three layers:

  1. Caller service / application code injects IPvNugsSecretManager
  2. Secret manager package (pvNugsSecretManagerNc10) orchestrates calls, caching, and logging
  3. Provider package (pvNugsSecretManagerNc10ProviderEnvironment) reads from configuration sources So the main application typically registers both:
  • IPvNugsSecretManager via PvNugsSecretManagerDi.TryAddPvNugsSecretManager(...)
  • one concrete IPvNugsSecretProvider, here EnvVarSecretProvider via PvNugsEnvVarSecretProviderDi.TryAddPvNugsEnvVarSecretProvider(...)
๐Ÿ‘ค Caller service
    โ†“ injects
๐Ÿ” IPvNugsSecretManager
    โ†“ delegates to
๐ŸŒ EnvVarSecretProvider
    โ†“ reads from
โš™๏ธ  Configuration Sources
    (Environment Variables, appsettings.json, User Secrets, etc.)

โœจ Features

  • ๐ŸŒ Retrieves secrets from environment variables, JSON files, user secrets, command-line args, and more
  • ๐Ÿ“ Optional prefix support for organizing secrets into namespaces
  • ๐Ÿ”ง DI-friendly registration
  • โšก Lightweight and fast - no external service calls
  • ๐Ÿงช Perfect for development and testing scenarios
  • โš ๏ธ Explicit unsupported-feature behavior for batch and dynamic secret APIs

โœ… Supported behavior

  • โœ”๏ธ GetStaticSecretAsync(...) retrieves one secret by the canonical parameter key secretName
  • โŒ GetStaticSecretsAsync(...) is not supported and throws PvNugsEnvVarProviderException
  • โŒ GetDynamicSecretAsync(...) is not supported and throws PvNugsEnvVarProviderException Environment variables and configuration files are static by nature and do not support dynamic credential rotation or batch secret retrieval like HashiCorp Vault.

๐Ÿ“ฆ Installation

Install-Package pvNugsSecretManagerNc10ProviderEnvironment

Or with the .NET CLI:

dotnet add package pvNugsSecretManagerNc10ProviderEnvironment

๐Ÿ“š Dependencies

This package depends on:

  • Microsoft.Extensions.Options.ConfigurationExtensions
  • pvNugsLoggerNc10Abstractions
  • pvNugsSecretManagerNc10Abstractions The application that uses this provider should also reference:
  • pvNugsSecretManagerNc10
  • one cache implementation and one logger implementation required by the secret manager package

โš™๏ธ Configuration

๐Ÿšจ SECURITY BEST PRACTICE

The JSON examples below are for illustrative purposes only. In production environments:

  • NEVER commit actual secrets to appsettings.json files
  • ALWAYS use environment variables for real production secrets
  • JSON files should only contain placeholders or configuration structure
  • Use .gitignore to exclude any local development configuration files with secrets

The provider is bound from the PvNugsEnvVarSecretProviderConfig section.

๐ŸŒ Without prefix (root-level secrets)

{
  "PvNugsEnvVarSecretProviderConfig": {
    "Prefix": null
  },
  // โš ๏ธ WARNING: These are EXAMPLES ONLY - never commit real secrets!
  "DatabasePassword": "REPLACE-WITH-ENV-VAR",
  "ApiKey": "REPLACE-WITH-ENV-VAR"
}

โœ… RECOMMENDED - Set environment variables directly:

# Windows
set DatabasePassword=my-dev-password
set ApiKey=my-dev-api-key
# Linux/macOS
export DatabasePassword=my-dev-password
export ApiKey=my-dev-api-key

๐Ÿ“‚ With prefix (organized secrets)

{
  "PvNugsEnvVarSecretProviderConfig": {
    "Prefix": "MyApp"
  },
  "MyApp": {
    // โš ๏ธ WARNING: These are EXAMPLES ONLY - never commit real secrets!
    "DatabasePassword": "REPLACE-WITH-ENV-VAR",
    "ApiKey": "REPLACE-WITH-ENV-VAR"
  }
}

โœ… RECOMMENDED - Set environment variables with hierarchical naming:

# Windows
set MyApp__DatabasePassword=my-dev-password
set MyApp__ApiKey=my-dev-api-key
# Linux/macOS
export MyApp__DatabasePassword=my-dev-password
export MyApp__ApiKey=my-dev-api-key

๐Ÿ”ง Multi-environment configuration

Leverage .NET's environment-specific configuration files:

appsettings.Development.json (local development only - DO NOT COMMIT with real secrets):

{
  "PvNugsEnvVarSecretProviderConfig": {
    "Prefix": "MyApp_Dev"
  },
  "MyApp_Dev": {
    // โš ๏ธ For local dev only - use User Secrets or local env vars
    "DatabasePassword": "local-dev-only",
    "ApiKey": "local-dev-only"
  }
}

appsettings.Production.json (โœ… BEST PRACTICE - no secrets in file):

{
  "PvNugsEnvVarSecretProviderConfig": {
    "Prefix": "MyApp_Prod"
  }
  // โœ… CORRECT: Secrets come from environment variables in production
  // โœ… NEVER include actual secret values in this file
  // โœ… Set environment variables:
  //    MyApp_Prod__DatabasePassword=<real-secret>
  //    MyApp_Prod__ApiKey=<real-secret>
}

๐Ÿ”ง Service registration

using pvNugsSecretManagerNc10;
using pvNugsSecretManagerNc10Abstractions;
using pvNugsSecretManagerNc10ProviderEnvironment;
var builder = WebApplication.CreateBuilder(args);
// Register the provider first
builder.Services.TryAddPvNugsEnvVarSecretProvider(builder.Configuration);
// Register the provider-agnostic manager
builder.Services.TryAddPvNugsSecretManager(builder.Configuration);
var app = builder.Build();

๐Ÿ’ก Usage

Your caller service should depend on IPvNugsSecretManager, not on the provider directly. You can use the helper PvNugsEnvVarSecretProviderParameters.CreateParameters(...) to avoid repeating dictionary boilerplate.

using pvNugsSecretManagerNc10Abstractions;
using pvNugsSecretManagerNc10ProviderEnvironment;
public class CallerService(IPvNugsSecretManager secretManager)
{
    public async Task<string?> GetDatabasePasswordAsync(CancellationToken ct = default)
    {
        var parameters = PvNugsEnvVarSecretProviderParameters
            .CreateParameters("DatabasePassword");
        return await secretManager.GetStaticSecretAsync(parameters, ct);
    }
    public async Task<string?> GetApiKeyAsync(CancellationToken ct = default)
    {
        var parameters = PvNugsEnvVarSecretProviderParameters
            .CreateParameters("ApiKey");
        return await secretManager.GetStaticSecretAsync(parameters, ct);
    }
}

๐Ÿ“ Parameter contract

The canonical key for single-secret retrieval is:

PvNugsEnvVarSecretProviderParameters.SecretName // "secretName"

The key is intentionally explicit so callers can build the dictionary once and reuse it consistently. Helper available:

PvNugsEnvVarSecretProviderParameters.CreateParameters("DatabasePassword")

The helper validates input and returns a read-only dictionary containing the canonical "secretName" key/value pair.

๐Ÿ” Configuration precedence

The provider follows standard .NET configuration precedence (last wins):

  1. appsettings.json (lowest priority)
  2. appsettings.{Environment}.json
  3. User secrets (development only)
  4. Environment variables
  5. Command-line arguments (highest priority) This means environment variables will override values from appsettings.json.

๐Ÿ’ก Use cases

โœ… Perfect for:

  • ๐Ÿงช Development and testing - Quick setup without external dependencies
  • ๐Ÿณ Container deployments - Inject secrets via environment variables
  • ๐Ÿ”’ User Secrets - Local development with sensitive data
  • โšก Simple applications - No need for complex secret management infrastructure
  • ๐Ÿ”„ Provider fallback - Graceful degradation when external secret services are unavailable
  • ๐Ÿ”„ Dynamic credentials - Use Azure provider or HashiCorp Vault for rotating credentials
  • ๐Ÿข Enterprise production - Consider Azure Key Vault, AWS Secrets Manager, or HashiCorp Vault
  • ๐Ÿ“ฆ Batch secret retrieval - This provider only supports single-secret access

โš ๏ธ Notes on unsupported APIs

This provider does not support:

  • Secret dictionaries by mount/path
  • Dynamic database credential generation
  • Secret rotation or expiration Unsupported operations fail fast with PvNugsEnvVarProviderException so callers can handle the limitation explicitly.

๐Ÿ” Security considerations

โ›” CRITICAL: Never Commit Secrets to Version Control

This is the #1 security rule when using this provider:

  • โŒ NEVER store real secrets in appsettings.json, appsettings.Production.json, or ANY file under version control
  • โŒ NEVER commit files containing actual passwords, API keys, connection strings, or tokens to Git
  • โŒ NEVER store production secrets in configuration files that could be accidentally exposed

For Production Environments:

  1. Environment Variables (Primary recommendation for this provider)

    • Set at the operating system level
    • Injected by deployment platform (Azure App Service, Kubernetes, Docker, etc.)
    • Never stored in files or version control
  2. Azure Key Vault Provider (Recommended for enterprise)

    • Use pvNugsSecretManagerNc10ProviderAzure instead of this provider
    • Proper secret rotation and auditing
    • Better for production environments

For Development Environments:

  1. User Secrets (dotnet user-secrets)

    • Stored outside project directory
    • Automatically excluded from source control
    • Only for local development
  2. Local Environment Variables

    • Set in your development machine
    • Not committed to version control

๐Ÿณ Container & Cloud Deployment Best Practices

  • Containers (Docker/Kubernetes): Inject secrets via environment variables or mounted volumes
  • Azure App Service: Use App Settings (environment variables) or Key Vault references
  • AWS: Use Systems Manager Parameter Store or Secrets Manager
  • Cloud platforms: Use platform-native secret injection mechanisms

๐Ÿ“‹ Configuration File Guidelines

If you must use JSON configuration files:

โœ… DO:

  • Store only non-sensitive configuration
  • Use placeholder values like "REPLACE-WITH-ENV-VAR" or "SET-VIA-ENVIRONMENT"
  • Document which values need to be set via environment variables
  • Add appsettings.*.local.json to .gitignore

โŒ DON'T:

  • Store any production secrets
  • Commit local development files with real credentials
  • Share configuration files containing sensitive data

๐Ÿšจ If Secrets Are Accidentally Committed

If you accidentally commit secrets to version control:

  1. Immediately rotate all exposed secrets
  2. Do NOT just delete the file and commit - the secret is still in Git history
  3. Consider the secret permanently compromised
  4. Use tools like git-secrets or truffleHog to scan repositories
  5. Review your repository's entire Git history

๐Ÿ” Additional Security Measures

  • Principle of Least Privilege: Only grant access to secrets that are absolutely necessary
  • Regular Rotation: Change secrets periodically even if not compromised
  • Monitoring: Log secret access attempts and investigate anomalies
  • Encryption at Rest: Ensure storage systems encrypt data
  • CI/CD Secrets: Use GitHub Secrets, Azure DevOps Variable Groups, or similar secure storage
  • pvNugsSecretManagerNc10Abstractions: interfaces
  • pvNugsSecretManagerNc10: caching, logging, orchestration
  • pvNugsSecretManagerNc10ProviderEnvironment: Environment Variable / Configuration provider
  • pvNugsSecretManagerNc10ProviderAzure: Azure Key Vault provider (for production)

๐Ÿ“„ License

MIT โ€” see LICENSE.

โš ๏ธ CRITICAL SECURITY WARNING

DO NOT store actual secrets in appsettings.json or any files under version control!

This provider should primarily use ENVIRONMENT VARIABLES for production secrets. While it can read from JSON configuration files, those should only contain non-sensitive configuration or be used for local development with placeholder values.

โœ… RECOMMENDED: Environment variables, User Secrets (dev only), Azure Key Vault

โŒ NEVER: Real secrets in appsettings.json files committed to Git/source control

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
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
10.0.0 115 6/21/2026

Fix missing config provisioning