Skip to content
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 authentication plugin support #1093

Merged
merged 7 commits into from May 30, 2019

Conversation

jhamrick
Copy link
Member

This PR moves the JupyterHub auth support for determining whether a student has access to a particular class into a special plugin class.

  1. Creates a new Authenticator object which has methods for determining which classes a student has access to, as well as for adding and removing students from access groups.
  2. Adds a plugin object to the Authenticator object, which is by default to have no authentication but there is also the option to use JupyterHub groups authentication, which uses the logic from Restrict access for students to different courses #1040
  3. The Authenticator object is passed around much like the CourseDirectory is so that the same object can be shared by multiple high-level nbgrader components.

cc @sigurdurb @damianavila @psychemedia @BertR

I will add docs and tests tomorrow. I also need to check that I haven't broken the JupyterHub auth.

@jhamrick
Copy link
Member Author

jhamrick commented May 30, 2019

Ok, I have added some test cases but still not tested with an actual JupyterHub instance but will try to do that next. FYI, to use the JupyterHub auth, you would set the following in your nbgrader_config.py file:

from nbgrader.auth import JupyterHubAuthPlugin
c = get_config()
c.Authenticator.plugin_class = JupyterHubAuthPlugin

@jhamrick
Copy link
Member Author

Confirmed that this works with jupyterhub assuming you provide the correct config. Here's what I used:

c = get_config()

# Our user list
c.Authenticator.whitelist = [
    'instructor1',
    'instructor2',
    'student1',
]

c.Authenticator.admin_users = {
    'instructor1',
    'instructor2'
}

# instructor1 and instructor2 have access to different shared servers:
c.JupyterHub.load_groups = {
    'formgrade-course101': [
        'instructor1',
        'grader-course101',
    ],
    'formgrade-course123': [
        'instructor2',
        'grader-course123'
    ],
    'nbgrader-course101': [],
    'nbgrader-course123': []
}

# Start the notebook server as a service. The port can be whatever you want
# and the group has to match the name of the group defined above.
c.JupyterHub.services = [
    {
        'name': 'course101',
        'url': 'http://127.0.0.1:9999',
        'command': [
            'jupyterhub-singleuser',
            '--group=formgrade-course101',
            '--debug',
        ],
        'user': 'grader-course101',
        'cwd': '/home/grader-course101',
        'api_token': ''  # include api token from admin user
    },
    {
        'name': 'course123',
        'url': 'http://127.0.0.1:9998',
        'command': [
            'jupyterhub-singleuser',
            '--group=formgrade-course123',
            '--debug',
        ],
        'user': 'grader-course123',
        'cwd': '/home/grader-course123',
        'api_token': ''  # include api token from admin user
    },
]

@jhamrick jhamrick merged commit 39525b8 into jupyter:multiple-classes-dev May 30, 2019
@jhamrick jhamrick deleted the add-auth-plugin branch May 30, 2019 11:57
@jhamrick jhamrick added this to In progress in Edinburgh Hackathon via automation May 31, 2019
@jhamrick jhamrick moved this from In progress to Done in Edinburgh Hackathon May 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

1 participant