Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow restricting profiles & profile_options based on JupyterHub groups #3883

Merged
merged 17 commits into from
May 7, 2024

Conversation

yuvipanda
Copy link
Member

@yuvipanda yuvipanda commented Mar 30, 2024

This PR does a bunch of things that would be difficult to do separately, and hence it's slightly big. Not too big!

1. Move from Auth0OAuthenticator to GenericOAuthenticator for EarthScope

The Auth0 authenticator made the EarthScope authentication mechanism look more custom than it really was - it's really just standard auth0, and if you look at the auth0 authenticator code it's fairly minimal - just a couple of convenience functions. This PR switches that (+ our auth0 documentation) to simply use GenericOAuthenticator. This has the following advantages:

  1. The Auth0 documentation we have can be easily ported to just support any Generic OAuth provider if needed in the future, for other communities.
  2. It signals that the EarthScope hub is not that special, just the first as a way for us to develop and offer new features. We should work on structuring how we do this, and signal when features are available in what hubs. But in the meantime, this reduces the overall apparent complexity to match actual complexity
  3. Removes the custom logout_url work, and instead just mentions you need to set the client_id in the logout_url, and adds that to our auth0 documentation. This removes more custom code we have for EarthScope. Once Add allowed_scopes to all authenticators to allow some users based on granted scopes jupyterhub/oauthenticator#719 is merged, this helps us remove all custom code here from earthscope. This part fixes [Support] Finalize earthscope domain migration, a documentation thing remains #3715

There is still a custom override for the authenticator, but most of that can be removed once jupyterhub/oauthenticator#719 is in a released version of OAuthenticator.

2. Provision JupyterHub groups for scopes

Auth0 allows us to use granted scopes to differentiate what rights various users on the JupyterHub should have. In this PR, we use our custom auth override to provision JupyterHub groups based on the scopes granted. We can not use the current claim_groups_key, as scopes are not a part of the user claim. jupyterhub/oauthenticator#735 fixes this, but until that lands, we can rely on the custom auth override to provision JupyterHub groups.

3. allowed_groups functionality

We currently have allowed_teams functionality that restricts which profiles are available to which users based on GitHub team membership. However, this is specific to GitHubOAuthenticator only. This PR expands it into allowed_groups functionality, which works for all authenticators. Until jupyterhub/oauthenticator#735 lands, we also directly treat GitHub teams as 'groups'. All existing references to allowed_teams is renamed to allowed_groups with no loss of functionality for us. This also allows us to restrict profiles on EarthScope based on JupyterHub group membership.

4. allowed_groups support for profile_option

Currently, allowed_groups (and allowed_teams) only supported restricting whole profiles (selected via radio buttons), but not profile_options (the dropdowns) or unlisted_choice (the textbox). This lead to some unclean duplication in places, and causes long term issues in places where the 'profile' is to select the environment and the dropdown is to select resource size. This PR adds allowed_groups support for both profile_option.choices and profile_option.unlisted_choice, so this awkwardness goes away.

Upstreaming strategy for this work is described in #4021

@yuvipanda yuvipanda requested a review from a team as a code owner March 30, 2024 00:26
Copy link

github-actions bot commented Mar 30, 2024

Merging this PR will trigger the following deployment actions.

Support and Staging deployments

Cloud Provider Cluster Name Upgrade Support? Reason for Support Redeploy Upgrade Staging? Reason for Staging Redeploy
aws victor No Yes Core infrastructure has been modified
gcp 2i2c-uk No Yes Core infrastructure has been modified
gcp meom-ige No Yes Core infrastructure has been modified
gcp cloudbank No Yes Core infrastructure has been modified
aws catalystproject-africa No Yes Core infrastructure has been modified
aws jupyter-meets-the-earth No Yes Core infrastructure has been modified
kubeconfig utoronto No Yes Core infrastructure has been modified
aws nasa-ghg No Yes Core infrastructure has been modified
aws kitware No Yes Core infrastructure has been modified
gcp 2i2c No Yes Core infrastructure has been modified
gcp leap No Yes Core infrastructure has been modified
gcp pangeo-hubs No Yes Core infrastructure has been modified
aws ubc-eoas No Yes Core infrastructure has been modified
aws earthscope No Yes Core infrastructure has been modified
gcp hhmi No Yes Core infrastructure has been modified
aws nasa-esdis No Yes Core infrastructure has been modified
gcp awi-ciroh No Yes Core infrastructure has been modified
aws smithsonian No Yes Core infrastructure has been modified
aws openscapes No Yes Core infrastructure has been modified
aws linc No Yes Core infrastructure has been modified
gcp qcl No Yes Core infrastructure has been modified
gcp catalystproject-latam No Yes Core infrastructure has been modified
aws nasa-cryo No Yes Core infrastructure has been modified
gcp linked-earth No Yes Core infrastructure has been modified
aws dandi No Yes Core infrastructure has been modified
aws jupyter-health No Yes Core infrastructure has been modified
aws nasa-veda No Yes Core infrastructure has been modified
aws gridsst No Yes Core infrastructure has been modified
aws bican No Yes Core infrastructure has been modified
aws opensci No Yes Core infrastructure has been modified
aws 2i2c-aws-us No Yes Core infrastructure has been modified

Production deployments

Cloud Provider Cluster Name Hub Name Reason for Redeploy
aws victor prod Core infrastructure has been modified
gcp 2i2c-uk lis Core infrastructure has been modified
gcp meom-ige prod Core infrastructure has been modified
gcp cloudbank bcc Core infrastructure has been modified
gcp cloudbank ccsf Core infrastructure has been modified
gcp cloudbank csm Core infrastructure has been modified
gcp cloudbank dvc Core infrastructure has been modified
gcp cloudbank elcamino Core infrastructure has been modified
gcp cloudbank evc Core infrastructure has been modified
gcp cloudbank glendale Core infrastructure has been modified
gcp cloudbank howard Core infrastructure has been modified
gcp cloudbank miracosta Core infrastructure has been modified
gcp cloudbank skyline Core infrastructure has been modified
gcp cloudbank demo Core infrastructure has been modified
gcp cloudbank fresno Core infrastructure has been modified
gcp cloudbank humboldt Core infrastructure has been modified
gcp cloudbank laney Core infrastructure has been modified
gcp cloudbank sbcc Core infrastructure has been modified
gcp cloudbank sbcc-dev Core infrastructure has been modified
gcp cloudbank elac Core infrastructure has been modified
gcp cloudbank lacc Core infrastructure has been modified
gcp cloudbank lamission Core infrastructure has been modified
gcp cloudbank mills Core infrastructure has been modified
gcp cloudbank mission Core infrastructure has been modified
gcp cloudbank norco Core infrastructure has been modified
gcp cloudbank palomar Core infrastructure has been modified
gcp cloudbank pasadena Core infrastructure has been modified
gcp cloudbank sjcc Core infrastructure has been modified
gcp cloudbank sacramento Core infrastructure has been modified
gcp cloudbank srjc Core infrastructure has been modified
gcp cloudbank saddleback Core infrastructure has been modified
gcp cloudbank santiago Core infrastructure has been modified
gcp cloudbank sjsu Core infrastructure has been modified
gcp cloudbank sierra Core infrastructure has been modified
gcp cloudbank tuskegee Core infrastructure has been modified
gcp cloudbank wlac Core infrastructure has been modified
gcp cloudbank csulb Core infrastructure has been modified
gcp cloudbank csum Core infrastructure has been modified
aws catalystproject-africa nm-aist Core infrastructure has been modified
aws catalystproject-africa must Core infrastructure has been modified
aws catalystproject-africa uvri Core infrastructure has been modified
aws catalystproject-africa wits Core infrastructure has been modified
aws catalystproject-africa kush Core infrastructure has been modified
aws catalystproject-africa molerhealth Core infrastructure has been modified
aws catalystproject-africa aibst Core infrastructure has been modified
aws catalystproject-africa bhki Core infrastructure has been modified
aws catalystproject-africa bon Core infrastructure has been modified
aws jupyter-meets-the-earth prod Core infrastructure has been modified
kubeconfig utoronto prod Core infrastructure has been modified
kubeconfig utoronto r-prod Core infrastructure has been modified
aws nasa-ghg prod Core infrastructure has been modified
aws kitware prod Core infrastructure has been modified
gcp 2i2c imagebuilding-demo Core infrastructure has been modified
gcp 2i2c demo Core infrastructure has been modified
gcp 2i2c ohw Core infrastructure has been modified
gcp 2i2c aup Core infrastructure has been modified
gcp 2i2c temple Core infrastructure has been modified
gcp 2i2c ucmerced Core infrastructure has been modified
gcp 2i2c climatematch Core infrastructure has been modified
gcp 2i2c mtu Core infrastructure has been modified
gcp 2i2c tufts Core infrastructure has been modified
gcp leap prod Core infrastructure has been modified
gcp pangeo-hubs prod Core infrastructure has been modified
gcp pangeo-hubs coessing Core infrastructure has been modified
aws ubc-eoas prod Core infrastructure has been modified
aws earthscope prod Core infrastructure has been modified
gcp hhmi prod Core infrastructure has been modified
gcp hhmi spyglass Core infrastructure has been modified
aws nasa-esdis prod Core infrastructure has been modified
gcp awi-ciroh prod Core infrastructure has been modified
aws smithsonian prod Core infrastructure has been modified
aws openscapes prod Core infrastructure has been modified
aws linc prod Core infrastructure has been modified
gcp qcl prod Core infrastructure has been modified
gcp catalystproject-latam unitefa-conicet Core infrastructure has been modified
gcp catalystproject-latam cicada Core infrastructure has been modified
gcp catalystproject-latam gita Core infrastructure has been modified
gcp catalystproject-latam iner Core infrastructure has been modified
gcp catalystproject-latam plnc Core infrastructure has been modified
gcp catalystproject-latam unam Core infrastructure has been modified
gcp catalystproject-latam uprrp Core infrastructure has been modified
aws nasa-cryo prod Core infrastructure has been modified
gcp linked-earth prod Core infrastructure has been modified
aws dandi prod Core infrastructure has been modified
aws jupyter-health prod Core infrastructure has been modified
aws nasa-veda prod Core infrastructure has been modified
aws gridsst prod Core infrastructure has been modified
aws bican prod Core infrastructure has been modified
aws opensci sciencecore Core infrastructure has been modified
aws 2i2c-aws-us showcase Core infrastructure has been modified
aws 2i2c-aws-us ncar-cisl Core infrastructure has been modified
aws 2i2c-aws-us go-bgc Core infrastructure has been modified
aws 2i2c-aws-us itcoocean Core infrastructure has been modified
aws 2i2c-aws-us cosmicds Core infrastructure has been modified

@yuvipanda
Copy link
Member Author

I'm going to mark this as draft, as I don't believe we should use our engineering capacity to review and merge this right now.

@yuvipanda yuvipanda marked this pull request as draft April 4, 2024 00:43
@yuvipanda yuvipanda force-pushed the earthscope-generic branch 2 times, most recently from 8f74c80 to 9b92edd Compare April 5, 2024 23:44
@yuvipanda yuvipanda force-pushed the earthscope-generic branch from d911502 to ed17f94 Compare April 18, 2024 19:17
@yuvipanda yuvipanda force-pushed the earthscope-generic branch from ed17f94 to c84ac83 Compare April 30, 2024 22:37
@yuvipanda yuvipanda changed the title Use GenericOAuthenticator to support Auth0 Implement profile restrictions on Earthscope using JupyterHub Groups May 1, 2024
@yuvipanda yuvipanda changed the title Implement profile restrictions on Earthscope using JupyterHub Groups Allow restricting profiles & profile_options based on JupyterHub groups May 2, 2024
@yuvipanda yuvipanda force-pushed the earthscope-generic branch from 31e6f19 to beaa424 Compare May 3, 2024 02:55
@yuvipanda
Copy link
Member Author

This is missing additional feature docs on enabling allowed_groups in profile_options, but otherwise good to go.

@yuvipanda
Copy link
Member Author

Added and cleaned up docs!

@yuvipanda yuvipanda marked this pull request as ready for review May 4, 2024 01:27
@yuvipanda yuvipanda requested review from GeorgianaElena and removed request for a team May 4, 2024 01:27
Copy link
Member

@GeorgianaElena GeorgianaElena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this @yuvipanda , it's looking great! <3 I left a few small comments, but none is blocking so please feel free to merge this PR when you think it's ready 🚀

config/clusters/earthscope/common.values.yaml Outdated Show resolved Hide resolved
Comment on lines +124 to +123
# Convert 'scope' from the OAuth2 response into JupyterHub groups
manage_groups: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can go, as manage_groups is already set to true at line 100 through
c.GenericOAuthenticator.manage_groups = True

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the line 100!

docs/howto/features/profile-list-restrict.md Outdated Show resolved Hide resolved
docs/howto/features/profile-list-restrict.md Outdated Show resolved Hide resolved
Comment on lines +203 to +212
## Enabling this feature for other Authenticators

Currently, the EarthScope hub has this feature enabled via custom overrides. Once
[this PR](https://github.com/jupyterhub/oauthenticator/pull/735) is merged and
deployed, we can enable this feature for hubs using other Authenticators more generally.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add this to the beginning of the page under a {warning} directive so that it's more clear that is not yet available outside of the CustomGenericOAuthenticator

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 1071 to 1072
# casefold teams so we can do case insensitive comparisons, as github itself is case insensitive (but preserving)
# for orgs and teams
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this ended up here by accident and should instead be before line 1035 maybe?

Suggested change
# casefold teams so we can do case insensitive comparisons, as github itself is case insensitive (but preserving)
# for orgs and teams

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Moved!

@yuvipanda yuvipanda force-pushed the earthscope-generic branch 2 times, most recently from bf9f382 to 0b77600 Compare May 7, 2024 17:23
yuvipanda added 5 commits May 7, 2024 11:35
The Auth0 authenticator made the EarthScope authentication mechanism
look more custom than it really was - it's really just standard
auth0, and if you look at the [auth0 authenticator](https://github.com/jupyterhub/oauthenticator/blob/main/oauthenticator/auth0.py)
code it's fairly minimal - just a couple of convenience functions.
This PR switches that (+ our auth0 documentation) to simply use
GenericOAuthenticator. This has the following advantages:

1. The Auth0 documentation we have can be easily ported to just
   support any Generic OAuth provider if needed in the future.
2. The GenericOAuthenticator has features the Auth0 one does not -
   particularly around groups management that we do want to use.
   While eventually I think this should be made available to all
   authenticators (and will work with upstream in doing so), moving
   to GenericOAuthenticator unblocks planning & scheduling engineering work here
   as soon as 2i2c-org#3818
   is merged.
3. It signals that the EarthScope hub is not *that* special, just the
   first as a way for us to develop and offer new features. We should
   work on structuring how we do this, and signal when features are
   available in what hubs. But in the meantime, this reduces the overall
   apparent complexity to match actual complexity
4. Removes the custom logout_url work, and instead just mentions you need
   to set the `client_id` in the logout_url, and adds that to our auth0
   documentation. This removes more custom code we have for EarthScope.
   Once jupyterhub/oauthenticator#719 is merged,
   this helps us remove all custom code here from earthscope. This
   part fixes 2i2c-org#3715

This was triggered as cleanup by https://2i2c.freshdesk.com/a/tickets/1453.
I'll create appropriate issues for next steps, and will prioritize any
future work accordingly with our engineering processes.
pre-commit-ci bot and others added 12 commits May 7, 2024 11:35
Otherwise, there were issues with closure capture in earthscope -
somehow, original_profile_list was actually still being magically
set to the function, even though it works fine in gh-teams set
in basehub/values.yaml! I suspect some traitlets magic. Instead
of debugging it through, let's partial our way out.

Also more cleanly set the profile_list override in gh-teams, so
the overriding function is not set unless necessary.
- `allowed_groups` functionality is put in basehub, and hence
  available to everyone! Individual authenticators still need to
  figure out how to enable groups, but that's separated out from
  `profile_list` filtering functionality.
- Pending jupyterhub/oauthenticator#735,
  we explicitly also treat GitHub teams from auth_state as 'groups'.
  This allows us to bring all our existing users along, without issue.
- Get rid of the code duplication in earthscope
- Rename all `allowed_teams` to `allowed_groups`.
@yuvipanda yuvipanda force-pushed the earthscope-generic branch from 0b77600 to b8a8e49 Compare May 7, 2024 18:36
@yuvipanda yuvipanda merged commit 7a67090 into 2i2c-org:main May 7, 2024
39 checks passed
Copy link

github-actions bot commented May 7, 2024

🎉🎉🎉🎉

Monitor the deployment of the hubs here 👉 https://github.com/2i2c-org/infrastructure/actions/runs/8990616478

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Support] Finalize earthscope domain migration, a documentation thing remains
2 participants