liveBook · Manning

Secret management

As explained in .NET in Action, Second Edition

Secret Manager is a .NET development tool for storing and retrieving user secrets outside an application's project files.

Secret Manager keeps local-development values out of project configuration files. Initialize it from the project directory; the resulting UserSecretsId can be checked in because it identifies a secret file stored on the developer’s machine. section 9.4.2

Listing 9.13 Adds the connection string to Secret Manager for ManningBooksApi project
dotnet user-secrets set "ConnectionStrings:Catalog"
  "DataSource=manningbooks.db;cache=shared"

Set a named connection string in Secret Manager with the .NET CLI. section 9.4.2

Listing 9.14 Getting connection string from secret through configuration
var builder = WebApplication.CreateBuilder(args);
var config = builder.Configuration;                        #1
 
builder.Services.AddDbContext<CatalogContext>(options =>
{
  var connStr = config.GetConnectionString("Catalog");     #2
  options.UseSqlite(connStr);
});

Read the stored connection string through application configuration when registering the database context. section 9.4.2

Secret Manager also supports values that vary by developer or environment:

  • Store Azure AD client and tenant IDs as user secrets instead of putting them in appsettings.json. section 9.5.2
  • Treat local user secrets as a development convenience, not a general production secret store; production options depend on the hosting environment. section 9.4.2

How .NET in Action, Second Edition covers it

How deep it goes
Shows initialization, storing values, and retrieving a connection string through configuration, while deferring container secret exposure.
Examples
Uses a Catalog connection string and Azure AD client and tenant IDs as stored values.
What you can do after
Operate/configure Secret Manager by initializing a project, setting named values, and reading a connection string through configuration.
How it connects
Connects secret management to .NET configuration, connection strings, environment variables, and Kubernetes secrets.

Also explained in

Compare how 6 books explain secret management →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET in Action, Second Edition. The section links point to the parts of the book it draws on.