Securely requesting a run time password

47 views
Skip to first unread message

John Omernik

unread,
Jun 19, 2017, 7:17:46 AM6/19/17
to Project Jupyter
Is there an accepted way to request a runtime password that can be stored in a variable in the running kernel for a notebook? The idea here is when a user starts using a specific data source, it may require authentication. Username is pretty easy, but I want to be able to prompt a user at instantiation of a data source object for the password rather than have it stored in a password. Now, I could put it in a cell, but the idea is I want to be able to write a wrapper module for my org that allows any user running the same notebook, to have the exact same code in the notebook execute on the datasource with their individual credentials. 

So I have notebook A

and I have users X and Y


User X creates the notebook, they do something like 

myds = instantiatedOrgDS()

it reads the context of the user, and then prompts for the datasource password from the user. They enter it in a box that doesn't echo the password, it setups up the Data source into the object mysql

next celll:

results = myds.query("select * from the all_the_data")

now the notebook has examples where the results are the same, as are the queries. (as long as both users have access to the data source) but either user can run the notebook and get the same results. 

The kicker is how to prompt for the password securely... any ideas? 

Thanks

John

Matthias Bussonnier

unread,
Jun 19, 2017, 12:29:47 PM6/19/17
to jup...@googlegroups.com
Hello John,

When using the Python kernel you can use :

```
from getpass import getpass

password = getpass('prompt='What is your favorite color:')
```

And that should work in the notebook, replacing what you type with *
(always stored in the notebook as six stars, so leak not information).
then `password` will be what you expect it to be[1], see the python
documentation for getpass[2] as it is not a jupyter specific function.

Hope that helps.

--
Matthias
[1]: Likely blue. No, red.
[2]: https://docs.python.org/3/library/getpass.html
> --
> You received this message because you are subscribed to the Google Groups
> "Project Jupyter" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jupyter+u...@googlegroups.com.
> To post to this group, send email to jup...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jupyter/58e97afd-abfd-4b8a-97a8-7776e1262f11%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

John Omernik

unread,
Jun 19, 2017, 12:38:34 PM6/19/17
to Project Jupyter
That works perfectly. I validated that the text isn't stored in the notebook file and I am happy with the user interaction. Thank you!

John
Reply all
Reply to author
Forward
0 new messages