Skip to content

Commit adf2bb4

Browse files
authored
Merge pull request #1155 from TomasBeuzen/cors_setup
2 parents 2b921f1 + d764f8f commit adf2bb4

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

doc/cors.rst

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
Enabling CORS
2+
=============
3+
4+
Cross-Origin Resource Sharing (CORS) is a mechanism that gives a
5+
web application running at one origin, access to resources from a
6+
different origin. For security reasons, browsers restrict these
7+
"cross-origin" requests by default.
8+
9+
In the context of a BinderHub deployment, CORS is relevant when you
10+
wish to leverage binder as a computing backend for a web application
11+
hosted at some other domain. For example, the amazing libraries
12+
`Juniper <https://github.com/ines/juniper>`_ and
13+
`Thebe <https://github.com/executablebooks/thebe>`_ leverage binder as
14+
a computing backend to facilitate live, interactive coding, directly
15+
within a static HTML webpage. For this functionality, CORS must be
16+
enabled.
17+
18+
Adjusting BinderHub config to enable CORS
19+
-----------------------------------------
20+
21+
As mentioned above, for security reasons, CORS is not enabled by
22+
default for BinderHub deployments. To enable CORS we need to add
23+
additional HTTP headers to allow our BinderHub deployment to be
24+
accessed from a different origin. This is as simple as adding the
25+
following to your ``config.yaml``:
26+
27+
.. code:: yaml
28+
29+
cors: &cors
30+
allowOrigin: '*'
31+
32+
jupyterhub:
33+
custom:
34+
cors: *cors
35+
36+
For example, if you're following on from the previous section
37+
:doc:`../https`, your ``config.yaml`` might look like this:
38+
39+
.. code:: yaml
40+
41+
config:
42+
BinderHub:
43+
hub_url: https://<jupyterhub-URL> # e.g. https://hub.binder.example.com
44+
45+
cors: &cors
46+
allowOrigin: '*'
47+
48+
jupyterhub:
49+
custom:
50+
cors: *cors
51+
ingress:
52+
enabled: true
53+
hosts:
54+
- <jupyterhub-URL> # e.g. hub.binder.example.com
55+
annotations:
56+
kubernetes.io/ingress.class: nginx
57+
kubernetes.io/tls-acme: "true"
58+
cert-manager.io/issuer: letsencrypt-production
59+
https:
60+
enabled: true
61+
type: nginx
62+
tls:
63+
- secretName: <jupyterhub-URL-with-dashes-instead-of-dots>-tls # e.g. hub-binder-example-com-tls
64+
hosts:
65+
- <jupyterhub-URL> # e.g. hub.binder.example.com
66+
67+
ingress:
68+
enabled: true
69+
hosts:
70+
- <binderhub-URL> # e.g. binder.example.com
71+
annotations:
72+
kubernetes.io/ingress.class: nginx
73+
kubernetes.io/tls-acme: "true"
74+
cert-manager.io/issuer: letsencrypt-production
75+
https:
76+
enabled: true
77+
type: nginx
78+
tls:
79+
- secretName: <binderhub-URL-with-dashes-instead-of-dots>-tls # e.g. binder-example-com-tls
80+
hosts:
81+
- <binderhub-URL> # e.g. binder.example.com
82+
83+
Once you've adjusted ``config.yaml`` to enable CORS, apply your changes
84+
with::
85+
86+
helm upgrade <namespace> jupyterhub/binderhub --version=<version> -f secret.yaml -f config.yaml
87+
88+
It may take ~10 minutes for the changes to take effect.

doc/customization/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ best-practices in debugging issues.
1313
../debug
1414
../authentication
1515
../https
16+
../cors

0 commit comments

Comments
 (0)