-
-
Notifications
You must be signed in to change notification settings - Fork 12
Vars in request context instead of location config; OAuth2Require #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ec works now. No custom install and uninstall targets needed any more.
request with a valid token set them. A second request passing no token at all would retrieve the values of the previous token because the local config object would be shared among the requests. The variables are now stored in an ngx_hash in a request context. It is destroyed after each request. * If the request passes no token the previous code still returned NGX_OK. Now we check if there was a OAuth2TokenVerify configuration directive for the location. If yes then we return NGX_HTTP_UNAUTHORIZED. An NGX_OK is returned only if there was no OAuth2TokenVerify configuration directive, meaning that the request is not 'for us'. * Added the optional configuration directive OAuth2Require. It takes between zero and seven arguments. Every argument is a variable name. The authorization callback returns NGX_OK only if every variable is defined and its value is the string '1'. We can combine the Nginx 'map' configuration directive and the variables that hold token values in order to synthesize the variables used by OAuth2Require. In this way we may check that the token holds desired values, for example that 'iss' matches a given regular expression or that the 'scope' is belongs to a required set. This new configuration directive is optional. If absent then the module behaves like before, i.e. it returns NGX_OK if the token can be decrypted, parsed, and it is not expired.
thanks, that looks very good indeed; it would be even better if you could pull (most of) that code up to liboauth2, into https://github.com/OpenIDC/liboauth2/blob/master/src/server/nginx.c and https://github.com/OpenIDC/liboauth2/blob/master/include/oauth2/nginx.h so that it is re-usable for ngx_openidc_module as well |
I'll look into that, but I can't do anything before the end of next week. |
2c39828
to
c718170
Compare
b00165e
to
c2787cb
Compare
see #7; thanks @pladen Signed-off-by: Hans Zandbelt <[email protected]>
I have adopted the "variables in request context" changes since they're clearly a security risk. Wrt. |
I don't think it obsoletes OAuth2Claim, as OAuth2Claim is just a mapping between token claim and ngx var. OAuth2Require allows to set one (or more) variable values as mandatory to give access to location. |
@pladen thanks for chiming in, that clarifies things for me a bit; however, it still feels that |
Yes, I get your point. When you practice nginx daily, you avoid IF as much a possible because "if is evil" : So OAuth2Require have sense and this is why @smanolache adds it. To sum up, without OAuth2Require it is possible to just make So, please, keep it ! |
see OpenIDC/ngx_oauth2_module#7; thanks @@smanolache and @pladen; bump to 1.6.3dev Signed-off-by: Hans Zandbelt <[email protected]>
see OpenIDC/ngx_oauth2_module#7; thanks @smanolache and @pladen Signed-off-by: Hans Zandbelt <[email protected]>
see OpenIDC/ngx_oauth2_module#7; thanks @smanolache and @pladen Signed-off-by: Hans Zandbelt <[email protected]>
see #7; thanks @smanolache Signed-off-by: Hans Zandbelt <[email protected]>
I have now adopted - I think - all suggested changes with minor modifications and merged them into the liboauth2 master branch, to be released with liboauth2 1.6.3. I'm closing this as any further refinements/comments can be done as part of a new thread/issue/discussion. Looking for your feedback before releasing liboauth2 1.6.3 and ngx_oauth2_module 3.5.0, thanks! |
Thanks for having merged my proposals. Here's an example of how I combine maps, ifs, and requirements: In /etc/nginx/nginx.conf, the http section:
In the virtual host configuration:
|
thank you for your contribution! |
I see your point about whether On one hand one could say that the module provides authentication only, i.e. no authorization. It authenticates the data found in the token. It is up to the application code to authorize the request, to take action depending on the data in the token. On the other hand one could argue that |
Hello,
I've made several modifications to the code:
The values of the variables were stored in the local config. A request with a valid token set them. A second request passing no token at all would retrieve the values of the previous token because the local config object would be shared among the requests.
The variables are now stored in an ngx_hash in a request context. It is destroyed after each request.
If the request passes no token the previous code still returned NGX_OK. Now we check if there was a OAuth2TokenVerify configuration directive for the location. If yes then we return NGX_HTTP_UNAUTHORIZED. An NGX_OK is returned only if there was no OAuth2TokenVerify configuration directive, meaning that the request is not 'for us'.
I've added the optional configuration directive OAuth2Require. It takes between zero and seven arguments. Every argument is a variable name. The authorization callback returns NGX_OK only if every variable is defined and its value is the string '1'. We can combine the Nginx 'map' configuration directive and the variables that hold token values in order to synthesize the variables used by OAuth2Require. In this way we may check that the token holds desired values, for example that 'iss' matches a given regular expression or that the 'scope' is belongs to a required set.
This new configuration directive is optional. If absent then the module behaves like before, i.e. it returns NGX_OK if the token can be decrypted, parsed, and it is not expired.
I've modelled the configuration directive on auth_jwt_require in the commercial distribution of nginx (https://nginx.org/en/docs/http/ngx_http_auth_jwt_module.html#auth_jwt_require).
Here's how it can be used: