Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This plugin will no longer be needed in Caddy v2.7.0 #14

Open
francislavoie opened this issue Apr 1, 2023 · 14 comments
Open

This plugin will no longer be needed in Caddy v2.7.0 #14

francislavoie opened this issue Apr 1, 2023 · 14 comments

Comments

@francislavoie
Copy link

Just wanted to mention here that this plugin will no longer be needed because of the work done in caddyserver/caddy#5104.

The real client IP will be parsed if trusted_proxies is configured in global options, and the header it's read from can be configured with client_ip_headers (defaulting to X-Forwarded-For). The logs will include it as a new client_ip field.

Compared to this plugin, this approach doesn't affect req.RemoteAddr, that's left intact, but any other modules/handlers that might care to get the real client IP can get it from the request context.

@lxhao61
Copy link

lxhao61 commented Apr 4, 2023

When will Caddy v2.7.0 be released?

@francislavoie
Copy link
Author

Caddy doesn't follow a release schedule. A release will be made when we have enough to release.

@kirsch33
Copy link
Owner

kirsch33 commented Apr 6, 2023

thanks for the heads up. i have referenced this discussion on the main page for this repo.

@crapthings
Copy link

can i use this for 2.6.4?

how to install this module?

@francislavoie
Copy link
Author

No @crapthings. You could build from the master branch though. It's not a plugin, it's changes in Caddy itself.

@mgagnant
Copy link

mgagnant commented Jun 6, 2023

Hello,
i use caddy 2.7 beta for testing the recuperation of source IP.
I have the field "client_ip" but the ip is the container ip....

where i must put trusted_proxies parameters please ?

after in my PHP code i use :
$user_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
echo "IP HTTP_X_FORWARDED_FOR : ".$user_ip."
";

Thanks for your reply.

@francislavoie
Copy link
Author

In global options, at the top of your Caddyfile:

{
	servers {
		trusted_proxies static <ips...>
	}
}

@mgagnant
Copy link

mgagnant commented Jun 6, 2023

Thanks a lot for your Quick answer.
Unfortunately still the Same problem. The client_ip value is 10.0.0.3 which is the container IP.
maybe i made a mistake on trusted_proxies.
What are the statics ips I must enter ? I try with 10.0.0.3 .
Thanks again

@francislavoie
Copy link
Author

If you're in Docker then you might be running into the problem where Docker is using a userland proxy which causes all TCP packets to appear that they're coming from Docker itself. That's not something you can fix with Caddy itself, it's a problem with Docker. See moby/moby#15086

@mgagnant
Copy link

mgagnant commented Jun 7, 2023

Ok thanks again for your quick answer. I will investigate on docker.

@EnfermeraSexy
Copy link

I'm using the new sintax but i don't know where I'm failing. I want to pass the IP present in the cloudflare header but it's not working as i thought. For example, with this config:

{
	servers {
		trusted_proxies static cloudflare_ips_range
		client_ip_headers CF-Connecting-IP
	}
}
domain.example {
	reverse_proxy example {
		header_up X-Forwarded-For {client_ip}
	}
}

The application is not getting the header. If i change the trusted header to:
client_ip_headers X-Forwarded-For

Then it works. Why is not taking the IP from the CF header? Did I misunderstood something?

@francislavoie
Copy link
Author

cloudflare_ips_range is not a thing.

If you want to automatically get the trusted proxies IPs for cloudflare, use this plugin https://github.com/WeidiDeng/caddy-cloudflare-ip instead of static.

Also remove your header_up X-Forwarded-For line, that's incorrect; Caddy will automatically set that header correctly if trusted_proxies is correct.

@EnfermeraSexy
Copy link

cloudflare_ips_range was just and example to not write all the IPs.

The problem is that some applications does not properly read the header if it contains multiple IP address client_ip, cloudflare_ip. That's why I want to overwrite the header and just set the client IP without the intermediate.

@francislavoie
Copy link
Author

francislavoie commented Aug 3, 2023

The problem is that some applications does not properly read the header if it contains multiple IP address

Then those should be fixed. They're not conformant to spec otherwise.

Also you might need to use Cf-Connecting-Ip and not CF-Connecting-IP (lowercase f and p)

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

No branches or pull requests

6 participants