Skip to content

Commit 2515b85

Browse files
Prevent copy/paste of password and warn (#44761)
1 parent f2a7b31 commit 2515b85

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

src/WebSdk/README.md

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ The `ProjectSystem` package defines the following for ASP.NET Core Web Projects:
1616
- Default [globs](https://learn.microsoft.com/dotnet/core/extensions/file-globbing)
1717
- Project Capabilities
1818

19+
Password best practices
20+
======================
21+
22+
For production deployments:
23+
24+
* Use MSBuild to create artifacts, but without deployment, so no credentials are required. Deploy apps as a separate non-MSBuild step that has fewer dependencies and is easier to audit.
25+
* Use deployment keys with short expiration times. A server in a separate root of trust is used to manage the deployment keys. Secrets aren't exposed to the project, ensuring that even if the project is compromised, the root of trust remains secure.
26+
27+
In this document, replace `<Deploy-/p:Password>` with the deployment password.
28+
29+
[Azure Key Vault](https://learn.microsoft.com/azure/key-vault/general/overview) and [.NET Aspire](https://learn.microsoft.com/dotnet/aspire/get-started/aspire-overview) provide the most secure way to store and retrieve secrets. Azure Key Vault is a cloud service that safeguards encryption keys and secrets like certificates, connection strings, and passwords. For .NET Aspire, see [Secure communication between hosting and client integrations](https://learn.microsoft.com/dotnet/aspire/extensibility/secure-communication-between-integrations).
30+
31+
Configuration data guidelines:
32+
33+
* Never store passwords or other sensitive data in configuration provider code or in plain text configuration files.
34+
* Don't use production secrets in development or test environments.
35+
* Specify secrets outside of the project so that they can't be accidentally committed to a source code repository.
36+
1937
`Microsoft.NET.Sdk.Publish`
2038
======================
2139

@@ -63,27 +81,27 @@ MSDeploy Publish:
6381
Using MsBuild with the default profile:
6482

6583
```
66-
msbuild WebApplication.csproj /p:DeployOnBuild=true /p:WebPublishMethod=MSDeploy /p:MSDeployServiceURL=<msdeployUrl> /p:DeployIisAppPath=<IISSiteName> /p:UserName=<username> /p:Password=<DeploymentPassword> /p:PublishProfile=DefaultMSDeploy
84+
msbuild WebApplication.csproj /p:DeployOnBuild=true /p:WebPublishMethod=MSDeploy /p:MSDeployServiceURL=<msdeployUrl> /p:DeployIisAppPath=<IISSiteName> /p:UserName=<username> /p:Password=<Deploy-/p:Password> /p:PublishProfile=DefaultMSDeploy
6785
```
6886

6987
Using dotnet with the default profile:
7088

7189
```
72-
dotnet publish WebApplication.csproj /p:WebPublishMethod=MSDeploy /p:MSDeployServiceURL=<msdeployUrl> /p:DeployIisAppPath=<IISSiteName> /p:UserName=<username> /p:Password=<DeploymentPassword> /p:PublishProfile=DefaultMSDeploy
90+
dotnet publish WebApplication.csproj /p:WebPublishMethod=MSDeploy /p:MSDeployServiceURL=<msdeployUrl> /p:DeployIisAppPath=<IISSiteName> /p:UserName=<username> /p:Password=<Deploy-/p:Password> /p:PublishProfile=DefaultMSDeploy
7391
```
7492

7593
Profile can be added to the following location in the project /Properties/PublishProfiles/<MsDeployProfile.pubxml>. MsDeploy Publish profile samples are available below:
7694

7795
Using MsBuild with a profile:
7896

7997
```
80-
msbuild WebApplication.csproj /p:DeployOnBuild=true /p:PublishProfile=<MsDeployProfile name> /p:Password=<DeploymentPassword>
98+
msbuild WebApplication.csproj /p:DeployOnBuild=true /p:PublishProfile=<MsDeployProfile name> /p:Password=<Deploy-/p:Password>
8199
```
82100

83101
Using dotnet with a profile:
84102

85103
```
86-
dotnet publish WebApplication.csproj /p:PublishProfile=<MsDeployProfile name> /p:Password=<DeploymentPassword>
104+
dotnet publish WebApplication.csproj /p:PublishProfile=<MsDeployProfile name> /p:Password=<Deploy-/p:Password>
87105
```
88106

89107
MsDeploy Package:
@@ -121,27 +139,27 @@ Zip Deploy:
121139
Using MsBuild with the default profile:
122140

123141
```
124-
msbuild WebApplication.csproj /p:DeployOnBuild=true /p:WebPublishMethod=ZipDeploy /p:PublishUrl=<Destination URL> /p:UserName=<username> /p:Password=<DeploymentPassword> /p:PublishProfile=DefaultZipDeploy
142+
msbuild WebApplication.csproj /p:DeployOnBuild=true /p:WebPublishMethod=ZipDeploy /p:PublishUrl=<Destination URL> /p:UserName=<username> /p:Password=<Deploy-/p:Password> /p:PublishProfile=DefaultZipDeploy
125143
```
126144

127145
Using dotnet with the default profile:
128146

129147
```
130-
dotnet publish WebApplication.csproj /p:WebPublishMethod=ZipDeploy /p:PublishUrl=<Destination URL> /p:UserName=<username> /p:Password=<DeploymentPassword> /p:PublishProfile=DefaultZipDeploy
148+
dotnet publish WebApplication.csproj /p:WebPublishMethod=ZipDeploy /p:PublishUrl=<Destination URL> /p:UserName=<username> /p:Password=<Deploy-/p:Password> /p:PublishProfile=DefaultZipDeploy
131149
```
132150

133151
Profile can be added to the following location in the project /Properties/PublishProfiles/<ZipDeploy.pubxml>.
134152

135153
Using MsBuild with a profile:
136154

137155
```
138-
msbuild WebApplication.csproj /p:DeployOnBuild=true /p:PublishProfile=<ZipDeployProfile name> /p:Password=<DeploymentPassword>
156+
msbuild WebApplication.csproj /p:DeployOnBuild=true /p:PublishProfile=<ZipDeployProfile name> /p:Password=<Deploy-/p:Password>
139157
```
140158

141159
Using dotnet with a profile:
142160

143161
```
144-
dotnet publish WebApplication.csproj /p:PublishProfile=<ZipDeployProfile name> /p:Password=<DeploymentPassword>
162+
dotnet publish WebApplication.csproj /p:PublishProfile=<ZipDeployProfile name> /p:Password=<Deploy-/p:Password>
145163
```
146164

147165
One Deploy:
@@ -151,15 +169,15 @@ Using dotnet with the default profile:
151169

152170
```
153171
154-
dotnet publish WebJobApplication.csproj /p:WebPublishMethod=OneDeploy /p:PublishUrl=<DestinationUrl> /p:UserName=<username> /p:Password=<DeploymentPassword> /p:PublishProfile=DefaultWebJobOneDeploy
172+
dotnet publish WebJobApplication.csproj /p:WebPublishMethod=OneDeploy /p:PublishUrl=<DestinationUrl> /p:UserName=<username> /p:Password=<Deploy-/p:Password> /p:PublishProfile=DefaultWebJobOneDeploy
155173
```
156174

157175
Profile can be added to the following location in the project /Properties/PublishProfiles/<OneDeploy.pubxml>.
158176

159177
Using dotnet with a profile:
160178

161179
```
162-
dotnet publish WebJobApplication.csproj /p:PublishProfile=<OneDeployProfile name> /p:Password=<DeploymentPassword>
180+
dotnet publish WebJobApplication.csproj /p:PublishProfile=<OneDeployProfile name> /p:Password=<Deploy-/p:Password>
163181
```
164182

165183
Sample folder profile:
@@ -198,7 +216,7 @@ Sample MsDeploy Publish Profile:
198216
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
199217
<EnableMSDeployBackup>True</EnableMSDeployBackup>
200218
<UserName>$vramakwebappwithdb</UserName>
201-
<Password>DeployPassword</Password>
219+
<Password></$Credential></Password>
202220
</PropertyGroup>
203221
</Project>
204222
```
@@ -257,16 +275,16 @@ Sample MsDeploy Profile With Destination Connection String & EF Migrations:
257275
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
258276
<EnableMSDeployBackup>True</EnableMSDeployBackup>
259277
<UserName>$vramakwebappwithdb</UserName>
260-
<Password>DeployPassword</Password>
278+
<Password></$Credential></Password>
261279
</PropertyGroup>
262280
<ItemGroup>
263281
<DestinationConnectionStrings Include="ShoppingCartConnection">
264-
<Value>Data Source=tcp:dbserver.database.windows.net,1433;Initial Catalog=shoppingcartdbdb_db;User Id=appUser@dbserver;Password=password</Value>
282+
<Value>Data Source=tcp:dbserver.database.windows.net,1433;Initial Catalog=shoppingcartdbdb_db;User Id=appUser@dbserver;Password=</$DB_Credential></Value>
265283
</DestinationConnectionStrings>
266284
</ItemGroup>
267285
<ItemGroup>
268286
<EFMigrations Include="ShoppingCartContext">
269-
<Value>Data Source=tcp:dbserver.database.windows.net,1433;Initial Catalog=shoppingcartdbdb_db;User Id=efMigrationUser@dbserver;Password=password</Value>
287+
<Value>Data Source=tcp:dbserver.database.windows.net,1433;Initial Catalog=shoppingcartdbdb_db;User Id=efMigrationUser@dbserver;Password=</$DB_Credential></Value>
270288
</EFMigrations>
271289
</ItemGroup>
272290
</Project>

0 commit comments

Comments
 (0)