Skip to content

Commit c44989d

Browse files
Update blog 5.9: add VS Manage User Secrets section and three-environment secret flow
1 parent bde3dbd commit c44989d

1 file changed

Lines changed: 66 additions & 1 deletion

File tree

blogs/series-5-devops-data/5.9-azure-key-vault-secrets.md

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ This article is part of the **AngularNetTutorial** series covering Angular 20, .
2525
* **`DefaultAzureCredential`** — how one credential works for both local development and Azure production with no code changes
2626
* **`AddAzureKeyVault()` in .NET** — how to wire Key Vault into `IConfiguration` so existing code requires zero changes
2727
* **`SecretClient`** — reading a specific secret directly in code when you need it on demand
28-
* **Local development** — using `dotnet user-secrets` locally, Key Vault in production
28+
* **Visual Studio Manage User Secrets** — the local development equivalent of Key Vault, stored in AppData and never committed to git
29+
* **Three secret sources, one IConfiguration key** — how user secrets, GitHub Secrets, and Key Vault work together across environments
2930

3031
---
3132

@@ -343,6 +344,70 @@ public class MyService(SecretClient secretClient)
343344

344345
---
345346

347+
## 🖥️ Local Development: Visual Studio Manage User Secrets
348+
349+
During local development you don't need Key Vault — it requires Azure network access and adds friction for every team member. Visual Studio has a built-in equivalent called **Manage User Secrets** that stores secrets outside the project folder so they're never committed to git.
350+
351+
### How to Open It
352+
353+
Right-click the `TalentManagementAPI.WebApi` project in Solution Explorer → **Manage User Secrets**
354+
355+
This opens a `secrets.json` file stored at:
356+
357+
```
358+
C:\Users\{you}\AppData\Roaming\Microsoft\UserSecrets\d7dba4fb-c08e-453d-9e13-d7d0f8ba8ff0\secrets.json
359+
```
360+
361+
The GUID is the `<UserSecretsId>` value already in `TalentManagementAPI.WebApi.csproj`. Each developer has their own copy — the file never appears in git.
362+
363+
### What to Put in secrets.json
364+
365+
```json
366+
{
367+
"ConnectionStrings": {
368+
"DefaultConnection": "Server=localhost;Database=TalentManagementApiDb;Trusted_Connection=True;MultipleActiveResultSets=true"
369+
},
370+
"JWTSettings": {
371+
"Key": "YourLocalJwtSigningKeyMinimum32Characters"
372+
},
373+
"Sts": {
374+
"ServerUrl": "https://localhost:44310",
375+
"ValidIssuer": "https://localhost:44310"
376+
}
377+
}
378+
```
379+
380+
These values override `appsettings.json` automatically in the `Development` environment — no code change required.
381+
382+
### The Full Picture: Three Secret Sources, One IConfiguration Key
383+
384+
The same `ConnectionStrings:DefaultConnection` key is read by the .NET app in every environment. What changes is where the value comes from:
385+
386+
**Local development — Visual Studio Manage User Secrets:**
387+
* Stored in `AppData` on your machine
388+
* Never in git, never in source control
389+
* Overrides `appsettings.json` automatically
390+
391+
**GitHub Actions deploy — GitHub Secrets:**
392+
* Used to log in to Azure and run Bicep
393+
* Writes `@Microsoft.KeyVault(...)` references to App Service settings
394+
* The actual database password is never in GitHub Secrets at all
395+
396+
**Azure App Service runtime — Key Vault:**
397+
* App Service resolves `@Microsoft.KeyVault(...)` references via managed identity
398+
* The running app receives the real connection string value
399+
* Never visible in plain text in the Portal
400+
401+
```
402+
Local dev → VS Manage User Secrets → AppData on your machine
403+
CI/CD deploy → GitHub Secrets → Azure login + KV reference URIs
404+
Azure runtime → Azure Key Vault → managed identity, resolved at startup
405+
```
406+
407+
**The application code never changes across environments.** `builder.Configuration["ConnectionStrings:DefaultConnection"]` works the same way whether the value came from `secrets.json`, an App Service setting, or a Key Vault reference.
408+
409+
---
410+
346411
## 🔄 When to Use Each Approach
347412
348413
**App Service Key Vault references** (`@Microsoft.KeyVault(...)` in settings):

0 commit comments

Comments
 (0)