jupyterhub / nativeauthenticator

JupyterHub-native User Authenticator
https://native-authenticator.readthedocs.io
BSD 3-Clause "New" or "Revised" License
71 stars 69 forks source link

TLJH Signup and login customizations not working #98

Open t3chbg opened 4 years ago

t3chbg commented 4 years ago

Having few issues with login and signup custom pages not displaying after enabling Native Authentication - jupyterhub/nativeauthenticator#69 suggestions do not seem to work for me and having trouble figuring out what the issues are.

Ran pytest ad getting 2 error and 2 warning messages. Also not sure if these errors are related to the issue or not.

platform linux -- Python 3.7.6, pytest-5.3.5, py-1.8.1, pluggy-0.13.1
rootdir: /opt/tljh/nativeauthenticator
plugins: asyncio-0.10.0
collected 27 items

nativeauthenticator/tests/test_authenticator.py ...................FF.. [ 85%]
nativeauthenticator/tests/test_orm.py .... [100%]

================================================================================================ FAILURES =================================================================================================
_____________________________________________________________________________ test_import_from_firstuse_dont_delete_db_after ______________________________________________________________________________

tmpcwd = None, app = <jupyterhub.tests.mocking.MockHub object at 0x7fa01d7ce490>

async def test_import_from_firstuse_dont_delete_db_after(tmpcwd, app):
    with dbm.open('passwords.dbm', 'c', 0o600) as db:
        db['user1'] = 'password'

    auth = NativeAuthenticator(db=app.db)
    auth.add_data_from_firstuse()

    files = os.listdir()
    assert UserInfo.find(app.db, 'user1')

      assert ('passwords.dbm' in files) or ('passwords.dbm.db' in files)

E AssertionError: assert ('passwords.dbm' in ['passwords.dbm.dat', 'passwords.dbm.dir', 'jupyterhub.sqlite', 'passwords.dbm.bak'] or 'passwords.dbm.db' in ['passwords.dbm.dat', 'passwords.dbm.dir', 'jupyterhub.sqlite', 'passwords.dbm.bak'])

/opt/tljh/nativeauthenticator/nativeauthenticator/tests/test_authenticator.py:182: AssertionError
------------------------------------------------------------------------------------------ Captured stderr setup ------------------------------------------------------------------------------------------
[I 2020-02-17 18:30:31.724 alembic.runtime.migration migration:154] Context impl SQLiteImpl.
[I 2020-02-17 18:30:31.725 alembic.runtime.migration migration:161] Will assume non-transactional DDL.
[I 2020-02-17 18:30:31.742 alembic.runtime.migration migration:513] Running stamp_revision -> 4dc2d5a8c53c
________________________________________________________________________________ test_import_from_firstuse_delete_db_after ________________________________________________________________________________

tmpcwd = None, app = <jupyterhub.tests.mocking.MockHub object at 0x7fa01d8dc910>

async def test_import_from_firstuse_delete_db_after(tmpcwd, app):
    with dbm.open('passwords.dbm', 'c', 0o600) as db:
        db['user1'] = 'password'

    auth = NativeAuthenticator(db=app.db)
    auth.delete_firstuse_db_after_import = True

      auth.add_data_from_firstuse()

/opt/tljh/nativeauthenticator/nativeauthenticator/tests/test_authenticator.py:192:

/opt/tljh/nativeauthenticator/nativeauthenticator/nativeauthenticator.py:246: in add_data_from_firstuse
self.delete_dbm_db()

self = <nativeauthenticator.nativeauthenticator.NativeAuthenticator object at 0x7fa01d8dca90>

def delete_dbm_db(self):
    db_path = Path(self.firstuse_db_path)
    db_dir = db_path.cwd()
    db_name = db_path.name
    db_complete_path = str(db_path.absolute())

    # necessary for BSD implementation of dbm lib
    if db_name + '.db' in os.listdir(db_dir):
        os.remove(db_complete_path + '.db')
    else:

          os.remove(db_complete_path)

E FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pytest-of-root/pytest-3/test_import_from_firstuse_dele0/passwords.dbm'

/opt/tljh/nativeauthenticator/nativeauthenticator/nativeauthenticator.py:232: FileNotFoundError
------------------------------------------------------------------------------------------ Captured stderr setup ------------------------------------------------------------------------------------------
[I 2020-02-17 18:30:32.429 alembic.runtime.migration migration:154] Context impl SQLiteImpl.
[I 2020-02-17 18:30:32.429 alembic.runtime.migration migration:161] Will assume non-transactional DDL.
[I 2020-02-17 18:30:32.446 alembic.runtime.migration migration:513] Running stamp_revision -> 4dc2d5a8c53c
============================================================================================ warnings summary =============================================================================================
nativeauthenticator/nativeauthenticator.py:23
/opt/tljh/nativeauthenticator/nativeauthenticator/nativeauthenticator.py:23: DeprecationWarning: metadata {'default': False} was set from the constructor. With traitlets 4.1, metadata should be set using the .tag() method, e.g., Int().tag(key1='value1', key2='value2')
help=("Creates a verification of password strength "

/opt/tljh/user/lib/python3.7/site-packages/notebook/notebookapp.py:47
/opt/tljh/user/lib/python3.7/site-packages/notebook/notebookapp.py:47: DeprecationWarning: zmq.eventloop.ioloop is deprecated in pyzmq 17. pyzmq now works with default tornado and asyncio eventloops.
ioloop.install()

-- Docs: https://docs.pytest.org/en/latest/warnings.html
================================================================================ 2 failed, 25 passed, 2 warnings in 29.47s ================================================================================
leportella commented 4 years ago

which version of NativeAuthenticator where you using? I just updated the package on pip, could you check if this problem persists?

t3chbg commented 4 years ago

which version of NativeAuthenticator where you using? I just updated the package on pip, could you check if this problem persists?

Hi @leportella - I installed NativeAuthenticator as per instructions found here https://native-authenticator.readthedocs.io/en/latest/quickstart.html

git clone https://github.com/jupyterhub/nativeauthenticator.git
cd nativeauthenticator
pip install -e .
Git status output:
/opt/tljh/nativeauthenticator$ sudo git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
leportella commented 4 years ago

I see now that the error is because the authenticator can't find the original database:

'passwords.dbm' in ['passwords.dbm.dat', 'passwords.dbm.dir', 'jupyterhub.sqlite', 'passwords.dbm.bak'] or 'passwords.dbm.db' in ['passwords.dbm.dat', 'passwords.dbm.dir', 'jupyterhub.sqlite', 'passwords.dbm.bak']

Could you try with removing the importing users from FirstUse Auth option? If that works, please be sure to configure the correct database using the following confiugration:

c.Authenticator.firstuse_dbm_path = '/home/user/passwords.dbm'

as showed in documentation

t3chbg commented 4 years ago

@leportella no difference after removing the FirstUse Auth option.

If I recall accurately I added FirstUse Auth as troubleshooting step after experiencing issues. Just to confirm default folder path for passwords.dbm is /opt/tljh/state/passwords.dbm?

t3chbg commented 4 years ago

Current tljh config

users:
  admin: []
https:
  enabled: true
  tls:
    key: /etc/ssl/private/wildcard_ahri_org.key
    cert: /etc/ssl/certs/wildcard_ahri_org.crt
auth:
  type: nativeauthenticator.NativeAuthenticator
user_environment:
  default_app: jupyterlab
Authenticator:
  check_common_password: true
  minimim_password_length: 10
  allowed_failed_logins: 5
  ask_email_on_signup: true
  open_signup: true
limits:
  memory: 8G
  cpu: 1
paulbaracch commented 4 years ago

@leportella i have exactly the same problem in the same config.

paulbaracch commented 4 years ago

@t3chbg Did you find a fix to your problem?

t3chbg commented 4 years ago

@Paul-Barac not yet unfortunately.....

consideRatio commented 2 years ago

I noted this as well, but I haven't debugged this more in detail. Will try find time to do so in a few weeks, thanks for your effort to debug and document this experience so far! Note also that nativeauthenticator 1.0.5 has been released.

consideRatio commented 2 years ago

I think by using nativeauthenticator 1.0.5, and by configuring this in a jupyterhub config file:

import os
import nativeauthenticator

if not isinstance(c.JupyterHub.template_paths, list):
    c.JupyterHub.template_paths = []
c.JupyterHub.template_paths.append(
    f"{os.path.dirname(nativeauthenticator.__file__)}/templates/"
)

Things will work.