Support setting the Host header on health checks #175
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.
Many web applications validate the
Hostheader for security (think Django'sALLOWED_HOSTS, Rails, etc.). When kamal-proxy performs health checks using internal IPs likehttp://10.0.1.5:3000/up, the application seesHost: 10.0.1.5:3000and rejects it. This causes the proxy to incorrectly mark healthy targets as unhealthy.For example, if your app only allows
example.comin its host validation, health checks using the internal IP will fail even though the application is working fine.Solution
This PR adds a
--health-check-hostflag that lets you set a customHostheader for health check requests.Now health checks will include
Host: example.comand pass validation.The flag is optional and backward compatible. When not specified, the default behavior is unchanged. It works with both GET and HEAD health checks, and is available via both CLI and JSON API.
Testing
Added unit tests to verify the custom Host header is sent correctly, health checks pass/fail based on header validation, and default behavior works when the flag isn't used.