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

Abierto
#5,852 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
php
Área
security

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
PHP
Estrellas
1.2k
Forks
932
Merge medio
1 d 11 h
PR fusionados (30 d)
22

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de opnsense/plugins

Todos los issues de opnsense/plugins

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.