Sourcegraph DocsSourcegraph Docs
Changelog↗
Theme
  1. Docs
  2. self-hosted
  3. private-network

Private network configuration

Overview

A private network is your organization's secure, internal network space - separated from the public internet. Think of it as your company's own protected environment where internal systems can communicate safely, keeping your sensitive data and operations shielded from external access.

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.

The following Sourcegraph services initiate outbound connections to external services:

  • executor: Sourcegraph Executor batch change or precise indexing jobs may need to connect to services hosted within an organization's private network
  • frontend: The frontend service communicates externally when connecting to:
    • External auth providers
    • Sending telemetry data
    • Testing code host connections
    • Connecting to externally hosted Sourcegraph services
    • Connecting to external LLM providers with Cody
  • gitserver: Executes git commands against externally hosted code hosts
  • migrator: Connects to Postgres instances (which may be externally hosted) to process database migrations
  • worker: Sourcegraph Worker background jobs that may require establishing connections to services hosted within an organization's private network

Outbound access to Sourcegraph services

Sourcegraph makes requests to https://services.sourcegraph.com for key product capabilities.

To ensure a smooth experience, instances must allow outbound TCP port 443 to 34.36.231.254, with HTTPS and HTTP/2 gRPC support through your firewall or proxy. For hostname-based filtering, allow services.sourcegraph.com. Keep the hostname for TLS; do not replace it with the IP address. No inbound firewall rule is required.

HTTP proxy configuration

Sourcegraph services use the conventional HTTP_PROXY, HTTPS_PROXY, and NO_PROXY environment variables. Set them on the frontend and worker services, using the example override file for your deployment method:

  • Kubernetes Helm
  • Docker Compose

NO_PROXY must list every Sourcegraph service, so traffic between them does not go through the proxy. If services fail their health checks after adding the proxy, also add your cluster or Docker network CIDR ranges, for example 10.10.0.0/16,10.20.0.0/16.

Docker networking configuration

If there is an IP conflict on between the host network and the Docker network, you may need to configure the docker CIDR range in the docker-compose override file.

Additional information on docker networking can be found here:

  • Docker networking overview
  • Networking in Compose

Trusting TLS certificates using internal PKI

If your organization uses internal Public Key Infrastructure to manage TLS certificates, you may need to configure your Sourcegraph instance to trust your internal Root Certificate Authorities, so your instance can connect to other internal services, ex. code hosts, authentication providers, etc.

This method offers several advantages:

  • Works consistently across both Cloud and self-hosted deployments
  • Requires minimal configuration changes
  • Can be managed entirely through the web UI
  • Maintains certificates in a centralized location
  • Aligns with enterprise PKI best practices

The configuration process involves identifying and adding the public key of your organization's root Certificate Authority (CA) to Sourcegraph's advanced configuration. This approach is particularly efficient because:

  • Root CA certificates typically have long expiration periods (often measured in years)
  • A single root CA certificate usually covers multiple internal services
  • The configuration can be managed without container modifications or filesystem changes

Obtain the certificate chain

Use the OpenSSL command to extract the certificate chain from your code host. Replace the domain and port with your internal code host's values:

BASH
openssl s_client -showcerts -connect example.com:8443 \ -nameopt lname < /dev/null > certs.log 2>&1

Identify the root certificate

In the generated certs.log file, locate the root CA certificate:

Certificate chains typically include 3 certificates:

  • Root certificate authority (depth=2)
  • Intermediate certificate authority (depth=1)
  • Server (leaf) certificate (depth=0)

The last certificate in the chain will be the root CA certificate and will typically have:

  • A long expiration period (years)
  • A descriptive common name (e.g., "Enterprise Root CA 2023")

Example root CA certificate for github.com:

TEXT
Connecting to 140.82.114.3 depth=2 countryName=US, stateOrProvinceName=New Jersey, localityName=Jersey City, organizationName=The USERTRUST Network, commonName=USERTrust ECC Certification Authority verify return:1 depth=1 countryName=GB, stateOrProvinceName=Greater Manchester, localityName=Salford, organizationName=Sectigo Limited, commonName=Sectigo ECC Domain Validation Secure Server CA verify return:1 depth=0 commonName=github.com verify return:1 CONNECTED(00000005) --- ... 2 s:countryName=US, stateOrProvinceName=New Jersey, localityName=Jersey City, organizationName=The USERTRUST Network, commonName=USERTrust ECC Certification Authority i:countryName=GB, stateOrProvinceName=Greater Manchester, localityName=Salford, organizationName=Comodo CA Limited, commonName=AAA Certificate Services a:PKEY: id-ecPublicKey, 384 (bit); sigalg: RSA-SHA384 v:NotBefore: Mar 12 00:00:00 2019 GMT; NotAfter: Dec 31 23:59:59 2028 GMT -----BEGIN CERTIFICATE----- MII...c= -----END CERTIFICATE-----

Format the certificate

Once you've identified the root CA certificate:

  • Extract the certificate content including the BEGIN and END markers.
  • Format the certificate for the advanced configuration:
    • Replace newlines with \n characters
    • Enclose the entire certificate in double quotes
    • Add a trailing comma

The following command can be used to easily obtain, extract, and format the root certificate from a 3 certificate chain. Be sure to adjust the hostname and port to match your internal code host. If your certificate chain is of a different depth, adjust the awk command accordingly. awk '/BEGIN CERTIFICATE/{i++} i==X'

BASH
openssl s_client -showcerts -connect example.com:8443 \ -nameopt lname < /dev/null 2>&1 \ | awk '/BEGIN CERTIFICATE/,/END CERTIFICATE/' \ | awk '/BEGIN CERTIFICATE/{i++} i==2' \ | awk '{printf "%s\\n", $0}' | sed 's/\\n$//' \ | awk '{print "\"" $0 "\","}'

Add the certificate to the advanced configuration

Add the formatted certificate to your Sourcegraph advanced configuration.

JSON
{ "tls.external": { "certificates": [ "-----BEGIN CERTIFICATE-----\naZ...==\n-----END CERTIFICATE-----" ] } }

For organizations with multiple root CAs (uncommon), additional certificates can be added to the array:

JSON
{ "tls.external": { "certificates": [ "-----BEGIN CERTIFICATE-----\naZ...==\n-----END CERTIFICATE-----", "-----BEGIN CERTIFICATE-----\nMI...I7\n-----END CERTIFICATE-----" ] } }

Validation of certificate configuration

These steps confirms that configuring the root CA certificate through tls.external is sufficient for all standard Sourcegraph operations that require secure connections to internal services.

  1. Code host connectivity

    • Verify using the UI "Test Connection" button
    • Trigger validate completed sync jobs
      Executed by: frontend service
  2. Repository operations

    • Verify individual repository synchronization
    • Verify cloning operations
      Executed by: gitserver service
  3. Permission synchronization

    • Verify user-centric permission sync jobs
      Executed by: worker service

Repository-centric permission sync jobs are expected to behave identically, as they use the same underlying TLS configuration mechanisms.

Recommended best practices

  • Only include root CA certificates, not intermediate or server certificates.
  • Avoid using insecureSkipVerify: true and add TLS certificates if needed, as it bypasses important security checks.
  • Document certificate sources and expiration dates in your organization's runbooks.
  • Plan for certificate rotation well before root CA expiration.
  • Most enterprises use a single root CA, so adding one certificate often covers all internal services.
  • Keep the certificate list minimal and well-maintained.

On this page

  1. Private network configuration

    1. Overview
    1. Outbound access to Sourcegraph services
    1. HTTP proxy configuration
    1. Docker networking configuration
    1. Trusting TLS certificates using internal PKI

Edit this page on GitHub
View as Markdown