For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

fanxun_191227's avatar
fanxun_191227
Icon for Nimbostratus rankNimbostratus
Nov 02, 2015

HELP!!!!!!!!!!!, Got Crazy of Session persistence with irule and cookie

scenario . Please Help!!!!!!!!!!

 

{ Virtual server https://xxx.abc.com Pool1 10.0.0.1 80 10.0.0.2 80 }

 

Pool2 { 10.0.0.3 80 10.0.0.4 80 }

 

Like above list, I have a VS with default pool1 and two default pool member. There's an another pool2 with two pool member which running same site. My request is: 1. when request coming with target parameter, such as https://xxx.abc.com/regist.asp?id=321&pid=123 , clients connect to pool2 and session persistence to the pool2 member. 2. If clients request without target id, then goes to default pool and session persistence to the pool1 member.

 

Now I configured cookie insert session persistence for Virtual server and also configured Irule.

 

when HTTP_REQUEST { if { [HTTP::uri] starts_with "xxx.abc.com/regist.asp?id=321&pid=123" } { pool pool2 persist cookie } }

 

Now, session persistence without target ID is no problem. But if request coming with target ID,(https://xxx.abc.com/regist.asp?id=321&pid=123) , BIGIP will send request to pool2 member first, but the url will change after access the Pool2 member, the BigIP will redirect connection to Pool1 and send back to clents.

 

So , How can I bind clients to Pool2 member once it comes with target ID ? Even Url changed, client still will access pool2 member? Am I describe clearly? Thanks so much for any answer!!!!!

 

2 Replies

  • So if I understand this correctly, once a client requests the target ID you want that particular client to always go to the member in pool2, is that correct?

     

    For this I would use the table command and set an entry that specifies that this client should always go to that member in pool2. I'll whip up an example later unless someone else do it before me.

     

  • To answer your question first, no there is no such persistence that will do this out of the box - the idea with persistence is that you should be able to have different persistence entries for different pool members depending of which pool is selected. So in order to do this we must do some custom persistence to make it happen.

     

    Now for the solution. At first I had some quite elaborate code to take care of this but once I started wrapping my head around the solution I realized that it was actually a lot easier than that - all we need to do is to add another cookie once pool2 has been selected and the presence of this cookie should then force the BIG-IP to henceforth send the traffic to pool2.

     

    I also made use of variables to set the pool name, URI and so on, since I suspect that "pool2" isn't the actual name of the pool in your implementation, so this makes it easier for you to change the pool name according to your configuration. So this is what I've got:

     

    when RULE_INIT {
        This variable defines the name of the custom cookie sent to
        the client to keep track of that this user should persist to
        the secondary pool only.
    
       set static::St_Cookie "mycookie"
    
        This variable contains the name of the pool to which the client
        should stick once it has been selected
        *** IMPORTANT ***
        This MUST be the full name, including partition - for example
        "/Common/pool2" - otherwise the iRule will not work as intended
    
       set static::Pool_Name "/Common/pool2"
    
        This is the URI that signifies that the secondary pool should be
        selected. Note that the HTTP::uri command does not include the
        hostname
    
       set static::Select_URI "/regist.asp?id=321&pid=123"
    }
    when HTTP_REQUEST {
       if { [HTTP::cookie exists $static::St_Cookie] }{
           The sticky cookie is here so the secondary pool should be used
          pool $static::Pool_Name
           Clean up the request before sending it to the server
          HTTP::cookie remove $static::St_Cookie
       }
       elseif {[ string tolower [HTTP::uri]] starts_with $static::Select_URI }{
          pool $static::Pool_Name
       }
    
    }
    when HTTP_RESPONSE {
       if { [LB::server pool] eq $static::Pool_Name }{
           Insert the sticky cookie, it has a value of 1, which is not used
           for anything since we're looking for the presence of the cookie
           and not the value
          HTTP::cookie insert name $static::St_Cookie value "1" path "/"
       }
    }