iRule to access database

Is it possible to create an iRule that do something like getting a http header value and checking it against a database? We used to do this using Reactivity. Now we are trying to see if BigIP can do the same thing. I did a bit research and didn’t find much.

Thank you for advice!

iRules have Data Groups -- internal lists that you can look up values in. If you are talking about an external database like MySQL or the like, you can’t query real-time but you could hack up a method of loading database values into a data group automatically. Picture this -- set up a cron job to request a web page through the BIG-IP every so often. That web page has a list of the database values. An iRule parses that page and stores it in a Data Group for later use by the iRules in real-time.

What we want to do is actually authentication against databases. If as another member suggested, we cache values in iRule data group, do you have idea how big cache BigIP can support?

I know there is a limit to the size of a data group I’m just not sure what it is. But you could consider purchasing the Advanced Client Authentication Module for your BIG-IP which is made to do authentication. It can’t talk to a database directly but it can do LDAP, RADIUS, etc.

Thank you for your suggestion! I will do some research on that to see if it is an option. I would like to figure out what the cache limit is.

And I just thought I should clarify a misstatement made earlier in this thread: There really isn’t any way currently for an iRule to update a data group -- you’d have to use an internal array for that, and they are not mirrored across a redundant pair, so you’d have to account for that in your iRule initiation logic.

HTH

/deb

Just want to get some suggestion on this. Do you think creating an iRule to accesss an external service which handles accessing the database a feasible solution? The iRule would send a http request and parse the response.

Is there any similar example out there that I can reference? Thank you very much for any help!

I don’t think it is a clean solution -- something like the Advanced Client Authentication module using an industry standard authentication database would be much better.

But if you have an external source trigger an occasional HTTP request through the BIG-IP to another external server that can provide the database dump in an easy-to-parse web page, then there is no reason you can’t parse the results in an iRule, store it in a global array, and then use that array in another iRule to authenticate an HTTP header against the array. I don’t know that it has ever been done before. The iRule can not request the database dump on its own, however.

I am trying to make my iRule to send request to a web server. I thought I could use the http package from TCL. However, both package and http commands are disabled. So I tried to see if I can use socket command instead but found out that is disabled too. Why does F5 disable those standard tcl commands? What’s the drawback of enabling them if that’s possible?

Thanks a lot!

Check out this recent article “Conditioning iRule Logic on External Information - 1 - HTTP::retry”.

It explains why those commands have been disabled and demonstrates using an external DB query to condition traffic management:

DevCentral - An F5 Technical Community (Click here)

HTH

/deb

As I said above the iRule can’t initiate the request -- try something like a cron job doing a “curl” every minute that hits a VIP on the BIG-IP.

Well, there are a couple of ways besides standard authentication DB calls that you can condition an iRule on external data, and the link I mentioned above details one of them: A nifty trick using “HTTP::retry” to initiate an out-of-band request which should help solve this problem as requested.

/deb

Hi qqdixf5

I have created a working solution for calling another website, doing a vaildation and resending the original request. This solution sends the source IP and the path to a validation site, which checks that this IP are allowed to access this path. (this is just an example, but I have some similar working code which I don’t want to post in an open forum ;-), so there may be some missing variables or something).

when CLIENT_ACCEPTED {

set client_approved 0

}

when HTTP_REQUEST {

set orginal_request [HTTP::request]

if {!$client_approved} {

If client not approved yet, check the clients IP against the checkIP.aspx site at the backend servers

set checkuri “/checkIP.aspx?ip=$SourceIP&path=[HTTP::path]”

HTTP::uri $checkuri

}

}

when HTTP_RESPONSE {

if {!$client_approved} {

if { [HTTP::header exists “Content-Length”] } {

set content_length [HTTP::header “Content-Length”]

} else {

set content_length 1000000

}

if { $content_length > 0 } {

HTTP::collect $content_length

}

}

}

Reads the response, and validates if response contanis Accespted

when HTTP_RESPONSE_DATA {

if {!$client_approved} {

set payload [HTTP::payload]

Check wether response contains Accepted. In that case set client approved to true.

if {$payload contains “Accepted”} {

set client_approved 1

if response contains Accepted, the original_request is sent

HTTP::retry $orginal_request

}

}

}

Thank you for the article and example! I will try to implement my own tomorrow. I will let you know how it goes.

Can anyone tell me what is wrong with the following code snippet? iRule Editor complains that [HTTP::retry] is undefined procedure. I am not sure what’s wrong. Thanks for help!

if {$payload contains “Accepted”} {

HTTP::retry $original_request

}

or

if {$payload contains “Accepted”} {

[HTTP::retry] $original_request

}

Hmmmm…

The first is valid syntax, but the 2nd should generate a “wrong of args” error.

Since you’re getting an “undefined procedure” error instead, it looks like it must not be implemented in your version. (HTTP::retry wasn’t introduced until LTM 9.2 - Click here)

/deb

Hi deb,

Is http::retry the only way to make external call from iRule? In your article, you mentioned that there are a few ways that can make iRule using external information. I am interested in knowing any other option that might work since our network group is not planning to upgrade to 9.2 very soon. Thanks a lot!

The only others are specific types of lookups: standard authentication transactions using the AUTH:: commands, or DNS lookups using the NAME:: commands.

To make a call to a web-fronted database, HTTP::retry is currently your only choice.

/deb

Thanks, Deb! Go back to my earlier questions. Is it possible to enable those tcl commands?