Skip to content

feat: Add PROXY protocol support for RTMP and RTSP servers#5754

Open
alexmck wants to merge 3 commits into
bluenviron:mainfrom
alexmck:feature/proxy-protocol
Open

feat: Add PROXY protocol support for RTMP and RTSP servers#5754
alexmck wants to merge 3 commits into
bluenviron:mainfrom
alexmck:feature/proxy-protocol

Conversation

@alexmck
Copy link
Copy Markdown

@alexmck alexmck commented May 12, 2026

Summary

Adds support for PROXY protocol v1/v2 for RTMP, RTMPS, RTSP, and RTSPS ingest, allowing the real client IP to be preserved when connections pass through a load balancer or reverse proxy. This feature was first mentioned in #602.

Two new configuration options control this:

  • rtspTrustedProxies list of IPs/CIDRs trusted to send PROXY headers on RTSP connections
  • rtmpTrustedProxies same for RTMP connections

This follows the same format that webrtcTrustedProxies uses.

Connections from trusted proxies have their PROXY protocol header parsed, and the original client IP is used for logging and authentication. Connections from non-trusted IPs ignore any PROXY header and are passed through unchanged.

For RTMPS, the PROXY header is read before TLS negotiation to ensure correct ordering.

Also, when rtspTrustedProxies is configured with RTSPS encryption, the dumpPackets feature will not capture TLS-level traffic for RTSP. I assume the undocumented dumpPackets is for debug only, but wanted to mention it just in case this is intentionally here. I can make a revision here if requested.

This is a non-breaking change. I have also tested this PR in production and I can confirm that it works as expected.

New Dependency

This PR uses the go-proxyproto library. I wanted to make sure it's very clear that this PR introduces a new dependency to the library.

Please let me know if you have any questions.

Support PROXY protocol v1/v2 on RTMP, RTMPS, RTSP, and RTSPS TCP
listeners so real client IPs are visible when running behind L4 proxies
(nginx stream, HAProxy, AWS NLB).

New per-protocol config fields rtmpTrustedProxies and rtspTrustedProxies
follow the existing trustedProxies naming convention. Empty by default.
When set, connections from trusted IPs have their PROXY header parsed if
present, while other connections pass through unchanged. This is a
non-breaking change.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

❌ Patch coverage is 37.73585% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.00%. Comparing base (a384135) to head (32bedce).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
internal/servers/rtsp/server.go 0.00% 16 Missing and 2 partials ⚠️
internal/servers/rtmp/server.go 26.66% 9 Missing and 2 partials ⚠️
internal/packetdumper/listen.go 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5754      +/-   ##
==========================================
- Coverage   63.12%   63.00%   -0.13%     
==========================================
  Files         217      218       +1     
  Lines       18328    18411      +83     
==========================================
+ Hits        11569    11599      +30     
- Misses       5818     5866      +48     
- Partials      941      946       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@aler9 aler9 left a comment

Choose a reason for hiding this comment

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

thanks for providing this long-awaited feature, i left some comments. In particular, we must find a way to make dumpPackets and trustedProxies coexist.

Comment thread internal/servers/rtsp/server.go Outdated
Comment thread internal/servers/rtmp/server.go Outdated
Comment thread internal/protocols/proxyprotocol/listener.go
Comment thread internal/core/core.go
alexmck added 2 commits May 13, 2026 12:53
- Move proxyprotocol package to internal/protocols/proxyprotocol
- Add package comment and fix prealloc lint issue
- Deduplicate v1/v2 tests into table-driven test
- Add rtspTrustedProxies and rtmpTrustedProxies to openapi.yaml
- Fix DumpPackets and TrustedProxies to coexist for RTSP and RTMP
Reorder listener wrapping so proxy protocol is applied before
the packet dumper. This ensures the packetdumper sees connections
with the real client IP and the TLS secret logging works correctly.

Add InnerListen field to packetdumper.Listen to allow injecting
a custom listen function underneath the packet dumper.
@alexmck
Copy link
Copy Markdown
Author

alexmck commented May 13, 2026

Thank you for your review and feedback on this PR. I now have addressed all feedback items and lint issues.

I have made one tradeoff so the PROXY header bytes themselves don't appear in the packet dump, since they're stripped before the packetdumper sees the connection. Adding these headers to the dump would require a change to the packetdumper. I feel this could be achieved in a follow up PR if requested, but I gather the main reason for this feature is inspecting the media stream which this change will still allow.

Please let me know if you have any other feedback or concerns.

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.

2 participants