URL access based on IP\LDAP

Im new to F5 ASM so I apologize for my ignorance in advance. Is it possible to create an IRule to allow access to a webpage based on IP adresses and\ or LDAP group?

I see this as an example but not sure how to add multiple IP addresses and I dont want a redirect. Any help is appreciated.

when HTTP_REQUEST { if { ([HTTP::uri] starts_with “/admin”) and ([matchclass [IP::remote_addr] equals $$IPAddressDataGroup]) } { HTTP::redirect “https://foo.com/admin/index/index/” } else { HTTP::redirect “https://foo.com/login/index/login/” } }

It’s definitely possible. In that example, you’re using a data group. You can add addresses to a data group from the config utility through Local Traffic Manager > iRules > Data Groups.

Are you trying to limit access to a specific page, or a directory?

Actually I want to limit access via ASM not LTM and only to a web site .

As far as blocking by IP goes, I’ve seen most people do so via LTM iRules…I’ll see whether there’s an option in ASM but don’t recall seeing one. Any reason you’re trying to avoid using LTM?

I don’t think current versions of ASM allow you to restrict access by client IP, subnet or GeoIP region, etc. I’m pretty sure there is at least one request for enhancement related to this type of functionality. You could open a case with F5 Support and have your request added to the existing RFE(s).

In the meantime, you could try a few approaches:

Create an address type datagroup containing the allowed subnets/hosts and use an iRule to check for requests to /admin that aren’t from an allowed IP. Rewrite the URI to something that will always get blocked in the ASM policy like /illegal_client_request_to_admin.exe (assuming you don’t have .exe or wildcard filetypes allowed in your policy).

Use a separate VS which goes to a separate ASM policy that allows /admin URI access (or no policy if you trust the app administrators). Restrict access to the VS using an iRule and the same address type datagroup as you would for option one. Then block all access to /admin on your main ASM policy using an attack signature.

Aaron

Note that I like the second option better as ASM can normalize URI encoding attacks much better than we can with an iRule. This is particularly relevant if the web app is IIS based:

http://devcentral.f5.com/Forums/tabid/1082223/asg/50/showtab/groupforums/aff/5/aft/30900/afv/topic/Default.aspx

Aaron

No its not using IIS…but after thinking about it - why not just use the LTM as you suggested…

I have this so far but have a question: Can I add multiple URL’s to check in this irule e.g. in BOLD I have adstructure/ i want to add other sites that have a login.jsp or login\password locations…

when HTTP_REQUEST { if { ([HTTP::uri] starts_with “/adstructure”) and ([matchclass [IP::remote_addr] equals $$IPAddressDataGroup]) } { HTTP::redirect “XXX.com | XXX Sex Videos & Porn Movies Tube” } else { HTTP::redirect “https://www.xxx.com/” } }

You have a great start!

Yes, you can absolutely check as many URLs as you want. Can you elaborate on everything you’d like to check, and if there’s a match, what you’d like to do with the request?

Sorry for the delay…basically i need to redirect certain externally accessible sites to internal network only. And if you are not part of the IP adress redirect you to home page. This needs to be done at F5 level… So question is how do I add multiple sites to check???

basic URL site check:

when HTTP_REQUEST { if { ([HTTP::uri] starts_with “/adstructure”) and ([matchclass [IP::remote_addr] equals $$IPAddressDataGroup]) } { HTTP::redirect “XXX.com | XXX Sex Videos & Porn Movies Tube” } else { HTTP::redirect “https://www.xxx.com/” } }

my attempt to do multiple site lookups: ( yeah its wrong - i know)

when HTTP_REQUEST { if { ([HTTP::uri] starts_with “/adstructure” or starts_with "/ CiteCode or /jsp/funsite ) and ([matchclass [IP::remote_addr] equals $$IPAddressDataGroup]) } { HTTP::redirect “XXX.com | XXX Sex Videos & Porn Movies Tube” } else { HTTP::redirect “https://www.xxx.com/” } }

You can add multiple URI checks using a switch statement.

http://devcentral.f5.com/wiki/default.aspx/iRules/switch

Also to reference a datagroup from an iRule in 9.4.4+, remove the $:: prefix from the name (or $$ as you have it).

Aaron

I read it and I said “que??”…care to send me what I have posted (example) so I can comprehend please??

This is what I was thinking of for your second scenario of an IP and multiple URI checks:

when CLIENT_ACCEPTED {
    Look up client IP once per TCP connection
   if { [matchclass [IP::client_addr] equals IPAddressDataGroup] }{
      set matched_ip 1
   } else {
      set matched_ip 0
   }
}
when HTTP_REQUEST {
    If we had a match on the client IP, check the requested URI with wildcards
   if {$matched_ip==1}{
      switch -glob [HTTP::uri] {
         "/adstructure*" -
         "/CiteCode*" -
         "/jsp/funsite*" {
             IP and URI check were both true, so redirect client to custom URL
            HTTP::redirect "https://www.xxx.com/adstructure/xxx/login.jsp/index/index/"
             Exit this event in this iRule
            return
         }
      }
   }
    If we haven't exited this event already, send a default redirect
   HTTP::redirect "https://www.xxx.com/"
}

Aaron