security/acme-client: needsRenewal() ignores a renewed certificate that was never imported into the trust store

Aperta
#5,852 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
php
Ambito
security

Direzione di ricerca

Start in LeCertificate.php: read issue() (around the 'renewal not required' log and the import() call after validation->run()), needsRenewal(), and import(). Reproducing needs a certificate whose on-disk cert.pem is newer than the trust store copy, so the work involves the trust store and certRefId lookup, not just the renewal check. Done means a cron run imports the newer disk certificate in place, keeps the refid, sets status 200 and runs automations, and leaves a newer-or-equal trust store entry untouched. The maintainer has not yet agreed to the proposed approach, so confirm the design in the issue before writing code.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

support

Important notices

Before you add a new report, we ask you kindly to acknowledge the following:

Describe the bug

LeCertificate::needsRenewal() decides only from the certificate file that acme.sh wrote to certs/<id>/cert.pem (validFrom_time_t + renewInterval). It never checks whether that certificate was imported into the OPNsense trust store (LeCertificate.php#L400-L442).

If acme.sh has written a new cert.pem but import() and the automations did not run, issue() logs issue/renewal not required for certificate: ...
(#L328-L332) on every following cron run.
The trust store and all services keep serving the old certificate until it expires, the status stays at the failure status (e.g. 'validation failed').

issue() only calls import() after a successful validation->run()
(#L372-L381), so any failure between acme.sh writing cert.pem and the import leaves this state permanently. One concrete trigger is a failing stale deploy hook (see #5851, where acme.sh exits non-zero after issuing); a failed import, a killed process or a crash have the same effect. Same symptom as #5746.

Plugin version where the bug appeared: not determined. The code path is the same in 4.17 and current master.
Last known working version: unknown.

To Reproduce

Any way to get a newer cert.pem without a completed import will do. One that is easy to set up (see #5851):

  1. Issue an acme.sh based certificate and import it normally (Services > ACME Client > Certificates).
  2. Make the renewal fail after issuance, e.g. a recorded Le_DeployHook= in /var/etc/acme-client/cert-home/<id>/*/*.conf that fails (acme.sh then exits non-zero after writing cert.pem; the plugin skips the import).
  3. Wait until the certificate is due and run configctl acmeclient cron-auto-renew.
  4. openssl x509 -in /var/etc/acme-client/certs/<id>/cert.pem -noout -serial shows a new serial, the trust store certificate (System > Trust > Certificates) still has the old one.
  5. Run configctl acmeclient cron-auto-renew again: issue/renewal not required for certificate: ..., no import, no automations.

Expected behavior

Before logging "not required", the plugin should compare the on-disk certificate with the certificate in the trust store referenced by the ACME certificate's certRefId (SHA-256 fingerprint, or serial).

  • If the disk certificate is newer, import it in place (this keeps the refid and thus the WebGUI binding), set status 200 and run the automations. This needs no ACME request, so it does not consume rate limit.
  • If the import fails, log it and set an error status, so the next cron run retries.
  • Only reconcile when the disk certificate is newer than the trust store copy, so a manually updated trust store certificate is not overwritten with an older file.
  • import() should also verify that the certificate and private key match (openssl_x509_check_private_key()) before overwriting the trust store entry. It currently does not.

Screenshots
N/A

Relevant log files
Plugin log, cron run (domain anonymized):

2026-10-31T00:00:xx AcmeClient: issue/renewal not required for certificate: *.sense.example.com

There were no other log entries for this certificate. The log of the original failing run was no longer available (only one day of /var/log/acmeclient was retained).

State on the box (read-only checks):

# acme certificate entry vs. WebGUI certificate: same refid

certRefId=644c12fbbec25   webgui ssl-certref=644c12fbbec25
status=400   lastUpdate=2026-08-24T09:16:51+02:00   statusLastUpdate=2026-10-24T00:20:45+02:00

# certs/<id>/cert.pem (acme.sh output)

serial=<REDACTED>7A0B
notBefore=Oct 23 21:22:09 2026 GMT   notAfter=Jan 21 21:22:08 2027 GMT

# trust store / WebGUI certificate

serial <REDACTED>:3B:6D
notBefore Aug 24 06:18:12 2026 GMT   notAfter Nov 22 06:18:11 2026 GMT

# acme.sh domain conf

Le_CertCreateTimeStr='2026-10-23T22:20:42Z'
Le_DeployHook='unifi,'

The Unifi automation was still attached at the time of the failure; the service had moved to another host, so the hook failed.

lastUpdate is still the August import time, i.e. import() never ran for the October certificate.
statusLastUpdate is 3 seconds after Le_CertCreateTimeStr.

Additional context

  • Related: #5746 (same symptom, flagged as lacking the template), #5851 (stale deploy hook, a concrete trigger), #5719 / #4908 (non-zero acme.sh exit always reported as "validation failed").
  • The WebGUI certificate was fixed by "(Re-) Import certificate" followed by "Run automations".
  • Proposed fix: add a small trustStoreOutdated() check in LeCertificate and call it in issue() before the needsRenewal() gate. It looks up the trust cert by certRefId (never by CN, duplicate common names are possible), compares fingerprints, applies the "newer only" guard, and then runs import(true), setStatus(200) and runAutomations(). It should honour the global and per-certificate auto-renewal settings when called from cron. I can prepare a PR if this approach is acceptable.

Environment

OPNsense 26.7.7
os-acme-client 4.17
acme.sh v3.1.6
DNS-01 validation, ECC (EC) key

Lingua principale
PHP
Stelle
1.2k
Fork
932
Merge medio
1g 11h
PR unite (30g)
22

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di opnsense/plugins

Tutte le issue di opnsense/plugins

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.