docker-composelets-encrypttraefikacme

Traefix v1.7 static certificates and dynamic acme certificates


I am using traefik:1.7.6-alpine in docker in swarm mode. I need to specify static ssl certificates and other self-managed acme certificates.

This is the error I get when lifting the container:

time="2020-06-18T02:45:52Z" level=info msg="\nStats collection is disabled.\nHelp us improve Traefik by turning this feature on :)\nMore details on: https://docs.traefik.io/basics/#collected-data\n"
time="2020-06-18T02:45:52Z" level=error msg="Failed to read new account, ACME data conversion is not available : unexpected end of JSON input"
time="2020-06-18T02:45:52Z" level=error msg="Unable to add ACME provider to the providers list: unable to get ACME account : unexpected end of JSON input"
time="2020-06-18T02:45:52Z" level=info msg="Preparing server https &{Address::443 TLS:0xc000288630 Redirect:<nil> Auth:<nil> WhitelistSourceRange:[] WhiteList:<nil> Compress:false ProxyProtocol:<nil> ForwardedHeaders:0xc0006a45c0} with readTimeout=0s writeTimeout=0s idleTimeout=3m0s"
time="2020-06-18T02:45:52Z" level=info msg="Preparing server traefik &{Address::8080 TLS:<nil> Redirect:<nil> Auth:<nil> WhitelistSourceRange:[] WhiteList:<nil> Compress:false ProxyProtocol:<nil> ForwardedHeaders:0xc0006a4560} with readTimeout=0s writeTimeout=0s idleTimeout=3m0s"
time="2020-06-18T02:45:52Z" level=info msg="Starting server on :443"
time="2020-06-18T02:45:52Z" level=info msg="Preparing server http &{Address::80 TLS:<nil> Redirect:<nil> Auth:<nil> WhitelistSourceRange:[] WhiteList:<nil> Compress:false ProxyProtocol:<nil> ForwardedHeaders:0xc0006a4580} with readTimeout=0s writeTimeout=0s idleTimeout=3m0s"
time="2020-06-18T02:45:52Z" level=info msg="Starting provider configuration.ProviderAggregator {}"
time="2020-06-18T02:45:52Z" level=info msg="Starting server on :8080"
time="2020-06-18T02:45:52Z" level=info msg="Starting provider *docker.Provider {\"Watch\":true,\"Filename\":\"\",\"Constraints\":null,\"Trace\":false,\"TemplateVersion\":2,\"DebugLogGeneratedTemplate\":false,\"Endpoint\":\"unix:///var/run/docker.sock\",\"Domain\":\"arkaangel.com\",\"TLS\":null,\"ExposedByDefault\":false,\"UseBindPortIP\":false,\"SwarmMode\":false,\"Network\":\"\",\"SwarmModeRefreshSeconds\":15}"
time="2020-06-18T02:45:52Z" level=info msg="Starting server on :80"

This is my traefik.toml

debug = true
logLevel = "INFO"
defaultEntryPoints = ["http", "https"]
[entryPoints]
    [entryPoints.http]
        address = ":80"
    [entryPoints.https]
        address = ":443"
        [entryPoints.https.tls]
            [[entryPoints.https.tls.certificates]]
                certFile = "/path/to/first/first.crt"
                keyFile = "/path/to/first/first.key"
            [[entryPoints.https.tls.certificates]]
                certFile = "/path/to/second/second.crt"
                keyFile =  "/path/to/second/second.key"
[api]
  dashboard = true
  [api.statistics]
    recentErrors = 10
[docker]
  exposedbydefault = false
  watch = true
  domain = "mydomain.com"

[acme]
email = "myemail@gmail.com"
storage = "/etc/traefik/acme/acme.json"
entryPoint = "https"
acmeLogging = true
onHostRule = true
    [acme.httpChallenge]
       entryPoint = "http"
    [[acme.domains]]
       main = "third-site.com"

And this is how I mount the acme.json file in the docker-compose to keep the generated certificates:

volumes:
./traefik/acme/acme.json:/etc/traefik/acme/acme.json

the acme.json file has 600 permissions and owner root:root.

In addition to the configuration shown, things that I have tried without being able to generate the certificate:

  1. not map the acme.json file but the parent folder so that traefik create the acme.json file (failed)
  2. do not map any volume for the acme.json so that it is lost when the container is removed. (failed)
  3. changed the owner to the file acme.json to myuser: myuser, so from the container the user 1000 is shown as owner (failed)

Solution

  • The way I was able to solve the error of: "Failed to read new account, ACME data conversion is not available : unexpected end of JSON input", was writing inside the file acme.json {}, apparently when trying to read an empty file and parsing it to json it gave an error.

    Summary: when creating the acme.json on the host to be mapped then you have to do:

    touch acme.json
    echo '{}'> acme.json
    chmod 600 acme.json