Validate on-demand TLS against active tunnels#14
Merged
Conversation
Add a local /expose/can-issue-certificate endpoint that Caddy's on-demand TLS asks before issuing a certificate. It returns 200 only when a live tunnel exists for the requested host (using the same connection lookup as request routing), 404 otherwise. Gated to the loopback interface so it can't shadow tunnelled paths or leak active-tunnel info externally. Stops the on-demand cert pool from growing for hosts nobody is tunnelling: the current platform ask approves any subdomain of a registered domain, causing large cert fan-out (259 registered domains -> ~17k stored certs on eu-1) that Caddy then loads/parses under handshake floods, spiking memory and CPU.
77d2e5a to
1b15ba3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Caddy's on-demand TLS
askcurrently points at the platform (https://expose.dev/api/tunnel), which approves any subdomain of a registered custom domain. On eu-1 that has produced 259 registered domains → ~16,954 stored certs (~65× fan-out) — bot/crawler/www-variant subdomains each mint a permanent cert. That huge pool is what Caddy loads + parses (crypto/x509.parseCertificate+encoding/pem.Decodedominate the heap) under handshake floods, spiking memory ~1 GB and pinning CPU — which on smaller boxes (us-1: 1 vCPU / 1 GB) trips the health-check timeout/restart loop.What
A local endpoint
GET /expose/can-issue-certificate?domain=<host>on the expose server that Caddy can ask before issuing:findControlConnectionForSubdomainAndServerHost, the same lookup request routing uses.Gated to the loopback interface (
Host∈127.0.0.1[:port]) so it can only be reached by the local Caddy process — it can't shadow a tunnelled app's path or leak which tunnels are live to external callers. Registered before the catch-all tunnel route.Tests
it_refuses_certificate_issuance_for_a_host_without_an_active_tunnel→ 404it_allows_certificate_issuance_for_a_host_with_an_active_tunnel→ 200Full
tests/Feature/Serversuite passes (48 tests).