← Back to Pull requests

acme: use the hotplug system #17721

Closed
unknown closed this pull request without merging on Aug 15, 2022 22:32 UTC
View on GitHub
unknown unknown commented on Jan 29, 2022 14:11 UTC
Author

Signed-off-by: Glen Huang <heyhgl@gmail.com>

Maintainer: @tohojo
Compile tested: not yet
Run tested: not yet

cc httpd maintainers and major contributors: @micmac1 @Ansuel @neheb @peter-stadler @jow- @feckert @nbd168

Why

This PR might come off as presumptuous, since it removes a lot of code and is not backward compatible, but allow me to explain myself.

I think the acme package suffers from assuming too much responsibilities for interacting with httpds. It currently does the following:

1. Finding and turning off httpds listening on port 80 when standalone mode is specified.
2. Making httpds reload once certs are issued/renewed.

The way it does them is pretty brittle (also dangerous, since it modifies other package's config files), and it has to account for every supported httpd, which is unmaintainable.

The situation can be improved, if:

1. This package uses the hotplug system to send issue/renew events
2. Each httpd package plugs into the system, and coordinates with this package via such events.

How

This package has to interact with httpds in the following ways:

1. HTTP-01 via webfoot
2. HTTP-01 via acme.sh standalone mode
3. Make the httpd reload the new certificates

For #1, currently the user is allowed to specify a path. With the hotplug system however, it should be a well-defined path like /var/run/acme/challenge, so each httpd can just serve challenge from this dir to make acme work.

For #2, it should be the user's responsibility to not use the standalone mode when a httpd is listening on 80. The way this package currently finds httpds is flawed, since it checks if port 80 is used on any interfaces, but standalone mode only requires 80 on WAN. Turning them off and restarting them later is also brittle.

For #3, if the hotplug system is employed, this package will call hotplud.d/acme, and scripts in it will be called with environment variables denoting if a domain is (about to be issued/issued/renewed/failed to do the proceedings) along with others that are set by acme.sh. Each httpd should know better how it should reload itself and add certificates to its config when first issuing.

This package also supports user script options for setting up and cleaning up. They can be removed as the user can just put scripts in the hotplug system.

Implementation

This PR has not been tested. It only serves to start the conversation, and demonstrates how it should work in theory. Once the design is finalized, I will make sure it's actually runnable and hopefully bug-free. At the moment, I'd be interested to know if @tohojo and httpd maintainers and major contributors think this approach is sound, and if adding acme support in each httpd package is something the maintainers and contributors would oppose to.

To reload a httpd after successfully issuing or renewing a certificate, a hotplug script could look something like:

case "$ACTION" in
issued)
	# change config so it specifies the certificates

	/etc/init.d/nginx reload
	;;
renewed)
	/etc/init.d/nginx reload
	;;
*) exit ;;
esac

This script ideally should ideally live in a separate package like nginx-acme, so it can be optionally enabled.

An even simpler approach is to require that the user runs this package at least once (either via the command line or LuCI), before specifying the certificates in the httpd config. That way the hotplug script no longer needs to mess with user's config.

I also wonder, since it's not backward compatible, should it be implemented as a separate package? Or it should be updated in place only for a new OpenWrt major version?

Details

I also took the liberty to change some small things, let me know if you think any of them are terrible ideas:

1. It should not use a init script since it's not a daemon.
2. Cron job is added once by ipk, instead of checking repeatedly by command.
3. Cron job is run each month, instead of every day.
2. cert section is enabled by default, to follow the convention.
3. Renamed option use_staging to staging.
4. Use ec-256 as keylength by default.
5. No need to resend INT signal, since it's not prevented.
6. Rename err to logerr
8. Cleaning up is automatically run at shell exit, not at the end of each issue_cert.
9. Keep issuing certificates if one fails.
10. Not printing logs where they should be clear either from acme.sh's logs or passed flags

Questions

I'm not sure what CURL_CA_BUNDLE and NO_TIMESTAMP are for?

Diff: 582 lines (+436 / -146) across 7 files Reviewer: hgl Review duration: 285620m
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 582 lines diff across 7 files
0.50
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.381
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #17721"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 49.9% (MEDIUM) · Higher = larger blast radius
49.9%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 19.7% · Safe to merge
19.7%