Skip to content

Commit ff8edb9

Browse files
authored
ROPC remediation - more files with connection strings (#33990)
1 parent 1a47fc6 commit ff8edb9

File tree

16 files changed

+45
-42
lines changed

16 files changed

+45
-42
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: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ description: Learn how to store and retrieve sensitive information during the de
55
ms.author: tdykstra
66
monikerRange: '>= aspnetcore-3.0'
77
ms.custom: mvc
8-
ms.date: 10/29/2024
8+
ms.date: 10/30/2024
99
uid: security/app-secrets
1010
---
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,15 @@ 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)]
205+
Storing passwords in plain text is insecure. Never store secrets in a configuration file such as `appsettings.json`, which might get checked in to a source code repository.
207206

208-
A more secure approach is to store the password as a secret. For example:
207+
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:
209208

210209
```dotnetcli
211-
dotnet user-secrets set "DbPassword" "pass123"
210+
dotnet user-secrets set "DbPassword" "`<secret value>`"
212211
```
213212

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:
213+
Replace the `<secret value>` 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:
219214

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

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

Lines changed: 6 additions & 11 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,17 @@ 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)]
176+
Storing passwords in plain text is insecure. Never store secrets in a configuration file such as `appsettings.json`, which might get checked in to a source code repository.
178177

179-
A more secure approach is to store the password as a secret. For example:
178+
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:
180179

181180
```dotnetcli
182-
dotnet user-secrets set "DbPassword" "pass123"
181+
dotnet user-secrets set "DbPassword" "<secret value>"
183182
```
184183

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:
184+
Replace the `<secret value>` 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:
190185

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

193188
## List the secrets
194189

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
}

aspnetcore/security/authentication/mfa/includes/mfa-5-8.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
:::moniker range=">= aspnetcore-6.0 <= aspnetcore-8.0"
2+
<!-- ms.sfi.ropc: t -->
23

34
By [Damien Bowden](https://github.com/damienbod)
45

aspnetcore/security/data-protection/configuration/overview.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ description: Learn how to configure Data Protection in ASP.NET Core.
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: tdykstra
77
ms.custom: mvc
8-
ms.date: 6/14/2023
8+
ms.date: 10/30/2024
99
uid: security/data-protection/configuration/overview
1010
---
1111
# Configure ASP.NET Core Data Protection
12+
<!-- ms.sfi.ropc: t -->
1213

1314
:::moniker range=">= aspnetcore-6.0"
1415

@@ -317,6 +318,8 @@ services.AddDataProtection()
317318
.ProtectKeysWithAzureKeyVault(new Uri("<keyIdentifier>"), new DefaultAzureCredential());
318319
```
319320
321+
[!INCLUDE [managed-identities](~/includes/managed-identities-conn-strings.md)]
322+
320323
## PersistKeysToFileSystem
321324
322325
To store keys on a UNC share instead of at the *%LOCALAPPDATA%* default location, configure the system with <xref:Microsoft.AspNetCore.DataProtection.DataProtectionBuilderExtensions.PersistKeysToFileSystem%2A>:

aspnetcore/signalr/redis-backplane.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ description: Learn how to set up a Redis backplane to enable scale-out for an AS
55
monikerRange: '>= aspnetcore-2.1'
66
ms.author: wpickett
77
ms.custom: mvc
8-
ms.date: 02/06/2024
8+
ms.date: 10/31/2024
99
uid: signalr/redis-backplane
1010
---
11-
11+
<!-- ms.sfi.ropc: t -->
1212
# Set up a Redis backplane for ASP.NET Core SignalR scale-out
1313

1414
By [Andrew Stanton-Nurse](https://twitter.com/anurse), [Brady Gaster](https://twitter.com/bradygaster), and [Tom Dykstra](https://github.com/tdykstra).
@@ -17,6 +17,8 @@ By [Andrew Stanton-Nurse](https://twitter.com/anurse), [Brady Gaster](https://tw
1717

1818
This article explains SignalR-specific aspects of setting up a [Redis](https://redis.io/) server to use for scaling out an ASP.NET Core SignalR app.
1919

20+
[!INCLUDE [managed-identities](~/includes/managed-identities-conn-strings.md)]
21+
2022
## Set up a Redis backplane
2123

2224
* Deploy a Redis server.

aspnetcore/signalr/redis-backplane/includes/redis-backplane.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
:::moniker range="> aspnetcore-2.0 <= aspnetcore-5.0"
2+
<!-- ms.sfi.ropc: t -->
23

34
This article explains SignalR-specific aspects of setting up a [Redis](https://redis.io/) server to use for scaling out an ASP.NET Core SignalR app.
45

6+
[!INCLUDE [managed-identities](~/includes/managed-identities-conn-strings.md)]
7+
58
## Set up a Redis backplane
69

710
* Deploy a Redis server.

0 commit comments

Comments
 (0)