Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I use User secrets only in the Development environment?

I have to save keys out of project and repository. For this, I want to use User secrets. But it is written there,

Call AddUserSecrets only when the app runs in the Development environment, as shown in the following example

And I can't understand or find a cause. Why can't I use it in the Production environment?

like image 437
Nodon Avatar asked Jun 17 '19 07:06

Nodon


People also ask

Why might you use the user secrets functionality?

The whole point of User Secrets is that developers can store their sensitive data for the application they're working on (passwords, api keys, connection strings, etc.) in a file separate from the code tree. This means that they cannot be accidentally committed into source control.

What is an advantage of using the secret Manager in an ASP NET core project?

The Secret Manager tool stores sensitive data during the development of an ASP.NET Core project. In this context, a piece of sensitive data is an app secret. App secrets are stored in a separate location from the project tree. The app secrets are associated with a specific project or shared across several projects.

Where are user secrets stored?

In a Windows machine, they are stored in the %APPDATA%\Microsoft\UserSecrets\<user_secrets_id>\secrets. json file. In a Linux/macOS machine, they are stored in the ~/. microsoft/usersecrets/<user_secrets_id>/secrets.

Do secrets override Appsettings?

Microsoft offers a secret manager tool that allows one to store secrets (in plain text) on the local development PC and these secrets are available locally during application development. These secrets overwrite any settings in appsettings. json and appsettings. {environment}.


2 Answers

You can find it in the link you provided to the User Secrets documentation:

The Secret Manager tool doesn't encrypt the stored secrets and shouldn't be treated as a trusted store. It's for development purposes only. The keys and values are stored in a JSON configuration file in the user profile directory.

like image 129
ALFA Avatar answered Oct 14 '22 04:10

ALFA


I think the short answer is that you probably could if you wanted to but that it is not what it is intended for.

My understanding is that the primary purpose of User Secrets is to keep credentials out of source control. In the days before GitHub and the cloud, most developers just stuck any and all credentials in the web.config and it was mostly ok. Then lots of people started using public repositories and AWS and all of a sudden https://www.zdnet.com/article/trufflehog-high-entropy-key-hunter-released-to-the-masses/

There are now a great many different tools out there for managing secrets, which one best suits your needs is a much harder question, but you could consider:

  • Are you using access controlled source control?
  • Are you cloud or on-prem for build and deploy?
  • Who has read access to the live servers?
  • How sensitive is the data you are storing?
  • What other applications are running on the server?

I was just poking around in the CreateDefaultBuilder method and found this, which is perhaps relevant:

if (hostingEnvironment.IsDevelopment())
{
    Assembly assembly = Assembly.Load(new 
              AssemblyName(hostingEnvironment.ApplicationName));

    if (assembly != (Assembly) null)
          config.AddUserSecrets(assembly, true);
 }

Obviously you don't have to use the default version and you could add secrets for all the environments, but there it is.

like image 37
ste-fu Avatar answered Oct 14 '22 05:10

ste-fu