Skip to content

Conversation

@kroepke
Copy link
Member

@kroepke kroepke commented Jun 12, 2025

/prd https://github.com/Graylog2/graylog-plugin-enterprise/pull/11072

Description

This change adds a netty channel handler that extracts the original IP from various headers if configured appropriately.
The default settings behave as before, users can enable handling X-Forwarded-For/Forwarded headers, optionally enforcing all proxy IPs to be in the trusted_proxies setting, as well as taking the client's IP from a X-Real-IP (or similar style) header.

When checking against trust_proxies Graylog will also consider the remote address of the HTTP socket to be a proxy and check its address. Some proxies do not include themselves, e.g. traefik does this, so Graylog considers the remote side to be a proxy in this case as well.

Motivation and Context

If Graylog runs behind a load balancer or proxy and the codec or processing doesn't explicitly set the message source, Graylog will use the remote address of the HTTP network connection, which ends up being the proxy's address, not the client's IP.

This change allows overriding the IP, based on standard headers, or de-facto industry conventions.

How Has This Been Tested?

Added unit tests.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

Fixes #22837

kroepke added 5 commits June 12, 2025 17:54
add hashcode/equals to resolvable inet socket address wrapper, comparing them in tests
add RawMessageHandler test
fix subnet trusted proxy code (yay tests)
@kroepke kroepke changed the title wip initial push for forwarded-for and real-ip headers in http inputs Add support for Forwarded-For and Real-IP headers in HTTP inputs Jun 16, 2025
@kroepke kroepke requested a review from a team June 16, 2025 14:14
@kroepke kroepke marked this pull request as ready for review June 16, 2025 14:18
@bernd bernd self-assigned this Jun 19, 2025
Copy link
Member

@bernd bernd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed two issues during testing that need to be addressed before I can continue testing and review.

kroepke added 3 commits June 23, 2025 12:54
…ke it clear

FullHttpMessage objects need to be retained, because they contain the body as well (the reason we switched the type)
guard against invalid ip literals and log a warning in case we cannot parse the ip address
debug log if we don't know any relaying proxy
…roxies don't include themselves in the forwarded-for list
@kroepke kroepke requested a review from bernd June 23, 2025 15:41
Copy link
Member

@bernd bernd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I tested this change with different setting configurations.

@kroepke kroepke merged commit 88a6da5 into master Jun 26, 2025
8 checks passed
@kroepke kroepke deleted the feat/forwarded-for-httpinput branch June 26, 2025 07:31
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

Successfully merging this pull request may close these issues.

Allow Raw HTTP input to understand x-forwarded-for or x-real-ip headers

3 participants