Forum Discussion
iRule load balance based on HTTP header username
I'm trying to modify an existing iRule below by creating a logic where it will parse the username being used, and load balance based on the username, while still using the HTTP::uri command. I know the below configuration does not work. The GUI throws an error when trying to execute this config. However, the logic goes something like the example config below. Can someone please advise if this is the best and easiest way to do this? What are my options and proper way to handle this? So usernames 1 - 3 would be sent to pool pool1, and everyone else, gets sent to the default pool assigned to the VIP.
when HTTP_REQUEST { if { [HTTP::uri] equals "/" } { HTTP::uri /login/ pool default }
elseif { [HTTP::uri] equals "/" and [HTTP::username] contains "username1" or "username2" or "username3" } { HTTP::uri /3dspace/ pool pool1 } }
8 Replies
- Yann_Desmarest_
Nacreous
when HTTP_REQUEST { if { [HTTP::uri] equals "/" } { HTTP::uri /login/ pool default } elseif { [HTTP::uri] equals "/" and [HTTP::username] contains "username1" or [HTTP::username] contains "username2" or [HTTP::username] contains "username3" } { HTTP::uri /3dspace/ pool pool1 } }- meenny_60187
Nimbostratus
Thanks for the response Yann, but it doesn't look like this iRule works. It is not load balancing username1 to pool1. The initial HTTP request will send me to pool default, which shows me a login page of the application, which is fine. However, when I log in with my credentials (i.e. username1), either the LTM does not see anything in the HTTP::username, or I'm not parsing the username string correctly. I'm not sure what is missing here. Any help would be appreciated. - Yann_Desmarest_
Nacreous
If I understand correctly, your authentication process is a web login page. The HTTP::username command get the username from the Basic Authorization header so this irule can't work for you. You have to parse the POST body of the login url to get the username. You can use the command HTTP::payload and HTTP::collect to retrieve the username. - Derek_Qiao_1388Historic F5 AccountThere is an example in https://devcentral.f5.com/codeshare?sid=652 for how to handle HTTP username.
when HTTP_REQUEST { if { [HTTP::uri] equals "/" } { HTTP::uri /login/ pool default } elseif { [HTTP::uri] equals "/" and [HTTP::username] contains "username1" or [HTTP::username] contains "username2" or [HTTP::username] contains "username3" } { HTTP::uri /3dspace/ pool pool1 } }- meenny_60187
Nimbostratus
Thanks for the response Yann, but it doesn't look like this iRule works. It is not load balancing username1 to pool1. The initial HTTP request will send me to pool default, which shows me a login page of the application, which is fine. However, when I log in with my credentials (i.e. username1), either the LTM does not see anything in the HTTP::username, or I'm not parsing the username string correctly. I'm not sure what is missing here. Any help would be appreciated. - If I understand correctly, your authentication process is a web login page. The HTTP::username command get the username from the Basic Authorization header so this irule can't work for you. You have to parse the POST body of the login url to get the username. You can use the command HTTP::payload and HTTP::collect to retrieve the username.
- Derek_Qiao_1388Historic F5 AccountThere is an example in https://devcentral.f5.com/codeshare?sid=652 for how to handle HTTP username.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com