I require universal persistence based upon a XFF header value, but for any source IP. The scenario is that an initial client connection hits the F5 and is load balanced to node A (the F5 need to persist to a member in poolA using XFF value received or inserted). Then a back end server makes a connection to the F5 and sends the XFF value that was originally received from the client, targets the same VS but a different poolB. This connection must persist to the same node A as in the separate connection from the client. Is this possible using persist lookup functions?
So there will be 1 VIP (using proxypass for selecting the target pool). There will be 2 or more pools with the same members to different ports.
Client connection is sent to poolA nodeA (XFF value is used to persist to nodeA). A separate connection from a server needs to be sent to the same nodeA but in poolB, using the XFF header value for persistence.
this setup will be somewhat complicated then and requires other/additional coding techniques than using
[persist]
to team the instances.
What is the reason to forward the backend connection to your F5 if the DST_IP is always the orginating SRC_IP? It would be much easier if the service on 1.2.3.4:994 will always directly connect to 1.2.3.4:499 (aka. 127.0.0.1:499) and the service on 1.2.3.5:994 will always request to 1.2.3.5:499 (aka. 127.0.0.1:499 too)…
Beside of that, it would be good to know how your iRule/LTM Policy configuration selects the different backend pools based on the incomming HTTP requests?
take a look to the iRule below and tell me what you think?
The iRule uses the
CLIENT_ACCEPTED
event to differentiate between client and backend connections. If a backend connection is identified, then it will be checked during the
LB_SELECTED
event if
[LB::server addr]
(currently selected pool member) equals the
[IP::client_addr]
(backend IP address). If the IPs are matching no action is taken. But if the IPs are different the
[IP::client_addr]
will be used as new
[LB::server addr]
by executing the
[pool]
command a second time.
when CLIENT_ACCEPTED {
if { ( [IP::client_addr] starts_with "1.2.3.4" )
or ( [IP::client_addr] starts_with "1.2.3.5" ) } then {
set backend_connection 1
} else {
set backend_connection 0
}
}
when LB_SELECTED {
if { $backend_connection } then {
if { [LB::server addr] equals [IP::client_addr] } then {
The selected node is already correct...
} else {
pool [LB::server pool] member [IP::client_addr] [LB::server port]
}
} else {
Use LB decissions / persistence records for client connections.
}
}
Note: The iRule can be combined with any persistence profile / LB algorythm you wish. The backend connection will be overwritten on demand without affecting client connections.
Warning: Didn’t tested nor saved the iRule at all. So better apply this iRule on a test-system…
“What is the reason to forward the backend connection to your F5 if the DST_IP is always the orginating SRC_IP?”
This is not the case, the only requirements are that the target pool member both be the same for the two separate connections from the client and the server. At present this is how the application has to work, but of course standard load balancing must distribute load.
I am now looking at adding a new header to the clients initial request to the server (containing the target node IP), then when the server request arrives with this header value use it to target the required node, but I would prefer to use universal persistence (persist lookup perhaps) if possible.
This is not the case, the only requirements are that the target pool member both be the same for the two separate connections from the client and the server. At present this is how the application has to work, but of course standard load balancing must distribute load.
This means in effectively, that if a client connects initially to NodeA (via Random selection), the NodeA will then always connect its backend connection to itself. Thats why I’m asking if this connection really needs to pass your F5 and I’ve proposed a solution (see at the very buttom of this page) which doesn’t require any
[persist]
commands at all to team the backend connections.
I am now looking at adding a new header to the clients initial request to the server (containing the target node IP), then when the server request arrives with this header value use it to target the required node, but I would prefer to use universal persistence (persist lookup perhaps) if possible.
Okay… will write you an
[persist]
iRule with
Match Across Service
options. Should take only a few minutes so stay tuned…
event to differentiate between client and backend connections. If a backend connection is identified, the submitted
X-Forwarded-For
header value (if exist) will be used to query and build the
[persist]
information. If the backend server does not send a
X-Forwarded-For
header the
[IP::client_addr]
of the backend system will be used to query and build the
[persist]
information. If a client connection is identified, the existing
X-Forwarded-For
headers will become sanitized (may contain untrusted information) and a new
X-Forwarded-For
header will be inserted based on the
[IP::client_addr]
. The client system will also use its
[IP::client_addr]
to to query and build the
[persist]
information.
when RULE_INIT {
set static::xff_persist_timeout 900 ; persist information timeout in seconds
}
when CLIENT_ACCEPTED {
if { ( [IP::client_addr] starts_with "1.2.3.4" )
or ( [IP::client_addr] starts_with "1.2.3.5" ) } then {
set trusted_xff_sender 1
} else {
set trusted_xff_sender 0
}
}
when HTTP_REQUEST {
if { $trusted_xff_sender } then {
if { [HTTP::header value "X-Forwarded-For"] ne "" } then {
persist uie [HTTP::header value "X-Forwarded-For"] $static::xff_persist_timeout
} else {
HTTP::header insert "X-Forwarded-For" [IP::client_addr]
persist uie [IP::client_addr] $static::xff_persist_timeout
}
} else {
HTTP::header remove "X-Forwarded-For"
HTTP::header insert "X-Forwarded-For" [IP::client_addr]
persist uie [IP::client_addr] $static::xff_persist_timeout
}
}
Note: To make this iRule work you have to make sure that your HTTP-Profile does not insertheaders. The insert will be done selectively by the provided iRule. In addition to that, you need to create a custom “Universal Persistence” profile, with theoption selected (see config snippet below). This profile needs to be attached to your Virtual Server.
Match across services will not work as the client is not the same and therefore the target pool member selection and resultant persistence entry will be completely independent.
I get your point about the server connecting effectively to itself, but I am told by the app team that there are various reasons why they need to reconnect back through the F5 one of which is the other intelligence the F5 provides through the proxypass configuration.
What I really need is this.
Client makes a connection to the F5, the F5 sets a persistence record to a pool member based upon XFF or another header I insert (maybe containing the selected pool member). Then when the server makes it’s connection the F5 will see either the preserved XFF value (or the headre value for the selected pool member in the first connection) and will target the same IP.
I would prefer to use persistence records and lookups if possible as it makes it much easier to support an understand what is happening as the logic will be that the persistence table entry for a client informs the F5 where to send server connections for the same use session.
Match across services will not work as the client is not the same and therefore the target pool member selection and resultant persistence entry will be completely independent.
The
[persist uie]
method isn’t aware of the client. It will create/query persistence information based on a free-text values which would in your case either the
[IP::client_addr]
-string value if a client connects, or the
X-Forwarded-For=[IP::client_addr]
-string value if the backend system connects. This approach WILL team the connections accordingly even if the underlying connection is comming from different SRC_IPs.
The
Match across services
option is mandatory in your specific case and allows LTM to resolve persistence entries in a X.X.X.X:any style, so that an existing persistence record for poolA:1.2.3.4:994 can be reused to persist request to poolB:1.2.3.4:499.
If you’ve doubts, then build a lab environment, apply the
[persist uie]
iRule at the buttom of this thread and check if the persist information for 1.2.3.4:994 (entry will be shown in the persist table) will be reused for acces to 1.2.3.4:499 (no additional entry will be shown in the persist table). In addition perform failovers as needed and notice that (for an example) a connection to poolA:1.2.3.4:994 will create a persist entry for poolA:1.2.3.4:994 and that this entry will become overwritten (via Force Offlines of poolB:1.2.3.4:499) to poolB:1.2.3.5:499 and which will cause the initial connection to poolA:1.2.3.4:994 to automatically fail over to poolA:1.2.3.5:994.
Client makes a connection to the F5, the F5 sets a persistence record to a pool member based upon XFF or another header I insert (maybe containing the selected pool member). Then when the server makes it’s connection the F5 will see either the preserved XFF value (or the headre value for the selected pool member in the first connection) and will target the same IP.
See the
[persist uie]
iRule at the buttom of this thread. It does exactly what you’ve asked for…