feat: add load-balance hash-key to pin a session on the inbound user - #3133
Open
jianzhichun wants to merge 1 commit into
Open
feat: add load-balance hash-key to pin a session on the inbound user#3133jianzhichun wants to merge 1 commit into
jianzhichun wants to merge 1 commit into
Conversation
Both hashing strategies derive their key from addresses: consistent-hashing from the destination, sticky-sessions from source plus destination. That assumes one client's traffic to one destination is one unit of work. It is not, for a client whose single unit of work walks several destinations — an entry URL, a redirect to another domain, then that domain's CDN. The hash moves with the host, so the egress IP changes underneath a session the destination is tracking, and any state bound to the first address (a cookie issued to that IP, an authenticated session) is dead on the next request. Source plus destination does not help: such a client is usually one local address, so its concurrent jobs share a key and cannot be told apart, while the destination half still moves the pin. `hash-key: user` keys on the authenticated inbound user instead. It is the one identity the client itself controls and can vary per job, and `IN-USER` rules already match on it, so nothing new is asked of the config format. Routing every such job through an IN-USER rule is not equivalent: that enumerates users statically, and these identities are minted per job. Opt-in and unset by default, so no existing config changes behaviour. An unauthenticated request keeps the strategy's own key rather than collapsing every anonymous request onto one member, and round-robin rejects the option outright rather than silently ignoring stickiness it cannot provide.
Collaborator
|
This feature is quite interesting, but: The name |
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
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.
Problem
Both hashing strategies of a
load-balancegroup derive their key from addresses:consistent-hashingsticky-sessionsThat assumes one client's traffic to one destination is one unit of work.
It is not, for a client whose single unit of work walks several destinations — an entry URL, a redirect to another domain, then that domain's CDN. The hash moves with the host, so the egress IP changes underneath a session the destination is tracking, and any state bound to the first address (a cookie issued to that IP, an authenticated session) is dead on the next request. The group is supposed to be the thing that holds such work on one member, and today it cannot.
sticky-sessionsdoes not solve it either: a client like this is usually one local source address, so its concurrent jobs share a key and cannot be told apart, while the destination half still moves the pin.What this adds
An opt-in
hash-keyoption onload-balancegroups.hash-key: userkeys on the authenticated inbound user instead of on an address:The client varies the proxy-auth username per unit of work, and every request carrying that username lands on the same member for as long as it stays healthy.
The inbound user is the one identity the client itself controls and can vary per job, and
IN-USERrules already match on it, so this asks nothing new of the config format.Routing each job through an
IN-USERrule instead is not equivalent: that enumerates users statically in the config, and these identities are minted per job.Behaviour
hash-keyis absent the code path is unchanged, so no existing config behaves differently.round-robinrejectshash-keyat parse time instead of ignoring it — it hashes nothing, so accepting the option would promise stickiness it cannot provide.Tests
adapter/outboundgroup/loadbalance_test.go, 6 cases, including two that assert the current behaviour is what it is: the default key demonstrably moves across destinations for one user, andsticky-sessionsdemonstrably cannot separate two jobs sharing a source address.Also checked end to end with
mihomo -t:hash-key: userloads on both hashing strategies,hash-key: nonsensefails withunsupported hash-key: nonsense,round-robin+hash-keyfails withround-robin does not hash, and a group without the option still loads.Notes
No new dependency. Documentation lives in
MetaCubeX/Meta-Docs; happy to open the matching docs PR if this direction is acceptable.