HAProxy IP Spoofing

HAProxy is not correctly forwarding the client's IP address.

Understanding HAProxy

HAProxy is a popular open-source software that provides high availability, load balancing, and proxying for TCP and HTTP-based applications. It is widely used to improve the performance and reliability of web applications by distributing the workload across multiple servers.

Identifying the Symptom: IP Spoofing

In the context of HAProxy, IP spoofing refers to the situation where the client's original IP address is not correctly forwarded to the backend servers. Instead, the backend servers see the IP address of the HAProxy server itself. This can lead to issues with logging, security, and application logic that relies on the client's IP address.

Common Observations

  • Backend servers log the IP address of the HAProxy server instead of the client's IP.
  • Security rules based on client IP addresses do not work as expected.
  • Analytics and tracking systems show incorrect client locations.

Explaining the Issue

The root cause of this issue is that HAProxy is not configured to forward the client's IP address to the backend servers. By default, HAProxy uses its own IP address when making requests to the backend servers. To preserve the client's IP address, HAProxy must be configured to use the X-Forwarded-For header.

Technical Details

The X-Forwarded-For header is a standard HTTP header used to identify the originating IP address of a client connecting to a web server through an HTTP proxy or load balancer. HAProxy can be configured to append this header to requests it forwards to backend servers.

Steps to Fix the Issue

To resolve the IP spoofing issue, you need to configure HAProxy to forward the client's IP address using the X-Forwarded-For header. Follow these steps:

Modify HAProxy Configuration

  1. Open your HAProxy configuration file, typically located at /etc/haproxy/haproxy.cfg.
  2. Locate the frontend section where you define your frontend settings.
  3. Add or modify the following line to ensure the X-Forwarded-For header is set:

http-request add-header X-Forwarded-For %[src]

Example Configuration

frontend http_front
bind *:80
default_backend servers
http-request add-header X-Forwarded-For %[src]

Restart HAProxy

  1. After making the changes, restart HAProxy to apply the new configuration:

sudo systemctl restart haproxy

Additional Resources

For more detailed information on configuring HAProxy, you can refer to the official HAProxy Documentation. Additionally, the HAProxy Blog provides insights and best practices for using HAProxy effectively.

By following these steps, you should be able to resolve the IP spoofing issue and ensure that the client's IP address is correctly forwarded to your backend servers.

Master

HAProxy

in Minutes — Grab the Ultimate Cheatsheet

(Perfect for DevOps & SREs)

Most-used commands
Real-world configs/examples
Handy troubleshooting shortcuts
Your email is safe with us. No spam, ever.

Thankyou for your submission

We have sent the whitepaper on your email!
Oops! Something went wrong while submitting the form.

HAProxy

Cheatsheet

(Perfect for DevOps & SREs)

Most-used commands
Your email is safe with us. No spam, ever.

Thankyou for your submission

We have sent the whitepaper on your email!
Oops! Something went wrong while submitting the form.

MORE ISSUES

Made with ❤️ in Bangalore & San Francisco 🏢

Doctor Droid