JupyterHub Singleuser Extensions#

Module: jupyterhub.singleuser.extension#

Integrate JupyterHub auth with Jupyter Server as a Server Extension

Instead of earlier versions, implemented via subclassing jupyter-notebook’s NotebookApp. This code runs only in each user’s Jupyter Server process.

Jupyter Server 2 provides two new APIs:

  • IdentityProvider, which authenticates the user making the request

  • Authorizer, which determines whether an authenticated user is authorized to take a particular action

This Extension implements both for resolving permissions with JupyterHub scopes. By default, in JupyterHub we only _authenticate_ users with sufficient access:servers permissions, therefore the JupyterHub Authorizer allows any authenticated user to take any action, but custom deployments may refine these permission to enable e.g. read-only access.

Requires Jupyter Server 2.0, which in turn requires Python 3.7.

JupyterHubUser#

class jupyterhub.singleuser.extension.JupyterHubUser(hub_user)#

Subclass jupyter_server User to store JupyterHub user info

JupyterHubIdentityProvider#

class jupyterhub.singleuser.extension.JupyterHubIdentityProvider(*args: t.Any, **kwargs: t.Any)#

Identity Provider for JupyterHub OAuth

Replacement for JupyterHub’s HubAuthenticated mixin

cookie_name c.JupyterHubIdentityProvider.cookie_name = Unicode('')#

Name of the cookie to set for persisting login. Default: username-${Host}.

cookie_options c.JupyterHubIdentityProvider.cookie_options = Dict()#

Extra keyword arguments to pass to set_secure_cookie. See tornado’s set_secure_cookie docs for details.

Extra keyword arguments to pass to get_secure_cookie. See tornado’s get_secure_cookie docs for details.

login_handler_class c.JupyterHubIdentityProvider.login_handler_class = Type('jupyter_server.auth.login.LoginFormHandler')#

The login handler class to use, if any.

Specify whether login cookie should have the secure property (HTTPS-only).Only needed when protocol-detection gives the wrong answer due to proxies.

updatable_fields c.JupyterHubIdentityProvider.updatable_fields = List()#

List of fields in the User model that can be updated.

JupyterHubAuthorizer#

class jupyterhub.singleuser.extension.JupyterHubAuthorizer(*args: t.Any, **kwargs: t.Any)#

Authorizer that looks for permissions in JupyterHub scopes.

Currently only checks the access:servers scope(s), which ought to be redundant with checks already in JupyterHubIdentityProvider for safety.

JupyterHubSingleUser#

class jupyterhub.singleuser.extension.JupyterHubSingleUser(*args: t.Any, **kwargs: t.Any)#

Jupyter Server extension entrypoint.

Enables JupyterHub authentication and some JupyterHub-specific configuration from environment variables

Server extensions are loaded before the rest of the server is set up

answer_yes c.JupyterHubSingleUser.answer_yes = Bool(False)#

Answer yes to any prompts.

config_file c.JupyterHubSingleUser.config_file = Unicode('')#

Full path of a config file.

config_file_name c.JupyterHubSingleUser.config_file_name = Unicode('')#

Specify a config file to load.

default_url c.JupyterHubSingleUser.default_url = Unicode('')#

No help string is provided.

generate_config c.JupyterHubSingleUser.generate_config = Bool(False)#

Generate default config file.

handlers c.JupyterHubSingleUser.handlers = List()#

Handlers appended to the server.

hub_activity_interval c.JupyterHubSingleUser.hub_activity_interval = Int(300)#

Interval (in seconds) on which to update the Hub with our latest activity.

Uses $JUPYTERHUB_ACTIVITY_INTERVAL environment variable by default.

hub_activity_url c.JupyterHubSingleUser.hub_activity_url = Unicode('')#

URL for sending JupyterHub activity updates.

Uses $JUPYTERHUB_ACTIVITY_URL environment variable by default.

log_datefmt c.JupyterHubSingleUser.log_datefmt = Unicode('%Y-%m-%d %H:%M:%S')#

The date format used by logging formatters for logging.Formatter datefmt parameter

log_format c.JupyterHubSingleUser.log_format = Unicode('[%(name)s]%(highlevel)s %(message)s')#

The Logging format template

log_level c.JupyterHubSingleUser.log_level = Enum(30)#

Set the log level by value or name.

logging_config c.JupyterHubSingleUser.logging_config = Dict()#

Configure additional log handlers.

The default stderr logs handler is configured by the log_level, log_datefmt and log_format settings.

This configuration can be used to configure additional handlers (e.g. to output the log to a file) or for finer control over the default handlers.

If provided this should be a logging configuration dictionary, for more information see: https://docs.python.org/3/library/logging.config.html#logging-config-dictschema

This dictionary is merged with the base logging configuration which defines the following:

  • A logging formatter intended for interactive use called console.

  • A logging handler that writes to stderr called console which uses the formatter console.

  • A logger with the name of this application set to DEBUG level.

This example adds a new handler that writes to a file:

c.Application.logging_config = {
    "handlers": {
        "file": {
            "class": "logging.FileHandler",
            "level": "DEBUG",
            "filename": "<path/to/file>",
        }
    },
    "loggers": {
        "<application-name>": {
            "level": "DEBUG",
            # NOTE: if you don't list the default "console"
            # handler here then it will be disabled
            "handlers": ["console", "file"],
        },
    },
}
open_browser c.JupyterHubSingleUser.open_browser = Bool(False)#

Whether to open in a browser after starting. The specific browser used is platform dependent and determined by the python standard library webbrowser module, unless it is overridden using the –browser (ServerApp.browser) configuration option.

settings c.JupyterHubSingleUser.settings = Dict()#

Settings that will passed to the server.

show_config c.JupyterHubSingleUser.show_config = Bool(False)#

Instead of starting the Application, dump configuration to stdout

show_config_json c.JupyterHubSingleUser.show_config_json = Bool(False)#

Instead of starting the Application, dump configuration to stdout (as JSON)

static_paths c.JupyterHubSingleUser.static_paths = List()#

paths to search for serving static files.

This allows adding javascript/css to be available from the notebook server machine, or overriding individual files in the IPython

static_url_prefix c.JupyterHubSingleUser.static_url_prefix = Unicode('')#

Url where the static assets for the extension are served.

template_paths c.JupyterHubSingleUser.template_paths = List()#

Paths to search for serving jinja templates.

Can be used to override templates from notebook.templates.