-
Notifications
You must be signed in to change notification settings - Fork 25.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to setup the dev certificate when using Docker in development #6199
Comments
Subject: RE: Docker for ASP.NET Core 2.1 Preview 2 . Provided that your docker file and docker compose look like the ones that VS generates when you add VS support, there are a couple of steps you need to take to enable it manually. • Modify the dockerfile to expose the port 443 with per Javier: |
Is there an update for this now they we are in RTM for 2.1 and preparing for 2.1.1 release? |
Can we please avoid things like "Create an application on Visual Studio using the MVC template." in the documentation for a cross-platform framework like .NET Core, that also runs on Linux and Mac devices? |
Hi. The method works fine if I run the application in development environment. Is there are way to specify what certificate and port should kestrel use in production mode? |
When using a pfx file generated by dotnet dev-certs on my local Windows machine, I ran into a
So I switched to simply calling dotnet dev-certs https --export-path ./localhost.pfx -p $LOCALHOST_CERTIFICATE_PWD as part of building the Docker image and then referencing that in Startup.cs using KestrelServerOptions:
|
I had an issue with Docker-Compose.yml and Visual Studio.Net 15.7.5.
|
I have tried this in Docker and unless I specify the certificate location and password in the Startup configuration it crashes with: I followed the guide provided by @Rick-Anderson which seems to imply that UseStartup() now checks for the existence of the cert at root/.aspnet/https/<>.pfx or checks the UserSecrets for Kestrel:Certificates:Development:Path and Kestrel:Certificates:Development:Password The UserSecrets is working and configured correctly as i am using it to get the path and password, it works using this code:
|
I have found that if the path to the cert is specified in user secrets or an env var, it breaks. I was able to get it to work using the default startup by removing the path which i added when trying a bunch of other things: I can break it again by re-adding the path: The path is correct and the cert file exists as demonstrated in the code above, but for some reason it doesn't like having the path specified even if it is correct. The guide above does only say to add the password, but there should be no reason that adding the correct path, or even any valid path where the cert exists could not be made to work. This only applies to Development environment, in Production environment it works as per the docs using the 'Default' path: |
I have published a repo which uses this technique which can be used to reproduce this issue: |
@danroth27 what's the priority on this? We might need some help - at least for the first draft. |
@Rick-Anderson I should be revisiting that repo soon to build something out so will have a dig around to see what is causing the issue i posted about. |
Ok, i traced back the error message:
which occurs when "Kestrel:Certificates:Development:Path" is specified in the configuration from UserSecrets or env vars despite the path being correct and the file existing. I cloned the KestrelHttpServer repo and traced the message back to the Load() method inside the KestrelConfigurationLoader class (line 216). The Load() method calls However if the "Kestrel:Certificates:Default" config entry does not exist is call The following particularly ugly piece of code is used to locate the development certificate:
The TryGetCertificatePath(out certificatePath) method looks for a cert named That piece of code is completely broken if it's intention is to either use the certificateConfig.Path or go and find the certificate file from a default location and naming convention, which would be the sensible thing to do. The result of that 'if' statement is that if a certificate path is supplied in the config it is never used. It also will report a misleading error because a missing password would result in a log error which says that the certificate could not be located and also an exception inside the Load() method stating that that certificate could not be found. Experiencing misleading errors has always been an issue when working with Microsoft software in the past, was hoping that the situation has been improving. I also noticed that the IsDevelopmentCertificate method checks is the certificate.Subject is equal to "CN=localhost", which may not always be the case for every developers development environment. For example if you are developing using docker running on another machine or a VM etc. The code can be simplified, i don't really see the need to use the 2 separate configuration structures: "Kestrel:Certificates:Default" and "Kestrel:Certificates:Development" and check the subject of the cert. Just one config with a check to try and find the cert from the default location and name if it is not supplied in ":Path"? |
Looking at the referenced issue on line 332 of KestrelConfigurationLoader.cs It looks like the broken code was added as part of that, which seemed to start off with good intentions. Maybe the behaviour is intentional, if so i would like to know the reasoning. @Rick-Anderson Any documentation written to cover this setup with its current behaviour would look rather odd. |
It's not meant to be used with a path, the development certificate key is only there to support tooling scenarios. If you want to specify a path and a password, simply use the Default key.
It's only meant to support localhost scenarios (including docker localhost). Other scenarios will have security implications we would have to worry about.
There's no way AFAIK to check the validity of the password on the PFX. |
I've been trying to follow this example and I'm tearing my hair out! I get these exceptions: I have two containers, one talks to the other by HTTPS and by use of an alias configured in the compose file. The container being talked to doesn't have a public IP on purpose (Gateway Microservice architecture). I have generated a certificate and am applying it to the service being called. Any ideas? |
Turns out I needed this: https://blog.roushtech.net/2016/12/20/ignoring-ssl-certificate-errors-net-core-httpclient/ and yes this is in my development environment. |
Thanks, @jcoutch this worked for me. It's a little jankey seeing the full assembly name as the project name in my solution but w/e.... |
@scottaddie are you able to do this in the next 6 weeks or should we assign to the PU? |
Easiest workaround, works for me (when creating new project with https and docker support with linux container):
Note: I am on a Windows 10 Home VM running on Mac inside Parallels. I stopped and removed all the old docker containers before trying this, where I was facing the errors mentioned here. |
@Rick-Anderson Please assign to PU |
There are docs for this here https://github.com/dotnet/dotnet-docker/blob/master/samples/aspnetapp/aspnetcore-docker-https.md |
@mkArtakMSFT I've already pointed out to the related docs, now sure what you expect from me here. I think this was already discussed on a thread and addressed, but I might be wrong. @danroth27 can confirm. |
I see, hadn't read through all this. Should this be closed then? @Rick-Anderson ? |
The content in https://github.com/dotnet/dotnet-docker/blob/master/samples/aspnetapp/aspnetcore-docker-https.md should be part of our official docs. Someone needs to do the work of turning that content into official doc content. |
I've done that - see https://docs.microsoft.com/en-us/aspnet/core/security/docker-https?view=aspnetcore-2.2 |
Ah! Cool, sounds good then 😃. |
I know this is closed already.. but, does the suggested configuration work with 3.0? I've followed above steps and I am getting a weird docker compose error "Duplicate mount point: /root/.aspnet/https" using the following images: FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build Any help would be greatly appreciated. Thanks, |
Hi. It looks like you are posting on a closed issue! We're very likely to lose track of your bug/feedback/question unless you:
|
@jorgeolive -- kia ora. Did you end up opening a new issue regarding this and whether it works on .NET Core 3.x? I am also having difficulty getting a multi-containerised topology up and running, so it is either "user error" on my part, or possibly something you have already fixed. So, I'm just checking :) |
I started with the suggestions Rick-Anderson commented on May 22, 2018 but I am running into 'access denied' when exporting the certificate, for not only the .aspnet path as suggested but what seems to be any path. Ideas on how to get over this hurdle? |
Hi. It looks like you are posting on a closed issue! We're very likely to lose track of your bug/feedback/question unless you:
|
i updated my application from 2.2 to 3.1 and facing the following error.It was working perfectly in 2.2 with docker it was working fine with 2.2 but now facing an error in development mode. i run the following command to generate the dev certificate
program.cs
|
one question, can someone please answer, |
Easiest is to simply use mkcert (https://github.com/FiloSottile/mkcert) to generate any self-signed certificates, using a root cert, then place something like cloudflare in front with flexible SSL, this way you maintain SSL all the way through. Example base docker image
Then each application uses this base docker image and overrides the domains if needed
As all the correct environment variables are setup, using the default webhost builder is all that is needed.
|
related #3310
Javier is contact:
This needs to go in Enforce HTTPS in an ASP.NET Core
The first time you run dotnet after installing the SDK you get this message
Successfully installed the ASP.NET Core HTTPS Development Certificate.
To trust the certificate run 'dotnet dev-certs https --trust' (Windows and macOS only). For establishing trust on other platforms please refer to the platform specific documentation.
For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.
Copied from #3310
We also need to cover how to setup the dev certificate when using Docker in development:
EXPOSE 443
The text was updated successfully, but these errors were encountered: