Homebrew
Send Homebrew’s formula API and its bottle downloads through the proxy. The
examples use the upstream name homebrew; replace it with the name your
operator gave the upstream (what you need).
| Upstream type | homebrew |
| Package source | https://proxy.example.com/v1/homebrew/api (formula API) and https://proxy.example.com/v1/homebrew (bottles) |
| Clients | brew |
| Tested | Homebrew 4.6 on Linux: in CI on every push and in the client lab. macOS: not tested. |
Configure
Two variables, and both are required:
export HOMEBREW_API_DOMAIN=https://proxy.example.com/v1/homebrew/api
export HOMEBREW_ARTIFACT_DOMAIN=https://proxy.example.com/v1/homebrew
HOMEBREW_API_DOMAIN routes the formula index. That index is signed, so the
proxy cannot rewrite the bottle URLs in it; it is brew itself that replaces
ghcr.io in every bottle URL with HOMEBREW_ARTIFACT_DOMAIN. Without the
second variable, brew reads its metadata through the proxy and downloads every
bottle from ghcr.io directly.
Make brew fail, rather than use a default host, for the few downloads that have one:
export HOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK=1
Authenticate
Only when the proxy has access control switched on. Bottles and the formula API take the proxy token by different routes; the lab runs with both.
For bottle downloads, brew sends a registry token as a bearer token to the artifact domain:
export HOMEBREW_DOCKER_REGISTRY_TOKEN="<token>"
For the formula API, brew’s curl takes credentials for the proxy’s host from
~/.netrc, once ~/.curlrc (enabled as shown under
Trust a private CA) says so:
netrc
machine proxy.example.com
login pullthrough
password <token>
curl looks the entry up by host name alone: when the proxy’s address has a
port (https://proxy.example.com:8443), the machine line still names only the
host, machine proxy.example.com. An entry with the port is never used.
Trust a private CA
brew runs curl with a scrubbed environment and without ~/.curlrc: neither
SSL_CERT_FILE nor CURL_CA_BUNDLE reaches it. Tell brew to read ~/.curlrc:
export HOMEBREW_CURLRC=1
and name the CA there:
cacert = "/etc/ssl/corp-ca.pem"
A certificate brew cannot verify sends it to the public API. When the request to
HOMEBREW_API_DOMAINfails — an untrusted certificate is enough — brew falls back toformulae.brew.shfor the formula index. In the lab, where that host does not exist, this showed as a lookup offormulae.brew.sh; on a network with a way out, brew would simply use it.
Check that it works
brew install hello
prints the URL of every download (==> Downloading
https://proxy.example.com/v1/homebrew/v2/homebrew/core/hello/…).
Good to know
- Metadata falls back, bottles do not. If the proxy cannot be reached, brew
reads the formula index from
formulae.brew.sh(its signature is verified either way). WithHOMEBREW_ARTIFACT_DOMAINset, a bottle the proxy refuses is not installed. - Not
HOMEBREW_BOTTLE_DOMAIN. That variable asks for a different, flat-file layout, which the proxy does not serve, and brew falls back from it toghcr.io. -
brew updates itself before it installs. That is a Git fetch from
github.comand a question toapi.github.com— both of which the lab saw brew look up — not a request to the proxy. Switch it off, or route Git through the proxy (Git):export HOMEBREW_NO_AUTO_UPDATE=1 -
Usage reports go to Homebrew’s analytics service, not to the proxy. The lab did not see one go out — a first run sends none — and switches them off all the same:
export HOMEBREW_NO_ANALYTICS=1 - Only bottles. What brew builds from source (
--build-from-source, a formula without a bottle for the platform) and cask downloads come from their own upstream URLs.
On the proxy
upstreams:
homebrew:
type: homebrew
url: https://formulae.brew.sh
The signed index is passed through byte for byte; bottle manifests are served
live and bottle blobs are verified against the SHA-256 in their URL and cached
immutably. settings.bottleRegistryUrl names the registry bottles come from
(default https://ghcr.io). Details: backends: homebrew.