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

Implement support for jupyterlab-gallery config #2501

Merged

Conversation

krassowski
Copy link
Member

@krassowski krassowski commented Jun 4, 2024

Reference Issues or PRs

What does this implement/fix?

Put a x in the boxes that apply

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds a feature)
  • Breaking change (fix or feature that would cause existing features not to work as expected)
  • Documentation Update
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Build related changes
  • Other (please describe):

Testing

  • Did you test the pull request locally?
  • Did you add new tests?

Any other comments?

@krassowski krassowski force-pushed the support-jupyter-gallery-configuration branch from 6453d5b to 85ca022 Compare June 4, 2024 14:44
@kenafoster
Copy link
Contributor

Any consideration yet into how we could handle authenticating to a Github/Gitlab server with this workflow?

As a workaround to date, we've put a PAT in the HTTPS URL. But that would mean committing a PAT Into source code. Might not be a HUGE problem if it's scoped to read-only on the needed repo and the nebari config is protected... still not ideal

@krassowski
Copy link
Member Author

@kenafoster One possibility would be to source the PATs from environment variables and substitute in the URLs; let's continue the discussion in nebari-dev/jupyterlab-gallery#2

@krassowski
Copy link
Member Author

krassowski commented Jun 7, 2024

Tested locally:

image

jupyterlab:
  gallery_settings:
    title: Example repositories
    destination: examples
    exhibits:
      - title: Nebari
        git: https://github.com/nebari-dev/nebari.git
        homepage: https://github.com/nebari-dev/nebari
        description: 🪴 Nebari - your open source data science platform
        icon: https://raw.githubusercontent.com/nebari-dev/nebari-design/main/logo-mark/horizontal/Nebari-Logo-Horizontal-Lockup-White-text.svg
      - title: PyTorch Tutorial
        git: https://github.com/yunjey/pytorch-tutorial.git
        homepage: https://github.com/yunjey/pytorch-tutorial
        description: PyTorch Tutorial for Deep Learning Researchers
        icon: https://github.com/yunjey/pytorch-tutorial/raw/master/logo/pytorch_logo_2018.svg
default_images:
  jupyterlab: quay.io/nebari/nebari-jupyterlab:jupyterlab-gallery-db9c173-20240604

@krassowski
Copy link
Member Author

A limitation for now is that users can see contents /etc/jupyter/. If we want to put PATs in we should configure, at least for jupyter_gallery config this file to be not readable for users. Alternatively, we need to use a Python file (rather than JSON) and pass environment variables.

@krassowski
Copy link
Member Author

krassowski commented Jun 12, 2024

I attempted passing the file_permission: "0400" to the local_sensitive_file resource, but it is not used as a file at all, but just as a temporary variable.

Currently, all the config files get passed on to the of JupyterHub Helm chart via custom.extra-mounts as kubernetes config maps:

extra-mounts = merge(
var.extra-mounts,
{
"/etc/ipython" = {
name = kubernetes_config_map.etc-ipython.metadata.0.name
namespace = kubernetes_config_map.etc-ipython.metadata.0.namespace
kind = "configmap"
}
"/etc/jupyter" = {
name = kubernetes_config_map.etc-jupyter.metadata.0.name
namespace = kubernetes_config_map.etc-jupyter.metadata.0.namespace
kind = "configmap"
}
"/opt/conda/envs/default/share/jupyter/lab/settings" = {
name = kubernetes_config_map.jupyterlab-settings.metadata.0.name
namespace = kubernetes_config_map.jupyterlab-settings.metadata.0.namespace
kind = "configmap"
}

which then get populated by the custom logic during the spawn sequence. This logic also only works with k8s but this is not a problem for nebari.

The problem is that Kubernetes config maps are designed to store non-confidential data as per the documentation.

A possibly better solution would be to use singleuser.extraFiles as these allow to set the file mode, and are recommended for providing configuration.

@krassowski
Copy link
Member Author

I managed to use the dedicated k8 secrets via JupyterHub's singleuser.extraFiles but:

@krassowski
Copy link
Member Author

The latest commit, b3a5bf9, includes a PoC implementation for setting the mode of config file to 0400. Unfortunately, this removes the access from server too, so the configs are not applied. We would need to spawn the server with elevated privilege as compared to the user who is accessing it, and later reduce them once creating kernels or terminals. This is possible on Linux by using capabilities with FOWNER or SETGID but will need extensive testing to ensure that the elevated permissions are cleared for any process that user may spawn, and it might not be secure if we cannot scope it appropriately.

An alternative might be to either:

  • pass the settings via an environmental variable and unset it immediately once consumed, or
  • pass the settings as a config file and remove it immediately once the gallery extension starts.

For now we can instead revert to using the configuration files as before, and document that the PAT need to be scoped to the specific repositories that are used and to be read-only (which is a good practice anyways) and that it might be accessed by the user.

@krassowski krassowski marked this pull request as ready for review June 14, 2024 17:00
@Adam-D-Lewis Adam-D-Lewis requested review from Adam-D-Lewis and viniciusdc and removed request for Adam-D-Lewis and viniciusdc June 20, 2024 17:19
@marcelovilla marcelovilla added this to the 2024.6.1 milestone Jun 21, 2024
@Adam-D-Lewis Adam-D-Lewis requested review from Adam-D-Lewis and kcpevey and removed request for viniciusdc June 24, 2024 17:20
@Adam-D-Lewis
Copy link
Member

Adam-D-Lewis commented Jun 25, 2024

@krassowski It seems like Nebari would benefit from having docs on this. Could you open a docs PR that explain how to use it or at a minimum point to the docs in https://github.com/nebari-dev/jupyterlab-gallery?

@krassowski
Copy link
Member Author

nebari-dev/nebari-docs#478 is waiting for review over a week now.

@Adam-D-Lewis
Copy link
Member

Adam-D-Lewis commented Jun 25, 2024

Actually, is there a way to update the example repos? If so and it's not obvious how to do so or if there is not a way to update the example repo could you add that info to the docs? It sounds like there is an update button that shows up. If that's the case, docs may not be needed.

@krassowski
Copy link
Member Author

Actually, is there a way to update the example repos? If so and it's not obvious how to do so or if there is not a way to update the example repo could you add that info to the docs? It sounds like there is an update button that shows up. If that's the case, docs may not be needed.

Thank you, this is actually a good point - I opened nebari-dev/jupyterlab-gallery#23 to track this on the jupyterlab-gallery side.

@krassowski krassowski merged commit c385172 into nebari-dev:develop Jun 26, 2024
11 checks passed
@krassowski krassowski deleted the support-jupyter-gallery-configuration branch June 26, 2024 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

4 participants