Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Adam-D-Lewis committed Jan 28, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 59078cc commit f799f3e
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ async def get_username_hook(spawner):
async def pre_spawn_hook(spawner):
# if we are starting a service account pod, set/update auth_state
if spawner.user.name == spawner.authenticator.JHUB_SERVICE_ACCOUNT_NAME:
await spawner.authenticator.set_service_account_auth_state(spawner.user)
await spawner.authenticator.set_jhub_service_account_auth_state(spawner.user)
await get_username_hook(spawner)


Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
from pathlib import Path

import z2jh
from tornado import gen


def base_profile_home_mounts(username):
@@ -546,12 +547,13 @@ def preserve_envvars(spawner):
return profile


async def render_profiles(spawner):
@gen.coroutine
def render_profiles(spawner):
# jupyterhub does not yet manage groups but it will soon
# so for now we rely on auth_state from the keycloak
# userinfo request to have the groups in the key
# "auth_state.oauth_user.groups"
auth_state = await spawner.user.get_auth_state()
auth_state = yield spawner.user.get_auth_state()
username = auth_state["oauth_user"]["preferred_username"]

# only return the lowest level group name
Original file line number Diff line number Diff line change
@@ -38,12 +38,11 @@ def _default_jhub_service_account_name(self):
reset_managed_roles_on_startup = Bool(True)

async def set_jhub_service_account_auth_state(self, user):
auth_model = await self.authenticate_service_account()
if user.name != self.JHUB_SERVICE_ACCOUNT_NAME:
raise ValueError(
'User name "{user.name}" does not match service account name "{self.JHUB_SERVICE_ACCOUNT_NAME}"'
)

auth_model = await self.authenticate_service_account()
await user.save_auth_state(auth_model["auth_state"])
logging.info(f'Auth state set for service account: "{user.name}"')

0 comments on commit f799f3e

Please sign in to comment.