We have a forwarding ip vserver that currently has an irule that references a data group to check if the client ip exists in the data group, if it does it forwards the traffic to the server else it drops. This ensures users can’t bypass the f5 and access the server(s) directly unless your an admin.
I now need to edit this irule to allow any client to access these servers only on ports 50,000 to 59,999 ports.
Is it possible to have the irule allow admins to access these servers if they are in the data group but drop other clients and allow all clients only on ports 50,000 to 59,999
You could follow the idea laid out in the wiki entry. There’s also SOL6018 which talks about port range checking in iRules.
when CLIENT_ACCEPTED {
Check the data group
if { ! ([class match [IP::client_addr] equals NETWORK_DATAGROUP_NAME] && ([TCP::local_port] >= 50000) && ([TCP::local_port] <= 59999)) } {
Not valid client
drop
}
}
I have tried the irule below and the port range doesn’t work. Any idea’s?
when CLIENT_ACCEPTED { Check if client IP is not defined in the allowed_clients datagroup if { not ([class match [IP::client_addr] equals Admin_Data_Group]) } { Client not in allowed IP list, one more check to see whether destination TCP port is in the range of 50000 to 59999 inclusive if { [TCP::remote_port] >= 80 or [TCP::remote_port] <= 443 } { Drop further packets from the client drop } } }
Codewhen CLIENT_ACCEPTED {
Check if client IP is not defined in the allowed_clients datagroup
if { not ([class match [IP::client_addr] equals Admin_Data_Group]) } {
Client not in allowed IP list, one more check to see whether destination TCP port is in the range of 50000 to 59999 inclusive
if { [TCP::remote_port] >= 80 or [TCP::remote_port] <= 443 } {
Drop further packets from the client
drop
}
}
}
Try adding some logging to see what happens and look in the LTM logs to verify things are coming in as expected. And you’re trying to drop all connections with IPs in the data group and ports 80-443 (inclusive)?
when CLIENT_ACCEPTED {
Check if client IP is not defined in the allowed_clients datagroup
log local0. "IP address: [IP::client_addr]"
if { not ([class match [IP::client_addr] equals Admin_Data_Group]) } {
Client not in allowed IP list, one more check to see whether destination TCP port is in the range of 50000 to 59999 inclusive
log local0. " Port: [TCP::remote_port]"
if { [TCP::remote_port] >= 80 or [TCP::remote_port] <= 443 } {
Drop further packets from the client
drop
}
}
I’m trying to allow anyone in the admin data group (any port for admin access) and also allow any source address but only on 50,000 to 59,999 port range.
this is the error I get when applying this irule
01070151:3: Rule [/Common/Infoblox_Management] error: /Common/Infoblox_Management:1: error: [parse error: missing close-brace][{
Check if client IP is not defined in the allowed_clients datagroup
log local0. “IP address: [IP::client_addr]” if { not ([class match [IP::client_addr] equals Infoblox_Management]) } {
Client not in allowed IP list, one more check to see whether destination TCP port is in the range of 50000 to 59999 inclusive
log local0. " Port: [TCP::remote_port]" if { [TCP::remote_port] >= 80 or [TCP::remote_port] <= 443 } {
Drop further packets from the client
drop } }] /Common/Infoblox_Management:3: error: [command is not valid in the current scope][log local0. “IP address: [IP::client_addr]”] /Common/Infoblox_Management:3: error: [command is not valid in the current scope][IP::client_addr] /Common/Infoblox_Management:4: error: [command is not valid in the current scope][if { not ([class match [IP::client_addr] equals I
how bout try this and see what you get in the logs
when CLIENT_ACCEPTED {
Check if client IP is not defined in the allowed_clients datagroup
log local0. "IP address: [IP::client_addr]"
if { [class match [IP::client_addr] equals Admin_Data_Group] } {
Client in allowed IP list, so no more checks. ALLOW ACCESS
log local0. " ALLOWED by IP address"
return
}
log local0. "Source Port: [TCP::remote_port]"
if { [TCP::remote_port] >= 50000 && [TCP::remote_port] <= 59999 } {
log local0. " IP in ALLOW range"
return
}
Drop any connections that don't fit the previous criteria
log local0. "IP and Port checks failed. DROPPING connection"
drop
}
that works. I checked the logs and the f5 is dropping my connection. My ip address is in the data group which should be allowed on any port.
ok i found part of the problem. The irule is checking to make sure my ip is not in the data group. I need to make sure it checks that my ip is in the data group. I removed my ip from the data group and i can access the box now. almost there.
Couple things then. 1. What type of data group are you using? Did you create it as an “address” group? 2. What are the entries you have in your data group and what’s your ip that’s coming through (in the log)
ah. good catch. I updated my most recent code block with the right code. You just need to take out the NOT in the if statement for the ip.
yep I removed not and I can connect to the end device through the f5. You can see below I removed the not. I also changed the port range from 22 to 23 for testing. I can have another machine not in the admin group try to ssh to the vserver address but doesn’t get anything.
when CLIENT_ACCEPTED {
Check if client IP is not defined in the allowed_clients datagroup
log local0. "IP address: [IP::client_addr]"
if { ([class match [IP::client_addr] equals Infoblox_Management]) } {
Client in allowed IP list, so no more checks. ALLOW ACCESS
log local0. " ALLOWED by IP address"
return
}
log local0. "Source Port: [TCP::remote_port]"
if { [TCP::client_port] >= 22 && [TCP::client_port] <= 23 } {
log local0. " IP in ALLOW range"
return
}
Drop any connections that don't fit the previous criteria
log local0. "IP and Port checks failed. DROPPING connection"
drop
}
the logs on the f5 for the client trying to ssh is Rule /Common/Infoblox_Management : IP address: x.x.x.x
client gets connection reset.
I notice you are using TCP::client_port instead of TCP::remote_port… That may have something to do with it.
i changed that to remote port. I now see in the logs why it is rejecting the other client Tue Jan 20 09:24:56 CST 2015infoF5TESTtmm[12495] Rule /Common/Infoblox_Management : IP address: x.x.x.x Tue Jan 20 09:24:56 CST 2015infoF5TESTtmm[12495] Rule /Common/Infoblox_Management : Source Port: 50454 Tue Jan 20 09:24:56 CST 2015infoF5TESTtmm[12495] Rule /Common/Infoblox_Management : IP and Port checks failed. DROPPING connection
is it looking at the source port and not destination port?
You can check out the TCP wiki page for TCP to see what the different options are (TCP).
I got it to work. I will move into prod soon and verify it works. thanks for all your help.
Good deal. Don’t forget to mark one of the answers as the solution if it seems like the best solution.