Skip to content

Directory-specific configuration files? #13663

Closed

Description

@mgeier

In the past, I've used ipython_kernel_config.py configuration files in the same directory as my notebook files, so that if others checked out my files (e.g. with git), they automatically were using the settings I intended.

I also recommended this at https://nbsphinx.readthedocs.io/en/0.8.8/code-cells.html#Plots and those same settings were even used by nbsphinx (via nbconvert), which worked great!

However, some time ago this stopped working, and I just traced this back to 1ec91eb, which mentions a CVE.

So if using a per-directory ipython_kernel_config.py is unsafe, is there safe way to get per-directory settings?

Activity

  1. MrMino commented on May 6, 2022

    @MrMino
    Member

    Not unless we make the configuration declarative, and even then I don't think this would stop a CVE like this from popping up.
    Why not just add a cell that runs appropriate settings via %run?

  2. fperez commented on Sep 4, 2022

    @fperez
    Member

    I'm not an expert in security best practices, so there may be some great, clean solution I'm overlooking. But as much as I sympathize with @mgeier about the major loss of convenience from this, I worry just as much about the point @MrMino makes. Ultimately (and I bear a lot of responsibility for this, as I argued pretty strongly ages ago for having this design in our config system, with .py files at its core for the convenience and power they provide), a configuration system that is based on executing arbitrary code seems like a really hard beast to tame from a security standpoint. Its power and convenience for the legitimate user are wonderful, but it's very easy for that same power to be hijacked in a million subtle, and hard to predict ways.

    I don't know - I'd love to hear of ideas for clean solutions that let us have our cake and eat it here, but I don't see an easy one. @Carreau, you've been on top of a lot of security work lately, any ideas? Also @rcthomas and others from the security team might have input? Our entire traitlets-based config approach is predicated on giving users the full power of python to manage their ipython/jupyter tools, but it opens the door to these problems.

  3. MrMino commented on Sep 4, 2022

    @MrMino
    Member

    An idea just popped into my head: could Jupyter add a synthetic cell, which would allow the user to opt-into running a config file, based on its hash?

    Excuse my pathetic attempts at mocking this up:

    image

    You could then keep a database of what configs are enabled for which notebooks. When starting a notebook with enabled config, the config cell would be loaded automatically. Each update of a config file would require a reauthorization by the user.

    This would prevent execution of untrusted code - the user is responsible for ensuring that they are running code that is safe. More importantly (IMO), it makes the whole mechanism explicit - a quality the lack of which made the original mechanism more exploitable.

  4. Carreau commented on Sep 5, 2022

    @Carreau
    Member

    This is much more complicated than it looks as even declarative configuration can somehow execute arbitrary code, and even with signed configuration one could do the same.

    I thought about this as traitlets also support json config file, but the problem is that those config files can manipulate sys.path, which extensions are loaded, or even dynamic subclass for some things (historymanager, etc).

    SO I could perfectly append . to sys path, and say create a pandas.py file in CWD. And boom , I have arbitrary execution.

    The secondary problem with the cell that @MrMino suggest, is that not all configuration parameters are changeable after startup, so while those cells could be made, they would cover only a subset of parameters.

    Really the only viable solution is an explicit list of configuration options we would allow in CWD.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions