To start off, I’d like to mention that I am pretty new at this F5 business (been reading on it for about 2wks).
I am trying to find the best way to filter a list of URLs. Below is the current iRule that we are using, but as you can imagine as the need for additional URLs to be added to the iRule arises, it will be harder to keep track of them. So as a different solution, I would like to be able to insert a new URL into a list instead of having to create an “elseif” statement everytime.
Any help will be greatly appreciated
when HTTP_REQUEST {
where member is the parameter name
set member_param_1 “/mailSchedulingServices/mailSchedulingService.svc”
set member_param_2 “/cardPayMatrixSvc/cardPayMatrixSvc.svc”
set response_data “Unauthorized request”
if {[string match $member_param_1 [HTTP::path]]}{
Do nothing
}
elseif {[string match $member_param_2 [HTTP::path]]} {
Welcome to the forums. If you want to create a whitelist of allowed URIs, you could add them to a string datagroup (in the GUI under Local Traffic >> iRules >> Datagroup tab >> Create. You could then use the class command to look up the current path against the datagroup. If the requested path isn’t in the datagroup, you could send a 200 response with content.
Here is the datagroup as it would appear in the bigip.conf:
class whitelist_paths_class {
{
"/cardPayMatrixSvc/cardPayMatrixSvc.svc"
"/mailSchedulingServices/mailSchedulingService.svc"
}
}
And here is an example iRule to do the lookup:
when RULE_INIT {
set static::block_html {Access denied!}
}
when HTTP_REQUEST {
if { not [class match [HTTP::path] equals whitelist_paths_class]}{
HTTP::respond 200 content $static::block_html
}
}
The reason I ask is because I was given this assignment as a “good starting point” to understand iRules. The person that assigned this task to me asked me to see if there is a way to do it using the “array” syntax.
matchclass looks up to see if the HTTP::path value exactly matches any entry in the datagroup named “whitelist_paths_class”. Then not negates that. So if the requested path isn’t in the datagroup, a 200 response is sent back to the client with the HTML content.
You can get more info on the matchclass wiki page:
I edited your suggestion and rewrote it like this so that I don’t use Run_init …when i use this it looks like i am no longer to connect to that URL through the browser
when HTTP_REQUEST {
set response_data “Unauthorized request”
if { not [matchclass [HTTP::path] equals Dev_URL_List]}{
I copied it just like you have it and I get a message on the browser saying “Internet Explorer cannot display webpage”
So I have a Data Group titled “Dev_URL_List” with a list of URLs in it. Then I have the following iRule and I am not able to connect to that site anymore
when HTTP_REQUEST {
set response_data “Unauthorized request”
if { not [matchclass [HTTP::path] equals Dev_URL_List]} {
If you get a page cannot be displayed error in the GUI it generally indicates the client has received a TCP reset. Can you check /var/log/ltm to see if there is a runtime TCL error from the iRule? If it’s something about the class not being found, can you post the following:
TCL error: Rule junk HTTP_REQUEST - Invalid matchclass operands - no class or list type found, lhs: string, rhs: Dev_URL_List line 2 invoked from within matchclass [HTTP::path] equals Dev_URL_List