Bazel
build tools
proxy settings
developer tools
software development

Bazel build behind a corporate proxy: env vars, truststore and mirrors

Codemia Knowledge Hub ·

Bazel can fail behind a corporate proxy even when ordinary command-line tools work. Usually external repository fetches do not inherit the proxy settings, a TLS-intercepting proxy breaks certificate validation, or the Java runtime Bazel uses is configured differently from your shell. Treat Bazel downloads, the host environment and repository rules as one connected network path.

Where proxy problems show up

Bazel may start fine and fail later during dependency resolution. Common failure points:

  • http_archive or git_repository fetches
  • remote module downloads
  • registry access for external dependencies
  • Java-based HTTPS requests made by Bazel internals

So a successful curl from the shell does not prove Bazel is configured correctly.

Set the standard proxy environment variables

First, export the proxy variables in the shell that launches Bazel.

bash
export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=http://proxy.example.com:8080
export NO_PROXY=localhost,127.0.0.1,.internal.example.com

Many tools also read the lowercase variants, so in restrictive environments set both forms.

bash
export http_proxy=$HTTP_PROXY
export https_proxy=$HTTPS_PROXY
export no_proxy=$NO_PROXY

Then run Bazel from that same shell:

bash
bazel build //app:server

Forward the variables in .bazelrc

If developers keep forgetting the shell setup, forward the environment in .bazelrc.

text
1build --action_env=HTTP_PROXY
2build --action_env=HTTPS_PROXY
3build --action_env=NO_PROXY
4build --repo_env=HTTP_PROXY
5build --repo_env=HTTPS_PROXY
6build --repo_env=NO_PROXY

repo_env matters most, because repository fetch logic can run in a different environment from ordinary actions.

Fix PKIX errors with the Java truststore

Some corporate proxies inspect HTTPS traffic and re-sign certificates with an internal certificate authority. Bazel then fails with SSL or PKIX validation errors even though the proxy address is correct. Typical symptoms:

  • certificate path building failure
  • unable to find valid certification path
  • handshake failure during repository download

If your organization provides a corporate root certificate, the Java runtime Bazel uses may need to trust it.

bash
1keytool -importcert \
2  -alias corp-proxy-root \
3  -keystore "$JAVA_HOME/lib/security/cacerts" \
4  -file corp-root-ca.pem

Use the truststore path of the JDK Bazel actually runs with, and coordinate with your security team instead of modifying random JDK installations.

Check which JDK Bazel uses

Bazel's network behavior depends partly on the JVM it runs with, so confirm the Java setup before going further:

bash
bazel info java-home
java -version

If Bazel and your shell use different JDKs, one may trust the proxy CA while the other does not.

Make sure repository URLs are reachable

Even with the proxy configured, WORKSPACE or module URLs must be valid and allowed by policy. For example:

python
1load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2
3http_archive(
4    name = "rules_pkg",
5    urls = ["https://github.com/bazelbuild/rules_pkg/releases/download/0.10.0/rules_pkg-0.10.0.tar.gz"],
6    sha256 = "example_sha256_value",
7)

If GitHub or the public registry is blocked, proxy settings alone will not help. You may need an internal artifact mirror.

Use an internal mirror on locked-down networks

On tightly controlled enterprise networks, the most reliable setup is often to mirror external archives internally and point Bazel at them. This gives you:

  • fewer internet dependencies during builds
  • better compliance and auditability
  • faster repeated fetches inside the network

Teams typically mirror release tarballs and list internal endpoints first in urls, keeping public URLs only as a fallback if policy allows.

Debugging order

When Bazel still fails, check these in order:

  1. proxy variables in the current shell
  2. .bazelrc forwards the needed variables
  3. Bazel can resolve and reach dependency hosts
  4. truststore setup if certificates are intercepted
  5. repository URLs are permitted by company policy

This separates network, certificate and repository-rule problems.

Mistakes that keep the build failing

  • Setting proxy variables in a shell but launching Bazel from an IDE that does not inherit them. Fix: check the real process environment or use .bazelrc.
  • Forwarding action_env but not repo_env. Fix: configure both when repository fetching is affected.
  • Assuming proxy settings fix certificate interception. Fix: validate the truststore of the JDK Bazel uses.
  • Leaving blocked public URLs in repository rules. Fix: use an approved internal mirror.
  • Debugging before checking which JDK Bazel uses. Fix: run bazel info java-home early.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design