Skip to content

Commit 800d345

Browse files
authored
Merge branch 'main' into upgrade
2 parents 389c853 + 3133a53 commit 800d345

File tree

1 file changed

+180
-43
lines changed

1 file changed

+180
-43
lines changed

docs/admin/config/private-network.mdx

Lines changed: 180 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
11
# Private network configuration
22

3-
A **private network** refers to a secure network environment segregated from the public internet, designed to facilitate internal communications and operations within an organization. This network setup restricts external access, enhancing security and control over data flow by limiting exposure to external threats and unauthorized access.
4-
5-
When deploying self-hosted Sourcegraph instances in private networks with specific compliance and policy requirements, additional configuration may be required to ensure all networking features function correctly. The reasons for applying the following configuration options depend on the specific functionality of the Sourcegraph service and the unique network and infrastructure requirements of the organization.
6-
7-
The following is a list of Sourcegraph services and how and when each initiates outbound connections to external services:
8-
9-
- **executor**: Sourcegraph [Executor](../executors) batch change or precise indexing jobs may need to connect to services hosted within an organization's private network
10-
- **frontend**: The frontend service communicates externally when connecting to external [auth providers](../auth), sending [telemetry data](../pings), testing code host connections, and connecting to [externally hosted](../external_services) Sourcegraph services
3+
## Overview
4+
A private network is your organization's secure, internal network space - separated from the public internet.
5+
Think of it as your company's own protected environment where internal systems can communicate safely,
6+
keeping your sensitive data and operations shielded from external access.
7+
8+
When deploying self-hosted Sourcegraph instances in private networks with specific compliance and policy requirements,
9+
additional configuration may be required to ensure all networking features function correctly. The reasons for applying the following configuration options depend on the specific functionality of the Sourcegraph service and the unique network and infrastructure requirements of the organization.
10+
11+
The following is a list of Sourcegraph services that initiate outbound connections to external services. Sourcegraph services not included in this list can be assumed to only connect to services within the Sourcegraph deployment's network segment:
12+
- **executor**: Sourcegraph [Executor](../executors) batch change or precise indexing jobs may need to connect to
13+
services hosted within an organization's private network
14+
- **frontend**: The frontend service communicates externally when connecting to:
15+
* External [auth providers](../auth)
16+
* Sending [telemetry data](../pings)
17+
* Testing [code host connections](../code_hosts)
18+
* Connecting to [externally hosted](../external_services) Sourcegraph services
19+
* Connecting to external [LLM providers](../../cody/capabilities/supported-models) with Cody
1120
- **gitserver**: Executes git commands against externally hosted [code hosts](../external_service)
1221
- **migrator**: Connects to Postgres instances (which may be [externally hosted](../external_services/postgres)) to process database migrations
1322
- **repo-updater**: Communicates with [code hosts](../external_service) APIs to coordinate repository synchronization
14-
- **worker**: Sourcegraph [Worker](../workers) run various background jobs that may require establishing connections to services hosted within an organization's private network
23+
- **worker**: Sourcegraph [Worker](../workers) run various background jobs that may require establishing connections to
24+
services hosted within an organization's private network
1525

1626
## HTTP proxy configuration
1727

18-
All Sourcegraph services respect the conventional `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` environment variables for routing Sourcegraph client application HTTP traffic through a proxy server. The steps for configuring proxy environment variables will depend on your Sourcegraph deployment method.
28+
All Sourcegraph services respect the conventional `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` environment variables for
29+
routing Sourcegraph client application HTTP traffic through a proxy server. The steps for configuring proxy environment
30+
variables will depend on your Sourcegraph deployment method.
1931

2032
### Kubernetes Helm
2133

@@ -32,48 +44,173 @@ executor|frontend|gitserver|migrator|repo-updater|worker:
3244
value: "blobstore,codeinsights-db,codeintel-db,sourcegraph-frontend-internal,sourcegraph-frontend,github-proxy,gitserver,grafana,indexed-search-indexer,indexed-search,jaeger-query,pgsql,precise-code-intel-worker,prometheus,redis-cache,redis-store,repo-updater,searcher,symbols,syntect-server,worker-executors,worker,cloud-sql-proxy,localhost,127.0.0.1,.svc,.svc.cluster.local,kubernetes.default.svc"
3345
```
3446
35-
<Callout type="warning">Failure to configure `NO_PROXY` correctly can cause the proxy configuration to interfere with local networking between internal Sourcegraph services.</Callout>
47+
### Docker Compose
3648
37-
## Using private CA root certificates
38-
Some organizations maintain a private Certificate Authority (CA) for issuing certificates within their private network. When Sourcegraph connects to TLS encrypted service using a self-signed certificate that it does not trust, you will observe an `x509: certificate signed by unknown authority` error message in logs.
49+
Add the proxy environment variables your docker compose override file.
50+
```yaml
51+
services:
52+
<service-name>:
53+
environment:
54+
- HTTP_PROXY=http://proxy.example.com:8080
55+
- HTTPS_PROXY=http://proxy.example.com:8080
56+
- NO_PROXY='blobstore,caddy,cadvisor,codeintel-db,codeintel-db-exporter,codeinsights-db,codeinsights-db-exporter,sourcegraph-frontend-0,sourcegraph-frontend-internal,gitserver-0,grafana,migrator,node-exporter,otel-collector,pgsql,pgsql-exporter,precise-code-intel-worker,prometheus,redis-cache,redis-store,repo-updater,searcher-0,symbols-0,syntect-server,worker,zoekt-indexserver-0,zoekt-webserver-0,localhost,127.0.0.1'
57+
```
3958
40-
In order for Sourcegraph to respect an organization's self-signed certificates, the private CA root certificate(s) will need to be appended to Sourcegraph's trusted CA root certificate list in `/etc/ssl/certs/ca-certificates.crt`.
59+
<Callout type="warning">Failure to configure `NO_PROXY` correctly can cause the proxy configuration to interfere with
60+
local networking between internal Sourcegraph services.</Callout>
4161

42-
### Configuring sourcegraph-frontend to recognize private CA root certificates
43-
The following details the process for setting up the sourcegraph-frontend to acknowledge and trust a private CA root certificate for Sourcegraph instances deployed using [Helm](../deploy/kubernetes/helm). For any other Sourcegraph service that needs to trust an organization's private CA root certificate (including gitserver, repo-updater, or migrator), similar steps will need to be followed.
62+
## Docker networking configuration
63+
If there is an IP conflict on between the host network and the Docker network, you may need to configure the docker CIDR
64+
range in the docker-compose override file.
4465

45-
1. Copy out the existing `ca-certificates.crt` file from the sourcegraph-frontend container:
46-
```sh
47-
kubectl cp $(kubectl get pod -l app=sourcegraph-frontend -o jsonpath='{.items[0].metadata.name}'):/etc/ssl/certs/ca-certificates.crt sourcegraph-frontend-ca-certificates.crt
48-
```
49-
2. Concatenate the private CA root certificate to the `sourcegraph-frontend-ca-certificates.crt` file:
50-
```sh
51-
cat sourcegraph-frontend-ca-certificates.crt {private-ca-certificate.crt file} > ca-certificates.crt
66+
Additional information on docker networking can be found here:
67+
* [Docker networking overview](https://docs.docker.com/network/)
68+
* [Networking in Compose](https://docs.docker.com/compose/how-tos/networking/)
69+
70+
## Trusting TLS certificates using internal PKI
71+
72+
If your organization uses internal Public Key Infrastructure to manage TLS certificates, you may need to configure your
73+
Sourcegraph instance to trust your internal Root Certificate Authorities, so your instance can connect to other internal
74+
services, ex. code hosts, authentication providers, etc.
75+
76+
This method offers several advantages:
77+
- Works consistently across both Cloud and self-hosted deployments
78+
- Requires minimal configuration changes
79+
- Can be managed entirely through the web UI
80+
- Maintains certificates in a centralized location
81+
- Aligns with enterprise PKI best practices
82+
83+
The configuration process involves identifying and adding the public key of your organization's root Certificate
84+
Authority (CA) to Sourcegraph's site configuration. This approach is particularly efficient because:
85+
* Root CA certificates typically have long expiration periods (often measured in years)
86+
* A single root CA certificate usually covers multiple internal services
87+
* The configuration can be managed without container modifications or filesystem changes
88+
89+
### Obtain the certificate chain
90+
Use the OpenSSL command to extract the certificate chain from your code host.
91+
Replace the domain and port with your internal code host's values:
92+
93+
```bash
94+
openssl s_client -showcerts -connect example.com:8443 \
95+
-nameopt lname < /dev/null > certs.log 2>&1
5296
```
53-
3. Create a new Kubernetes ConfigMap containing the concatenated `ca-certificates.crt` file:
54-
```sh
55-
kubectl create configmap sourcegraph-frontend-ca-certificates --from-file=ca-certificates.crt
97+
98+
### Identify the root certificate
99+
In the generated `certs.log` file, locate the root CA certificate:
100+
101+
Certificate chains typically include 3 certificates:
102+
103+
* Root certificate authority (depth=2)
104+
* Intermediate certificate authority (depth=1)
105+
* Server (leaf) certificate (depth=0)
106+
107+
The last certificate in the chain will be the root CA certificate and will typically have:
108+
109+
* A long expiration period (years)
110+
* A descriptive common name (e.g., "Enterprise Root CA 2023")
111+
112+
Example root CA certificate for github.com:
113+
114+
```text
115+
Connecting to 140.82.114.3
116+
depth=2 countryName=US, stateOrProvinceName=New Jersey, localityName=Jersey City, organizationName=The USERTRUST Network, commonName=USERTrust ECC Certification Authority
117+
verify return:1
118+
depth=1 countryName=GB, stateOrProvinceName=Greater Manchester, localityName=Salford, organizationName=Sectigo Limited, commonName=Sectigo ECC Domain Validation Secure Server CA
119+
verify return:1
120+
depth=0 commonName=github.com
121+
verify return:1
122+
CONNECTED(00000005)
123+
---
124+
...
125+
2 s:countryName=US, stateOrProvinceName=New Jersey, localityName=Jersey City, organizationName=The USERTRUST Network, commonName=USERTrust ECC Certification Authority
126+
i:countryName=GB, stateOrProvinceName=Greater Manchester, localityName=Salford, organizationName=Comodo CA Limited, commonName=AAA Certificate Services
127+
a:PKEY: id-ecPublicKey, 384 (bit); sigalg: RSA-SHA384
128+
v:NotBefore: Mar 12 00:00:00 2019 GMT; NotAfter: Dec 31 23:59:59 2028 GMT
129+
-----BEGIN CERTIFICATE-----
130+
MII...c=
131+
-----END CERTIFICATE-----
56132
```
57-
4. Mount the `sourcegraph-frontend-ca-certificates` ConfigMap to the sourcegraph-frontend Deployment:
58-
```yaml
59-
frontend:
60-
extraVolumes:
61-
- name: ca-certificates
62-
configMap:
63-
name: sourcegraph-frontend-ca-certificates
64-
extraVolumeMounts:
65-
- name: ca-certificates
66-
mountPath: /etc/ssl/certs/
133+
134+
### Format the certificate
135+
Once you've identified the root CA certificate:
136+
137+
* Extract the certificate content including the BEGIN and END markers.
138+
* Format the certificate for the site configuration:
139+
* Replace newlines with \n characters
140+
* Enclose the entire certificate in double quotes
141+
* Add a trailing comma
142+
143+
144+
The following command can be used to easily obtain, extract, and format the root certificate from a 3 certificate chain.
145+
Be sure to adjust the hostname and port to match your internal code host. If your certificate chain is of a different
146+
depth, adjust the awk command accordingly. `awk '/BEGIN CERTIFICATE/{i++} i==X'`
147+
```bash
148+
openssl s_client -showcerts -connect example.com:8443 \
149+
-nameopt lname < /dev/null 2>&1 \
150+
| awk '/BEGIN CERTIFICATE/,/END CERTIFICATE/' \
151+
| awk '/BEGIN CERTIFICATE/{i++} i==2' \
152+
| awk '{printf "%s\\n", $0}' | sed 's/\\n$//' \
153+
| awk '{print "\"" $0 "\","}'
67154
```
68155

69-
Once deployed, you should see the private CA root certificate in the sourcegraph-frontend container's `/etc/ssl/certs/ca-certificates.crt` file.
70-
```sh
71-
kubectl exec -it $(kubectl get pod -l app=sourcegraph-frontend -o jsonpath='{.items[0].metadata.name}') -- tail /etc/ssl/certs/ca-certificates.crt
156+
### Add the certificate to the site configuration
157+
Add the formatted certificate to your Sourcegraph site configuration.
158+
159+
```json
160+
{
161+
"experimentalFeatures": {
162+
"tls.external": {
163+
"certificates": [
164+
"-----BEGIN CERTIFICATE-----\naZ...==\n-----END CERTIFICATE-----"
165+
]
166+
}
167+
}
168+
}
72169
```
73170

74-
You can verify that the self-signed certificate is trusted using `curl`:
75-
```sh
76-
kubectl exec -it $(kubectl get pod -l app=sourcegraph-frontend -o jsonpath='{.items[0].metadata.name}') -- curl -v {https://internal.service.example.com} > /dev/null
171+
For organizations with multiple root CAs (uncommon), additional certificates can be added to the array:
172+
```json
173+
{
174+
"experimentalFeatures": {
175+
"tls.external": {
176+
"certificates": [
177+
"-----BEGIN CERTIFICATE-----\naZ...==\n-----END CERTIFICATE-----",
178+
"-----BEGIN CERTIFICATE-----\nMI...I7\n-----END CERTIFICATE-----"
179+
]
180+
}
181+
}
182+
}
77183
```
78184

79-
<Callout type="note">It is recommended to repeat these steps on a regular cadence to ensure that Sourcegraph's CA root certificate list stays up to date.</Callout>
185+
### Validation of certificate configuration
186+
These steps confirms that configuring the root CA certificate through `tls.external` is sufficient for all standard
187+
Sourcegraph operations that require secure connections to internal services.
188+
189+
1. **Code host connectivity**
190+
- Verify using the UI "Test Connection" button
191+
- Trigger validate completed sync jobs
192+
<Callout type="info">Executed by: frontend service</Callout>
193+
194+
2. **Repository operations**
195+
- Verify individual repository synchronization
196+
- Verify cloning operations
197+
<Callout type="info">Executed by: gitserver service</Callout>
198+
199+
3. **Permission synchronization**
200+
- Verify user-centric permission sync jobs
201+
<Callout type="info">Executed by: worker service</Callout>
202+
203+
<Callout type="note">
204+
Repository-centric permission sync jobs are expected to behave identically, as they use the same underlying TLS configuration mechanisms.
205+
</Callout>
206+
207+
### Recommended best practices
208+
* Only include root CA certificates, not intermediate or server certificates.
209+
* Avoid using `insecureSkipVerify: true` and add TLS certificates if needed, as it bypasses important security checks.
210+
* Document certificate sources and expiration dates in your organization's runbooks.
211+
* Plan for certificate rotation well before root CA expiration.
212+
* Most enterprises use a single root CA, so adding one certificate often covers all internal services.
213+
* Keep the certificate list minimal and well-maintained.
214+
215+
216+

0 commit comments

Comments
 (0)