Hi im looking for a way to accept traffic with * expression, is it possible?
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] eq "*.example.com*"} {
pool $HTTP_pool
} else {
HTTP::respond 403
}
}
Hi im looking for a way to accept traffic with * expression, is it possible?
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] eq "*.example.com*"} {
pool $HTTP_pool
} else {
HTTP::respond 403
}
}
Hi,
you need to use the relevant string comparison - eq is for numbers. You can use contains, ends_with,starts_with,equals, matches_glob & matches_regex.
So this syntax is right?:
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] contains "mydomain.com"} {
pool $HTTP_pool
} else {
HTTP::respond 403
}
}
So this syntax is right?:
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] contains "mydomain.com"} {
pool $HTTP_pool
} else {
HTTP::respond 403
}
}
yes, looks good to me
Great! Thank you.
Another question, i want to also be able allow traffic by ORIGIN, is it possible? When i say origin i mean the site from where im trying to reach (and i don’t mean referrer)
This example of how i think it should be, not sure this is the right way to do it:
when HTTP_REQUEST {
if { [HTTP::header exists Origin] } {
set origin_host [HTTP::header Origin]
}
}
when HTTP_RESPONSE {
if { [info exists origin_host] } {
if { $origin_host contains "mydomain1.com, mydomain2.com, mydomain3.com" } {
pool $HTTP_pool
} else {
HTTP::respond 403
}
}
}
rather than having multiple entries in your statement you need to use a datagroup and the class match command. Take a look at class and specifically the examples, it’s pretty simple to use and very extensible.
Thank you for your time, however i don’t understand how to fit in in my rule.. maybe someone can help me to write it correctly? Maybe i can do it simpler like this?
when HTTP_REQUEST {
if { [HTTP::header exists Origin] } {
set origin_host [HTTP::header Origin]
}
}
when HTTP_RESPONSE {
if { [info exists origin_host] } {
if { $origin_host contains "mydomain1.com" } {
pool $HTTP_pool
}elsif{
{ $origin_host contains "mydomain2.com" } {
pool $HTTP_pool
}elsif{
{ $origin_host contains "mydomain3.com" } {
pool $HTTP_pool
} else {
HTTP::respond 403
}
}
}
I ended with this script, however its not working, i don’t get any 403 respond nor accept when it spoof the origin, all i get is connection reset, any suggestions?
when HTTP_REQUEST {
if { [HTTP::header exists Origin] } {
set origin_host [HTTP::header Origin]
}
}
when HTTP_RESPONSE {
if { [info exists origin_host] } {
if { $origin_host contains "mydomain1.com" } {
pool $HTTP_pool
} elseif { $origin_host contains "mydomain2.com" } {
pool $HTTP_pool
} elseif { $origin_host contains "mydomain3.com" } {
pool $HTTP_pool
} else {
HTTP::respond 403
}
} else {
HTTP::respond 403
}
}
I think this might work better. You need to set the pool in HTTP_REQUEST event, not in response. Obviously this is globbing so in this case the Origin ends with mydomainX.com.
when RULE_INIT {
set HTTP_pool "poolname"
}
when HTTP_REQUEST {
if { [HTTP::header exists Origin] } {
switch -glob ([string tolower [HTTP::header Origin]]) {
"*mydomain1.com" { pool $HTTP_pool }
"*mydomain2.com" { pool $HTTP_pool }
"*mydomain3.com" { pool $HTTP_pool }
default { HTTP::respond 403 }
}
}
}
Thank you, i will test it now
I get syntax error:
01070151:3: Rule [/Common/Origin] error: /Common/Origin:19: error: [Duplicate event/priority][when HTTP_REQUEST { if { [HTTP::header exists Origin] } {set origin_host [HTTP::header Origin]} }]
i’m able to load it on my lab box OK. Is it part of a larger iRule that already uses the HTTP_REQUEST event? Maybe you can post or send me the whole Origin iRule.
No actully this is the full iRule: Now i dont have syntax error, however its always send “err_connection_reset”
when RULE_INIT {
set HTTP_pool MY_POOL_HTTP
}
when HTTP_REQUEST {
if { [HTTP::header exists Origin] } {
switch -glob ([string tolower [HTTP::header Origin]]) {
"test.com" { pool $HTTP_pool }
"test2.com" { pool $HTTP_pool }
"test3.com" { pool $HTTP_pool }
default { HTTP::respond 403 }
}
}
}
OK, can you run ‘tail -f /var/log/ltm’ and show the output from there relevant to the irule when you test it.
Nothing usefully, the errors related to irule is the last errors i had when the syntax was wrong.
May 28 14:10:53 ams-f501 err mcpd[8729]: 01070151:3: Rule [/Common/Origin] error: /Common/Origin:4: error: [parse error: missing close-brace][{ if { [HTTP::header exists Origin] } { switch -glob ([string tolower [HTTP::header Origin]]) { "*mydomain1.com" { pool $HTTP_pool } "*mydomain2.com" { pool $HTTP_pool } "*mydomain3.com" { pool $HTTP_pool } default { HTTP::respond 403 } } }] /Common/Origin:5: error: [command is not valid in the current scope][if { [HTTP::header exists Origin] } { switch -glob ([string tolower [HTTP::header Origin]]) { "*mydomain1.com" { pool $HTTP_pool } "*mydomain2.com" { pool $HTTP_pool } "*mydomain3.com" { pool $HTTP_pool } default { HTTP::respond 403 } } }]
May 28 14:11:00 ams-f501 err mcpd[8729]: 01070151:3: Rule [/Common/Origin] error: /Common/Origin:4: error: [parse error: missing close-brace][{ if { [HTTP::header exists Origin] } { switch -glob ([string tolower [HTTP::header Origin]]) { "*mydomain1.com" { pool $HTTP_pool } "*mydomain2.com" { pool $HTTP_pool } "*mydomain3.com" { pool $HTTP_pool } default { HTTP::respond 403 } } }] /Common/Origin:5: error: [command is not valid in the current scope][if { [HTTP::header exists Origin] } { switch -glob ([string tolower [HTTP::header Origin]]) { "*mydomain1.com" { pool $HTTP_pool } "*mydomain2.com" { pool $HTTP_pool } "*mydomain3.com" { pool $HTTP_pool } default { HTTP::respond 403 } } }]
May 28 14:18:44 ams-f501 notice mcpd[8729]: 01071682:5: Resuming log processing at this invocation; held 4 messages.
May 28 14:18:44 ams-f501 notice mcpd[8729]: 01071682:5: SNMP_TRAP: Virtual /Common/TESTORIGIN has become unavailable
I see the VS is down - Virtual /Common/TESTORIGIN has become unavailable
Maybe the reset is coming from the backend server, not from the LTM. Can you check whether it’s up and if not then sort it out and try again.
If it’s up and running then it’s worth adding some debugging entries to the iRule to check what it’s doing.
No, this wasn’t the problem. I ended with this one, and it works like a charm, thank you for the support:
when HTTP_REQUEST {
set CORS_DOMAINS_REGEX ".(domain1.com|domain2.com)$"
set HTTP_pool "mypool"
if { [HTTP::header exists Origin] } {
set origin_host [HTTP::header Origin]
if { $origin_host matches_regex $CORS_DOMAINS_REGEX } {
pool $HTTP_pool
} else {
HTTP::respond 403
}
}
else {
pool $HTTP_pool
}
}