Skip to content

Conversation

@ianrodrigues
Copy link

Many web applications validate the Host header for security (think Django's ALLOWED_HOSTS, Rails, etc.). When kamal-proxy performs health checks using internal IPs like http://10.0.1.5:3000/up, the application sees Host: 10.0.1.5:3000 and rejects it. This causes the proxy to incorrectly mark healthy targets as unhealthy.

For example, if your app only allows example.com in 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-host flag that lets you set a custom Host header for health check requests.

kamal-proxy deploy myapp \
  --target http://10.0.1.5:3000 \
  --health-check-path /up \
  --health-check-host example.com

Now health checks will include Host: example.com and 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.

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.

1 participant