Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 2개 있습니다.)

ASP.NET Core를 docker에서 실행 시 "Failed with a critical error." 오류 발생

"Enable Docker Support"와 "Configure for HTTPS" 옵션을 켜고 생성한 ASP.NET Core Web Application을 실행 시 다음과 같은 질문 창이 뜹니다.

This project is configured to use SSL. In order for debugging to work, the self-signed certificate that ASP.NET Core has generated should be trusted.

If you do not want to be asked to trust the certificate again, please open "Tools -> Options -> Container Tools" and check "Do not prompt for trusting localhost SSL certificate".

Would you like to trust the ASP.NET Core SSL certificate?


"Yes"를 선택하고 진행하는데 오류 창이 뜨면서 실행이 막힙니다.

Adding the certificate to the Trusted Root Certficates store failed with the following error:

Failed with a critical error.

검색해 보면 저 질문 후의 과정이 https 지원 시 "localhost"에 대한 인증서를 자동으로 발급하는 거라고 합니다. 이에 대해서는 아래의 글에 어떤 작업을 하는지 상세하게 설명합니다.

VS2017 Docker debugging failed: Failed to create the certificate
; https://github.com/Microsoft/DockerTools/issues/99

실제로 Visual Studio가 자동화하는 과정을 수동으로 할 수 있는데 우선 다음의 명령어로 Web Application에 해당하는 테스트 인증서를 생성하는 것으로 시작합니다.

[형식]
dotnet dev-certs https --trust -ep "%APPDATA%\ASP.NET\https\{WebApplication_프로젝트_이름}.pfx" -p {인증서_암호}

[예제 - 프로젝트 이름이 "netcore_web"인 경우]
dotnet dev-certs https --trust -ep "%APPDATA%\ASP.NET\https\netcore_web.pfx" -p TestPassword

위와 같이 실행하면 "%APPDATA%\ASP.NET\https" 폴더에 netcore_web.pfx라는 이름으로 인증서가 만들어집니다. 그리고 이 인증서를 마우스로 두 번 클릭해 등록해 줍니다. 2군데에 등록해야 하는데 "Personal"과 "Trusted Root Certification Authorities"에 각각 있어야 합니다. (명령행에서 "certmgr"을 입력해 "Certificates - Current User" 인증서 관리 창을 띄워 다음과 같이 등록된 것을 확인할 수 있습니다.)

[그림 - "ASP.NET Core HTTPS development certificate" 인증서]
aspnet_docker_ssl_support_1.png

그다음 인증서에 대한 암호(위의 예에서는 TestPassword)를 csproj 파일에 등록해야 합니다. 방법은 이전에 한번 소개했던 user-secrets로 하는데,

dotnet user-secrets 명령어
; https://www.sysnet.pe.kr/2/0/11447

따라서 웹 애플리케이션의 csproj 파일이 위치한 폴더에서 다음의 명령을 실행합니다.

[형식]
dotnet user-secrets set Kestrel:Certificates:Development:Password {인증서_암호}

예)
dotnet user-secrets set Kestrel:Certificates:Development:Password TestPassword

실행 후 csproj에는 UserSecretsId가 등록되고,

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <DockerTargetOS>Linux</DockerTargetOS>
    <UserSecretsId>{...GUID...}</UserSecretsId>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.0.1916590" />
  </ItemGroup>

</Project>

해당 GUID 이름의 폴더가 %APPDATA%\Microsoft\UserSecrets 하위에 생성되고 그 안의 "secrets.json" 파일은 다음의 내용을 포함하게 됩니다.

{
  "Kestrel:Certificates:Development:Password": "TestPassword"
}

바로 여기까지가 Visual Studio가 자동으로 해주는 작업입니다. 그런데, 이렇게 맞추고 실행해도 여전히 "Failed to create the certificate" 오류가 발생합니다. 글쎄요... 다음의 글들에 따라 해봐도,

Adding the certificate to the Trusted Root Certificate store failed with the following error: Failed with a critical error.
; https://github.com/Microsoft/DockerTools/issues/147

VS2017 Docker debugging failed: Failed to create the certificate
; https://github.com/Microsoft/DockerTools/issues/99

Visual Studio 2017 gives 'Adding the Certificate to The Trusted Root Certificates store failed with the following Errror'
; https://stackoverflow.com/questions/47413183/visual-studio-2017-gives-adding-the-certificate-to-the-trusted-root-certificate?rq=1

제 경우에는 해당 오류가 없어지지 않았습니다. 그럼 어떻게 해결할 수 있을까요? ^^

해결하지 않아도 됩니다. 어차피 인증서까지 모두 등록되었으므로 Visual Studio는 실행을 할 수 있기 때문에 그냥 저 확인 과정을 생략하도록 "Tools" / "Options" 메뉴에서 "Container Tools" 범주의 "Do not prompt for trusting localhost SSL certificate" 옵션을 설정해 주면 됩니다.

이렇게 하고 실행하면 환경 구성이 잘 되었으므로 Visual Studio는 아무런 문제없이 docker 배포 후 웹 사이트를 구동시켜 줍니다.




참고로, 인증서를 로그인한 계정 외의 환경에서도 사용해야 한다고 하면 pfx 인증서를 "Certificates - Local Computer" 범주로도 등록시켜 주면 됩니다. (확인을 위해 명령행에서 "certlm"을 실행해 정상적으로 "Personal"과 "Trusted Root Certification Authorities"에 등록 여부를 보면 됩니다.)

참고로, "Do not prompt for trusting localhost SSL certificate" 옵션이 켜져 있어서 이후의 웹 프로젝트를 새로 등록했을 때에는 저 과정을 잊어버리고 웹 애플리케이션을 실행할 수 있을 텐데요, 이런 경우 다음과 같은 오류가 발생합니다.

System.InvalidOperationException
  HResult=0x80131509
  Message=Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found.
To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.
For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.
  Source=Microsoft.AspNetCore.Server.Kestrel.Core
  StackTrace:
   at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions, Action`1 configureOptions)
   at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.<BindAsync>d__2.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.<BindAsync>d__0.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.<StartAsync>d__22`1.MoveNext()
...[생략]...
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
   at netcore_web.Program.Main(String[] args) in F:\netcore_web\netcore_web\Program.cs:line 17

잊지 말고 ^^ 웹 애플리케이션 이름의 pfx를 생성해 주고 user-secrets를 등록해야 합니다.




check 한번 해보는 것도 좋겠습니다.

c:\temp> dotnet dev-certs https --check
A valid certificate was found: 3827...[생략]...85E5 - CN=localhost - Valid from 2022-01-18 10:03:29Z to 2023-01-18 10:03:29Z - IsHttpsDevelopmentCertificate: true - IsExportable: true
Run the command with both --check and --trust options to ensure that the certificate is not only valid but also trusted.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 11/14/2023]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2021-02-25 08시58분
[정환] 저처럼 헤매실 분을 위해 글을 남깁니다.
프로젝트를 "Enable Docker Support"와 "Configure for HTTPS" 선택후 Kestrel로 디버깅 실행을 했는데 인증서가 없다는 오류로 인해 실행이 되질 않았습니다.
IIS Express로 실행하니 정상적으로 실행되길래 이유를 찾아봤는데 stackoverflow에 나온 방식은
dotnet dev-certs https --clean
dotnet dev-certs https --trust
dotnet dev-certs https --check
만 설명되어있었습니다.
결과는 No valid certificate found.
해도 안되길래 자체인증서 서명을 찾다가 지금 아티클을 보고 느낌받아서
인증서 생성, 등록 &
프로젝트폴더에서 dotnet user-secrets set Kestrel:Certificates:Development:Password {인증서_암호} 까지 처리해주니 정상적으로 Kestrel로 작동됩니다.

즐코딩들 하시기 바랍니다.
[guest]

... [16]  17  18  19  20  21  22  23  24  25  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
13220정성태1/19/20234281오류 유형: 837. NETSDK1045 The current .NET SDK does not support targeting .NET ...
13219정성태1/18/20233856Windows: 220. 네트워크의 인터넷 접속 가능 여부에 대한 판단 기준
13218정성태1/17/20233779VS.NET IDE: 178. Visual Studio 17.5 (Preview 2) - 포트 터널링을 이용한 웹 응용 프로그램의 외부 접근 허용
13217정성태1/13/20234381디버깅 기술: 185. windbg - 64비트 운영체제에서 작업 관리자로 뜬 32비트 프로세스의 덤프를 sos로 디버깅하는 방법
13216정성태1/12/20234648디버깅 기술: 184. windbg - 32비트 프로세스의 메모리 덤프인 경우 !peb 명령어로 나타나지 않는 환경 변수
13215정성태1/11/20236147Linux: 56. 리눅스 - /proc/pid/stat 정보를 이용해 프로세스의 CPU 사용량 구하는 방법 [1]
13214정성태1/10/20235724.NET Framework: 2087. .NET 6부터 SourceGenerator와 통합된 System.Text.Json [1]파일 다운로드1
13213정성태1/9/20235259오류 유형: 836. docker 이미지 빌드 시 "RUN apt install ..." 명령어가 실패하는 이유
13212정성태1/8/20235024기타: 85. 단정도/배정도 부동 소수점의 정밀도(Precision)에 따른 형변환 손실
13211정성태1/6/20235106웹: 42. (https가 아닌) http 다운로드를 막는 웹 브라우저
13210정성태1/5/20234130Windows: 219. 윈도우 x64의 경우 0x00000000`7ffe0000 아래의 주소는 왜 사용하지 않을까요?
13209정성태1/4/20234022Windows: 218. 왜 윈도우에서 가상 메모리 공간은 64KB 정렬이 된 걸까요?
13208정성태1/3/20233956.NET Framework: 2086. C# - Windows 운영체제의 2MB Large 페이지 크기 할당 방법파일 다운로드1
13207정성태12/26/20224266.NET Framework: 2085. C# - gpedit.msc의 "User Rights Assignment" 특권을 코드로 설정/해제하는 방법파일 다운로드1
13206정성태12/24/20224471.NET Framework: 2084. C# - GetTokenInformation으로 사용자 SID(Security identifiers) 구하는 방법 [3]파일 다운로드1
13205정성태12/24/20224869.NET Framework: 2083. C# - C++과의 연동을 위한 구조체의 fixed 배열 필드 사용 (2)파일 다운로드1
13204정성태12/22/20224148.NET Framework: 2082. C# - (LSA_UNICODE_STRING 예제로) CustomMarshaler 사용법파일 다운로드1
13203정성태12/22/20224274.NET Framework: 2081. C# Interop 예제 - (LSA_UNICODE_STRING 예제로) 구조체를 C++에 전달하는 방법파일 다운로드1
13202정성태12/21/20224646기타: 84. 직렬화로 설명하는 Little/Big Endian파일 다운로드1
13201정성태12/20/20225271오류 유형: 835. PyCharm 사용 시 C 드라이브 용량 부족
13200정성태12/19/20224153오류 유형: 834. 이벤트 로그 - SSL Certificate Settings created by an admin process for endpoint
13199정성태12/19/20224432개발 환경 구성: 656. Internal Network 유형의 스위치로 공유한 Hyper-V의 VM과 호스트가 통신이 안 되는 경우
13198정성태12/18/20224309.NET Framework: 2080. C# - Microsoft.XmlSerializer.Generator 처리 없이 XmlSerializer 생성자를 예외 없이 사용하고 싶다면?파일 다운로드1
13197정성태12/17/20224264.NET Framework: 2079. .NET Core/5+ 환경에서 XmlSerializer 사용 시 System.IO.FileNotFoundException 예외 발생하는 경우파일 다운로드1
13196정성태12/16/20224393.NET Framework: 2078. .NET Core/5+를 위한 SGen(Microsoft.XmlSerializer.Generator) 사용법
13195정성태12/15/20224987개발 환경 구성: 655. docker - bridge 네트워크 모드에서 컨테이너 간 통신 시 --link 옵션 권장 이유
... [16]  17  18  19  20  21  22  23  24  25  26  27  28  29  30  ...