Bazel (Bzlmod)
Use the proxy as the module registry. The examples use the upstream name
bazel; replace it with the name your operator gave the upstream
(what you need).
| Upstream type | bazel |
| Package source | https://proxy.example.com/v1/bazel |
| Clients | bazel (6 and later, with Bzlmod) |
| Tested | Bazel 7.4: in CI on every push and in the client lab. |
Configure
In the workspace’s .bazelrc (or ~/.bazelrc):
common --registry=https://proxy.example.com/v1/bazel
A module’s source archive — usually a release on GitHub — comes through the
proxy as well: the proxy rewrites each module’s source.json to point at
itself, and verifies the archive against the registry’s integrity hash.
Authenticate
Only when the proxy has access control switched on. The proxy takes your proxy
token as the password of HTTP Basic authentication, with any user name. Bazel
reads credentials for a host from ~/.netrc (mode 600):
machine proxy.example.com
login pullthrough
password <token>
Trust a private CA
Bazel’s server is a JVM with its own trust store, and it does not read PEM bundles. Copy the trust store of a JDK — it holds the public CAs, which Bazel still needs for what it downloads directly — and add the CA to the copy:
cp "$JAVA_HOME/lib/security/cacerts" /etc/ssl/corp-truststore.jks
keytool -importcert -noprompt -trustcacerts -alias corp-ca -file /etc/ssl/corp-ca.pem \
-keystore /etc/ssl/corp-truststore.jks -storepass changeit
(keytool on a file that does not exist creates a store with the corporate CA
alone.)
and hand it to the server in .bazelrc:
startup --host_jvm_args=-Djavax.net.ssl.trustStore=/etc/ssl/corp-truststore.jks --host_jvm_args=-Djavax.net.ssl.trustStorePassword=changeit
Without it, every registry request fails with PKIX path building failed.
Check that it works
bazel fetch --repo="@platforms"
bazel mod graph resolves the whole module graph through the registry.
Good to know
MODULE.bazel.lockrecords the registry URL of every file it read, with a hash. A lock file written through the proxy is valid for the proxy’s address, not forbcr.bazel.build, and the other way round; runbazel mod deps --lockfile_mode=updateafter switching.- Only Bzlmod.
http_archiverules in aWORKSPACEfile download from the URLs they name.git_repositorymodule sources are cloned from their forge (see Git). - Bazel’s own downloads (toolchains fetched by rules, Bazelisk’s download of Bazel) do not go through the registry.
- With a personal cache link the registry belongs in
your user-level
~/.bazelrc, not the workspace’s.bazelrc.MODULE.bazel.lockrecords registry URLs, link included, and the link works like a password: do not commit one written through a personal link.
On the proxy
upstreams:
bazel:
type: bazel
url: https://bcr.bazel.build
Registry files are served live; source.json is rewritten so the source
archive is fetched through the proxy (which is why server.publicUrl must be
set), verified against its integrity hash and cached immutably. Details:
backends: bazel.