Skip to content

caddyfile: Add renewal_window_ratio global option#7473

Merged
francislavoie merged 5 commits intocaddyserver:masterfrom
mehrdadbn9:feature/renewal-window-ratio-caddyfile
Feb 13, 2026
Merged

caddyfile: Add renewal_window_ratio global option#7473
francislavoie merged 5 commits intocaddyserver:masterfrom
mehrdadbn9:feature/renewal-window-ratio-caddyfile

Conversation

@mehrdadbn9
Copy link
Contributor

@mehrdadbn9 mehrdadbn9 commented Feb 12, 2026

Summary

This PR adds support for configuring the TLS certificate renewal_window_ratio parameter in the Caddyfile:

  1. Global options block - Configure for all sites
  2. TLS directive - Configure per-site (overrides global)

Previously, this setting was only available through JSON configuration at apps/tls/automation/policies/renewal_window_ratio, requiring users to either abandon the Caddyfile workflow or use complex scripts to modify the JSON output.

Usage

Global option:

{
    # Renew when ~16.66% of lifetime remains (approx 13-14 days for Let's Encrypt 90-day certs)
    renewal_window_ratio 0.1666
}

Per-site in tls directive:

example.com {
    tls {
        renewal_window_ratio 0.25
    }
}

The value must be a float between 0 and 1 (exclusive). This ratio determines when Caddy should attempt to renew a certificate before it expires, as a proportion of the certificate's total lifetime.

Implementation

  • Added parseOptRenewalWindowRatio parser function in options.go to validate and parse the float value
  • Registered the new global option renewal_window_ratio
  • Modified newBaseAutomationPolicy in tlsapp.go to apply the setting to automation policies
  • Added support for renewal_window_ratio subdirective in the tls directive in builtins.go
  • Added caddyfile adapt tests for both global option and tls directive

Testing

The implementation follows the same pattern as other global TLS options like key_type and ocsp_stapling. Caddyfile adapt tests have been added.

AI Disclosure

This PR was developed with the assistance of AI tools (Claude). The implementation logic, code structure, and test cases were developed through an iterative process with AI assistance.

Fixes #7467

Adds support for configuring the TLS certificate renewal window ratio
directly in the Caddyfile global options block. This allows users to
customize when certificates should be renewed without needing to use
JSON configuration.

Example usage:
    {
        renewal_window_ratio 0.1666
    }

Fixes #7467
@CLAassistant
Copy link

CLAassistant commented Feb 12, 2026

CLA assistant check
All committers have signed the CLA.

@francislavoie
Copy link
Member

francislavoie commented Feb 12, 2026

Please add .caddyfileadapt test for this (or update an existing one)

I think the tls directive should also support configuring this option, not only global options.

Your PR is missing the AI disclosure section.

You must also sign the CLA.

@francislavoie francislavoie added the feature ⚙️ New feature or request label Feb 12, 2026
Adds support for renewal_window_ratio in the tls directive (not just
global options) and adds caddyfile adapt tests for both the global
option and tls directive.
@mehrdadbn9
Copy link
Contributor Author

Hi, I'm trying to sign the CLA but cla-assistant.io is timing out / inaccessible. Is there an alternative way to sign the CLA? I'm ready to proceed with the contribution.

@francislavoie
Copy link
Member

Tests are failing.

@mehrdadbn9
Copy link
Contributor Author

I've fixed the test expected outputs. The tests should now pass. Could a maintainer please approve/re-run the CI workflow? Thank you!

@francislavoie
Copy link
Member

Tests are still failing. Did you actually try to run the tests locally? Please stop relying so much on LLMs to do all the work for you. Take some initiative.

@francislavoie
Copy link
Member

Commit d6a9b5c is nonsense, you deleted important code.

@mehrdadbn9
Copy link
Contributor Author

mehrdadbn9 commented Feb 13, 2026

I apologize for the previous mistake. My edit accidentally deleted critical code. I've now properly fixed it:

What was wrong:
My previous edit accidentally removed certificate managers, and bind host handling.

What was fixed:

  • Restored all the deleted code
  • Properly added the global renewal_window_ratio inheritance logic (only 2 lines added)

Test Results from previous CI run showing our tests pass:

--- PASS: TestCaddyfileAdaptToJSON/renewal_window_ratio_global.caddyfiletest (0.00s)
--- PASS: TestCaddyfileAdaptToJSON/renewal_window_ratio_tls_directive.caddyfiletest (0.00s)

The renewal_window_ratio tests were passing. The failure was caused by my accidental code deletion breaking other tests.

is therre anything i should do as well?

@francislavoie francislavoie added this to the v2.11.0 milestone Feb 13, 2026
@francislavoie francislavoie merged commit 929d0e5 into caddyserver:master Feb 13, 2026
27 checks passed
This was referenced Feb 20, 2026
@francislavoie francislavoie mentioned this pull request Feb 20, 2026
4 tasks
francislavoie added a commit to caddyserver/website that referenced this pull request Feb 22, 2026
francislavoie added a commit to caddyserver/website that referenced this pull request Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature ⚙️ New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integrated the renewal_window_ratio parameter into the Caddyfile syntax

3 participants