kereis / traefik-certs-dumper

Dumps Let's Encrypt certificates of a specified domain which Traefik stores in acme.json.
Apache License 2.0
129 stars 24 forks source link

Pasring Error for Trafik V3 #193

Closed t-abraham closed 3 weeks ago

t-abraham commented 5 months ago

Hi i am having an issue for the container. It cannot parse. Can anyone help me out

YAML

services:
  certdumper:
    command: --restart-containers plex
    container_name: Traefik_cert_dumper
    depends_on:
    - traefik
    environment:
      ACME_FILE_PATH: /traefik/lets_encrypt_ssl.json
      COMBINED_PEM: concatted_cert.pem
      COMBINE_PKCS12: "yes"
    image: ghcr.io/kereis/traefik-certs-dumper:latest
    labels:
      com.centurylinklabs.watchtower.enable: "true"
    logging:
      options:
        max-file: '3'
        max-size: 5m
    networks:
      CognitiveSystems: {}
    user: 0:0
    volumes:
    - /home/data/shared/certificates/ssl:/output:rw
    - /home/traefik/lets_encrypt_ssl.json:/traefik/lets_encrypt_ssl.json:ro
    - /var/run/docker.sock:/var/run/docker.sock:ro
  traefik:
    command: redacted
    environment: redacted
    container_name: Traefik
    healthcheck:
      test:
      - NONE
    image: traefik:latest
    labels: redacted
    logging:
      options:
        max-file: '3'
        max-size: 5m
    ports:redacted
    restart: unless-stopped
    user: redacted
    volumes:
    - /etc/localtime:/etc/localtime:ro
    - /home/traefik/lets_encrypt_ssl.json:/lets_encrypt_ssl.json:rw
    - /home/traefik/users.htpasswd:/users.htpasswd:rw
    - /var/run/docker.sock:/var/run/docker.sock:ro
version: '3.5'

Error

Error: v2: dump failed: failed to unmarshal file "/traefik/lets_encrypt_ssl.json": invalid character 'a' looking for beginning of value

Usage:

  traefik-certs-dumper file [flags]

Flags:

  -h, --help             help for file

      --source string    Path to 'acme.json' file. (default "./acme.json")

      --version string   Traefik version. If empty use v1. Possible values: 'v2'.

Global Flags:

      --clean              Clean destination folder before dumping content. (default true)

      --config string      config file (default is $HOME/.traefik-certs-dumper.yaml)

      --crt-ext string     The file extension of the generated certificates. (default ".crt")

      --crt-name string    The file name (without extension) of the generated certificates. (default "certificate")

      --dest string        Path to store the dump content. (default "./dump")

      --domain-subdir      Use domain as sub-directory.

      --key-ext string     The file extension of the generated private keys. (default ".key")

      --key-name string    The file name (without extension) of the generated private keys. (default "privatekey")

      --post-hook string   Execute a command only if changes occurs on the data source. (works only with the watch mode)

      --watch              Enable watching changes.

2024/06/24 22:47:39 root.go:45: v2: dump failed: failed to unmarshal file "/traefik/lets_encrypt_ssl.json": invalid character 'a' looking for beginning of value

[2024-06-24T22:47:39+0000]: Certificates for domain '*' don't exist. Omitting...
kereis commented 4 months ago

Hi @t-abraham,

unfortunately, I cannot tell right away if traefik-certs-dumper is compatible with V3 in case there have been any data structure changes.

It definitely works with V2 however.

arcoast commented 2 months ago

If it's helpful in debugging/troubleshooting, I'm using v3 of Traefik successfully, but a pretty basic setup. I've included a redacted acme.json on the off chance it helps anyone narrow down and specific issues or edge cases.

{
  "letsencrypt-dns": {
    "Account": {
      "Email": "MYEMAIL@DOMAIN.COM",
      "Registration": {
        "body": {
          "status": "valid",
          "contact": [
            "mailto:MYEMAIL@DOMAIN.COM"
          ]
        },
        "uri": "https://acme-v02.api.letsencrypt.org/acme/acct/xxxxxxxxx"
      },
      "PrivateKey": "xxxxxxxxxx",
      "KeyType": "4096"
    },
    "Certificates": [
      {
        "domain": {
          "main": "DOMAIN.COM",
          "sans": [
            "*.DOMAIN.COM"
          ]
        },
        "certificate": "xxxxxxxxxx",
        "key": "xxxxxxxxxx",
        "Store": "default"
      }
    ]
  },
  "zerossl-dns": {
    "Account": null,
    "Certificates": null
  }
}
kereis commented 4 weeks ago

Unfortunately, it's hard to tell what's wrong because the error says

Error: v2: dump failed: failed to unmarshal file "/traefik/lets_encrypt_ssl.json": invalid character 'a' looking for beginning of value

meaning that something is wrong with your JSON file.

@t-abraham Is it read correctly by Traefik? Can you provide an example?

@arcoast Did you run into this issue as well?

arcoast commented 4 weeks ago

@kereis I did not, I've got it set up and working in "production" with V3 of Traefik and have had since I last posted.

Just deleted my certs and run traefik-certs-dumper and the certs have been dumped perfectly.

2024-10-30T22:02:26.380866609Z [2024-10-30T22:02:26+0000]: Got value of DOMAIN: SERVER.COM. Splitting values.
2024-10-30T22:02:26.381460778Z [2024-10-30T22:02:26+0000]: Values split! Got 'SERVER.COM'
2024-10-30T22:02:26.382059863Z [2024-10-30T22:02:26+0000]: ACME file path: /traefik/acme.json
2024-10-30T22:02:26.383133973Z [2024-10-30T22:02:26+0000]: Clearing dumping directory
2024-10-30T22:02:26.384083730Z [2024-10-30T22:02:26+0000]: Dumping certificates
2024-10-30T22:02:26.430181699Z [2024-10-30T22:02:26+0000]: Certificate or key for 'SERVER.COM' differ, updating
2024-10-30T22:02:26.432994295Z [2024-10-30T22:02:26+0000]: Combining key and cert to single PEM with name SERVER.COM.pem
2024-10-30T22:02:26.434252057Z [2024-10-30T22:02:26+0000]: Converting key to RSA key file
2024-10-30T22:02:26.445009109Z writing RSA key
2024-10-30T22:02:26.447363697Z [2024-10-30T22:02:26+0000]: Changing ownership of certificates and keys

Currently running Traefik v3.2.0 and like I said in my last post, I'm using this successfully. (Although I admit re-reading my earlier comment I could have made it clearer it's working for me, I just posted to see if it was helpful to try and narrow down @t-abraham's issue.

kereis commented 3 weeks ago

I will close this issue for now I guess. Please reopen or create a new issue and add steps to reproduce!

/close