-
-
Notifications
You must be signed in to change notification settings - Fork 667
add new backend support for wott #1165
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
add new backend support for wott #1165
Conversation
Introduce abstract Auth class, BasicAuth providing HTTP Authentication and its dummy subclass WoTTAuth. Move assetdir initialization to a separate function run by Flask.
Let Auth classes specify their config.
Rewrite auth settings update procedure.
Add NoAuth backend ("Disabled").
and it need to do something with permission to acces to credentials file |
@a-martynovich Could you review the last part of this? |
auth.py
Outdated
|
||
# self.settings['user'] = self.user | ||
# self.settings['password'] = self.password | ||
# self.settings['openpass'] = self.openpass |
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're no settings, so update_settings
shouldn't do anything.
auth.py
Outdated
def update_settings(self, current_password): | ||
auth_backend = self.settings['auth_backend'] | ||
current_pass_correct = True if auth_backend == '' \ | ||
else self.settings.auth_backends[auth_backend].check_password(current_password) |
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.
@eugenosm Please rebase your branch on top of #1162 . In my PR this line looks different.
144c30c
to
6ccde00
Compare
is_authorized -> is_authenticated, authorize -> authenticate_if_needed.
@vpetersson what should happen if we can't load WoTT credentials? Hide the backend from the dropdown? Act as if auth is disabled? Show error when switching to WoTT backend (and disallow switching)? |
That's an interesting use case.I don't think we should disable auth, as that's a potential attack vector. I'd suggest throwing a 50x maybe? |
I meant what if we can’t load wott credentials when we have other backend selected? Should we allow switching to wott backend in Settings (but show error after saving settings)? Or should we hide the option? |
Oh, i was purely talking about if WoTT was selected. If WoTT isn't selected, then it doesn't really matter. In that case we should probably just log it. |
I’m asking about th UI. Should we allow switching to wott backend in Settings (but show error after saving settings)? Or should we hide the option? |
After a discussion on Slack.
These are somewhat naive assumptions, but will do the trick for now. |
auth.py
Outdated
from flask import request, Response | ||
|
||
WOTT_CREDENTIALS_PATH = '/opt/wott/credentials' | ||
WOTT_SCREENLY_CREDENTIAL_NAME = 'screenly_credentials' |
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 it is used only to be appended with ".json" - I guess it could be named WOTT_SCREENLY_CREDENTIAL_FILE
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.
No, the logic implies that this name will be used in WoTT Credentials UI in the "Name" field.
auth.py
Outdated
login_record = login_record.split(':', 1) | ||
if len(login_record) == 2: | ||
self.user, password = login_record | ||
self.password = '' if password == '' else hashlib.sha256(password).hexdigest() |
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.
Seems password is stored in raw form in file - I'm not sure if it is fine, but I guess that is wott cred format.
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.
Exactly so.
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.
It's actually the way that the basic auth is done in Screenly OSE too. It's not good, but that's a problem for another day.
return True | ||
|
||
|
||
class BasicAuth(Auth): |
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.
This seems to be the same code as in #1162 and I guess will be removed after requested by you rebase.
auth.py
Outdated
return True | ||
|
||
self.user = '' | ||
self.password = '' |
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.
Few minor comments here.
- Can't it be done stateless, without need of storing user and password in the object? Just by reading them from cred during the check? Probably cached with cache decorators f.e?
- I believe this function can be simplified by common practices:
- Return early
- Reverse if and return early
- Moving these 2 statements to top of the func.
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.
- It can, but why? We already have username/password in settings (basic auth) loaded into memory from screenly.conf
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.
- done
Rewrite fetch_credentials. Hide WoTTAuth option if it can't load credentials at startup. Respond with 503 if auth backend raises ValueError.
Rewrite fetch_credentials. Hide WoTTAuth option if it can't load credentials at startup. Respond with 503 if auth backend raises ValueError.
Follow-up changes:
If credential file is missing when switching to WoTT backend in settings an error will be shown (it was already done by @eugenosm ). |
closes #1149
based on #1148 (PR #1162)