tyk
tyk copied to clipboard
[TT-9985] add proxy protocol for http
Ha proxy protocol handling added
Description
- When creating HTTPS listener - create default http listener and upgrade it. Because of flow we need. Usually, flow looks like proxyproto.Listener -> tls.Listener -> net.Listener. Because of it - we have an early tls handshake and fail. Now, we have a middle wrap, like tls.Listener -> proxyproto.Listener -> net.Listener , and it works smooth.
- Create helper functions to prevent repeating code
- Add parameters to setRouter func to create proxy with "useProxyProtocol"
- Add gateway config toggle named EnableProxyProtocolHTTP (HTTP because it toggle all kinds of HTTP traffic)
When i trying to upgrade listener in generateListener func - it throws error like "port is already in use". Because of it - listener upgrading now before HTTP server start.
Related Issue
https://github.com/TykTechnologies/tyk/issues/5463
Motivation and Context
With this feature we can use ha-proxy-protocol in our projects, with easy toggle from config file.
How This Has Been Tested
Tested in our infrastructure using ha-proxy to wrap request with tls, and sending to tyk. Result: we have a new header "x-forwarded-for" with correct IP on the board.
Screenshots (if appropriate)
Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality)
Checklist
- [x] I ensured that the documentation is up to date
- [x] I explained why this PR updates go.mod in detail with reasoning why it's required
- [x] I would like a code coverage CI quality gate exception and have explained why