No secret in production environment? A possible total solution.
Currently it is just for developing, in production key/value still has to be read from somewhere, which is a hell lot of work and burden. Also the following code is confusing: what? No secret in production environment? production environment is less important? if (env.IsEnvironment("Development")) { cfgbuilder.AddUserSecrets(); }
So I think Secrets tool should be extended to handle production as follows: During project building, Secrets tool loads key/value from its store and plugs them into according configuration file. For a total solution example:
- User creates appsettings.json has the following section: "AppSettings": { "SiteTitle": "ZaxiTech" }
- User adds appsettings.json. .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
- Users adds key/value and its mapping path. dotnet user-secrets AppSettings.SiteTitle = ZaxiTech_123.
Key/value: AppSettings.SiteTitle = ZaxiTech_123 Mapping path: AppSettings.SiteTitle
- In project.json: "scripts": { "prebuild": [“dotnet user-secrets apply appsettings.json”], }
During building, the Secret Tool replaces value of AppSettings.SiteTitle in appsettings.json. And the result appsettings.json (to be run or published) will be: "AppSettings": { "SiteTitle": "ZaxiTech_123" }
So source control sees "SiteTitle"="ZaxiTech"; but in runtime, it is "SiteTitle"= " ZaxiTech_123"
I hope this gets added to next build and makes asp.net a little easier to use.
@xatabhk This is a development time only tool. Storing any kind of secret in a file is risky, because you may accidentally check it in. In production, you can for example use environment variables to hold secrets (or any other more secure mechanism.)
@muratg Yes. It is a development tool. But it should not be wove into the code; that is, in code there should be no trace of the tool's existence, like EF tool or IIS publish tool. In short, no cfgbuilder.AddUserSecrets() or the like in code.
This repository is now deprecated. I'm closing this issue as we don't intend to take further action to address this issue. If you feel this issue should still be addressed, issues for UserSecrets can be opened on its new home at https://github.com/aspnet/DotNetTools.
cref https://github.com/aspnet/Announcements/issues/206.