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.
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.
Jeff: 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.
Good 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
“/Dealer/”
“/Help/”
“/Image/”
“/Login/”
“/User/”
I am new to this but is a value required when adding these strings to the group?
The iRule I used is this
when HTTP_REQUEST {
if { ![class match [HTTPS::path] starts_with $::blue] } {
Chris, yes we are terminating the SSL connection on the F5.
I am getting closer. It is definatly reading the iRule but I am not so sure it is triggering the data group and the defaul landing page is in the data group but the page continues to redirect.
landing page: I have this exact string added to the blue data group with no luck, it still redirects.
We ended up opening a support case with F5 and here is the iRule and data group syntax that we had to use.
when HTTP_REQUEST {
log local0. “path is [HTTP::path]”
set search_id [class startsearch blue_ACL]
while { [class anymore blue_ACL $search_id] } {
nextelement returns an array with two elements (for a string class, we just care about the first element)
set elem [class nextelement blue_ACL $search_id]
set elem [lindex $elem 0]
log local0. “elem is $elem”
if { [string tolower [HTTP::path]] matches_regex $elem } {
log local0. “$elem matched !”
return
}
}
HTTP::respond 200 content “PERMISSION DENIED TO: [HTTP::uri]”
}
The trick is that your datagroup (blue_ACL) strings need to be entered using REGEX notation. ( You will need to start each string with a “^” and for the / path (root), you need to enter “^/$”.
^/$ (the $ means “end of string”)
^/Dealer
^/Help
^/Image
^/Login
^/User
You also need to enter all the strings in lower case because of the " tolower" command, if they are upper case they won’t match.
I appreciate everyones help but I just wanted to update the forum with what worked for us.
That 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.
Note, if that doesn’t work for your scenario, try adding logging of the requested URI and then when an “invalid” request is redirected. This should help you identify what’s failing.
I have no way to defince / without giving access to everything after it. I have this working on a test site that I just put up that has a different landing page (http://mycompany.com/en-us and all seems to be working ok.
there is only one string in the SplunkTest data group for /en-us but the site and rule work as expected. Anyone have any ideas how to allow the root?
when HTTP_REQUEST {
if { ![class match [string tolower [HTTP::uri]] starts_with SplunkTest] } {
HTTP::respond 200 content “ErrorPERMISSION DENIED TO: [HTTP::uri]”
Aaron thank you for the correct coding, although the
[HTTP::uri] eq “/”)
is still being blocked. This is the issue we initially were running into, not being able to allow the “/”. Once we get over this hurdle of allowing the root “/” I think we are golden. The datagroup call seems to be working perfectly.
Aaron thank you for the correct coding, although the
[HTTP::uri] eq “/”)
is still being blocked. This is the issue we initially were running into, not being able to allow the “/”. Once we get over this hurdle of allowing the root “/” I think we are golden. The datagroup call seems to be working perfectly.
We are running BIG-IP 10.2.0 Build 1707.0
I seem to have misunderstood your requirements. Here you go:
when HTTP_REQUEST {
if { ![class match [string tolower [HTTP::uri]] starts_with SplunkTest] or [HTTP::uri] ne "/" } {
HTTP::respond 200 content "PERMISSION DENIED TO: [HTTP::uri]"
}
}