-
Notifications
You must be signed in to change notification settings - Fork 324
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
Cat won't talk to strangers if not allowed to #904
Cat won't talk to strangers if not allowed to #904
Conversation
|
||
# chatting over websocket | ||
if auth_resource == AuthResource.CONVERSATION and api_key == ws_api_key: | ||
if not http_key and not ws_key: | ||
return AuthUserInfo( | ||
id=user_id, | ||
name=user_id, | ||
permissions=get_base_permissions() |
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.
If no keys are set, I guess we can give full permissions to anybody?
In this way if there are no keys set, you cannot use most endpoints (I need to check)
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.
Yep, agree with that, otherwise we could differentiate by requested resource:
if not http_key and not ws_key:
return AuthUserInfo(
id=user_id,
name=user_id,
permissions=get_base_permissions() if auth_resource == AuthResource.CONVERSATION else get_full_permissions()
# any http endpoint | ||
if api_key == http_api_key: | ||
if auth_resource == AuthResource.CONVERSATION: | ||
return self._authorize_websocket_key(user_id, api_key, ws_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.
There are also endpoints for conversation not related to websocket :(
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.
Damn, you're right! So, currently, you have to pass the WS api key for the http message endpoint if only the WS key is set? And when only the http key is set if you not passing the api key you can message freely because None == None...
Thanks @lucagobbi I left some comments |
Thank you Piero, I think we might need some more adjustments, ping me whenever you want |
API KEY permissions rationale:
JWT:
P.S.: intervention point (here) |
I cant manage to find a way to do what we have said during the last dev meeting without a proper refactor of those classes, which, for the moment, I'd avoid. my alt proposal is to:
What do you think? |
Sorry for this :(
Not sure introducing new permissions is the best way. What's wrong with this PR as is? POST /message is an http endpoint, so no issue right? |
@pieroit I've added the protocol based control that we talked about yesterday, this decouples auth key methods from auth resources. What do you think about it? |
Looks great! Will check asap locally |
Thanks @lucagobbi for the contribution and patience :) |
Description
Currently, if you set only the CCAT_WS_API_KEY you'll still be able to talk to the Cat even when no key is passed.
I fixed it refactoring the
authorize_user_from_key
method.Actually, I think that, in the future, we should move out the control: "if no keys are set, then always pass", but is it strictly related to the AuthHandler? If so, then its right to keep it there even if out of scope. Plus, is it correct to gave base permissions if no keys are set? Probably would be better to distinguish even there the requested resource.
Related to issue #895
Type of change
Checklist: