Skip to content

Commit

Permalink
Support username / password auth provider
Browse files Browse the repository at this point in the history
Uses a 'database' connector[1] with auth0 to provide
username / password authentication.

demo.cloudbank.2i2c.cloud is now moved over to this,
making it easier for people to give demos. This also
removes any current restrictions on who can log in,
and opens it up to everyone. We add some resource
restrictions to match this.

Fixes 2i2c-org#403

[1]: https://auth0.com/docs/connections/database
  • Loading branch information
yuvipanda committed May 17, 2021
1 parent 2704f10 commit 0bf3064
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
20 changes: 10 additions & 10 deletions config/hubs/cloudbank.cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ hubs:
domain: demo.cloudbank.2i2c.cloud
template: basehub
auth0:
connection: google-oauth2
connection: password
config:
jupyterhub:
homepage:
Expand All @@ -206,15 +206,15 @@ hubs:
url: http://cloudbank.org/
hub:
config:
Authenticator:
allowed_users: &demo_users
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
admin_users: *demo_users
JupyterHub:
# No more than 100 users at a time
active_server_limit: 100
cull:
# Cull after 30min of inactivity
every: 300
timeout: 1800
# No pods over 12h long
maxAge: 43200
- name: lassen
domain: lassen.cloudbank.2i2c.cloud
template: basehub
Expand Down
3 changes: 2 additions & 1 deletion config/hubs/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ properties:
properties:
connection:
type: string
enum:
enum:
- google-oauth2
- github
- ORCID
- password
description: |
Authentication method users of the hub can use to log in to the hub.
We support a subset of the [connectors](https://auth0.com/docs/identityproviders)
Expand Down
22 changes: 20 additions & 2 deletions deployer/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
USERNAME_KEYS = {
'github': 'nickname',
'google-oauth2': 'email',
'ORCID': 'sub'
'ORCID': 'sub',
'password': 'email'
}


Expand Down Expand Up @@ -79,6 +80,7 @@ def _ensure_client_callback(self, client, domains):
}
)


def ensure_client(self, name, domains, connection_name):
current_clients = self.get_clients()
if name not in current_clients:
Expand All @@ -89,12 +91,28 @@ def ensure_client(self, name, domains, connection_name):
self._ensure_client_callback(client, domains)

current_connections = self.get_connections()

if connection_name == 'password':
db_connection_name = f'database-{name}'

if db_connection_name not in current_connections:
# connection doesn't exist yet, create it
connection = self.auth0.connections.create({
'name': db_connection_name,
'display_name': name,
'strategy': 'auth0'
})
current_connections[db_connection_name] = connection
selected_connection_name = db_connection_name
else:
selected_connection_name = connection_name

for connection in current_connections.values():
# The chosen connection!
enabled_clients = connection['enabled_clients'].copy()
needs_update = False
client_id = client['client_id']
if connection['name'] == connection_name:
if connection['name'] == selected_connection_name:
if client_id not in enabled_clients:
enabled_clients.append(client_id)
needs_update = True
Expand Down
3 changes: 2 additions & 1 deletion deployer/hub.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from auth import KeyProvider
import hashlib
import hmac
import json
Expand Down Expand Up @@ -100,7 +101,7 @@ def __init__(self, cluster, spec):
self.cluster = cluster
self.spec = spec

def get_generated_config(self, auth_provider, secret_key):
def get_generated_config(self, auth_provider: KeyProvider, secret_key):
"""
Generate config automatically for each hub
Expand Down

0 comments on commit 0bf3064

Please sign in to comment.