Disclaimer: I'm new to Traefik, so there might be a better solution than this that I'm not aware of.
What I've done is used a Python script by JayH5 to extract the keys files from the acme.json file.
def read_domain_certs(acme_json_path, domain):
with open(acme_json_path) as acme_json_file:
acme_json = json.load(acme_json_file)
certs_json = acme_json['DomainsCertificate']['Certs']
domain_certs = [cert['Certificate'] for cert in certs_json
if cert['Domains']['Main'] == domain]
if not domain_certs:
raise RuntimeError(
'Unable to find certificate for domain "%s"' % (domain,))
elif len(domain_certs) > 1:
raise RuntimeError(
'More than one (%d) certificates for domain "%s"' % (domain,))
[domain_cert] = domain_certs
return (base64.b64decode(domain_cert['PrivateKey']),
base64.b64decode(domain_cert['Certificate']))
Depending on your use case, you could skip saving the files and load the keys directly from the JSON file using that code. However, if you do need the PEM files, the script does also writes the key contents, if you need the files on disk.
def write_cert(storage_dir, filename, cert_content):
cert_path = os.path.join(storage_dir, filename)
with open(cert_path, 'w') as cert_file:
cert_file.write(cert_content)
os.chmod(cert_path, 0o600)