GM.Secrets 1.0.1

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

GM.Secrets

A provider-agnostic secrets abstraction for the GM.* ecosystem. Your code depends on one interface — ISecretsService — and the backend (environment variables, configuration, and, as follow-on packages, Azure Key Vault / AWS Secrets Manager / HashiCorp Vault) is chosen by configuration. Remote lookups are cached with a TTL via GM.Caching, so reads are cheap and rotation happens automatically when the cache entry expires.

  • GM.Secrets — the core ISecretsService / ISecretsProvider, caching, typed & required access, and config-driven provider selection. Depends only on GM.Caching.
  • GM.Secrets.Environment — reads environment variables (with prefix + name normalization).
  • GM.Secrets.Configuration — reads from IConfiguration (appsettings, user secrets, any source).

Install

dotnet add package GM.Secrets
dotnet add package GM.Secrets.Environment     # and/or
dotnet add package GM.Secrets.Configuration

Register

builder.Services.AddGMCaching();   // optional — enables TTL caching / rotation of secret reads

// Register the providers you want available…
builder.Services.AddGMEnvironmentSecrets(builder.Configuration);
builder.Services.AddGMConfigurationSecrets(builder.Configuration);

// …and select the active one (+ options) from configuration.
builder.Services.AddGMSecrets(builder.Configuration);
{
  "Secrets": {
    "Provider": "Environment",          // which backend wins
    "CacheDuration": "00:05:00",        // 0 disables caching
    "Environment": { "Prefix": "MYAPP_" },
    "Configuration": { "SectionName": "SecretValues" }
  }
}

Switching backends (dev → prod, Environment → Key Vault) is a config change — no code change — as long as the provider package is registered.

Use

public sealed class PaymentClient(ISecretsService secrets)
{
    public async Task ChargeAsync(...)
    {
        // Required: throws SecretNotFoundException if absent (fail fast at the edge).
        var apiKey = await secrets.GetRequiredSecretAsync("Payments:ApiKey");

        // Optional: null when absent.
        var webhookSecret = await secrets.GetSecretAsync("Payments:WebhookSecret");

        // Typed: a structured secret stored as JSON.
        var creds = await secrets.GetSecretAsync<DbCredentials>("Db:Credentials");
        // …use them; never log a secret value.
    }
}

Values returned are sensitive — pass them straight to the consumer (a connection string, an SDK credential); don't log them. SecretNotFoundException and error messages carry only the secret name, never a value.

Add a provider

Implement ISecretsProvider and register it as a keyed singleton under a provider name — the core selector resolves whichever Secrets:Provider names:

public sealed class VaultSecretsProvider : ISecretsProvider
{
    public string Name => "Vault";
    public Task<string?> GetSecretAsync(string name, CancellationToken ct = default) => /* fetch */;
}

services.AddKeyedSingleton<ISecretsProvider, VaultSecretsProvider>("Vault");

Follow-up provider packages (flagged, not built)

Cloud backends slot in behind the same ISecretsProvider — deliberately left as follow-ups so each ships tested against its SDK:

  • GM.Secrets.AzureKeyVault — Azure.Security.KeyVault.Secrets + DefaultAzureCredential.
  • GM.Secrets.AwsSecretsManager — AWSSDK.SecretsManager.
  • GM.Secrets.Vault — HashiCorp Vault via VaultSharp.

A configuration-provider integration (surface secrets through IConfiguration at startup) and using GM.Secrets to supply runtime overrides elsewhere in the stack (e.g. rate-limit policy values) are natural extensions.

Samples

GM.Secrets.Samples — a runnable API that consumes secrets without ever exposing them.

License

MIT — see LICENSE.

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 (8)

Showing the top 5 NuGet packages that depend on GM.Secrets:

Package Downloads
GM.API

An opinionated ASP.NET Core Web API starter for .NET. A single AddGMAPI/UseGMAPI pair wires up controllers, CORS, API versioning, Swagger docs, FluentValidation, Serilog, and middlewares for exception handling, request logging (with sensitive-data masking) and request localization. Loads secrets into configuration from a local appsecrets.json or the store the SECRETS_PROVIDER environment variable names (Doppler, AWS Secrets Manager, Azure Key Vault, HashiCorp Vault). Bundles the GM.API.* companion packages.

GM.Secrets.AzureKeyVault

Azure Key Vault secrets provider for GM.Secrets — loads a vault's enabled secrets into IConfiguration at startup with DefaultAzureCredential (managed identity in Azure, az login / Visual Studio locally), with optional periodic reload. Db--Password maps to Db:Password. Register with builder.AddGMSecrets(s => s.AddAzureKeyVault()) and select via Secrets:Provider = "AzureKeyVault".

GM.Secrets.AwsSecretsManager

AWS Secrets Manager provider for GM.Secrets — reads the configured secrets (a JSON secret is flattened into keys, a plain one is keyed by its name) with the AWS SDK's default credential chain, and loads them into IConfiguration at startup, with optional periodic reload. Works with LocalStack/moto via ServiceUrl. Register with builder.AddGMSecrets(s => s.AddAwsSecretsManager()) and select via Secrets:Provider = "AwsSecretsManager".

GM.Secrets.Doppler

Doppler store for GM.Secrets — downloads a Doppler config's secrets (REST API, no SDK dependency) and loads them into IConfiguration at startup, with optional periodic reload. DB__PASSWORD maps to Db:Password. With a personal or CLI token the app environment picks the config (Development → dev, Staging → stg, Production → prd). Register with builder.AddGMSecrets(s => s.AddDoppler()) and select with the SECRETS_PROVIDER=Doppler environment variable.

GM.Secrets.Vault

HashiCorp Vault secrets provider for GM.Secrets — reads KV v2 paths over Vault's HTTP API (token or AppRole auth, no SDK dependency) and loads them into IConfiguration at startup, with optional periodic reload. Nested values become sections. Register with builder.AddGMSecrets(s => s.AddVault()) and select via Secrets:Provider = "Vault".

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 1,188 10/30/2026
1.0.1 245 8/31/2026
1.0.0 215 8/5/2026