Skip to content

Commit

Permalink
Try setting oauth_redirect_url dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Davidson committed Nov 2, 2023
1 parent eb0d1a6 commit 389ed8c
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions binderhub-azimuth/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ binderhub:
oauth_no_confirm: true
# NOTE: This won't work in general, not sure if possible to workaround...
# oauth_redirect_uri: "http://binder.scott-test-1.svc/oauth_callback"
oauth_redirect_uri: "http://tqeiz9jvie1xiuxr0rkitqpszljzsvy0ow.apps.128-232-226-111.sslip.io/oauth_callback"
# oauth_redirect_uri: "http://tqeiz9jvie1xiuxr0rkitqpszljzsvy0ow.apps.128-232-226-111.sslip.io/oauth_callback"
loadRoles:
user:
scopes:
Expand Down Expand Up @@ -290,21 +290,33 @@ binderhub:

extraConfig:
zenith-hub-url.py: |
# Looks up Zenith FQDN for hub instance on cluster and passes to BinderHub
# so that we get redirected to correct Zenith url when notebook is ready
# Here we look up the Zenith FQDN for jupyterhub + binderhub instances on the cluster
# and set some traitlets based on these values so that browser redirections between
# binderhub and jupyterhub work correctly for both OAuth flows and for notebook
# launching.
from kubernetes import client, config
config.load_incluster_config()
api = client.CustomObjectsApi()
current_namespace = open("/var/run/secrets/kubernetes.io/serviceaccount/namespace").read()
reservations = api.list_namespaced_custom_object(
'zenith.stackhpc.com', 'v1alpha1', current_namespace, 'reservations'
)['items']
hub_zenith_reservation = list(filter(
lambda x: '-binderhub-azimuth-jupyterhub' in x['metadata']['name'], reservations
)['items']
jupyter_zenith_reservation = list(filter(
lambda r: r['metadata']['name'].endswith('-binderhub-azimuth-jupyterhub'), reservations
))
if len(hub_zenith_reservation) > 0:
# Do some error logging here?
pass
zenith_url = hub_zenith_reservation[0]['status']['fqdn']
c.BinderHub.hub_url = f'http://{zenith_url}'
c.HubOAuth.hub_host = f'http://{zenith_url}'
binder_zenith_reservation = list(filter(
lambda r: r['metadata']['name'].endswith('-binderhub-azimuth'), reservations
))
if len(jupyter_zenith_reservation) != 1 or len(binder_zenith_reservation) != 1:
pass # TODO: Error logging?
jupyter_zenith_url = jupyter_zenith_reservation[0]['status']['fqdn']
binder_zenith_url = binder_zenith_reservation[0]['status']['fqdn']
c.BinderHub.hub_url = f'http://{jupyter_zenith_url}'
c.HubOAuth.hub_host = f'http://{jupyter_zenith_url}'
c.HubOAuth.oauth_redirect_uri = f'http://{binder_zenith_url}/oauth_callback'

0 comments on commit 389ed8c

Please sign in to comment.