Skip to content

Conversation

@ianrodrigues
Copy link

Many web applications validate the Host header for security (think Django's ALLOWED_HOSTS, Rails host authorization, 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 integrates with basecamp/kamal-proxy#175, which added the --health-check-host flag to kamal-proxy. Now you can configure a custom Host header for health check requests in your deploy.yml:

proxy:
  host: example.com
  healthcheck:
    interval: 1
    timeout: 5
    path: "/up"
    host: "example.com"  # Custom Host header for health checks

When Kamal deploys your app, health checks will include Host: example.com and pass validation.

The option is optional and fully backward compatible. When not specified, the default behavior is unchanged.

Changes

  1. Configuration (lib/kamal/configuration/proxy.rb): Added health-check-host to deploy_options to extract and pass the custom host header to kamal-proxy
  2. Documentation (lib/kamal/configuration/docs/proxy.yml): Documented the new host option in the healthcheck section with examples and use cases
  3. Tests (test/configuration/proxy_test.rb): Added test cases to verify the option is correctly passed and backward compatibility is maintained

Testing

  • Added unit tests to verify the custom host option is correctly extracted from configuration
  • Verified backward compatibility when the option is not specified
  • All existing tests continue to pass

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