support kamal-proxy --health-check-host #1693
Open
+36
−0
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 host authorization, 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 integrates with basecamp/kamal-proxy#175, which added the
--health-check-hostflag to kamal-proxy. Now you can configure a customHostheader for health check requests in yourdeploy.yml:When Kamal deploys your app, health checks will include
Host: example.comand pass validation.The option is optional and fully backward compatible. When not specified, the default behavior is unchanged.
Changes
lib/kamal/configuration/proxy.rb): Addedhealth-check-hosttodeploy_optionsto extract and pass the custom host header to kamal-proxylib/kamal/configuration/docs/proxy.yml): Documented the newhostoption in the healthcheck section with examples and use casestest/configuration/proxy_test.rb): Added test cases to verify the option is correctly passed and backward compatibility is maintainedTesting