Skip to content

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

Merged

Conversation

eugenosm
Copy link
Contributor

closes #1149
based on #1148 (PR #1162)

@eugenosm
Copy link
Contributor Author

and it need to do something with permission to acces to credentials file

@vpetersson
Copy link
Contributor

@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
Copy link
Contributor

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)
Copy link
Contributor

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.

@a-martynovich a-martynovich force-pushed the 1149-add-new-backend-support-for-WoTT branch from 144c30c to 6ccde00 Compare June 18, 2019 18:23
is_authorized -> is_authenticated, authorize -> authenticate_if_needed.
@a-martynovich
Copy link
Contributor

@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)?

@vpetersson
Copy link
Contributor

@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?

@a-martynovich
Copy link
Contributor

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?

@vpetersson
Copy link
Contributor

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.

@a-martynovich
Copy link
Contributor

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?

@vpetersson
Copy link
Contributor

After a discussion on Slack.

  • If the file (normally /opt/wott/credentials/screenly.json unless overridden in config) is absent, prevent save and display “Can’t load /opt/wott/credentials/screenly.json”.
  • If the folder /opt/wott is absent, then assume the WoTT agent is not installed.

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'

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

Copy link
Contributor

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()

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly so.

Copy link
Contributor

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):

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 = ''

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor comments here.

  1. 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?
  2. 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. It can, but why? We already have username/password in settings (basic auth) loaded into memory from screenly.conf

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. done

eugenosm and others added 4 commits June 20, 2019 20:44
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.
@a-martynovich
Copy link
Contributor

a-martynovich commented Jun 20, 2019

Follow-up changes:

  • WoTT option will be hidden if there's no /opt/wott directory.
  • Server will respond with 503 if credentials file suddenly disappears while WoTT backend is active.
  • Credentials are read at every request. There're few requests right now so it shouldn't be a problem (later we can add cache and stuff).

If credential file is missing when switching to WoTT backend in settings an error will be shown (it was already done by @eugenosm ).

@vpetersson vpetersson merged commit a4235a6 into Screenly:master Jun 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add new backend support for WoTT
4 participants