Skip to content

Commit 3a566d0

Browse files
author
Yves Hilpisch
committed
Added password & encryption.
1 parent f8bd457 commit 3a566d0

8 files changed

Lines changed: 114 additions & 16 deletions

File tree

README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
This repository contains a few small files that allow to easily deploy Python (cf. http://python.org) and Jupyter Notebook (cf. http://jupyter.org) in the cloud.
44

5-
It all works (apart from the parallel computation example) even on the smallest **DigitalOcean droplet** (cf. https://www.digitalocean.com/?refcode=fbe512dd3dac).
5+
It all works even on the smallest **DigitalOcean droplet** (cf. https://m.do.co/c/fbe512dd3dac) which currently costs 5 USD per month with 1 CPU core, 512 MB of RAM and 20 GB of SSD storage.
66

7-
When setting up such a droplet it is recommended to use the latest version of **Ubuntu**.
7+
When setting up such a droplet it is recommended to use a current version of **Ubuntu**.
88

99
I assume that you have **cloned the repository** to your local machine (Linux or Mac):
1010

@@ -16,9 +16,9 @@ git clone --depth=1 https://github.com/yhilpisch/cloud-python
1616

1717
If you do not have a **DigitalOcean account** yet, generate one here
1818

19-
https://www.digitalocean.com/?refcode=fbe512dd3dac
19+
https://m.do.co/c/fbe512dd3dac
2020

21-
You will start with 10 USD worth of compute power (= e.g. 2 monthly fees for the smallest droplet).
21+
You will start with 10 USD worth of compute power (= e.g. 2 monthly fees for the smallest droplet) although you'll only get charged the hours your droplet is alive.
2222

2323
Now **create a droplet** giving it a name like "cloud-python" and chosing the size, location and operating system (e.g. Ubuntu 14.04).
2424

@@ -29,17 +29,21 @@ When you have created the droplet, you are redirected to the droplet overview pa
2929
Then navigate to the **repository folder** and do:
3030

3131
```
32-
cd path-to/cloud-python
32+
cd your-path-to/cloud-python
3333
bash setup_server.sh THE-IP-ADDRESS
3434
```
3535

36-
The setup might take a while. The last step in the setup fires up a **Jupyter Notebook** server on the **port 8888**. You can access it in the browser under
36+
The setup might take a while (about 4 minutes; you'll see the progress on the shell). The last step in the setup fires up a **Jupyter Notebook** server on the **port 8888**. You can access it in the browser under
3737

3838
```
39-
http://THE-IP-ADDRESS:8888
39+
https://THE-IP-ADDRESS:8888
4040
```
4141

42-
You can now click on the example notebooks and play around.
42+
There is **SSL encryption** enabled which uses by default the certificate files as provided in the repo (you should replace them by your own; see the comments in the respective Jupyter Notebook configuration file). This feature might require you to add a security exception in your browser due to the nature of the certificate files used.
43+
44+
There is also **password protection** enabled (the password is by default **jupyter**). You should also replace the password hash key in the Jupyter Notebook config file by one of your own (again see the comments in the configuration file itself).
45+
46+
After a successful login, you can now click on the example notebooks and play around.
4347

4448
## Flask Web app
4549

@@ -63,7 +67,7 @@ http://THE-IP-ADDRESS:7777
6367

6468
## Security
6569

66-
Note that all this is **really insecure**. All is run as root user, no password protection or encryption is in place. It is only for illustration purposes. However, security features can easily be added to the set-up.
70+
Note that all this is quite **insecure**. All is run as root user and there is only password protection and encryption for the notebook server in place. It is only for illustration purposes. However, additional security features (e.g. for the Flask app) can easily be added to the set-up.
6771

6872
## datapark.io
6973

@@ -82,14 +86,16 @@ The code in this repository comes with no representations or warranties, to the
8286
http://tpq.io \| team@tpq.io \|
8387
http://twitter.com/dyjh
8488

89+
**Python for Finance Training** \| http://training.tpq.io
90+
8591
**datapark.io** \| http://datapark.io
8692

8793
**Quant Platform** \| http://quant-platform.com
8894

89-
**Derivatives Analytics with Python (Wiley Finance)** \|
90-
http://derivatives-analytics-with-python.com
91-
9295
**Python for Finance (O'Reilly)** \|
9396
http://python-for-finance.com
9497

98+
**Derivatives Analytics with Python (Wiley Finance)** \|
99+
http://derivatives-analytics-with-python.com
100+
95101
**For Python Quants Conference** \| http://fpq.io

cloud_recipe.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
STEPS TO SET-UP CLOUD INSTANCE
2+
WITH JUPYTER NOTEBOOK
3+
4+
Generate private/public RSA key pair
5+
------------------------------------
6+
ssh-keygen -t rsa
7+
copy keys to ~/.ssh
8+
9+
10+
Set-up DigitalOcean account
11+
---------------------------
12+
https://m.do.co/c/fbe512dd3dac
13+
(if you register via this link, you get 10 USD bonus)
14+
15+
16+
Create a Droplet (provide public RSA key):
17+
------------------------------------------
18+
provide public RSA key during creation
19+
copy IP-ADDRESS after creation
20+
21+
22+
On the shell do:
23+
----------------
24+
git clone http://github.com/yhilpisch/cloud-python
25+
cd cloud-python
26+
bash setup_server.sh IP-ADDRESS (replace with your address!!)
27+
28+
29+
Running a Jupyter Notebook server:
30+
----------------------------------
31+
http://jupyter-notebook.readthedocs.io/en/latest/public_server.html

generate_rsa_ssl.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mykey.key -out mycert.pem

jupyter_notebook_config.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# set options for certfile, ip, password, and toggle off browser auto-opening
2+
#
3+
# execute the bash script generate_rsa_ssl.sh to generate your certificate files
4+
# replace the following file names (and files used) by your choice/files
5+
c.NotebookApp.certfile = u'/root/mycert.pem'
6+
c.NotebookApp.keyfile = u'/root/mykey.key'
7+
8+
# set ip to '*' to bind on all interfaces (ips) for the public server
9+
c.NotebookApp.ip = '*'
10+
11+
# to generate a password hash, do in Python:
12+
#
13+
# from notebook.auth import passwd
14+
# passwd()
15+
#
16+
# here: 'jupyter' as password
17+
# replace the hash key with the one for your password
18+
c.NotebookApp.password = 'sha1:bb5e01be158a:99465f872e0613a3041ec25b7860175f59847702'
19+
20+
c.NotebookApp.open_browser = False
21+
22+
# it is a good idea to set a known, fixed default port for server access
23+
c.NotebookApp.port = 8888

mycert.pem

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIICfDCCAeWgAwIBAgIJAKgmQTbnwNzkMA0GCSqGSIb3DQEBCwUAMFcxCzAJBgNV
3+
BAYTAkRFMRMwEQYDVQQIDApTb21lLVN0YXRlMQ0wCwYDVQQHDARob21lMQ0wCwYD
4+
VQQKDARBQ01FMRUwEwYDVQQDDAxpbGx1c3RyYXRpb24wHhcNMTYwNjI3MDY1MDI4
5+
WhcNMTcwNjI3MDY1MDI4WjBXMQswCQYDVQQGEwJERTETMBEGA1UECAwKU29tZS1T
6+
dGF0ZTENMAsGA1UEBwwEaG9tZTENMAsGA1UECgwEQUNNRTEVMBMGA1UEAwwMaWxs
7+
dXN0cmF0aW9uMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCpPlaFJbnu/15K
8+
9ZL1Om9UeI67DyTYHcxoAF3T+9jMzRojiSdV/i/haKCzX9ar5Yf8HnIPbUWgzTHx
9+
DBR66izlHhB6KbRNqI9hrYe3MrWlpOGzYTEosRwa8YjNW+kCVVK0cz43SjUY9qGC
10+
Okxl9FqjabSIhNGq9WC+n+sse/LbvQIDAQABo1AwTjAdBgNVHQ4EFgQUbLZseq/j
11+
sE0FO+8js+xgpIQWFNAwHwYDVR0jBBgwFoAUbLZseq/jsE0FO+8js+xgpIQWFNAw
12+
DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOBgQA2zRh2gK5ZympJ+0/e7FZg
13+
6GHB0GnJlXvuTW47rsGspYYv0yfuUSyK5/HnIJXbWY4F7xmhbEVkAGc0d8d8uVHu
14+
WuWVBqFfUwkG/mKuLdq1O2X108+siaP8arDq5hbGeQb0KDl7MIvfHB6tZYrjXjIU
15+
TN1GlKASd6OsWbMbPs8zHA==
16+
-----END CERTIFICATE-----

mykey.key

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-----BEGIN PRIVATE KEY-----
2+
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKk+VoUlue7/Xkr1
3+
kvU6b1R4jrsPJNgdzGgAXdP72MzNGiOJJ1X+L+FooLNf1qvlh/wecg9tRaDNMfEM
4+
FHrqLOUeEHoptE2oj2Gth7cytaWk4bNhMSixHBrxiM1b6QJVUrRzPjdKNRj2oYI6
5+
TGX0WqNptIiE0ar1YL6f6yx78tu9AgMBAAECgYApAD4rsZES8nDgjg/VMxvnhfFm
6+
JewSI13y0CvrADdsnj+33jFWZucon5VW/1/dcxT3olSVoi5dH3j64adQg8zuK90E
7+
NJq32G6uw7fMVlAJjIIhyOPljBo3UFtVpsZHS1nVqYkM6zr5oT+AoBQVCVMAnDNq
8+
45PM1/N+AeTBYJ+IYQJBANoDx6Hwqs5OpZtejv8prSxKJIdwAEN89Kf/U9rJ6yjq
9+
jCs/7vl2csijDBbnhxEPGIlIuTnWwEHcHyWlYnlDFeUCQQDGuzCPrqrxwMm0kXpm
10+
REUEz6Hkg6uUmNrA4EUNKLtF3VBTwJW89Eu4fyH2PE0KSDz2YaqUJ9jz6WX5MCV5
11+
v1D5AkEAql1bykt0XmWM+j3JRtI9lieWJhQ60II7+XAICifR0RaAVGfQijaqeekX
12+
0Go63PTL+rPOsskDUjP+Tv/PVO08lQJAW50HsfUPkQsS8U7vYh2uw50EQNgCTSp6
13+
DdhVfM9+JaL02Oc7IDRug8r32Q/LZCYRFHPJsyr7dNXv0IRFgm6T4QJAKFOjDtZ3
14+
hCgG3dtnwyinPz3j6Qh4H/nmzYU8uxTsJ3+WEtlhlP3eKgyr3sb12yVcaZd/29Tk
15+
fm06t3CxTHaSEQ==
16+
-----END PRIVATE KEY-----

python-setup.sh renamed to python_setup.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ conda install -y matplotlib
2626
conda install -y pandas
2727
conda install -y seaborn
2828
conda install -y pandas-datareader
29+
conda install -y pytables
30+
conda install -y scikit-learn
2931

3032
pip install --upgrade pip
3133
pip install plotly
3234
pip install cufflinks
3335
pip install flask-wtf
3436

35-
# COPYING FILES TO WORKING DIRECTORY
37+
# COPYING FILES
38+
mkdir ${HOME}/.jupyter
39+
mv ${HOME}/jupyter_notebook_config.py ${HOME}/.jupyter/
3640
mkdir ${HOME}/notebook
3741
mv ${HOME}/*.ipynb ${HOME}/notebook
3842
rm ${HOME}/*.ipynb
@@ -41,4 +45,4 @@ rm ${HOME}/stock_int.zip
4145
cd ${HOME}/notebook
4246

4347
# STARTING JUPYTER NOTEBOOK
44-
jupyter notebook --ip=0.0.0.0 --no-browser --notebook-dir=$HOME/notebook
48+
jupyter notebook --notebook-dir=$HOME/notebook

setup_server.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ MASTER_IP=$1
1212

1313
IDENTITY=~/.ssh/digital_ocean # change to your identity file
1414

15-
scp python-setup.sh root@${MASTER_IP}:
15+
scp python_setup.sh root@${MASTER_IP}:
16+
scp mycert.pem mykey.key jupyter_notebook_config.py root@${MASTER_IP}:
1617
scp *.ipynb root@${MASTER_IP}:
1718
scp *.zip root@${MASTER_IP}:
18-
ssh root@${MASTER_IP} bash /root/python-setup.sh
19+
ssh root@${MASTER_IP} bash /root/python_setup.sh

0 commit comments

Comments
 (0)