You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cloudstack.apache.org by "senthilnathan-am (via GitHub)" <gi...@apache.org> on 2024/08/14 12:31:19 UTC
[D] Preserve Client Source IP in Virtual Router [cloudstack]
GitHub user senthilnathan-am created a discussion: Preserve Client Source IP in Virtual Router
Why virtual router is not preserving source IP during port forwarding?
GitHub link: https://github.com/apache/cloudstack/discussions/9529
----
This is an automatically sent email for users@cloudstack.apache.org.
To unsubscribe, please send an email to: users-unsubscribe@cloudstack.apache.org
Re: [D] Preserve Client Source IP in Virtual Router [cloudstack]
Posted by "senthilnathan-am (via GitHub)" <gi...@apache.org>.
GitHub user senthilnathan-am added a comment to the discussion: Preserve Client Source IP in Virtual Router
@zap51
As expected, annotation is not working for Istio.
GitHub link: https://github.com/apache/cloudstack/discussions/9529#discussioncomment-10366160
----
This is an automatically sent email for users@cloudstack.apache.org.
To unsubscribe, please send an email to: users-unsubscribe@cloudstack.apache.org
Re: [D] Preserve Client Source IP in Virtual Router [cloudstack]
Posted by "senthilnathan-am (via GitHub)" <gi...@apache.org>.
GitHub user senthilnathan-am added a comment to the discussion: Preserve Client Source IP in Virtual Router
> @senthilnathan-am, That's correct. However, I would recommend you to use annotations instead of manually tweaking the VR. Please see https://docs.cloudstack.apache.org/en/latest/plugins/cloudstack-kubernetes-provider.html#usage This is one of the recommended ways to have the applications load-balanced when you're using CKS or when deploying the provider manually.
>
> Correct, PROXY protocol will contain additional information which your applications should be configured to accept.
>
> Regards, Jayanth
Thanks for the suggestions @zap51 . I am not sure whether that annotation will support in Istio, anyway will give a try.
GitHub link: https://github.com/apache/cloudstack/discussions/9529#discussioncomment-10364891
----
This is an automatically sent email for users@cloudstack.apache.org.
To unsubscribe, please send an email to: users-unsubscribe@cloudstack.apache.org
Re: [D] Preserve Client Source IP in Virtual Router [cloudstack]
Posted by "weizhouapache (via GitHub)" <gi...@apache.org>.
GitHub user weizhouapache added a comment to the discussion: Preserve Client Source IP in Virtual Router
haproxy supports transparent mode, however, it requires some changes in route table, iptables rules and haproxy config
refer to https://www.haproxy.com/blog/howto-transparent-proxying-and-binding-with-haproxy-and-aloha-load-balancer
there is also a related PR https://github.com/apache/cloudstack/pull/7484
GitHub link: https://github.com/apache/cloudstack/discussions/9529#discussioncomment-10404483
----
This is an automatically sent email for users@cloudstack.apache.org.
To unsubscribe, please send an email to: users-unsubscribe@cloudstack.apache.org
Re: [D] Preserve Client Source IP in Virtual Router [cloudstack]
Posted by "weizhouapache (via GitHub)" <gi...@apache.org>.
GitHub user weizhouapache added a comment to the discussion: Preserve Client Source IP in Virtual Router
> Why virtual router is not preserving source IP during port forwarding?
Do you use vpc ?
GitHub link: https://github.com/apache/cloudstack/discussions/9529#discussioncomment-10340955
----
This is an automatically sent email for users@cloudstack.apache.org.
To unsubscribe, please send an email to: users-unsubscribe@cloudstack.apache.org
Re: [D] Preserve Client Source IP in Virtual Router [cloudstack]
Posted by "zap51 (via GitHub)" <gi...@apache.org>.
GitHub user zap51 added a comment to the discussion: Preserve Client Source IP in Virtual Router
@senthilnathan-am,
Thanks for the update. Ignoring `proxy_set_header` in your backend server at the moment, I see that `$http_x_forwarded_for` is still being read as only one address.
So, please make sure the XFF configuration is properly configured at Istio. You should try increasing `numTrustedProxies`, which ideally adds the request with what's that is actually coming with "X-Forwarded-For` to the first and then appends the SNAT IP separated by a comma like the below
```
<ip_in_xff_req_header>, 10.40.0.0 10.40.0.0 ...
```
Also, VR is **not** considered a proxy, hence the amount in `numTrustedProxies` makes less sense unless there are more number of http-parsing proxies which add XFF request headers in front of the VR.
GitHub link: https://github.com/apache/cloudstack/discussions/9529#discussioncomment-10357760
----
This is an automatically sent email for users@cloudstack.apache.org.
To unsubscribe, please send an email to: users-unsubscribe@cloudstack.apache.org
Re: [D] Preserve Client Source IP in Virtual Router [cloudstack]
Posted by "zap51 (via GitHub)" <gi...@apache.org>.
GitHub user zap51 added a comment to the discussion: Preserve Client Source IP in Virtual Router
@senthilnathan-am,
That's correct. However, I would recommend you to use annotations instead of manually tweaking the VR. Please see https://docs.cloudstack.apache.org/en/latest/plugins/cloudstack-kubernetes-provider.html#usage
This is one of the recommended ways to have the applications load-balanced when you're using CKS or when deploying the provider manually.
Correct, PROXY protocol will contain additional information which your applications should be configured to accept.
Regards,
Jayanth
GitHub link: https://github.com/apache/cloudstack/discussions/9529#discussioncomment-10364801
----
This is an automatically sent email for users@cloudstack.apache.org.
To unsubscribe, please send an email to: users-unsubscribe@cloudstack.apache.org
Re: [D] Preserve Client Source IP in Virtual Router [cloudstack]
Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
GitHub user DaanHoogland added a comment to the discussion: Preserve Client Source IP in Virtual Router
Ithought it was @senthilnathan-am . can you add the scenario you are using here, for people to reproduce the possible issue, please?
GitHub link: https://github.com/apache/cloudstack/discussions/9529#discussioncomment-10337392
----
This is an automatically sent email for users@cloudstack.apache.org.
To unsubscribe, please send an email to: users-unsubscribe@cloudstack.apache.org
Re: [D] Preserve Client Source IP in Virtual Router [cloudstack]
Posted by "senthilnathan-am (via GitHub)" <gi...@apache.org>.
GitHub user senthilnathan-am added a comment to the discussion: Preserve Client Source IP in Virtual Router
Finally found a solution to preserve client IP for Kubernetes platform in ACS.
Below are the things to be done:
1. For K8s, if it setup manually then it is recommended to use Load Balancing rules instead of port forwarding rules for network traffic diversion.
2. If Istio service mesh is used to expose the cluster ports then proxy protocol has to be enabled in VR haproxy service in the appropriate listen section, just by adding 'send-proxy-v2' after check.
3. Restart the haproxy service in VR. Also, make sure the proxy protocol is enabled in Istio level.
Now, actual client source IP will get displayed in the backend server/pod log as expected.
GitHub link: https://github.com/apache/cloudstack/discussions/9529#discussioncomment-10364752
----
This is an automatically sent email for users@cloudstack.apache.org.
To unsubscribe, please send an email to: users-unsubscribe@cloudstack.apache.org
Re: [D] Preserve Client Source IP in Virtual Router [cloudstack]
Posted by "senthilnathan-am (via GitHub)" <gi...@apache.org>.
GitHub user senthilnathan-am added a comment to the discussion: Preserve Client Source IP in Virtual Router
> I thought it was @senthilnathan-am . can you add the scenario you are using here, for people to reproduce the possible issue, please?
> > Why virtual router is not preserving source IP during port forwarding?
>
> Do you use vpc ?
@DaanHoogland @weizhouapache I have narrow down it and found this is occurring only in Kubernetes platform. Normal VM running inside/outside vpc is showing actual source IP in it's log but K8 isn't.
Kubernetes cluster is created manually and running as one controlplane and one worker node VMs.
CloudStack 4.19.1.1
K8s version => v1.30.3
Istio version => 1.17.3
CNI is Weave Net
Nginx pod is running
Exposing the port 80 to public through Istio Ingress Gateway. As suggested by Istio, I have mentioned #1 as trusted proxy in their gateway topology config while installing Istio since VR is running in-front of Istio LB.
https://istio.io/latest/docs/ops/configuration/traffic-management/network-topologies/
Currently, in the nginx log, it is showing weave interface IP instead of actual source IP.
I would really appreciate your inputs here.
GitHub link: https://github.com/apache/cloudstack/discussions/9529#discussioncomment-10355090
----
This is an automatically sent email for users@cloudstack.apache.org.
To unsubscribe, please send an email to: users-unsubscribe@cloudstack.apache.org
Re: [D] Preserve Client Source IP in Virtual Router [cloudstack]
Posted by "zap51 (via GitHub)" <gi...@apache.org>.
GitHub user zap51 edited a comment on the discussion: Preserve Client Source IP in Virtual Router
@senthilnathan-am,
Thanks for the update. Ignoring `proxy_set_header` in your backend server at the moment, I see that `$http_x_forwarded_for` is still being read as only one address.
So, please make sure the XFF configuration is properly configured at Istio. You should try increasing `numTrustedProxies`, which ideally adds the request with what's that is actually coming with `X-Forwarded-For` to the first and then appends the SNAT IP separated by a comma like the below
```
<ip_in_xff_req_header>, 10.40.0.0 10.40.0.0 ...
```
Also, VR is **not** considered a proxy, hence the amount in `numTrustedProxies` makes less sense unless there are more number of http-parsing proxies which add XFF request headers in front of the VR.
GitHub link: https://github.com/apache/cloudstack/discussions/9529#discussioncomment-10357760
----
This is an automatically sent email for users@cloudstack.apache.org.
To unsubscribe, please send an email to: users-unsubscribe@cloudstack.apache.org
Re: [D] Preserve Client Source IP in Virtual Router [cloudstack]
Posted by "senthilnathan-am (via GitHub)" <gi...@apache.org>.
GitHub user senthilnathan-am added a comment to the discussion: Preserve Client Source IP in Virtual Router
> Hi @senthilnathan-am, Please try capturing "X-Forwarded-For" header sent by envoy on your backend server which should have the end-client IP. Due to the nature of Kubernetes & depending on the configuration, you'll likely not see end-client IPs due to Source NAT being done by nodes and pods acting as reverse proxies.
>
> Regards, Jayanth
Thanks for the reply @zap51
I have already used XFF and also enabled real-ip module in the nginx which is the server running behind istio. Below are the directives used in the configuration and also provided the sample log.
```shell
log_format main '$http_x_forwarded_for $remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$remote_addr"';
real_ip_header X-Forwarded-For;
real_ip_recursive on;
set_real_ip_from 127.0.0.6;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
```
`10.40.0.0 10.40.0.0 - - [16/Aug/2024:07:00:21 +0000] "GET /css/ajax-loader.gif HTTP/1.1" 404 548 "http://ams.com/css/slick-theme.css" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" "10.40.0.0"`
In the above log, you could see both XFF and real-ip headers are showing same IP which is Weave interface IP not the actual client IP.
GitHub link: https://github.com/apache/cloudstack/discussions/9529#discussioncomment-10356919
----
This is an automatically sent email for users@cloudstack.apache.org.
To unsubscribe, please send an email to: users-unsubscribe@cloudstack.apache.org
Re: [D] Preserve Client Source IP in Virtual Router [cloudstack]
Posted by "zap51 (via GitHub)" <gi...@apache.org>.
GitHub user zap51 added a comment to the discussion: Preserve Client Source IP in Virtual Router
> @zap51
> As expected, annotation is not working for Istio.
This only works when using CloudStack Kubernetes Provider. I see that you'd manually configured the LB and its rules.
Regards,
Jayanth
GitHub link: https://github.com/apache/cloudstack/discussions/9529#discussioncomment-10366208
----
This is an automatically sent email for users@cloudstack.apache.org.
To unsubscribe, please send an email to: users-unsubscribe@cloudstack.apache.org
Re: [D] Preserve Client Source IP in Virtual Router [cloudstack]
Posted by "zap51 (via GitHub)" <gi...@apache.org>.
GitHub user zap51 added a comment to the discussion: Preserve Client Source IP in Virtual Router
Hi @senthilnathan-am,
Please try capturing "X-Forwarded-For" header sent by envoy on your backend server which should have the end-client IP.
Due to the nature of Kubernetes & depending on the configuration, you'll likely not see end-client IPs due to Source NAT being done by nodes and pods acting as reverse proxies.
Regards,
Jayanth
GitHub link: https://github.com/apache/cloudstack/discussions/9529#discussioncomment-10355349
----
This is an automatically sent email for users@cloudstack.apache.org.
To unsubscribe, please send an email to: users-unsubscribe@cloudstack.apache.org
Re: [D] Preserve Client Source IP in Virtual Router [cloudstack]
Posted by "senthilnathan-am (via GitHub)" <gi...@apache.org>.
GitHub user senthilnathan-am edited a comment on the discussion: Preserve Client Source IP in Virtual Router
> I thought it was @senthilnathan-am . can you add the scenario you are using here, for people to reproduce the possible issue, please?
> > Why virtual router is not preserving source IP during port forwarding?
>
> Do you use vpc ?
@DaanHoogland @weizhouapache I have narrow down it and found this is occurring only in Kubernetes platform. Normal VM running inside/outside vpc is showing actual source IP in it's log but K8 isn't.
Kubernetes cluster is created manually and running as one controlplane and one worker node VMs.
CloudStack 4.19.1.1
K8s version => v1.30.3
Istio version => 1.17.3
CNI is Weave Net
Nginx pod is running
Exposing the port 80 to public through Istio Ingress Gateway. As suggested by Istio, I have mentioned #1 as trusted proxy in their gateway topology config while installing Istio since VR is running in-front of Istio LB.
https://istio.io/v1.17/docs/ops/configuration/traffic-management/network-topologies/
Currently, in the nginx log, it is showing weave interface IP instead of actual source IP.
I would really appreciate your inputs here.
GitHub link: https://github.com/apache/cloudstack/discussions/9529#discussioncomment-10355090
----
This is an automatically sent email for users@cloudstack.apache.org.
To unsubscribe, please send an email to: users-unsubscribe@cloudstack.apache.org
Re: [D] Preserve Client Source IP in Virtual Router [cloudstack]
Posted by "senthilnathan-am (via GitHub)" <gi...@apache.org>.
GitHub user senthilnathan-am closed a discussion: Preserve Client Source IP in Virtual Router
Why virtual router is not preserving source IP during port forwarding?
GitHub link: https://github.com/apache/cloudstack/discussions/9529
----
This is an automatically sent email for users@cloudstack.apache.org.
To unsubscribe, please send an email to: users-unsubscribe@cloudstack.apache.org
Re: [D] Preserve Client Source IP in Virtual Router [cloudstack]
Posted by "senthilnathan-am (via GitHub)" <gi...@apache.org>.
GitHub user senthilnathan-am closed the discussion with a comment: Preserve Client Source IP in Virtual Router
Closing this...
GitHub link: https://github.com/apache/cloudstack/discussions/9529#discussioncomment-10405104
----
This is an automatically sent email for users@cloudstack.apache.org.
To unsubscribe, please send an email to: users-unsubscribe@cloudstack.apache.org