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

use NB_USER rather than getpass.getuser() #132

Merged
merged 3 commits into from
Jun 16, 2022

Conversation

vivian-rook
Copy link
Contributor

Sorry for the open/close PRs this gets us unblocked in a way that doesn't use my repository.

Resolves #129

@manics
Copy link
Member

manics commented Jun 15, 2022

Is this extension designed to only work with jupyter/docker-stacks images where NB_USER is guaranteed to be defined, or should it also work for more general cases?

@ryanlovett
Copy link
Collaborator

@manics It should work in the more general case. So either the authenticator needs to pass in something useful in @vivian-rook's deployment, or the username needs to be configurable here.

Copy link
Contributor

@yuvipanda yuvipanda left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

@@ -45,7 +45,7 @@ def rewrite_auth(response, request):

def setup_rserver():
def _get_env(port):
return dict(USER=getpass.getuser())
return dict(USER=os.environ.get('NB_USER'))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should go through the following hierarchy:

  1. If JUPYTER_USER is set, use that. That's the logged-in username, if using a JupyterHub
  2. If NB_USER is set, use that. This defaults to jovyan I think?
  3. Use getpass.getuser() if neither of these are set.

Choose a reason for hiding this comment

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

Is JUPYTER_USER guaranteed to exist as a system user? I only see JUPYTERHUB_USER in PAWS, and that is not a system user in the container.

The args to --server-user and --user-identity need to be a system user, as I understand it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should the rsession-proxy use the above order, but have additional logic to verify that it is also a system user?

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, I meant JUPYTERHUB_USER not JUPYTER_USER.

@vivian-rook I don't think it matters for rsession-proxy that it is a system user. Is that right, @ryanlovett?

Choose a reason for hiding this comment

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

@yuvipanda I think the problem with #129 is that Chicocvenancio not a system user.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah goddamit, apparently i left my reading comprehension skills at home. Sorry!

In that case, can we try:

  1. pwd.getpwuid(os.getuid())[0], which should return a username that's in the pwd database.
  2. If this fails, then use NB_USER.

How does that sound?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something like this?

Copy link
Contributor

@yuvipanda yuvipanda left a comment

Choose a reason for hiding this comment

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

This LGTM. @ryanlovett looks ok to you?

Thanks a lot, @vivian-rook!

@ryanlovett
Copy link
Collaborator

@yuvipanda The only suggestion I have is to have a fallback in the call to retrieve NB_USER, e.g. user = os.environ.get('NB_USER', getpass.getuser()), so that if everything fails then we're back to the previous behavior. What do you think?

@yuvipanda
Copy link
Contributor

@vivian-rook if you can test this and it works, am happy to merge.

@chicocvenancio
Copy link

@yuvipanda, @vivian-rook works for me with local jupyterhub.

@vivian-rook
Copy link
Contributor Author

@yuvipanda Works for me off the latest build in toolforge/paws#173

@yuvipanda yuvipanda merged commit c3bb6d6 into jupyterhub:master Jun 16, 2022
@welcome
Copy link

welcome bot commented Jun 16, 2022

Congrats on your first merged pull request in this project! 🎉
congrats
Thank you for contributing, we are very proud of you! ❤️

@yuvipanda
Copy link
Contributor

Thanks a lot, @vivian-rook @chicocvenancio and @ryanlovett!

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.

Fails to start if user from getpass.getuser can't run it.
5 participants