Forum Discussion
SalishSeaSecurity
Altostratus
Jan 12, 2010Specifying node kills cookie persistence
I have a virtural server with a pool of four web servers. Load balancing is by least connection; oneconnect with a mask of 0.0.0.0 is enabled; persistence is by cookie insert (custom profile with non-standard cookie name). The web admins have asked for the ability to select a specific web server manually. There's plenty of code samples posted here to accomplish that, and below is what I put together (some lines of excised for readibility)
when HTTP_REQUEST {
if { [ findstr [string tolower [HTTP::query]] "node=" 5 2 ] != "" } {
log local0. "Found [ findstr [string tolower [HTTP::query]] "node=" 0 7 ]"
need to remove any stale cookies to prevent web server confusion
if {[HTTP::cookie exists "runId"]} {
HTTP::cookie remove "runId"
}
......
switch [ findstr [string tolower [HTTP::query]] "node=" 5 2] {
01 { set nodeTo 192.168.100.2 }
02 { set nodeTo 192.168.100.5 }
03 { set nodeTo 192.168.100.8 }
04 { set nodeTo 192.168.100.11 }
}
remove the ?query from the URI to prevent web server confusion
HTTP::path "/"
node $nodeTo 80
log local0. "Setting pool member node to $nodeTo"
}
}
Naturally I'm looking for a URL that looks like: http://www.mywebsite.com/?node=02
This works: the initial connection is sent to the appropriate server. But it also creates another problem: the cookie is not inserted into the initial HTTP response. If I comment out the line "node $nodeTo 80", then the cookie will be inserted into the initial HTTP response. So why would specifying the node impact the cookie insertion? Manually specifying persistence after the node selection ( persist cookie insert "mycookiename") has no effect.
Am I missing some other code or configuration?
- hoolio
Cirrostratus
I think use of the node command prevents persistence from being used as there isn't a pool to associate the persistence record with. Can you try using the pool command instead of node: - SalishSeaSecurity
Altostratus
I started with that. Then I remembered this doc: - hoolio
Cirrostratus
I don't think that using the node command would assume any pool info as the node command could be used to specify an arbitrary destination IP:port.when HTTP_REQUEST { if {[HTTP::uri] starts_with "/node1"}{ log local0. "selecting pool test_www_http_pool member 10.41.0.22 80" pool test_www_http_pool member 10.41.0.22 80 persist cookie insert persist_cookie } } when LB_SELECTED { log local0. "[IP::client_addr]:[TCP::client_port]: Pool info: [LB::server]" } when SERVER_CONNECTED { log local0. "[IP::client_addr]:[TCP::client_port]: Server info: [IP::server_addr]:[TCP::server_port]" } when HTTP_RESPONSE { foreach a_cookie [HTTP::cookie names] { log local0. "$a_cookie: [HTTP::cookie value $a_cookie]" } }
- SalishSeaSecurity
Altostratus
Aaron, - hoolio
Cirrostratus
If you don't get a conclusive response here, you might try opening a support case. - hoolio
Cirrostratus
Actually, I found an old post from UnRuley and Joe where they provided a sample iRule to encode an IP:port in the persistence cookie format:From: http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&tpage=1&view=topic&postid=9756 Generate a persistence cookie for a sample IP:port when HTTP_RESPONSE { set addr_port "10.10.10.10:80" scan $addr_port "%u.%u.%u.%u:%u" a b c d e set cookie "[format %u [expr ($d<<24)|($c<<16)|($b<<8)|$a]].[expr 256*$e].0000" HTTP::cookie insert name "BIGipServerFP_pool" value $cookie path "/" }
- SalishSeaSecurity
Altostratus
Aaron, - hoolio
Cirrostratus
Hi Jason,
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects