Skip to content

fix(provision): plain HTTP to a private-network IP reaches Trinity (#3821) - #3833

Merged
vybe merged 1 commit into
devfrom
feature/3821-private-http-ip
Oct 21, 2026
Merged

vybe merged 1 commit into
devfrom
feature/3821-private-http-ip

Conversation

@obasilakis

Copy link
Copy Markdown
Contributor

Summary

  • With PRIVATE_NETWORK_CIDRS set, http://<private-ip> returned a 308 to HTTPS instead of reaching the @private handler. Caddy's automatic redirects for the on-demand wildcard site (https://*.*.*.* matches a dotted IPv4 host) run ahead of the http:// block. Only a dotless MagicDNS name got through.
  • When the variable is set, the render now adds the global auto_https disable_redirects, so the http:// block is the only route on :80. Its fallback redirect is now 308 (was permanent, which is 301), the code the automatic redirects used, so a POST from outside the network keeps its method.
  • With the variable unset the Caddyfile renders byte-identical to before, so the unchanged-file check keeps those installs from restarting Caddy.

Caddy answers ACME HTTP challenges ahead of every route (modules/caddyhttp/server.go, v2.11.7, HandleHTTPChallenge), so certificate issuance and renewal are unaffected.

Changes

  • scripts/deploy/start.sh: provision_caddyfile
  • tests/unit/test_2692_private_network_access.py: private render carries disable_redirects + 308 fallback; unset render has no auto_https and no extra global line
  • docs/user-docs/guides/deploying/hardening.md: the IP and the MagicDNS name both work

Test Plan

  • cd tests && pytest unit/test_2692_private_network_access.py unit/test_2380_provision_single_source.py unit/test_3004_aws_provision.py unit/test_2281_marketplace_build_standard.py: 72 passed, 5 skipped. The new tests fail against the unfixed start.sh.
  • Caddy 2.11.7 (caddy:2 image), fed the Caddyfile start.sh actually renders, with client containers inside and outside the CIDR:
    • caddy adapt accepts both the unset and the set render
    • inside: private IP, public IP and domain Host → 200 over plain HTTP (each was 308 before)
    • outside: all → 308 to https, POST included
  • On a provisioned droplet with PRIVATE_NETWORK_CIDRS set: --caddy-only, then curl -i http://<private-ip>/api/setup/status from inside the CIDR → 200; from outside → redirect; https://<public-ip> unchanged

Upgrade note

Instances that already have PRIVATE_NETWORK_CIDRS set get the fix only after re-rendering:
sudo ./scripts/deploy/start.sh --provision --cloud <cloud> --caddy-only

Fixes #3821

🤖 Generated with Claude Code

…stead of redirecting (#3821)

Caddy's automatic HTTP->HTTPS redirects for the on-demand wildcard site
are routed by host pattern and run ahead of the user's `http://` block.
`https://*.*.*.*` matches a dotted IPv4 host, so `http://<tailnet-ip>`
got a 308 before the `@private remote_ip` handler saw it; only a dotless
MagicDNS name reached it.

When PRIVATE_NETWORK_CIDRS is set, the render now adds
`auto_https disable_redirects`, leaving the `http://` block as the only
route on :80, and its fallback redirect is 308 (the code the automatic
redirects used). Caddy answers ACME HTTP challenges ahead of every route,
so certificate issuance is unaffected. With the variable unset the file
renders byte-identical to before.

Fixes #3821

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@AndriiPasternak31 AndriiPasternak31 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.

Reviewed against Caddy 2.11.4 (the pinned version, not caddy:2). I rendered both configs with the test's _render harness and sent real requests at port 80. From inside the CIDR, private IP, public IP, domain and dotless Host all reach the upstream over plain HTTP. From outside, everything still gets a 308 to https, POST included, and so do a forged Host: 100.64.0.1 and a forged X-Forwarded-For. With the variable unset the render is byte-identical to dev. The ACME HTTP challenge runs ahead of the routes (server.go:384 at v2.11.4), so certificates aren't affected.

Teeth: the new test fails on the merge-base start.sh and when the _auto_https line is removed. It does pass if the rendered directive is commented out (# auto_https disable_redirects), because it matches the text rather than Caddy's behaviour. Could you add a check that runs the render through caddy adapt and asserts disable_redirects in the JSON, skipped when caddy isn't installed? Not blocking.

Approving. Please still tick the droplet check before merge.

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