User-secrets per machine?
I have many solutions and projects that use the same sql connection string user/password.
Currently I use DotNet User Secrets like this:
Which works fine, but it's at project level so I need to do it for each individual project, and I have many solutions/projects. And each dev would need to set those for each project
Is there a way to set a global/machine-level User Secret?
It would be great if all project could just read a central "sql-dev-user"/"sql-dev-pass"
27 Replies
GitHub
Reverse Engineering Page is Unclear On Utilizing User Secrets · Iss...
The page is very unclear as to how one should actually store user secrets in a way so that dotnet ef dbcontext scaffold Name=ConnectionStrings:Chinook Microsoft.EntityFrameworkCore.SqlServer could ...
that's still per-project i think
it looks like you can manually do it by editing the project file
set it up for 1 project, then copy/paste that <UserSecretsId>dotnet-UserSecrets-3825E1F5-F0B3-4C37-80C4-D5F24C7F6645</UserSecretsId> to all other project files, so they all point to the same user secrets
good enough for me
going via the dotnet user-secrets tool generates a new guid for each project
yea, I meant that I think the storage is shared enough to be shared. Glad this unblocks you
I have set my "global" secrets in environment variables
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
That is to me more hassle than using the environment variables. Having multiple user-secrets you have to apply all you need to each project. With the environment variables you are ready to go with doing nothing else.
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
to all computer?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
the user-secret is a simple json file in plain text not encrypted or secured in any way and it can be read by any application
how is this more secure than env vars?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Please stop with that leaky env vars - they are not more/less secure then a plain file.
period
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Oh yeah, that machine wide user secret solves the part with the two unrelated projects with the same config value names 😁
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Ok, I am out
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Idea 1:
@cow You don't need to manually overwrite. Follow the following steps.
1. Only invoke
* If you want to overwrite all project in a single solution then the active directory must be the solution directory. * If you want to overwrite a single project only then the active directory must be the project directory. Note The bash file only overwrites the contents of
dotnet user-secrets init
on projects that need user-secrets
as usual.
Their ids are of course unique but they will be overwritten later.
2. Assume you have already had an id of user-secrets
that you want to share globally.
Create the following bash file, save in the most convenient place, for example c:\idchanger.sh
, and register this path to system environment variable Path
.
3. Depending how many projects do you want to overwrite, you can invoke the bash at any level.
* If you want to overwrite all projects in a folder d:\allprojects
then your active directory must be d:\allprojects
.
Invoking c:/idchanger.sh
will overwrite all projects in d:\allprojects
and in its sub directories at any level.* If you want to overwrite all project in a single solution then the active directory must be the solution directory. * If you want to overwrite a single project only then the active directory must be the project directory. Note The bash file only overwrites the contents of
UserSecretId
tag that you add temporarily. It DOES NOT touch other tags. It is safe because this approach is carefully thought. 🙂
Idea 2:
I found another approach.
1. Create a class library project SharedUserSecrets.csproj
with only one interface IMarker.cs
.
2. Initialize this project with dotnet user-secrets init
.
3. Other projects that need to access the shared secrets now can just make a reference to this SharedUserSecret
project.
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Only overwriting temporary
<UserSecretId>
and the others are left untouched is not harmful. I don't know why it is a problem. This anxiety might occurred because of a lack of careful thorough analysis. 🙂Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Let OP decide which one he/she want to use. We can only provide as many reasonable alternatives as we can. For me my approach does the job done based on his/her requirement. She/he does not want to manually copy and paste the shared user secret id among other projects. Closing statement: Keep coding and stay awesome. 🙂
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
This comment might be made without trying to carefully analyze the script I provided and its impact on the config file. My script is actually safe.
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Code I provided has been tested and it works.
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View