-
Notifications
You must be signed in to change notification settings - Fork 0
fix: prevent HTTPS redirect loop & add API_HOSTNAME config #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
When redirect_http is enabled for a TLS ingress, the generated Caddy redirect route was matching all requests (both HTTP and HTTPS) because it only checked the hostname. This caused HTTPS requests to be caught in an infinite redirect loop. Add "protocol": "http" matcher to redirect routes so they only match HTTP requests, allowing HTTPS requests to pass through to the reverse proxy route.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Add configuration options to expose the Hypeman API through Caddy's ingress routing, separate from the instance ingress system. Configuration: - API_HOSTNAME: hostname for API access (e.g., api.hostname.kernel.sh) - API_TLS: enable TLS for API hostname (default: true) - API_REDIRECT_HTTP: redirect HTTP to HTTPS (default: true) When API_HOSTNAME is set, Caddy automatically adds a route that proxies requests to localhost:PORT (the Hypeman API). This allows the API to be accessed via HTTPS without requiring a separate ingress rule. Example: API_HOSTNAME=api.dev-yul-hypeman-0.kernel.sh API_TLS=true Results in: https://api.dev-yul-hypeman-0.kernel.sh/ -> localhost:8080
a43a262 to
7c07690
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Add validation to reject ingress creation when the hostname matches the configured API_HOSTNAME. This prevents users from hijacking API traffic by creating an ingress with the same hostname.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| // Add TLS configuration for API hostname | ||
| if g.apiIngress.TLS { | ||
| listenPorts[443] = true | ||
| tlsHostnames = append(tlsHostnames, g.apiIngress.Hostname) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API ingress TLS lacks ACME configuration validation
Medium Severity
When API_HOSTNAME is set, API_TLS defaults to true, causing the API hostname to be added to tlsHostnames and Caddy to listen on port 443. However, unlike instance ingress TLS (which validates that ACME is configured and returns a clear error), there's no validation for the API ingress. If ACME isn't configured, no TLS automation is generated (line 431 requires IsTLSConfigured()), so Caddy will attempt to serve HTTPS using its default ACME behavior (HTTP-01 challenge), which may fail silently in many environments.
Additional Locations (1)
API routes must come before wildcard routes in Caddy config, otherwise wildcards like *.example.com will match api.example.com and try to resolve "api" as a VM instance (resulting in 503).
Move the API hostname conflict check earlier in the validation flow so users get a clear "reserved for API" error instead of a confusing "instance not found" error.
Addressing Bugbot CommentsIssues 1 & 2:
|
Summary
1. Fix HTTPS redirect loop
When
redirect_http: trueis enabled for a TLS ingress, the generated Caddy redirect route was matching all requests (both HTTP and HTTPS) because it only checked the hostname. This caused HTTPS requests to be caught in an infinite redirect loop.Fix: Add
"protocol": "http"matcher to redirect routes so they only match HTTP requests.2. Add
API_HOSTNAMEconfig to expose Hypeman API via CaddyAdd configuration options to expose the Hypeman API through Caddy's ingress routing, separate from the instance ingress system.
Configuration:
When
API_HOSTNAMEis set, Caddy automatically adds a static route that proxies requests tolocalhost:8080(the Hypeman API).Result:
This is the right approach because:
Test plan
redirect_http: trueAPI_HOSTNAMEconfig and restart Hypemanhttps://api.<hostname>/healthreturns API responseNote
Introduces API ingress and resolves redirect loop issues while updating wiring and tests.
APIIngressConfigandAPI_HOSTNAME(API_TLS,API_REDIRECT_HTTP) to proxy the Hypeman API directly to127.0.0.1:<port>; route prepended to avoid wildcard conflicts; reserved hostname validation inmanager."protocol": "http"so HTTPS traffic is not re-matched.config.Load()reads new vars;providers.ProvideIngressManagerparses API port and setsAPIIngress;CaddyConfigGeneratorandManagerconstructors updated to acceptAPIIngressConfig.Written by Cursor Bugbot for commit 081cb53. This will update automatically on new commits. Configure here.