Cookie persistence and source address fallback

I wonder what will be result of such setup:

  • LB set to Round Robin
  • Default Persistence Profile: Cookie (Cookie Insert)
  • Fallback Persistence Profile: Source Address
  • Source IP same for all requests (SNATed)

My assumption is:

  • First new TCP connection established, no cookie present
  • Fallback Persistence used, no Persistence Record (PR) found
  • No persistence is applied because none exist so connection will be directed to first member
  • What will happen then? Persistence Record for source IP will be created pointing to first server?
  • In HTTP response cookie is inserted pointing to first pool member
  • Then second connection from the same IP comes, assuming that PR was created and did not time out then LB will be ignored and connection will be directed to first server
  • In HTTP response again cookie pointing to first server will be inserted
  • Then all returning connections (with cookies set) will be directed to first server, LB in fact will not be used, except for situation when there is enough period of inactivity between connections to allow PR to expire, but will then new connection be send to second server according to RR or not necessarily?

Is above correct?

Piotr

You are correct when putting Cookie and Source Persist together. If there is a persist record it will go to that server and cluster all the clients that share the same IP to the same server.

Thanks, good to have confirmation from experienced F5’ers Piotr

Piotr, If the clients have a persistence cookie then the source address records will not be used. LTM will attempt to match clients with no cookie with a source address persistence record and then insert a cookie into the response. Note that the source addr persistence record will be created using the client-side source address not the server-side snat source addr.

Yes…Because Persistence table check first before doing the SNAT on egress interface

Tell me please, with the same settings. 
The BIGipServer_keycloak cookie is created. When i am using different use profiles (firefox) i have the same cookie for all of them. Can i somehow get the situation, that each session from different browser/profile (and also private session) will have different cookie assigned?

Also, what i could do is to set up persistance options with cmd line, it was not saving settings from gui.
I used this command to check what are the settings :

tmsh show running-config ltm virtual vs_https

and this command to set it ip like on the screenshots:

tmsh modify ltm virtual vs_https persist replace-all-with {     Keycloak_cookies { default yes }     keycloak_pers_sourceaddr { default no } }

The result now is like this:

persist {
        Keycloak_cookies {
            default yes
        }
        keycloak_pers_sourceaddr {
            default no
        }
    }

but before it was like this:

persist {
        Keycloak_cookies {
            default yes
        }
        }

Is this normal behaviour? I understand this is correct? now in GUI it looks like this:

You have added two different persistence profiles to the virtual server, “Keycloak_cookies” and “keycloak_pers_sourceaddr”. Since “Keycloak_cookies” is set as the default persistence profile (default yes), then this will always be used. “keycloak_pers_sourceaddr” which is set to “default no” will never be used unless you call it using an iRule. Is this the behaviour that you wanted?

If not, then your intention may have instead been to have cookie persistence as the primary persistence method and source IP persistence as the fallback persistence. This would be configured like so:

tmsh modify ltm virtual vs_https persist replace-all-with { Keycloak_cookies { default yes } } fallback-persistence keycloak_pers_sourceaddr

When using different browsers you will have the same cookie name of “BIGipServer_keycloak”, but the cookie values themselves should be different. Is this not the case?

Edited. Cookie values can be the same.

and this is ok? It looks like only persistance profile is used and fallback not exists:

persist {
        Keycloak_cookies {
            default yes
        }
    }

My values are not different, they are the same. And i think, they should be different. (i am using different firefox user profiles).

The output you shared shows that only cookie persistence will be used. You are correct, fallback persistence is not configured.

The cookie values should be different  between Firefox user profiles as each user profile maintains its own set of cookies.

Edited. Cookie values can be the same.

I used Your command You provided. And the result of “tmsh show running-config ltm virtual vs_https” shows that.

OK so what is wrong here? How can i check where is the problem and fix the issue?

In the command output there should be a line before the “persist” configuration that you previously showed which states “fallback-persistence keycloak_pers_sourceaddr”.

Could you confirm that it’s there?

Apologies, I take back what I said. It’s perfectly normal to have the same cookie value between different browsers. If you were to decrypt and / or decode the cookie value, you would see that it just reveals the back-end pool member’s IP address (which is how the BIG-IP knows which pool member to send the request to).

So, there’s nothing wrong. Nothing to fix.

So how could i manage the situation, that on the same PC two different users need to use app, which needs their passwords. The cookie is used with keycloak to auth a person. I want 2 different users to have possibility to log in on their accounts (so they need two different cookies). ?

Yes i pasted it to other post by mistake, It is all ok.

I think you’re referring to a separate application cookie created by the back-end pool member rather than the persistence cookie created by the F5 BIG-IP. These are different things.

In the scenario describe, I would expect the client to receive two different cookies:

  1. An application cookie which is created by the back-end pool member application and sent to the client upon successful login (e.g. named “login_cookie”). The value of this cookie should be different between users in order to distinguish between them
  2. A load balancer cookie which is created by the F5 BIG-IP and is sent to the client upon the first HTTP response. This cookie contains no user information and is solely used by the BIG-IP so that it can forward subsequent HTTP(S) requests to the same back-end pool member. The decoded value of this cookie just contains the IP address of the back-end pool member.