project-pegaprox icon indicating copy to clipboard operation
project-pegaprox copied to clipboard

[Bug] ACME Custom Provider with Custom CA

Open goebelmeier opened this issue 7 months ago • 7 comments

Hey there! 👋 Thanks for taking the time to report this bug — we appreciate it!

Please keep in mind: PegaProx is developed and maintained entirely by volunteers in our free time. We do our best, but we can't work magic 🪄 — please be patient, we'll get to your issue as soon as we can.

Want to help keep PegaProx alive?

  • ⭐ Star the project — it's free and helps a lot!
  • 💖 Become a Sponsor — helps us dedicate more time to development
  • 🤝 Contributing code or docs is always welcome too!

Describe the bug

In the past i've used custom certificates from my internal Step-CA using certbot. To make this work i've imported our Root CA certificate into the operating system trusted root store. Now i wanted to migrate to the integrated ACME solution with custom ACME provider. Unfortunately it seems, that this does not use the system trusted root store but anything else like in #246

Steps to Reproduce

  1. Setup StepCA with custom root CA
  2. Inside Pegaprox go to settings, Server, SSL/TLS certificate
  3. Choose acmeProviderCustom
  4. Fill in acmeDirectoryUrl to StepCA https://ca.example.com/acme/acmeca/directory
  5. Fill in Email Address
  6. Click Request Certificate
  7. You're receiving following error: HTTPSConnectionPool(host='ca.example.com', port=443): Max retries exceeded with url: /acme/acmeca/directory (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1029)')))

Expected behavior

You get a working automated TLS certificate rollout.

Environment

  • PegaProx Version: Beta 0.9.6.1
  • Installation Method: Pre-deployed container image with manual update
  • OS: Debian GNU/Linux 13
  • Browser: Edge 146.0.3856.97
  • Behind Reverse Proxy? no
  • UI? Corporate

Logs

HTTPSConnectionPool(host='ca.example.com', port=443): Max retries exceeded with url: /acme/acmeca/directory (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1029)')))

Screenshots

Checklist

  • [X] I have searched existing issues to make sure this is not a duplicate
  • [X] I am using the latest version of PegaProx

goebelmeier avatar Apr 15 '26 07:04 goebelmeier

Hi @goebelmeier ,

did you restart pegaprox? As we use python3 as main codebase our manager needs a restart before he can accept the new certificate otherwise he just will be used the stored one's before you imported it.

MrMasterbay avatar Apr 15 '26 16:04 MrMasterbay

Hey @goebelmeier,

when using Docker (as stated) and saying In the past i've used custom certificates from my internal Step-CA using certbot. To make this work i've imported our Root CA certificate into the operating system trusted root store. - which approach did you take to achieve this?

I guess, the custom root CA is not injected and also not (re)loaded at that time, which must already be present before executing the entry point.

Cheers, gyptazy

gyptazy avatar Apr 15 '26 18:04 gyptazy

I will close this issue again @goebelmeier feel free to ping me if the steps above are not working so we can take a look at it again.

MrMasterbay avatar Apr 16 '26 16:04 MrMasterbay

Hello, we ran into the exact same issue. We are running an internal ACME Server with an internal certificate. All Certificate requests failed. We imported our root and intermediate certificate in the ca-certificate store of the container however this did also not solve the issue.

curl -kfsSL https://webserver.internal/Root.crt -o /usr/local/share/ca-certificates/Root.crt && curl -kfsSL https://webserver.internal/Sub.crt -o /usr/local/share/ca-certificates/Sub.crt && update-ca-certificates --fresh

We had an extended troubleshooting session with copilot aka ChatGPT and came to the following fix. The acme.py implementation is not using or falling back to the system certificate store instead it falls back to Certifi.

We had it write a quick patch which solved the issue for us. If you are interested in more troubleshooting, I can assist you.

Here is the patch it came up with:

python3 - <<'PY'
from pathlib import Path

p = Path('/app/pegaprox/core/acme.py')
txt = p.read_text()

if 'import ssl' not in txt:
    txt = txt.replace('import requests\n', 'import requests\nimport ssl\n')

if '_CA_BUNDLE =' not in txt:
    txt = txt.replace(
        'import secrets\n',
        'import secrets\n\n'
        '_CA = ssl.get_default_verify_paths()\n'
        '_CA_BUNDLE = _CA.cafile or _CA.openssl_cafile or True\n'
    )

txt = txt.replace(
    'allow_redirects=False)',
    'allow_redirects=False, verify=_CA_BUNDLE)'
)

p.write_text(txt)

print('patched')
PY

blueart1984 avatar Oct 09 '26 20:10 blueart1984

Thanks for digging into it, and you're right: the ACME client goes through Python's requests, which checks certificates against its own bundled CA list (certifi), not the system store, so update-ca-certificates doesn't help there. Reopening this.

Until that changes, you don't need to patch the code: requests honours REQUESTS_CA_BUNDLE. After your update-ca-certificates --fresh, start the container with -e REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt (that file then holds the public CAs plus your root and intermediate). Keep in mind the store inside the container is rebuilt with every new image, so it's easier to mount your own bundle (system CAs plus yours) read-only and point the variable at that.

Using the system store for ACME by default is noted, Nico will have a look at it. And if PegaProx is useful in your setup, there's https://opencollective.com/pegaprox, any support helps.

Marcus

mkellermann97 avatar Oct 10 '26 07:10 mkellermann97

Fixed on Testing with #1152: a custom ACME CA whose root is in the system trust store is trusted now, no extra CA bundle needed. It comes with the next release.

Nico

MrMasterbay avatar Oct 17 '26 19:10 MrMasterbay

Hi, this is in 1.4.0 now: a custom ACME CA whose root is in the system trust store is trusted, no extra bundle needed. I'll close it, but give me a shout if your CA still gets refused after the update.

Nico

MrMasterbay avatar Oct 19 '26 18:10 MrMasterbay