You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+65-8Lines changed: 65 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,14 +19,71 @@ Docker image `sourcegraph/lang-python` from Docker Hub.
19
19
20
20
### 🔐 Secure deployment 🔐
21
21
22
-
We recommend deploying the language server behind an auth proxy or firewall and
23
-
treating it like an authenticated user because anyone that connects to the
24
-
language server can access resources such as private code that the language
25
-
server has access to.
26
-
27
-
Make sure you set `python.sourcegraphUrl` to the URL that the language
28
-
server should use to reach Sourcegraph, which is likely different from the URL
29
-
that end users use.
22
+
If you have private code, we recommend deploying the language server behind an
23
+
auth proxy (such as the example below using HTTP basic authentication in NGINX), a firewall, or a VPN.
24
+
25
+
### HTTP basic authentication
26
+
27
+
You can prevent unauthorized access to the language server by enforcing HTTP basic authentication in nginx, which comes with the sourcegraph/server image. At a high level, you'll create a secret then put it in both the nginx config and in your Sourcegraph global settings so that logged-in users are authenticated when their browser makes requests to the Python language server.
28
+
29
+
Here's how to set it up:
30
+
31
+
Create an `.htpasswd` file in the Sourcegraph config directory with one entry:
Add a location directive the [nginx.conf](https://docs.sourcegraph.com/admin/nginx) that will route requests to the Python language server:
41
+
42
+
```nginx
43
+
...
44
+
http {
45
+
...
46
+
server {
47
+
...
48
+
location / {
49
+
...
50
+
}
51
+
52
+
location /python {
53
+
proxy_pass http://host.docker.internal:4288;
54
+
proxy_http_version 1.1;
55
+
proxy_set_header Upgrade $http_upgrade;
56
+
proxy_set_header Connection "Upgrade";
57
+
58
+
auth_basic "basic authentication is required to access the language server";
59
+
auth_basic_user_file /etc/sourcegraph/.htpasswd;
60
+
}
61
+
}
62
+
}
63
+
```
64
+
65
+
- If you're running the quickstart on Linux, change `host.docker.internal` to the output of `ip addr show docker0 | grep -Po 'inet \K[\d.]+'`.
66
+
- If you're using [Kubernetes](#using-kubernetes) (e.g. [deploy-sourcegraph](https://github.com/sourcegraph/deploy-sourcegraph)), change `host.docker.internal` to `lang-python`.
- If you're running the quickstart on Linux, change `host.docker.internal` to the output of `ip addr show docker0 | grep -Po 'inet \K[\d.]+'`.
78
+
- If you're using [Kubernetes](#using-kubernetes) (e.g. [deploy-sourcegraph](https://github.com/sourcegraph/deploy-sourcegraph)):
79
+
-`python.serverUrl` is the address of the Python language server from the perspective of a user's browser (e.g. https://sourcegraph.example.com/python)
80
+
-`python.sourcegraphUrl` is the address of the Sourcegraph instance from the perspective of the Python language server (e.g. http://sourcegraph-frontend:30080)
81
+
82
+
Finally, restart the sourcegraph/server container (or nginx deployment if deployed to Kubernetes) to pick up the configuration change.
83
+
84
+
After deploying the language server, unauthenticated access to `http://localhost:7080/python` (or https://sourcegraph.example.com/python) should be blocked, but code intelligence should work when you're logged in.
85
+
86
+
You can always revoke the `PASSWORD` by deleting the `.htpasswd` file and restarting nginx.
0 commit comments