Forum Discussion
jokragly
Nov 03, 2010Nimbostratus
iRule for URI ACL
Good afternoon. We are getting desperate trying to find a solution to allow specific URIs and deny all other traffic.
Basically what we are after is to allow access to 5 specific directories and the things within those directories but if someone tries to go to a URI that is not allowed then they get a denied message from the F5 with the URI path that is denied.
mycompany.com/Login/*
mycompany.com/Dealer/*
mycompany.com/Image/*
mycompany.com/User/*
mycompany.com/Help/*
Should this be done in an iRule? If so how? Is it possible to do this as an http class or data group with match only? I can list the URI Strings in a http class and assign that class to the Virtual Server but an invalid page is response is coming from the web server not the F5 deny because it doesn't match our allowed paths in the http class we created.
Any and all help would be greatly appreciated.
Thanks,
Jeff
- L4L7_53191NimbostratusJeff: This should be a clean and easy problem to solve. I'd go with a datagroup here, as it'll be a bit cleaner to manage as you add/remove URIs. I'm not able to give you examples or links (on a plane, shutting down my laptop!), but do a search or two on URI switching/acls using datagroups and you'll be off to a good start.
- George_Watkins_Historic F5 AccountHi Jeff,
rule mycompany_url_acl { when HTTP_REQUEST { if { ![matchclass [HTTP::path] starts_with $::mycompany_allowed_urls] } { HTTP::redirect http://mycompany.com/sorry_url.html } } }
class mycompany_allowed_urls { { "/Dealer/" "/Help/" "/Image/" "/Login/" "/User/" } }
- George_Watkins_Historic F5 AccountOne note: I used matchclass (http://devcentral.f5.com/Wiki/default.aspx/iRules.matchclass) here, which has been deprecated in favor of the class command (http://devcentral.f5.com/Wiki/default.aspx/iRules.class) in version 10. The equivalent code using the class command would look like this:
when HTTP_REQUEST { if { ![class match [HTTP::path] starts_with $::mycompany_allowed_urls] } { HTTP::redirect http://mycompany.com/sorry_url.html } }
- jokraglyNimbostratusGood morning George, thanks for the reply. I have attempted your solution but it doesn't seem to work. I created a datagroup "blue" with the strings as
- Chris_MillerAltostratusAre you terminating the SSL connection on your F5?
when HTTP_REQUEST { if { ![class match [HTTP::uri] starts_with blue] } { HTTP::redirect "http://www.google.com/" } }
- jokraglyNimbostratusChris, yes we are terminating the SSL connection on the F5.
- George_Watkins_Historic F5 AccountHi jokragly,
- jokraglyNimbostratusWe ended up opening a support case with F5 and here is the iRule and data group syntax that we had to use.
- George_Watkins_Historic F5 AccountGlad to hear you got it working. Thanks for posting your solution.
- hooleylistCirrostratusThat could be horribly inefficient to loop through a datagroup and run a regex operation on each element. I'd go back to George and Chris' examples using a datagroup and the iRule which uses starts_with. Make sure to remove the $:: prefix from the datagroup name in the iRule as that won't work in 10.x.
class mycompany_allowed_urls { { "/dealer/" "/help/" "/image/" "/login/" "/user/" } }
when HTTP_REQUEST { if { ![class match [string tolower [HTTP::uri]] starts_with blue] } { HTTP::redirect "http://www.google.com/" } }
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects