How to restrict a url access from a specific two ip's

Hi,

How to retsrict a url access from internet for a specific two ip’s !

whether it can be achieved via LTM policy or via irule?

logic that i have cretaed using irule given below:

when HTTP_REQUEST {

if{[HTTP::path] contains “/abc/update” and [IP::addr [IP::client_addr] equals 104.123.3.1] or [IP::addr [IP::addr [IP::client_addr] equals 117.23.2.1]}

else{

reject

}

Requesting immediate assistence

instead of irules scripting, you can use gui based local traffic policy.
the managebility and performance is better than irules.

https://community.f5.com/t5/technical-articles/to-irule-or-not-to-irule-introduction-to-local-traffic-policies/ta-p/279536

Hi,

thanks for the response

whether it is possible to share the LTM policy for the logic i have raised !

Hello,

I created a policy that restrict url access for the IPs listed above.

If you still wanted to do this with an iRule, you could do something like this:

# Create internal data groups
tmsh create ltm data-group internal DG-IP-WHITELIST type ip records add { 104.123.3.1 117.23.2.1 }
tmsh create ltm data-group internal DG-RESTRICTED-PATHS type string records add { /abc/update } 

# iRule
when HTTP_REQUEST {
    set DEBUG 1
    set DEFAULT_POOL [LB::server pool]
    set HOST [string tolower [HTTP::host]]
    set PATH [HTTP::path]
    set CLIENT_IP [IP::client_addr]

    if { [class match -- $PATH contains DG-RESTRICTED-PATHS] } {
        if { [class match -- $CLIENT_IP equals DG-IP-WHITELIST] } {
            if { $DEBUG } { log local0. "$CLIENT_IP has been granted access to $HOST with path $PATH" }
            pool $DEFAULT_POOL
        }
        else {
            if { $DEBUG } { log local0. "$CLIENT_IP has been refused access to $HOST with path $PATH" }
            reject
        }
    }
}

hi,

what about below irule: whether it will meet the requirement:

when HTTP_REQUEST {

if{[HTTP::path] contains “/abc/update” and [IP::addr [IP::client_addr] equals 104.123.3.1] or [IP::addr [IP::addr [IP::client_addr] equals 117.23.2.1]}

else{

reject

}

Could you confirm whether source IPs 104.123.3.1 and 117.23.2.1 should be *allowed* to access path “/abc/update”. Or should they be denied?

only IPs 104.123.3.1 and 117.23.2.1  can acces to path “/abc/update”. remainng Ip connections from internet towards acess path “/abc/update” should be droped/blocked

Thanks for confirming.

I made a few minor adjustments to fix syntax issues, but this should work:

when HTTP_REQUEST {

if { [HTTP::path] contains "/abc/update" and (([IP::addr [IP::client_addr] equals 104.123.3.1]) or ([IP::addr [IP::client_addr] equals 117.23.2.1])) } {
}
else {
    reject
}
}

i have checked in my application. while i am calling this irule in VS the other url’s pertaining to the application also not loading in the browser

i have checked LTM logs also below error recieving:

tmm[9714]: 01220001:3: TCL error: /Common/UIp_TEST <HTTP_REQUEST> - invalid command name “if{/” while executing “if{[HTTP::path] contains “/uHi/upjateMobShSRrq” and (([IP::addr [IP::client_addr] equals 1XX.250.X0.X]) or ([IP::addr [IP::client_addr] equals 1XX.1XX…”

Try this:

when HTTP_REQUEST {

if { [HTTP::path] contains "/abc/update" and !(([IP::addr [IP::client_addr] equals 104.123.3.1]) or ([IP::addr [IP::client_addr] equals 117.23.2.1])) } {
    reject
}
}
}

the gui is very simple:

i think the ip address inspection is better to be put in CLIENT_ACCEPTED event as it is lighter that HTTP_REQUEST event

Agreed.

when CLIENT_ACCEPTED {
 set CLIENT_IP [IP::client_addr]
}

when HTTP_REQUEST {

if { [HTTP::path] contains "/abc/update" and !(([IP::addr $CLIENT_IP equals 104.123.3.1]) or ([IP::addr $CLIENT_IP equals 117.23.2.1])) } {
    reject
}
}

is this CLIENT_IP is refered as a DataGrroup ?

CLIENT_IP is the variable you set in the beginning of the irule

set CLIENT_IP [IP::client_addr]

Regards

i have tried the irule, but too many errors coming. PFA

Thanks for the screenshot. Please ensure that there is a whitespace between the “CLIENT_ACCEPTED” event and the opening curly brace “{”

when CLIENT_ACCEPTED {