Skip to content

Commit 60c9863

Browse files
committed
more files with connection strings
1 parent 3319fde commit 60c9863

File tree

6 files changed

+12
-37
lines changed

6 files changed

+12
-37
lines changed

aspnetcore/performance/caching/distributed/samples/8.x/RedisCache/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
},
88
"AllowedHosts": "*",
99
"ConnectionStrings": {
10-
"MyAzureRedisConStr": "<cache name>.redis.cache.windows.net,abortConnect=false,ssl=true,allowAdmin=true,password=<primary-access-key>"
10+
"MyAzureRedisConStr": "<connection string>"
1111
}
1212
}

aspnetcore/security/app-secrets.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ uid: security/app-secrets
1111
<!-- ms.sfi.ropc: t -->
1212
# Safe storage of app secrets in development in ASP.NET Core
1313

14+
1415
[!INCLUDE[](~/includes/not-latest-version.md)]
1516

1617
:::moniker range=">= aspnetcore-6.0"
@@ -19,7 +20,7 @@ By [Rick Anderson](https://twitter.com/RickAndMSFT) and [Kirk Larkin](https://tw
1920

2021
[View or download sample code](https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/security/app-secrets/samples) ([how to download](xref:index#how-to-download-a-sample))
2122

22-
This article explains how to manage sensitive data for an ASP.NET Core app on a development machine. Never store passwords or other sensitive data in source code or configuration files. Production secrets shouldn't be used for development or test. Secrets shouldn't be deployed with the app. Production secrets should be accessed through a controlled means like Azure Key Vault. Azure test and production secrets can be stored and protected with the [Azure Key Vault configuration provider](xref:security/key-vault-configuration).
23+
This article explains how to manage sensitive data for an ASP.NET Core app on a development machine. Never store passwords or other sensitive data in source code or configuration files. Production secrets shouldn't be used for development or test. Secrets shouldn't be deployed with the app. Production secrets should be accessed through a controlled means like Azure Key Vault. Azure test and production secrets can be stored and protected with the [Azure Key Vault configuration provider](xref:security/key-vault-configuration).
2324

2425
For more information on authentication for deployed test and production apps, see [Secure authentication flows](xref:security/index#secure-authentication-flows).
2526

@@ -201,21 +202,13 @@ The `Movies:ConnectionString` and `Movies:ServiceApiKey` secrets are mapped to t
201202

202203
## String replacement with secrets
203204

204-
Storing passwords in plain text is insecure. For example, a database connection string stored in `appsettings.json` may include a password for the specified user:
205-
206-
[!code-json[](~/security/app-secrets/samples/3.x/UserSecrets/appsettings-unsecure.json?highlight=3)]
207-
208-
A more secure approach is to store the password as a secret. For example:
205+
Storing passwords in plain text is insecure. For example, a database connection string stored in `appsettings.json` should not include a password. Instead, store the password as a secret, and include the password in the connection string at runtime. For example:
209206

210207
```dotnetcli
211-
dotnet user-secrets set "DbPassword" "pass123"
208+
dotnet user-secrets set "DbPassword" "<CREDENTIAL_PLACEHOLDER>"
212209
```
213210

214-
Remove the `Password` key-value pair from the connection string in `appsettings.json`. For example:
215-
216-
[!code-json[](~/security/app-secrets/samples/3.x/UserSecrets/appsettings.json?highlight=3)]
217-
218-
The secret's value can be set on a <xref:System.Data.SqlClient.SqlConnectionStringBuilder> object's <xref:System.Data.SqlClient.SqlConnectionStringBuilder.Password%2A> property to complete the connection string:
211+
Replace the placeholder in the preceding example with the password value. Set the secret's value on a <xref:System.Data.SqlClient.SqlConnectionStringBuilder> object's <xref:System.Data.SqlClient.SqlConnectionStringBuilder.Password%2A> property to include it as the password value in the connection string:
219212

220213
[!code-csharp[](~/security/app-secrets/samples/6.x/UserSecrets/Program.cs?name=snippet_sql&highlight=5-8)]
221214

aspnetcore/security/app-secrets/includes/app-secrets-3-5.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ By [Rick Anderson](https://twitter.com/RickAndMSFT), [Kirk Larkin](https://twitt
88
This article explains how to manage sensitive data for an ASP.NET Core app on a development machine. Never store passwords or other sensitive data in source code or configuration files. Production secrets shouldn't be used for development or test. Secrets shouldn't be deployed with the app. Production secrets should be accessed through a controlled means like Azure Key Vault. Azure test and production secrets can be stored and protected with the [Azure Key Vault configuration provider](xref:security/key-vault-configuration).
99

1010
For more information on authentication for test and production environments, see [Secure authentication flows](xref:security/index#secure-authentication-flows).
11+
1112
## Environment variables
1213

1314
Environment variables are used to avoid storage of app secrets in code or in local configuration files. Environment variables override configuration values for all previously specified configuration sources.
@@ -172,23 +173,15 @@ The `Movies:ConnectionString` and `Movies:ServiceApiKey` secrets are mapped to t
172173

173174
## String replacement with secrets
174175

175-
Storing passwords in plain text is insecure. For example, a database connection string stored in `appsettings.json` may include a password for the specified user:
176-
177-
[!code-json[](~/security/app-secrets/samples/3.x/UserSecrets/appsettings-unsecure.json?highlight=3)]
178-
179-
A more secure approach is to store the password as a secret. For example:
176+
Storing passwords in plain text is insecure. For example, a database connection string stored in `appsettings.json` should not include a password. Instead, store the password as a secret, and include the password in the connection string at runtime. For example:
180177

181178
```dotnetcli
182-
dotnet user-secrets set "DbPassword" "pass123"
179+
dotnet user-secrets set "DbPassword" "<CREDENTIAL_PLACEHOLDER>"
183180
```
184181

185-
Remove the `Password` key-value pair from the connection string in `appsettings.json`. For example:
186-
187-
[!code-json[](~/security/app-secrets/samples/3.x/UserSecrets/appsettings.json?highlight=3)]
188-
189-
The secret's value can be set on a <xref:System.Data.SqlClient.SqlConnectionStringBuilder> object's <xref:System.Data.SqlClient.SqlConnectionStringBuilder.Password%2A> property to complete the connection string:
182+
Replace the placeholder in the preceding example with the password value. Set the secret's value on a <xref:System.Data.SqlClient.SqlConnectionStringBuilder> object's <xref:System.Data.SqlClient.SqlConnectionStringBuilder.Password%2A> property to include it as the password value in the connection string:
190183

191-
[!code-csharp[](~/security/app-secrets/samples/3.x/UserSecrets/Startup2.cs?name=snippet_StartupClass&highlight=14-17)]
184+
[!code-csharp[](~/security/app-secrets/samples/6.x/UserSecrets/Program.cs?name=snippet_sql&highlight=5-8)]
192185

193186
## List the secrets
194187

aspnetcore/security/app-secrets/samples/2.x/UserSecrets/appsettings-unsecure.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

aspnetcore/security/app-secrets/samples/3.x/UserSecrets/appsettings-unsecure.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

aspnetcore/security/app-secrets/samples/6.x/UserSecrets/appsettings.Development.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@
88
},
99
"ConnectionStrings": {
1010
"Movies": "Server=(localdb)\\mssqllocaldb;Database=Movie-1;User Id=johndoe;MultipleActiveResultSets=true"
11-
},
12-
"DbPassword": "MySecret"
11+
}
1312
}

0 commit comments

Comments
 (0)