.. _authentication: Authentication ============== Authentication allows you to control who has access to your JupyterHub deployment. There are many options available to you in controlling authentication, many of which are described below. Authenticating with OAuth2 -------------------------- JupyterHub's `oauthenticator `_ has support for enabling your users to authenticate via a third-party OAuth provider, including GitHub, Google, and CILogon. Follow the service-specific instructions linked on the `oauthenticator repository `_ to generate your JupyterHub instance's OAuth2 client ID and client secret. Then declare the values in the helm chart (``config.yaml``). Here are example configurations for common authentication services. Note that in each case, you need to get the authentication credential information before you can configure the helm chart for authentication. GitHub ^^^^^^ GitHub is the largest hosting service for git repositories. It is free to create an account at GitHub, and relatively straightforward to set up OAuth credentials so that users can authenticate with their GitHub username/password. To create OAuth credentials on GitHub, follow these steps: * Click your profile picture -> settings -> developer settings * Make sure you're on the "OAuth Apps" tab, then click "New OAuth App" * Fill out the forms (you'll need your hub address) and generate your ID/Secret. To enable GitHub authentication, add the following to your `config.yml`: .. code-block:: yaml auth: type: github github: clientId: "y0urg1thubc1ient1d" clientSecret: "an0ther1ongs3cretstr1ng" callbackUrl: "http:///hub/oauth_callback" Make sure that the `callbackUrl` matches the one you set in GitHub. Giving access to organizations on GitHub ++++++++++++++++++++++++++++++++++++++++ The configuration above will allow *any* GitHub user to access your JupyterHub. You can also restrict access to members of one or more GitHub organizations. To do so, see the configuration below. .. code-block:: yaml auth: type: github github: ... org_whitelist: - "SomeOrgName" scopes: - "read:user" ``auth.scopes`` can take other values as described in the `GitHub Oauth scopes documentation `_ but we recommend ``read:user`` as this requires no additional configuration by GitHub organisations and users. For example, omitting the scope means members of an organisation must `set their membership to Public `_ to login, whereas setting it to ``read:org`` may require approval of the application by a GitHub organisation admin. Please see `this issue `_ for further information. .. note:: Changing ``auth.scopes`` will not change the scope for existing OAuth tokens, you must invalidate them. Google ^^^^^^ Google authentication is used by many universities (it is part of the "G Suite"). Note that using Google authentication requires your Hub to have a domain name (it cannot **only** be accessible via an IP address). For more information on authenticating with Google oauth, see the :ref:`google_oauth`. .. code-block:: yaml auth: type: google google: clientId: "yourlongclientidstring.apps.googleusercontent.com" clientSecret: "adifferentlongstring" callbackUrl: "http:///hub/oauth_callback" hostedDomain: "youruniversity.edu" loginService: "Your University" CILogon ^^^^^^^ .. code-block:: yaml auth: type: cilogon cilogon: clientId: "y0urc1logonc1ient1d" clientSecret: "an0ther1ongs3cretstr1ng" callbackUrl: "http:///hub/oauth_callback" In order to overcome the `caveats `_ of implementing CILogon OAuthAuthenticator for JupyterHub, i.e. default username_claim of ePPN does not work for all providers, e.g. generic OAuth such as Google, Use c.CILogonOAuthenticator.username_claim = 'email' to use email instead of ePPN as the JupyterHub username: Add to your config.yaml file to `inject extra python based configuration that should be in jupyterhub_config.py `_ as below: .. code-block:: yaml hub: extraConfig: | c.CILogonOAuthenticator.username_claim = 'email' Globus ^^^^^^ Globus Auth is a foundational identity and access management platform service designed to address unique needs of the science and engineering community. Globus provides cloud-based services for reliably moving, sharing, publishing and discovering data, whether your files live on a supercomputer, lab cluster, tape archive, public cloud, or your own laptop. Start a Globus app `here `_! .. code-block:: yaml auth: type: globus globus: clientId: "y0urc1logonc1ient1d" clientSecret: "an0ther1ongs3cretstr1ng" callbackUrl: "https:///hub/oauth_callback" identityProvider: "youruniversity.edu" OpenID Connect ^^^^^^^^^^^^^^ `OpenID Connect `_ is an identity layer on top of the OAuth 2.0 protocol, implemented by `various servers and services `_. While OpenID Connect endpoint discovery is not supported by oauthentiator, you can still configure JupyterHub to authenticate with OpenID Connect providers by specifying all endpoints in GenericOAuthenticator. By setting `login_service` you can customize the label on the login button. Here's an example for authenticating against `keycloak `_, after you `configure an OIDC Client `_ and obtain the confidential client credentials. .. code-block:: yaml hub: extraEnv: OAUTH2_AUTHORIZE_URL: https://${host}/auth/realms/${realm}/protocol/openid-connect/auth OAUTH2_TOKEN_URL: https://${host}/auth/realms/${realm}/protocol/openid-connect/token auth: type: custom custom: className: oauthenticator.generic.GenericOAuthenticator config: login_service: "keycloak" client_id: "y0urc1logonc1ient1d" client_secret: "an0ther1ongs3cretstr1ng" token_url: https://${host}/auth/realms/${realm}/protocol/openid-connect/token userdata_url: https://${host}/auth/realms/${realm}/protocol/openid-connect/userinfo userdata_method: GET userdata_params: {'state': 'state'} username_key: preferred_username .. _google_oauth: Full Example of Google OAuth2 ----------------------------- If your institution is a `G Suite customer `_ that integrates with Google services such as Gmail, Calendar, and Drive, you can authenticate users to your JupyterHub using Google for authentication. .. note:: Google requires that you specify a fully qualified domain name for your hub rather than an IP address. 1. Log in to the `Google API Console `_. 2. Select a project > Create a project... and set 'Project name'. This is a short term that is only displayed in the console. If you have already created a project you may skip this step. 3. Type "Credentials" in the search field at the top and click to access the Credentials API. 4. Click "Create credentials", then "OAuth client ID". Choose "Application type" > "Web application". 5. Enter a name for your JupyterHub instance. You can give it a descriptive name or set it to be the hub's hostname. 6. Set "Authorized JavaScript origins" to be your hub's URL. 7. Set "Authorized redirect URIs" to be your hub's URL followed by "/hub/oauth_callback". For example, `http://{example.com}/hub/oauth_callback`. 8. When you click "Create", the console will generate and display a Client ID and Client Secret. Save these values. 9. Type "consent screen" in the search field at the top and click to access the OAuth consent screen. Here you will customize what your users see when they login to your JupyterHub instance for the first time. Click Save when you are done. 10. In your helm chart, create a stanza that contains these OAuth fields: .. code-block:: bash auth: type: google google: clientId: "yourlongclientidstring.apps.googleusercontent.com" clientSecret: "adifferentlongstring" callbackUrl: "http:///hub/oauth_callback" hostedDomain: "youruniversity.edu" loginService: "Your University" The ``callbackUrl`` key is set to the authorized redirect URI you specified earlier. Set ``hostedDomain`` to your institution's domain name. The value of ``loginService`` is a descriptive term for your institution that reminds your users which account they are using to login. Authenticating with LDAP -------------------------- JupyterHub supports LDAP and Active Directory authentication. Read the `ldapauthenticator `_ documentation for a full explanation of the available parameters. Example LDAP Configuration ^^^^^^^^^^^^^^^^^^^^^^^^^^ `auth.ldap.server.address` and `auth.ldap.dn.templates` are required. Other fields are optional. .. code-block:: yaml auth: type: ldap ldap: server: address: ldap.EXAMPLE.org dn: templates: - 'cn={username},ou=edir,ou=people,ou=EXAMPLE-UNIT,o=EXAMPLE' Example Active Directory Configuration ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This example is equivalent to that given in the `ldapauthenticator README `_. .. code-block:: yaml auth: type: ldap ldap: server: address: ad.EXAMPLE.org dn: lookup: true search: filter: '({login_attr}={login})' user: 'ldap_search_user_technical_account' password: 'secret' templates: - 'uid={username},ou=people,dc=wikimedia,dc=org' - 'uid={username},ou=developers,dc=wikimedia,dc=org' user: searchBase: 'ou=people,dc=wikimedia,dc=org' escape: False attribute: 'sAMAccountName' dnAttribute: 'cn' allowedGroups: - 'cn=researcher,ou=groups,dc=wikimedia,dc=org' - 'cn=operations,ou=groups,dc=wikimedia,dc=org' Adding a Whitelist ------------------ JupyterHub can be configured to only allow a specified `whitelist `_ of users to login. This is especially useful if you are using an authenticator with an authentication service open to the general public, such as GitHub or Google. You can specify this list of usernames in your `config.yaml`: .. code-block:: yaml auth: whitelist: users: - user1 - user2