Forum Discussion
iRule help for
I have a virtual server and need to modify the traffic via an iRule Requirement:
1. Need to add authorization via static credential
2. Request comes in as POST , should go as POST from the F5, but server sees as GET from the F5
3. Redirect to redirect to another url via an iRule
I have using the below but it is not working.
when HTTP_REQUEST {
set logindata [b64encode "usermane:password"]
HTTP::header insert Authorization "Basic $logindata"
HTTP::redirect "https://www.abc.com[HTTP::uri]"
} '
17 Replies
- youssef1
Cumulonimbus
Hi,
The problem is when you oper your redirect you lost your post data that's the reason why.
Could you explain why you redirect your Post request, (your irule seems correct)
Regards
- Kevin_Stewart
Employee
So to clarify, you need to change the client-side POST to a GET on the server-side, and inject some static credentials?
Will the POST have payload? And if so, do you want to mirror that payload to the server?
Will all requests be coming in as POSTs?
An HTTP::redirect command sends a 302 HTTP redirect back to the client, so probably not what you want. Can you elaborate on the desired traffic flow?
- Aditya_Mehra
Cirrus
Hi Kevin,
Below are the answers to address your query
Will the POST have payload? And if so, do you want to mirror that payload to the server?
Yes, POST will have payload (an xml file) and we need to mirror this.
.
Will all requests be coming in as POSTs? Yes, all requests come as POST ..we need to include credentials and still pass the payload as HTTP POST itself
.
Can you elaborate on the desired traffic flow?
.
1. Client sends a HTTP POST with xml payload to First External F5 (Internet facing)Here there is no pool, it redirects to another VIP on a second external F5, So on the 1st External F5e we use HTTP::redirect "https://www.abc.com[HTTP::uri]" Also we need to add static creds and the POST shall go as a POST (right mow server Sees it becomes a GET, which should not be the case)
.
2. Second External F5 with VIP -
From here it goes to an Internal F5 VIP which is Pool Member here
3. Internal F5 - pool member server
4. Server - Kevin_Stewart
Employee
Ah, I see. You're saying that the redirect changes the POST to a GET.
This is an expected behavior when you send a 301 or 302 redirect to a browser. Not all clients support this, but the better option may be to send a 307 instead.
See this: https://httpstatuses.com/307
You'd do this with an HTTP::respond instead:
HTTP::respond 307 Location "http://foo" - Aditya_Mehra
Cirrus
Thanks Kevin,
I will try with the below and check with the customer.
when HTTP_REQUEST { set logindata [b64encode "username:password"]
HTTP::header insert Authorization "Basic $logindata"
HTTP::respond 307 Location "https://www.abc.com[HTTP::uri]" } - Aditya_Mehra
Cirrus
Hi Kevin,
the new iRule solved the below 2.
1.Payload is coming
2.It is HTTP POSTonly missing is username/password in authorization headers -> the server do not see any authorization header
Response Error Message =Authentication challenge issued
Response Status Code= 401 - Kevin_Stewart
Employee
Aditya,
As Youssef is alluding, you're most likely going to have to proxify the request to the other VIPs, that is, pass the traffic through the first VIP to the second. A 307 redirect will cause the client to maintain the original POST method, but there's NO WAY to also pass an authorization header through the client into the next request. So you have maybe two options here:
-
Pool the traffic through VIP1 to VIP2 on the other F5, in which case you don't have to send a redirect and don't have to worry about the POST method changing. And you can insert the static authorization header here.
-
Have VIP2 insert the static credentials. Assuming the authentication isn't actually being consumed by VIP2, but rather the application servers behind it, it would be conceivable to simply have VIP2 insert the authorization header on the way to the application.
-
- Aditya_Mehra
Cirrus
Thanks Kevin,
So if we add the VIP of 2nd F5 as a pool on the first F5 will the payload and post we in place as it is?
Thanks, Aditya - Kevin_Stewart
Employee
Yes. You'd simply need to decrypt, insert your authorization header, and send it on its way. The contents of the HTTP request (method, headers and payload) will remain intact.
- Aditya_Mehra
Cirrus
ok, but there is problem
it has to be to a specific endpoint or url, we always need to redirect to
example : https://www.abc.com:/a/b/c/d/e/v2 url
just redirecting to will not work
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com