I’ve read a few articles about accomplishing this but nothing that has really suited my needs so far.
At a high level, we have a ‘shared’ vserver that we use for multiple services. We load balance to the appropriate pools using an iRule based on URIs. We’d like to explore the possibility of creating a new iRule that will match on a specific URI (for now - eventually we’ll want to class match to a datagroup) and implement cookie persistence if it matches. Otherwise, just continue to process the other iRules in the stack.
I’d like something similar to the following. This doesn’t work with cookie persistence but DOES work with source address:
when HTTP_REQUEST {
if { ([HTTP::path] contains "/xyz/") } { persist cookie }
}
We get the following error message when applying the iRule to the vserver:
01070372:3: Persistence mode (Cookie) called out in rule (/Common/test_cookie_persistence) requires a corresponding persistence profile for virtual server (/Common/pool_name).
However, a similar iRule using source address persistence doesn’t require an persistence profile on the virtual server:
when HTTP_REQUEST {
if { ([HTTP::path] contains "/xyz/") } { persist source_addr }
}
Can anybody shed some light on why this is? Or point me in the right direction of an example of a working cookie persistence iRule that doesn’t require the need for the persistence profile to be applied? The whole point of the iRule would be to avoid the persistence profile which would then apply to all services using this vserver, so applying one in this case kind of defeats the purpose.
Hm, I tried adding in some of the optional parameters (anything beyond ‘persist cookie’) as mentioned on that page, but still have the same issue.
Note: Items marked with are meant to be replaced with a value. Arguments bracketed by [ ] are used to note they are optional. They should not be confused with Tcl command evaluation.
persist simple [] []
persist source_addr [] []
persist sticky [] []
persist dest_addr [] []
persist ssl []
persist msrdp []
persist cookie [insert [] [] |
rewrite [] [] |
passive [] |
hash [ { []} []] ]
persist uie []
persist hash []
persist carp
persist none
= The timeout in seconds.
So using this still throws the same error:
when HTTP_REQUEST {
if { ([HTTP::path] contains "/xyz/") } { persist cookie insert BIGIP 0 }
}
The persistence profile contains information about the persistence cookie. i.e. is it type Insert/Rewrite/Hash. Does it have a user-defined name? Is it encrypted? When does it expire?
The iRule command tells the BigIP to use cookie persistence… but it needs this extra information to actually do that. (You can pass some of these things via the persist iRule command, but not all.)
Just noticed that same article says ‘Note: The following persistence methods require a corresponding persistence profile be added to the virtual server: ssl, msrdp, cookie.’ Sounds like there’s no way around this then?
Yes, you’ll need a cookie persistence profile in order to use cookie persistence. Note that you can manually apply more than one persist profile to a virtual. (The gui doesn’t let you do this, but it is useful when selecting between types of persistence via an iRule.)
I think I was overcomplicating this by assuming a default cookie persistence profile would take precedence over desired persistence behavior set in an iRule (specifically that the default persistence profile would be applied before parsing through the iRules). Looks like that was incorrect, but please correct me if I’m wrong.
Using a configuration similar to what’s below seems to work. With this, a cookie will only be set if you’re hitting a URI of either /xyz/ or /abc/. Anything else won’t use persistence (note the fallback persistence profile for source_addr shouldn’t be required on the vserver).
Keep in mind this is config from a device on 11.4.1.
I am very new to this but this looks like something that might help me if anyone could assist in clarifying what I would need to do…
I have an exchange server on our LTM running 11.5.3 and it has source address persistence working great for all users with the exception of a GOOD Mobile Messaging server that apparently the vendor says only works properly using cookie persistence.
I don’t want to break Exchange by changing the persistence profile for all users but was wondering if there was a way to look at the source IP of the GOOD (GMM) server and change it to a cookie persistence profile instead. Is this along the same lines as the irule in this thread?
Does this mean I could assign both persistence profiles to the exchange VS and make source address persistence the default but use an irule to associate the GMM IP to a cookie persistence profile instead?
Hi Mike P. I pulled this out of a rule I am using for mobile app VS: when HTTP_REQUEST { set seshuntoken [HTTP::cookie value “SESSION_TOKEN”] if { [IP::addr [IP::client_addr] equals 10.xxx.xxx.xxx/255.255.255.255] } { if { [HTTP::cookie exists “SESSION_TOKEN”] } { if { $seshuntoken != “” } { persist uie [HTTP::cookie “SESSION_TOKEN”] } } } }
I should clarify - this rule is added to a “universal” persistence profile, that is applied to the said VS, which also has a "source_addr " profile as backup.