Setting auth_request based on request method
February 27, 2017 02:58AM

I've implemented auth_request for a set of micro services I'm currently building and very much like this feature.
I am, however, having a bit of an issue with specifying what calls need the auth request based on the request method.

For example, I need to try and set up the following:
GET /object - NO auth needed
POST /object - auth needed
PATCH /object - auth needed

I've normalised the endpoints for the sake of this example and there are more endpoints but this should be enough to explain the scenario.

I currently have the following:

location /object {
auth_request /auth;
auth_request_set $auth $upstream_http_x_auth;

proxy_pass http://object; # an upstream
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Auth $auth;
proxy_set_header Host $http_host;

I tried using an IF statement but got errors because of auth_request not being allowed there.
How can I make it so that the GET request doesn't go through the auth request?

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 121
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready