You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: samples/host-aspnetcore-https.md
+5-91Lines changed: 5 additions & 91 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,97 +2,11 @@
2
2
3
3
ASP.NET Core uses [HTTPS by default](https://docs.microsoft.com/aspnet/core/security/enforcing-ssl). [HTTPS](https://en.wikipedia.org/wiki/HTTPS) relies on [certificates](https://en.wikipedia.org/wiki/Public_key_certificate) for trust, identity, and encryption.
4
4
5
-
This document explains how to run pre-built container images with HTTPS.
5
+
See [Hosting ASP.NET Core images with Docker over HTTPS](https://learn.microsoft.com/en-us/aspnet/core/security/docker-https) for [HTTPS](https://en.wikipedia.org/wiki/HTTPS) scenarios
6
6
7
-
See [Developing ASP.NET Core Applications with Docker over HTTPS](run-aspnetcore-https-development.md) for development scenarios.
7
+
## Get certificates into a container
8
8
9
-
This sample requires [Docker 17.06](https://docs.docker.com/release-notes/docker-ce) or later of the [Docker client](https://www.docker.com/products/docker).
9
+
The instructions show how to [bind-mount](https://docs.docker.com/engine/storage/bind-mounts/) certificates into containers. We recommend certificates ***NOT*** be added into the image with a `COPY` command in a Dockerfile for the following reasons:
10
10
11
-
## Certificates
12
-
13
-
You need a certificate from a [certificate authority](https://en.wikipedia.org/wiki/Certificate_authority) for [production hosting](https://blogs.msdn.microsoft.com/webdev/2017/11/29/configuring-https-in-asp-net-core-across-different-platforms/) for your domain. You may already have one. [Let's Encrypt](https://letsencrypt.org/) is a certificate authority that offers free certificates.
14
-
15
-
This document uses [self-signed development certificates](https://en.wikipedia.org/wiki/Self-signed_certificate) for hosting pre-built images over `localhost`. The instructions are similar to using production certificates.
16
-
17
-
For production certs, you do not need to use the `dotnet dev-certs` tool or store the certificates in the location used in the instructions. Any location should work, although storing certs within your site directory is an anti-pattern.
18
-
19
-
The instructions volume mount certificates into containers. You can add certificates into container images with a `COPY` command in a Dockerfile. Copying certificates into an image is an anti-pattern. It makes it harder to use the same image for testing with dev certificates and hosting with production certificates. There is also a significant risk of certificate disclosure if certificates are made part of container images.
20
-
21
-
## Running pre-built Container Images with HTTPS
22
-
23
-
Use the following instructions for your operating system configuration.
24
-
25
-
### Linux containers on Windows host
26
-
27
-
Generate cert and configure local machine:
28
-
29
-
> [!NOTE]
30
-
> If you are using CMD instead of PowerShell, substitute `$env:USERPROFILE` with `%USERPROFILE%`.
> The password must match the password used for the certificate. Running as ContainerAdministrator is not recommended in production scenarios. The `--user ContainerAdministrator` flag has been added in this example since there is a potential and intermittent race condition that throws a `WindowsCryptographicException` at the container/app startup when using self-signed certificates. This is a known bug and it has been [reported here](https://github.com/dotnet/runtime/issues/70386).
11
+
* It makes it harder to use the same image for testing with dev certificates and hosting with production certificates.
12
+
* It increases the risk of certificate disclosure if certificates are made part of your container image.
@@ -4,236 +4,98 @@ ASP.NET Core uses [HTTPS by default](https://docs.microsoft.com/aspnet/core/secu
4
4
5
5
This document demonstrates how to develop ASP.NET Core applications with HTTPS in Docker containers. It's recommended to try the [ASP.NET Core Docker Sample](README.md) first, which is simpler because the container only exposes HTTP. This more basic tutorial will help you validate that you have the sample working correctly, before adding the complication of certificates.
6
6
7
-
See [Hosting ASP.NET Core Images with Docker over HTTPS](host-aspnetcore-https.md) for production scenarios.
7
+
See [Hosting ASP.NET Core images with Docker over HTTPS](https://learn.microsoft.com/en-us/aspnet/core/security/docker-https) for production scenarios.
8
8
9
-
The Windows examples below are written for PowerShell. CMD users will need to change the format of the environment variables in the instructions from `$env:USERPROFILE` to `%USERPROFILE%`.
9
+
Windows instructions are written for PowerShell. If you are using CMD, change the format of environment variables from `${env:USERPROFILE}` to `%USERPROFILE%`.
10
10
11
-
This sample requires [Docker 17.06](https://docs.docker.com/release-notes/docker-ce) or later of the [Docker client](https://www.docker.com/products/docker).
11
+
This example requires [Docker Desktop](https://www.docker.com/products/docker-desktop/). We recommend the latest version.
12
12
13
-
## Getting the sample
13
+
## Getting the sample image
14
14
15
-
The easiest way to get the sample is by cloning the samples repository with git, using the following instructions:
You can also [download the repository as a zip](https://github.com/dotnet/dotnet-docker/archive/main.zip).
22
-
23
-
## Certificates
24
-
25
-
ASP.NET Core uses [self-signed development certificates](https://en.wikipedia.org/wiki/Self-signed_certificate) for development. Self-signed certificates are easy and free to create.
26
-
27
-
The instructions volume mount certificates into containers. You can add certificates into container images with a `COPY` command in a Dockerfile. This approach isn't recommended. It makes it harder to use the same image for testing with dev certificates and hosting with production certificates. There's also a significant risk of certificate disclosure if certificates are made part of container images.
28
-
29
-
## Application Secrets
30
-
31
-
These instructions assume that your project is configured for [application secrets](https://docs.microsoft.com/aspnet/core/security/app-secrets). The primary requirement is a [UserSecretsId](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/aspnetapp/aspnetapp.csproj#L5) element in your project file. If you're using the ASP.NET Core sample in this repo, you don't need to do anything. It's already correctly configured. If you're using your own project file, add an `UserSecretsId` element.
32
-
33
-
You can add the element manually or use Visual Studio to do it for you. The following image demonstrates the experience in Visual Studio.
34
-
35
-

36
-
37
-
The format of the `UserSecretsId` content doesn't matter. The sample in this repo used [Random String Generator](https://www.random.org/strings/?num=6&len=20&digits=on&unique=on&format=html&rnd=new) to produce a unique string.
38
-
39
-
> [!NOTE]
40
-
> `User Secrets` and `Application Secrets` terms are used interchangebly.
41
-
42
-
## Building and Running the Sample with HTTPS
43
-
44
-
Use the following instructions, for your operating system configuration. The commands assume that you are in the root of the repository.
45
-
46
-
> [!NOTE]
47
-
> The sample includes a banner to accept a cookie policy. When switching between HTTP and HTTPS, you may see the banner repeatedly. Delete the cookie for the site in `Developer Tools` in this case.
Further, if you're loading SSL certificates and trimming assemblies as part of the publish, you'll also need to update the project file for the sample. See details for how you can [support SSL certificates](https://docs.microsoft.com/en-us/dotnet/core/deploying/trim-self-contained#support-for-ssl-certificates).
> - The certificate name, in this case *aspnetapp*.pfx must match the project assembly name.
73
-
> -`<CREDENTIAL_PLACEHOLDER>` is used as a stand-in for a password of your own choosing.
74
-
> - If console returns "A valid HTTPS certificate is already present.", a trusted certificate already exists in your store. It can be exported using MMC Console.
75
-
76
-
Configure application secrets, for the certificate:
After the application starts, navigate to `https://localhost:8001` in your web browser.
99
-
100
-
### Linux containers on macOS host
101
-
102
-
```console
103
-
cd samples/aspnetapp
104
-
```
27
+
## Create and trust a development certificate
105
28
106
-
Create a certificate directory with appropriate permissions:
29
+
Follow the instructions for creating a [.NET development certificate](https://learn.microsoft.com/dotnet/core/tools/dotnet-dev-certs) from [Running pre-built container images with HTTPS](https://learn.microsoft.com/aspnet/core/security/docker-https#running-pre-built-container-images-with-https).
107
30
108
-
```console
109
-
mkdir -p -m 700 ${HOME}/.aspnet/https
110
-
```
31
+
## Enable HTTPS using environment variables
111
32
112
-
Generate cert and configure local machine:
33
+
See [Hosting ASP.NET Core images with Docker over HTTPS](https://learn.microsoft.com/aspnet/core/security/docker-https). See the following section if you don't want to use environment variables to store your development
> - The certificate name, in this case *aspnetapp*.pfx must match the project assembly name.
122
-
> -`<CREDENTIAL_PLACEHOLDER>` is used as a stand-in for a password of your own choosing.
38
+
Rather than using environment variable to specify the development certificate password, use [.NET user secrets](https://learn.microsoft.com/aspnet/core/security/app-secrets) to store the password.
123
39
124
-
Configure application secrets, for the certificate:
40
+
Initializing user-secrets for the first time on a project modifies the project file, so you will need a local copy of the `aspnetapp` sample. Clone this repo or [download the repository as a zip](https://github.com/dotnet/dotnet-docker/archive/main.zip).
After the application starts, navigate to `https://localhost:8001` in your web browser.
191
-
192
-
### Windows containers on Windows host
60
+
In Linux containers, .NET looks under the `~/.microsoft/usersecrets/` directory for user secrets data. Bind-mount your host machine's user secrets directory to the container's filesystem. If you are running your container as the `root` user, replace `/home/app/` with the `root` user's home directory, `/root/`.
> - The certificate name, in this case *aspnetapp*.pfx must match the project assembly name.
212
-
> -`<CREDENTIAL_PLACEHOLDER>` is used as a stand-in for a password of your own choosing.
213
-
> - If console returns "A valid HTTPS certificate is already present.", a trusted certificate already exists in your store. It can be exported using MMC Console.
88
+
**Windows containers on Windows:**
214
89
215
-
Configure application secrets, for the certificate:
After the application starts, navigate to `https://localhost:8001` in your web browser.
238
-
239
-
> In the case of using https, be sure to check the certificate you're using is trusted on the host. You can start with navigating to `https://localhost:8001` in the browser. If you're looking to test https with a domain name (e.g. `https://contoso.com:8001`), the certificate would also need the appropiate Subject Alternative Name included, and the DNS settings on the host would need to be updated. In the case of using the generated dev certificate, the trusted certificate will be issued from localhost and will not have the SAN added.
100
+
After the application starts, navigate to `https://localhost:8001` in your web
0 commit comments