Skip to content
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

Docker images: Unable to configure HTTPS endpoint #85

Open
D4sh12 opened this issue Apr 23, 2024 · 10 comments
Open

Docker images: Unable to configure HTTPS endpoint #85

D4sh12 opened this issue Apr 23, 2024 · 10 comments

Comments

@D4sh12
Copy link

D4sh12 commented Apr 23, 2024

Following the README file, everything works fine, but the main services like catalog, ordering, basket, etc., didn't worked due to HTTPS config exception.
Exception: System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date. To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.

Docker log Terminal:

2024-04-23 13:35:41 info: Marten.Services.MartenActivator[0]
2024-04-23 13:35:41       Applying initial data Catalog.API.Data.CatalogInitialData
2024-04-23 13:35:43 fail: Microsoft.Extensions.Hosting.Internal.Host[11]
2024-04-23 13:35:43       Hosting failed to start
2024-04-23 13:35:43       System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.
2024-04-23 13:35:43       To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.
2024-04-23 13:35:43       For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.
2024-04-23 13:35:43          at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions, Action`1 configureOptions)
2024-04-23 13:35:43          at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context, CancellationToken cancellationToken)
2024-04-23 13:35:43          at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(ListenOptions[] listenOptions, AddressBindContext context, Func`2 useHttps, CancellationToken cancellationToken)
2024-04-23 13:35:43          at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
2024-04-23 13:35:43          at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
2024-04-23 13:35:43          at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
2024-04-23 13:35:43          at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__15_1(IHostedService service, CancellationToken token)
2024-04-23 13:35:43          at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation)
2024-04-23 13:35:43 Unhandled exception. System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.
2024-04-23 13:35:43 To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.
2024-04-23 13:35:43 For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.
2024-04-23 13:35:43    at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions, Action`1 configureOptions)
2024-04-23 13:35:43    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context, CancellationToken cancellationToken)
2024-04-23 13:35:43    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(ListenOptions[] listenOptions, AddressBindContext context, Func`2 useHttps, CancellationToken cancellationToken)
2024-04-23 13:35:43    at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
2024-04-23 13:35:43    at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
2024-04-23 13:35:43    at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
2024-04-23 13:35:43    at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__15_1(IHostedService service, CancellationToken token)
2024-04-23 13:35:43    at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation)
2024-04-23 13:35:43    at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
2024-04-23 13:35:43    at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
2024-04-23 13:35:43    at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
2024-04-23 13:35:43    at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
2024-04-23 13:35:43    at Program.<Main>$(String[] args) in /src/Services/Catalog/Catalog.API/Program.cs:line 44

Any ideas?

@mbehnasr
Copy link

mbehnasr commented May 18, 2024

I have same problem and I don't how fix that
my os is ubuntu22

@JuliusKoronciCH
Copy link

JuliusKoronciCH commented May 18, 2024

this is a massive pain based on chatgpt the kestrel certificate and password need to be an env var I tried on my mac and also on windows

@BardiaYaghmaie
Copy link

this should be fixed

@JuliusKoronciCH
Copy link

let me pull again but I checked out the repo 2 days ago and I dont see any commits since

@JuliusKoronciCH
Copy link

@BardiaYaghmaie after some tinkering this works when running from visual studio as it does some additional magic but running docker-compose -f docker-compose.yml -f docker-compose.override.yml up -d is missing a few things so I would recommend updating the docker compose overrides and the documentation ..like the hardcoded windows paths and the fact that rider or just VS Code are not an option make it hard to use ..I had to switch from my mac to my windows machine to get it working

@mbehnasr
Copy link

Did you find any solution regarding the volumes set in docker-compose.override? I can't find 'usersecrets' and 'Https'. I can't find these two.

@JuliusKoronciCH
Copy link

@mbehnasr for db services I had to add
- POSTGRES_HOST_AUTH_METHOD=trust

  for the volumes on my mac its
    volumes:
  - ~/.microsoft/usersecrets:/home/app/.microsoft/usersecrets:ro
  - ~/.microsoft/devcerts:/home/app/.aspnet/https:ro
  
  but ask AI it helps
  
  this will still not solve the issues with https follow this article: https://learn.microsoft.com/en-us/aspnet/core/security/docker-https?view=aspnetcore-8.0 

@JuliusKoronciCH
Copy link

this one worked for me and the diff is that visual studio configure and runs with the correct certs while otherwise you need to generate your certs with a password amd mount the location and also tell dotnet where to find them and whats the password
dotnet dev-certs https -ep ./certs/aspnetapp.pfx -p SuperSecretPassword

shopping.web:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_HTTP_PORTS=8080
- ASPNETCORE_HTTPS_PORTS=8081
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
- ASPNETCORE_Kestrel__Certificates__Default__Password=SuperSecretPassword
- ApiSettings__GatewayAddress=http://yarpapigateway:8080
depends_on:
- yarpapigateway
ports:
- "6005:8080"
- "6065:8081"
volumes:
- ./certs:/https/

@ilkerciblak
Copy link

ilkerciblak commented Aug 10, 2024

Hello there,

I had the same problem with macOS M2 chip system, fixed the issue using given information under the ASP.NET documentation Docker Compose with HTTPS topic. Link for the documentation topic In summary it's saying for macOS:

Generate certificate and configure local machine:

dotnet dev-certs https -ep ${HOME}/.aspnet/https/aspnetapp.pfx -p $CREDENTIAL_PLACEHOLDER$
dotnet dev-certs https --trust

_dotnet dev-certs https --trust is only supported on macOS and Windows. You need to trust certificates on Linux in the way that is supported by your distribution. It is likely that you need to trust the certificate in your browser.

In the preceding commands, replace $CREDENTIAL_PLACEHOLDER$ with a password.

Create a docker-compose.debug.yml file with the following content:

version: '3.4'

services:
webapp:
image: mcr.microsoft.com/dotnet/samples:aspnetapp
ports:
- 80
- 443
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
- ASPNETCORE_Kestrel__Certificates__Default__Password=password
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx

volumes:
- ~/.aspnet/https:/https:ro

the password specified in the docker compose file must match the password used for the certificate.

Start the container with ASP.NET Core configured for HTTPS:
docker-compose -f "docker-compose.yml" up -d

Also its my docker_compose.yaml file for an example:

services:
  catalogdb:
    image: postgres
    container_name: catalogdb
    environment: 
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=pass
      - POSTGRES_DB=CatalogDb
    restart: always
    ports:
      - "5432:5432"
    volumes:
      - postgres_catalog:/var/lib/postgresql/data
  catalog.api:
    image: catalog.api
    build:
      context: .
      dockerfile: Services/Catalog/Catalog.API/Dockerfile
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_HTTP_PORTS=8080
      - ASPNETCORE_HTTPS_PORTS=8081
      - ConnectionStrings__Database=Server=catalogdb;Port=5432;Database=CatalogDb;User Id=postgres;Password=pass;Include Error Detail=true
      - ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
      - ASPNETCORE_Kestrel__Certificates__Default__Password=useyourpassword
    depends_on:
      - catalogdb
    ports:
      - "6000:8080"
      - "6060:8081"
    volumes:
      - /Users/<youruserpath>/.microsoft/usersecrets:/home/app/.microsoft/usersecrets:ro
      - ~/.aspnet/https:/https:ro

@realrgt
Copy link

realrgt commented Nov 19, 2024

For JetBrains Rider IDE users, try enabling the Share generated SSL certificate option as shown in this thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants