Skip to content

Add ability for sticky sessions to backend resource.#511

Merged
miloschwartz merged 3 commits into
fosrl:devfrom
x86txt:sticky_targets
Apr 22, 2025
Merged

Add ability for sticky sessions to backend resource.#511
miloschwartz merged 3 commits into
fosrl:devfrom
x86txt:sticky_targets

Conversation

@x86txt

@x86txt x86txt commented Apr 11, 2025

Copy link
Copy Markdown
Contributor

Community Contribution License Agreement

By creating this pull request, I grant the project maintainers an unlimited,
perpetual license to use, modify, and redistribute these contributions under any terms they
choose, including both the AGPLv3 and the Fossorial Commercial license terms. I
represent that I have the right to grant this license for all contributed content.

Description

Allow 'sticky sessions' to backend resources. This is required if there are multiple targets and the targets aren't stateless, like the VNC console sessions to Proxmox. This keep the user pinned to a single target for the duration of their session.

image

How to test?

mkdir -p /tmp/server1 && echo "server1" > /tmp/server1/index.html && \
mkdir -p /tmp/server2 && echo "server2" > /tmp/server2/index.html && \
python3 -m http.server 10000 --bind 0.0.0.0 --directory /tmp/server1 && \
python3 -m http.server 20000 --bind 0.0.0.0 --directory /tmp/server2

Add two targets as shown in the screenshot below. Browse to your Resource and hit refresh and notice the webpage rotates from server1 to server 2, etc. Enable Sticky Sessions, hit refresh several more times, and notice that Traefik now keeps your session pinned to a single target.

image

}
}
}
: {})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think we can use the cookie in the raw tcp/udp section because there is not a http cookie to set. Is that right? I think we want hashing here.

https://traefik.io/glossary/what-are-sticky-sessions/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch! 🤜🏻💥🤛🏻

Modified it to create a hash based off source IP + ephemeral port, which should account for multiple devices behind the same NAT. (server would see public IP + ephemeral port and sticky based on the hash of that). Will push a new PR shortly.

@oschwartz10612

Copy link
Copy Markdown
Member

This is awesome thanks for tackling this! Some thoughts on the UI:

I think it might not make sense to lump enabling or disabling SSL in with the advanced options. Not sure how @miloschwartz might feel about that? Maybe it makes more sense to make a new section toward the bottom under the targets called advanced and leave ssl where it was?

I am also thinking it might make sense to hide this option unless they have more than one target? Not committed to this one.

@x86txt

x86txt commented Apr 13, 2025

Copy link
Copy Markdown
Contributor Author

Love the comment about making it appear once a user inputs more than one target. I'm terrible at design though. I'll make it behave that way, stick it somewhere at the bottom, below the targets, which shouldn't be hard to position in a more visually pleasing location/manner.

Comment thread server/routers/traefik/getTraefikConfig.ts

@x86txt x86txt left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added two requested changes, please review.

@oschwartz10612

Copy link
Copy Markdown
Member

Getting to this soon we promise! Thanks for the hard work!

@miloschwartz

Copy link
Copy Markdown
Member

Thank you @x86txt! Sorry this took so long for us to merge.

@miloschwartz miloschwartz merged commit 9ea7c43 into fosrl:dev Apr 22, 2025
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.

3 participants