Fix Rust (cargo/rustup) & Go x509 SSL Errors on Mac
Fix Rust cargo, rustup & Go x509: certificate signed by unknown authority SSL errors behind Zscaler, Cloudflare WARP, or Netskope on macOS safely.
SWG bar · Updated
When running cargo build, cargo add, rustup update, go mod download, or go install on a work Mac behind Zscaler, Cloudflare WARP, Netskope, Cisco Umbrella, Palo Alto GlobalProtect, or Fortinet, Rust and Go toolchains frequently abort during TLS verification with errors like:
# Cargo (crates.io sparse index / libcurl)
error: failed to download from `https://index.crates.io/config.json`
Caused by:
[60] SSL peer certificate or SSH remote key was not OK
(SSL certificate problem: unable to get local issuer certificate)
# Rustup (rustls / reqwest)
error: could not download file from 'https://static.rust-lang.org/dist/channel-rust-stable.toml.sha256'
caused by: invalid peer certificate: UnknownIssuer
# Go (go mod download / go get / Go HTTP clients)
go: github.com/gin-gonic/[email protected]: Get "https://proxy.golang.org/...":
tls: failed to verify certificate: x509: certificate signed by unknown authority
Paste your raw terminal output into the free SWG & SSL Error Decoder to pinpoint the failing layer, or apply the upgrade-safe macOS trust-store fix below.
1. Why Rust (cargo/rustup) and Go reject corporate SWG certificates
Browsers like Safari and Chrome verify TLS chains via macOS System Keychain, where MDM installs your company’s SWG Root CA. Systems toolchains behave differently:
- Cargo & Rustup:
cargolinkslibcurl(andlibgit2for Git dependencies) andrustupusesreqwest/rustls. Neither automatically merges macOS System Keychain roots with static PEM bundles, andrustlsenforces strict X.509 certificate constraints that reject many legacy corporate SWG roots. - Go (
crypto/x509): Go on macOS usesSecurity.frameworkby default, unlessSSL_CERT_FILEorSSL_CERT_DIRis already set in your shell (which completely overrides macOS Keychain lookup—so a partial PEM file breaks every public CA), or your Go binary runs inside a Linux container / cross-compiled runtime, orgo getshells out togitforGOPRIVATErepositories.
Check your current environment variables and active binaries first:
env | grep -E 'SSL_CERT|CURL_CA|CARGO_HTTP|RUSTUP_USE_CURL|GOPROXY'
go env GOPROXY GOSUMDB GOPRIVATE
cargo --version && rustup --version
Never point SSL_CERT_FILE at only your corporate SWG root CA: doing so makes Go and Rust reject every non-inspected public HTTPS endpoint.
2. Build an upgrade-safe combined macOS + corporate SWG CA bundle
Create a single PEM bundle in ~/.certs/rust-go-combined-ca.pem that combines Apple’s built-in public root CAs plus your corporate SWG Root CA so upgrades to Homebrew, Rust, or Go never overwrite it:
mkdir -p "$HOME/.certs"
# 1. Export Apple's built-in trusted public root CAs
security find-certificate -a -p /System/Library/Keychains/SystemRootCertificates.keychain > "$HOME/.certs/rust-go-combined-ca.pem"
# 2. Append your corporate SWG Root CA (replace "Zscaler" with Cloudflare, goskope, Cisco Umbrella, Fortinet, etc.)
security find-certificate -c "Zscaler" -p /Library/Keychains/System.keychain >> "$HOME/.certs/rust-go-combined-ca.pem"
Because both standard public roots and your corporate SWG CA live in one bundle, inspected hosts (index.crates.io, static.rust-lang.org, proxy.golang.org, sum.golang.org) and direct non-inspected endpoints both verify cleanly.
3. Persist CA trust for Cargo, Rustup, Go & Git
Export SSL_CERT_FILE, CURL_CA_BUNDLE, and CARGO_HTTP_CAINFO in ~/.zshrc so Go’s crypto/x509, Cargo’s HTTP client, and Rustup all share the same combined trust bundle:
cat <<'EOF' >> ~/.zshrc
export SSL_CERT_FILE="$HOME/.certs/rust-go-combined-ca.pem"
export CURL_CA_BUNDLE="$HOME/.certs/rust-go-combined-ca.pem"
export CARGO_HTTP_CAINFO="$HOME/.certs/rust-go-combined-ca.pem"
EOF
source ~/.zshrc
Next, persist Cargo’s configuration (using an expanded absolute path, because Cargo does not expand ~ inside config.toml) and configure Git for GOPRIVATE and Cargo Git dependencies:
mkdir -p "$HOME/.cargo"
cat <<EOF >> "$HOME/.cargo/config.toml"
[http]
cainfo = "$HOME/.certs/rust-go-combined-ca.pem"
[net]
git-fetch-with-cli = true
EOF
git config --global http.sslCAInfo "$HOME/.certs/rust-go-combined-ca.pem"
If rustup update still fails with invalid peer certificate: UnknownIssuer because rustls rejects an extension on your corporate SWG root certificate, add export RUSTUP_USE_CURL=1 to ~/.zshrc so rustup uses libcurl with your CURL_CA_BUNDLE while keeping full TLS verification enabled.
Verify all three tools cleanly—never disable TLS verification (InsecureSkipVerify: true in Go tls.Config, danger_accept_invalid_certs(true) in Rust reqwest, git config --global http.sslVerify false, or curl -k):
rustup check
cargo search serde --limit 1
go list -m -versions golang.org/x/text
4. Fix rust-analyzer, gopls & IDE background tasks
If cargo build and go mod download succeed in Terminal but fail inside VS Code (rust-analyzer, gopls), RustRover, or GoLand, macOS GUI apps did not inherit your ~/.zshrc exports. Two persistent steps solve non-interactive IDE builds:
- Keep
[http] cainfoin~/.cargo/config.tomlandhttp.sslCAInfoin~/.gitconfig: both files are read directly by Cargo and Git regardless of shell startup scripts. - Export the CA bundle for GUI apps in the current login session:
Quit and relaunch VS Code, RustRover, or GoLand so background language servers pick up the new environment.launchctl setenv SSL_CERT_FILE "$HOME/.certs/rust-go-combined-ca.pem" launchctl setenv CURL_CA_BUNDLE "$HOME/.certs/rust-go-combined-ca.pem" launchctl setenv CARGO_HTTP_CAINFO "$HOME/.certs/rust-go-combined-ca.pem"
5. Avoid manual CA bundles with per-domain SWG bypass
Strict rustls validation, corporate intermediate rotations, and multi-toolchain projects can make manual PEM bundles brittle over time. Where your organization’s policy permits per-domain SWG bypass for developer registries, SWG bar identifies which domains are intercepted and restores the authentic TLS certificate per domain without turning off your corporate VPN or SSO (includes a 14 actual-use-day free trial):
swgbar probe index.crates.io
swgbar bypass enable index.crates.io
swgbar bypass enable static.rust-lang.org
swgbar bypass enable proxy.golang.org
Troubleshooting other developer stacks on the same corporate Mac? Continue with Fix Git & npm SSL certificate errors on Mac, Fix Python CERTIFICATE_VERIFY_FAILED & Docker x509 errors on Mac, and How to bypass SWG on a Mac.