Arshad Badar Khan
Arshad Badar Khan

Reputation: 1004

HTTPS in docker in Service Fabric for asp.net core not working

I have a asp.net core application hosted in docker . The docker file looks like this

FROM  mcr.microsoft.com/dotnet/core/aspnet:3.1
LABEL cmbappname="autocomplete"
ARG source
WORKDIR /cmbapp
ADD ${source} . 
ENV APP_UTILS=C:\\app 
VOLUME ${APP_UTILS}
HEALTHCHECK --retries=5  --interval=100s --start-period=10s   CMD curl --fail http://localhost || exit 1 
ENTRYPOINT ["dotnet", "MyBus.AutoApi.dll"]
EXPOSE 80
EXPOSE 443

the docker image in hosted in service fabric which has a service manifest like this

<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="AutoApiPkg"
                 Version="1.0.0"
                 xmlns="http://schemas.microsoft.com/2011/01/fabric"
                 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <ServiceTypes>
    <!-- This is the name of your ServiceType.
         The UseImplicitHost attribute indicates this is a guest service. -->
    <StatelessServiceType ServiceTypeName="AutoApiType" UseImplicitHost="true" />
  </ServiceTypes>

  <!-- Code package is your service executable. -->
  <CodePackage Name="Code" Version="1.0.0">
    <EntryPoint>
      <!-- Follow this link for more information about deploying Windows containers to Service Fabric: https://aka.ms/sfguestcontainers -->
      <ContainerHost>
        <ImageName>autoApi</ImageName>
      </ContainerHost>
    </EntryPoint>
    <!-- Pass environment variables to your container: -->

    <EnvironmentVariables>
      <EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value="Debug" />

      <EnvironmentVariable Name="ASPNETCORE_URLS" Value="https://*:443/;http://*:80/;https://*:54100/;http://*:54200/"/>
    </EnvironmentVariables>


  </CodePackage>

with the container policies in the Applicaiton manifest

 <Policies>
      <ContainerHostPolicies CodePackageRef="Code"  AutoRemove="false"  UseDefaultRepositoryCredentials="false"   ContainersRetentionCount="2"  RunInteractive="true">
        <!-- See https://aka.ms/I7z0p9 for how to encrypt your repository password -->
        <PortBinding ContainerPort="443" EndpointRef="AutApiTypeEndpoint" />
        <PortBinding ContainerPort="80" EndpointRef="LocalAutApiTypeEndpoint" />
        <RepositoryCredentials  AccountName="[AzureContainerUserName]" Password="[AzureContainerPassword]" PasswordEncrypted="false"/>
        <HealthConfig   IncludeDockerHealthStatusInSystemHealthReport="true" RestartContainerOnUnhealthyDockerHealthStatus="false" />            
      </ContainerHostPolicies>
      
    </Policies>

the application runs and is functional without the enviornment variable "ASPNETCORE_URLS"

but when adding the env variable its not functional nor is it reachable.

debugging the container gives the following error logs

Unable to start Kestrel. System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be fo und or is out of date.

Upvotes: 0

Views: 249

Answers (1)

LoekD
LoekD

Reputation: 11470

  1. Get a certificate, for example by using Letsencrypt [example], or use a self-signed certificate (for testing).
  2. Use a volume to attach the certificate file to your container.
  3. Use an environment variable to indicate where the certificate is stored:
ASPNETCORE_Kestrel__Certificates__Default__Path=certificate.pfx
  1. Use another environment variable to provide the password to allow access to the private key:
ASPNETCORE_Kestrel__Certificates__Default__Password="****"

More info here.

Upvotes: 1

Related Questions