Skip to content

feat: acme.json cleanup management - #103

Merged
DavidePrincipi merged 8 commits into
mainfrom
feat-7544
Sep 23, 2025
Merged

DavidePrincipi merged 8 commits into
mainfrom
feat-7544

Conversation

@DavidePrincipi

@DavidePrincipi DavidePrincipi commented Aug 5, 2025 •

Copy link
Copy Markdown
Member

This PR is adding API actions for richer certificate operations, better visibility, more control, and safer operations when altering/removing certs and HTTP routes.

Changes summary:

  • Implement list-certificates-v2 action, that will replace list-certificates in a future PR.
  • Change delete-certificate input key. Restart Traefik if acme.json was changed.
  • Add set-default-certificate action, specifically for the Traefik default certificate. Return ACME error, if present.
  • Change set-certificate as a special case of set-default-certificate, retaining current behaviour for existing apps.
  • Add set-route certificate optional validation when lets_encrypt:true.1 Return ACME error, if present.
  • Add set-route optional Traefik restart when lets_encrypt:false.1
  • Add delete-route optional Traefik restart if a Let's Encrypt certificate was obtained.1
  • Fixed automated test suite

See also individual commit messages.

Further work:

  • Configuration dir locking. HTTP route and certificate actions may be concurrent in file modifications. I think we'd introduce a file lock to ensure serial access to configuration writes and avoid unpredictable situations.

Refs NethServer/dev#7544

Footnotes

  1. New apps can enable and leverage this behavior as wanted. Existing apps can continue to use the actions as they are. ↩ ↩2 ↩3

@DavidePrincipi DavidePrincipi changed the title feat: TLS certificates detailed list feat: TLS certificates management and monitoring Aug 5, 2025
@DavidePrincipi
DavidePrincipi force-pushed the feat-7544 branch 6 times, most recently from 80cf1ef to 8740610 Compare September 5, 2025 08:30
@DavidePrincipi
DavidePrincipi force-pushed the feat-7544 branch 3 times, most recently from 8289489 to e28b611 Compare September 11, 2025 15:43
@DavidePrincipi
DavidePrincipi marked this pull request as ready for review September 15, 2025 15:36
@DavidePrincipi
DavidePrincipi marked this pull request as draft September 15, 2025 15:38
@DavidePrincipi
DavidePrincipi force-pushed the feat-7544 branch 3 times, most recently from ab046b4 to 7d66c10 Compare September 17, 2025 14:43
@DavidePrincipi DavidePrincipi changed the title feat: TLS certificates management and monitoring feat: acme.json cleanup management Sep 17, 2025
@DavidePrincipi
DavidePrincipi marked this pull request as ready for review September 17, 2025 15:02
@DavidePrincipi DavidePrincipi self-assigned this Sep 17, 2025
@Amygos
Amygos requested a review from Copilot September 18, 2025 11:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements richer certificate management operations for Traefik with better visibility, control, and safer operations when handling certificates and HTTP routes. The primary goal is to provide more granular control over ACME certificate lifecycle and improve error handling.

Key Changes

  • Introduce list-certificates-v2 action with detailed certificate attributes and enhanced output format
  • Modify certificate deletion to use serial/path identifiers instead of FQDN for more precise targeting
  • Add set-default-certificate action for dedicated default certificate management with validation

Reviewed Changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/20_traefik_certificates_api.robot Updates test cases to use new serial/path-based certificate deletion API
imageroot/pypkg/cert_helpers.py Major refactoring with new certificate management functions and improved ACME handling
imageroot/actions/set-route/validate-input.json Adds optional cleanup and validation options for Let's Encrypt certificates
imageroot/actions/set-route/20writeconfig Implements certificate cleanup functionality when disabling Let's Encrypt
imageroot/actions/set-route/11validate_host Adds optional certificate validation during route configuration
imageroot/actions/set-default-certificate/validate-input.json Schema for new default certificate action
imageroot/actions/set-default-certificate/50set_default_certificate Implementation of default certificate management
imageroot/actions/set-certificate/20writeconfig Refactors to use new certificate request functions
imageroot/actions/set-certificate/05check_routes Simplifies route conflict checking using new helper functions
imageroot/actions/list-certificates-v2/validate-output.json Schema for enhanced certificate listing output
imageroot/actions/list-certificates-v2/50list_certificates_v2 Implementation of detailed certificate listing
imageroot/actions/delete-route/validate-input.json Adds optional cleanup parameter
imageroot/actions/delete-route/21sync_hosts Converts to placeholder implementation
imageroot/actions/delete-route/20file Implements certificate cleanup when deleting routes
imageroot/actions/delete-certificate/validate-output.json Removes unnecessary type constraint
imageroot/actions/delete-certificate/validate-input.json Changes API to use serial/path instead of FQDN
imageroot/actions/delete-certificate/20writeconfig Refactors to use new purging functions
README.md Updates documentation for new actions and modified APIs

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread imageroot/pypkg/cert_helpers.py Resolved
Comment thread imageroot/pypkg/cert_helpers.py Resolved

@Amygos Amygos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread imageroot/pypkg/cert_helpers.py Resolved
- read acme.json (internal) and certificates from custom directory
- mark the default certificate
- mark certificates matching automatic HTTP routes with Let'Encrypt
  enabled
- parse and format validity dates
- calculate validity state: valid, expiring (30 days left), expired
- extract also attributes: issuer, subject, serial, and path
Delete certificates matching the given serial number (for internal
certs), or path (for custom certs).

If acme.json is modified, Traefik is immediately restarted.

The names of the removed certificate are notified with
certificate-changed event. If they match an HTTP route's Host name, ACME
cert resolver is forcibly disabled for that route, to prevent further
ACME requests.
If the deleted certificate is the one set as Traefik's default ACME
certificate, reset the configuration to prevent an immediate request
for a new equivalent certificate.
Completely override the default certificate configuration with a new
list of names. The first element of the list is used as main name.

Before issuing an ACME request, ensure that no certificate in acme.json
has the same set of names.

The new set of names is written to default configuration for a
time-boxed check. During this time frame, Traefik may expose its
self-signed certificate.
Require synchronous validation of Let's Encrypt certificate with the new
"lets_encrypt_check" request flag.

A temporary Traefik route is created to trigger a new ACME certificate
request. If the certificate is obtained validation passes, otherwise
set-route fails with a validation error.
Introduce the "lets_encrypt_cleanup" flag to the set-route and delete-route
actions to control Traefik restarts.

The flag is disabled by default to ensure backward compatibility:
- delete-route is triggered during uninstall, where a Traefik restart is
  unexpected and must be avoided.
- set-route is triggered during configuration. A restart should only occur
  if the application explicitly enables the flag and informs the Admin.

Note: during delete-route, write-hosts helper call was removed because
the automatic Traefik restart implicitly calls it.
Either `path` or `serial` must be provided. `fqdn` is now ignored.
@DavidePrincipi
DavidePrincipi force-pushed the feat-7544 branch 2 times, most recently from 65b1f1c to 9959186 Compare September 23, 2025 16:03
Move list-certificates-v2 implementation to stable list-certificates
action to preserve current authorizations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants