m-lab / ndt-server

docker native ndt5 and ndt7 server with prometheus integration
https://www.measurementlab.net/
Apache License 2.0
101 stars 41 forks source link

feat(ndt7): Use X-Forwarded-For hint for the client's IP address #403

Closed auvik-bheesham closed 6 months ago

auvik-bheesham commented 6 months ago

When running behind a proxy the RemoteAddr in various places won't return the real client's IP. This commit uses various hints to get it, falling back to using the default.

cc @pthankappan


This change is Reviewable

auvik-bheesham commented 6 months ago

Example:

; go run ./cmd/ndt7-client/main.go -service-url 'wss://speedtest.example.com/ndt/v7/upload'
upload in progress with speedtest.example.com
Avg. speed  :   114.6 Mbit/s
upload: complete

Test results

    Server: speedtest.example.com
    Client: 100.96.17.113

              Upload
     Throughput:   114.6 Mbit/s
        Latency:     0.6 ms

The Client: 100.96.17.113 is incorrect -- we're running the server in Kubernetes behind various proxies, so it's not quite returning the expected value.

auvik-bheesham commented 6 months ago

Retracted for now since I noticed a couple of other places where RemoteAddr was being used.

In the process of being reviewed internally: https://github.com/auvik-bheesham/ndt-server/commit/81df5128c7079493ed36885f2305748e64aa0210

auvik-bheesham commented 6 months ago

Updated MR here: https://github.com/m-lab/ndt-server/pull/404