-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Support TCP middlewares #12264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
david-garcia-garcia
wants to merge
15
commits into
traefik:master
Choose a base branch
from
david-garcia-garcia:tcp-middlewares
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Support TCP middlewares #12264
david-garcia-garcia
wants to merge
15
commits into
traefik:master
from
david-garcia-garcia:tcp-middlewares
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
|
Hello @david-garcia-garcia, Thank you for your contribution. We've set the status to "design-review" to allow us to check the PR and ensure there is no deep impact on Traefik before moving forward. |
|
👀 This would be excellent! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #12263
Enables plugins to support TCP middlewares by implementing an optional
NewTCP()function. Plugins can now work with both HTTP and TCP protocols using the same configuration and discovery system.The Serve() implementation for TCP plugins is also changed (not breaking because this is not public) to pass a Context, this change needs to be done before TCP middlewares go public because it would be impossible to introduce later without a breaking change. The middleware support implementatoin would have been so much simpler without this. Adding a context makes sense because it:
Motivation
Traefik currently has only 2 built-in TCP middlewares (
InFlightConnandIPAllowList), while the plugin system only supported HTTP. This prevented the community from building custom TCP solutions for rate limiting, geo-blocking, connection filtering, and security enhancements.The solution: Add a single function to your plugin, and it automatically becomes TCP-compatible, sort of.... if you are not using HTTP request specific stuff adding TPC support to existing plugins should be very easy.
Quick Example
Add one function to your plugin:
Use it in TCP routers:
Same config format and same discovery system.
Note
NewTCP() and ServeTCP() needed to use stdlib types that's why the signatures are messy and differ from the plugins that come bundled with traefik. I could not come up with a solution that would allow us to use the Traefik custom types that did not involve having Yaegi interpret all dependencies with the plugin again, including Traefik itself and transient dependencies. It might be possible to create a new stand alone library to centralize tcpHandler and closeWriter abstractions, and use both them both from the middleware and from traefik.
More