Re: Proxying a request based on RESPONSE_STATUS
2007-02-01 07:40:07 GMT
Dear Ryan & Christian,
I took all your advices and tried several options to build my user scenario. (Sorry, I cannot make this mail any shorter. Please read it to the end. It describes the options I tried and road-blocks I came across.)
My clear cut user scenario is:
=============================
1. We use a common Apache front end and several application back-ends.
2. Based on the different user request URIs we proxy the request to different internal application servers. We use "ProxyPass" & "ProxyPassReverse" directives from "mod_proxy" module for this porpose.
ProxyPass /ap/PostLeadAction http://db2-1:8001/ap/PostLeadAction
ProxyPassReverse /ap/PostLeadAction http://db2-1:8001/ap/PostLeadAction
ProxyPass / https://app1-1:8101/
ProxyPassReverse / https://app1-1:8101/
This works fine for us so far.
3. Now our requirement is to introduce another 3rd "spool" server which will take care of the /ap/PostLeadAction requests only in one of the following cases:
a. If the db2-1 server is unavailable.
b. If db2-1 server timeouts.
c. If the db2-1 server run out of threads.
d. If db2-1 responds with an HTTP 5xx response.
I am planning to use the functionalities provided by ModSecurity to accomplish the 3rd point above.
Here are some of the tryouts I did:
==================================
1. Use "proxy" action in "phase 3" based on the "HTTP_STATUS"
---------------------------------------------------------
# Detect when the original Lead handling server is down
# and proxy to the spooling server
SecRule RESPONSE_STATUS 4..|5.. "log,phase:3,proxy:http://spool/ap/PostLeadAction"
When the trigger is ditected “proxy” action was failed with following log message:
==> ../logs/https_modsec_debug_log <==Access denied with code 500 (phase 3) (Configuration Error: Proxy action requested but it does not work in output phases). Pattern match "5..|4.." at RESPONSE_STATUS.
2. Use “redirect” action at “phase 3” in conjunction with “ProxyPass”
----------------------------------------------------------------- # Proxying redirected Lead posts to the spooling VM ProxyPass /backup/PostLeadAction http://spool:8003/ap/PostLeadAction ProxyPassReverse /backup/PostLeadAction http://spool:8003/ap/PostLeadAction# Detect when the original Lead handling server is down # and redirect to the backup PostLeadAction URI # ProxyPass rule above will send these request to the spool VM. SecRule RESPONSE_STATUS 4..|5.. "log,phase:3,redirect:/backup/PostLeadAction"
This works fine for HTTP 4xx responses. However, the redirection fails (since the request does not pass across phase 3 & 4) for HTTP 502 (I guess this might be true for all HTTP 5xx) responses with following debug log:
Initialising transaction (txid VRXllAoAAAMAACKsTtIAAAAD).Adding request cookie: name "JSESSIONID", value "df742sklhjoar"Transaction context created (dcfg 9efe998).Starting phase REQUEST_HEADERS.Second phase starting (dcfg 9efe998).Input filter: This request does not have a body.Time #1: 493Starting phase REQUEST_BODY.Time #2: 561Hook insert_filter: Adding output filter (r 9f335c8).Initialising logging.Starting phase LOGGING.Audit log: Logging this transaction.
3. Use “redirect” action in “phase 5”
---------------------------------
# Detect when the original Lead handling server is down # and redirect to the backup PostLeadAction URI # ProxyPass rule above will send these request to the spool VM. SecRule RESPONSE_STATUS 4..|5.. "log,phase:5,redirect:/backup/PostLeadAction"
ModSecurity triggered with this setting, but was not effective since it could not perform an effective redirection (since the response is already sent to the user).
With these results, we thought that ModSecurity will not be able to handle our user scenario. However, I wanted to drop this email seeking for ModSecurity expert’s advice to finalize our decision.
Please correct me if I use wrong configuration to tackle the problem here or else please suggest me an alternative way/tool to handle this sort of user scenario.
Thank you very much for reading the mail to this point and all your support so far!
Regards,
Sumith
> -----Original Message-----
> From: Christian Bockermann [mailto:chris <at> jwall.org]
> Sent: Tuesday, January 30, 2007 12:53 AM
> To: Sumith Gamage
> Subject: Re: [mod-security-users] Proxying a request based on
> RESPONSE_STATUS
>
>
> Am 29.01.2007 um 17:50 schrieb Sumith Gamage:
>
> > Dear Ryan,
> >
> > Thanks for the comments. I went though them carefully. I will give
> > a try
> > tomorrow morning on the suggestions you made. However, I am afraid
> > that is
> > not the exact solution to my problem.
> >
> > In my scenario, all the processing behind the front-end web server
> > should be
> > hidden to the application user. Therefore, redirect will not help
> > me since
> > it will change the browser URL.
>
> That might also be possible with redirecting. Just consider the
> following (untested):
>
> ----BEGIN----
> #
> # Initialize the session-collections
> #
> SecRule REQUEST_COOKIES:JSESSIONID "!^$" nolog,phase:1,pass,chain
> SecAction setsid:%{REQUEST_COOKIES:JSESSIONID}
>
> #
> # If a session has been redirected for backup,
> # the request is sent to the backup-server
> #
> SecRule SESSION:server " <at> eq backup" "nolog,phase:2,pass,chain"
> SecAction "proxy:http://backup.server.com"
>
> #
> # assign a session to the backup-server
> #
> SecRule RESPONSE_STATUS 404 "log,phase:3,redirect:http://
> backup.server.com,setvar:server=backup,expirevar:server:3600"
> ----END----
>
> Unfortunately, the client will lose the request that failed
> processing in the app-server. A real
> hot-replacement would probably need some more 
>
> > It seems the Christian's suggestion on http://www.backhand.org/
> > mod_backhand/
> > going to help me. I will give a try on both your suggestion
> > tomorrow and
> > reply you back with the status.
>
> When using mod_backhand you could probably combine it with the
> mod_security-solution above. IIRC
> mod_backhand can access environment variable etc. so this might be
> worth a try.
>
> Regards,
> Chris
------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier. Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________ mod-security-users mailing list mod-security-users <at> lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mod-security-users
RSS Feed