-
Notifications
You must be signed in to change notification settings - Fork 15
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
Added solr route cookie for solr-service requests #143
Conversation
When a request is directed to solr-service, the user token is extracted from the request and its solr route (which link to a specific solr instance) is retreived from redis (if it exists) before passing the request to solr-service. Solr-service response is also inspected for "Set-Cookie" instructions with the solr route, in case it is present the solr route is stored in redis using the user's token as key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great job!
please see one question and one request; it is IMHO good to go - but the gap for the remote call should be covered
adsws/api/discoverer/utils.py
Outdated
@@ -61,6 +63,10 @@ def bootstrap_local_module(service_uri, deploy_path, app): | |||
# ensure the current_app matches local_app and not API app | |||
view = local_app_context(local_app)(view) | |||
|
|||
if service_uri == 'adsws.solr_service.solr': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the solr-service is ran in the remote mode? Maybe also need to add block in the remote_app_context?
adsws/api/discoverer/solr_route.py
Outdated
user_token = request.headers.get('X-Forwarded-Authorization', None) | ||
if user_token is None: | ||
user_token = request.headers.get('Authorization', None) | ||
if user_token and len(user_token) > 7: # This should be always true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
occurred to me that this depends on the oauth decorator running first (which is the case), however as it stands right now, it is conditional:
which might be OK (for now); but I have got a question for ya (since you might have been digging inside); when I am authenticated through a session cookie (ie. not sending the token), is the user object (and oauth info) loaded before your sroute gets called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have done some testing and we cannot actually make a request to solr-service only with a session cookie, it requires the bearer token or we just get "Unauthorized".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while that is probably true; there are endpoints, such as /user where an user is granted access with just a cookie; and so if this function expects user_token we should verify that it is there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the solr_route decorator is only for the solr-service, requests to /user do not go through the solr_route decorator. Do you know a microservice that grants access just with a session cookie and that contact solr-service for something?
@marblestation i can't agree with the latest change - the /search is IMO worse than the module path (and can be changed via config) but the most important thing was the remote context; that seems to be not addressed at all; unless i'm not seeing all commits: https://github.com/marblestation/adsws/blob/491f9f60b7c0238c1d885750b730cdfdbefb21f2/adsws/api/discoverer/utils.py#L95 |
The remote context was addressed here: https://github.com/marblestation/adsws/blob/491f9f60b7c0238c1d885750b730cdfdbefb21f2/adsws/api/discoverer/utils.py#L178 And actually that's what motivated the change to |
ok, sorry, here is the explanation - i was taking a mental shortcut first, the local/remote handling look identical - and I didn't notice that the remote was there, my bad. secondly, and that became clear to me only now: I was thinking "the mechanism should be generic". If you notice, we are hardcoding a tight coupling right into the heart of adsws (which escaped me at first, but now I see it clearly) -- adsws shouldn't know/care if it is running /search or treat some module specially So I'd say instead of
you do:
|
24ec221
to
ebac5db
Compare
ebac5db
to
382e8d4
Compare
I agree with your suggestion, I tried to implement something in those lines. What do you think now? |
When a request is directed to solr-service, the user token is extracted from the request and its solr route (which link to a specific solr instance) is retreived from redis (if it exists) before passing the request to solr-service.
Solr-service response is also inspected for "Set-Cookie" instructions with the solr route, in case it is present the solr route is stored in redis using the user's token as key.