-
Notifications
You must be signed in to change notification settings - Fork 507
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
Adding prelaunch hook for kernel instances #218
Conversation
Hi Tim, I like the idea, I wonder if this isn't better solved with a template? |
@maartenbreddels the tough part is making #216 and #239 and #105 play nicely together. I agree that my simple example here is better handled by a template (and indeed, I have a template that does exactly this). But if you can specify a template with a url parameter (which I think is a good idea), you'll still want some hook in (for example, I will want to put things like IMO we should try to build in a few of the same hooks that exist in JLab
probably more to follow |
Hey, I would love to hear from this. I've been wondering how to authenticate a user before he gets to a voila rendered notebook. I would like to experiment and give feedback on what's possible to do with these hooks, especially with OAuth2. |
Could you give a few pointers to where that is in the jlab code? |
Prelaunch hook is actually from IPython, you can specify lines to execute at startup All of these are useable via jupyter_server, so that's definitely the right approach |
I just wanted to comment here, I've been using this HEAVILY in my fork. Its super useful as a per-user hook into the notebook, letting you inject arbitrary code cells which is super nice for doing validation and authentication. |
Thanks for letting us know, we'll have to see how this mixes with the progressive loading and follow up plans, but I understand its usefulness. |
Another good use is logging, I can grab the notebook name and inject a cell that sends remote log info about who is executing what notebook |
I'd just like to +1 this. Given the current implementation, this looks like it's a nice way to handle granular authorization. That is, on a production system, we would like to put the voila app behind e.g. an OAuth authentication service (like e.g. here), which would pass on information (like user, scopes, etc.) in the request headers to voila. This information could be used to decide whether or not to load the notebook (ideally using information from the notebook, perhaps an access list stored in metadata?) and raise a This approach is somewhat different than that suggested by @leogout since the authentication would be handled elsewhere. |
@mgmarino we do something very similar, thats why the prelaunch hook has access to the handler. For us, it remote logs the user accessing the server, attempts to authenticate, raises a 401 with a redirect to authenticate if there are issues, then injects a few cells to log some other miscellaneous info. |
@maartenbreddels @SylvainCorlay you can also pretty trivally use this to embed arguments. just install a variable in the kernel from handler.request.arguments in your hook |
for example: def prelaunch_hook(handler, notebook, cwd):
args = handler.request.arguments
cell = NotebookNode()
cell.metadata = {}
cell.execution_count = 1
cell.outputs = []
cell.source = 'ARGS={}'.format(json.dumps(args))'
notebook.cells.insert(0, cell) now
|
Hey Tim, I want to let you know that I still like the idea, but I'm still not sure of the consequences for voila long term, e.g. for caching, kernel-forking. Not forgotten about it. |
@martinRenou theres a Callable traitlet added a while back but not in the docs still |
Hi Tim, this looks very useful! However when starting the voila.app on a folder of notebooks instead of a single one it seems the prelaunch hook does not run on individual notebooks inside the folder once clicked from the voila served links. |
reimplemented in #724 |
I will have an example of hooking this into auth in my dashboard repo, but for now here is a simple example of pre-processing a notebook prior to launch, which adds an extra title to the page.
Which yields: