graylog2-server icon indicating copy to clipboard operation
graylog2-server copied to clipboard

X-Forwarded-For field doesn't appear.

Open ghost opened this issue 10 years ago • 7 comments

It seems reading X-Forwarded-For header from incoming messages is not working. I configured GELF HTTP input, which gets logs through HAProxy with 'forwardfor' option, and 'trusted_proxies' in graylog.conf. But I can't see real client IP anywhere, just IP of HAProxy is everywhere.

Environment

  • Graylog Version: 2.0.3-1
  • Operating System: Debian 8.5

ghost avatar Jun 24 '16 09:06 ghost

@oleg1628 Can you see if the workarounds outlined in https://github.com/Graylog2/graylog2-server/issues/1102 work for you?

Otherwise this is a feature request, the HTTP input does not currently support this.

kroepke avatar Jun 27 '16 09:06 kroepke

It would be nice to get X-Forwarded-For IP in some message field from GELF HTTP input. I have many mobile clients behind NAT which send GELF HTTP messages through my reverse proxy (HAProxy) to Graylog. HAProxy sets X-Forwarded-For field, but I can't see it in Graylog now.

ghost avatar Jun 27 '16 22:06 ghost

I've been using workaround with nginx + lua (openresty). I modify HTTP request body with lua. which is in json format and always has "}}" in the end in my case.

server {
    listen       80;
    server_name  fqdn;

    location /<location1> {
        content_by_lua '
        ngx.req.read_body()
        local body = ngx.req.get_body_data()
        local realip = ngx.req.get_headers()["X-Forwarded-For"]
        local append = [[,"host":"]] .. realip .. [["]]
        local newbody = ngx.re.sub(body, "}}", append .. "${0}")
        res = ngx.location.capture("/gelf", {method = ngx.HTTP_POST, body = newbody})
        ngx.print(res.body)
        ';
    }

    location /gelf { 
        proxy_pass   http://127.0.0.1:12205/gelf;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}

ghost avatar Jul 01 '16 21:07 ghost

Thanks for the workaround @oleg1628 ! That really helped me out, good idea.

filmaj avatar Mar 21 '17 21:03 filmaj

Can we bring this back to life? I'm curious if anything ever came about with this, as using the GELF HTTP endpoint does not forward the client IP address.

kyl3n avatar Dec 12 '19 19:12 kyl3n

@kyl3n you might want to take this PR and rebase it to the current master:

https://github.com/Graylog2/graylog2-server/pull/3255

and open a PR

jalogisch avatar Dec 13 '19 09:12 jalogisch

Closing this issue - going to continue to track via https://github.com/Graylog2/graylog2-server/issues/11339

rich-graylog avatar Jan 08 '25 14:01 rich-graylog