Egress proxy
In an isolated data center the database hosts have no direct route to the internet. Run one Privoxy add-on on a host that does, and point the playbooks at it — installs, image pulls, runtime downloads and extension builds then share that egress.
Start the proxy
Run this on the host with internet access; the same pgcli binary and image set is enough, no extra package:
- Privoxy listens on
0.0.0.0:8118by default.--allow-networkis a client whitelist; with no ACL and a non-loopback listener the install prints an open-proxy warning. - One listener serves HTTP directly and HTTPS through
CONNECT, so a single URL covers both. - Verify from a host that will use it:
See Privoxy for ACL syntax, custom upstream SOCKS, autostart and logs.
Configure Ansible
Set two variables in group_vars/all/main.yml (copy it from
main.yml.example if it does not exist yet):
pgcli_proxy_url is exported to the deployment account as HTTP_PROXY and
HTTPS_PROXY (uppercase and lowercase). Leaving it empty keeps direct
connections: the derived pgcli_proxy_env is then {} and every play behaves
as before. Check the evaluated result with:
What uses the proxy
| Step | How it reaches the proxy |
|---|---|
| Install play | scripts/install.sh (apt, release download) and every get_url |
| Images | podman pull, image loading, lazy add-on image loads |
| Runtime downloads | pg addon install …, pg sqlite install — Go HTTP client |
| Extension builds | podman build behind pg extension install |
What does not
- Running services: containers are created with
--http-proxy=false, so PostgreSQL, backup, pgbouncer, PostgREST and Gitea never inherit the proxy. - Patroni and backup fallback image builds keep the proxy explicitly disabled.
- The LAN reachability checks in
offline-check.ymlbypass the proxy.
NO_PROXY
The playbooks append the hosts of the four offline URLs
(pgcli_install_binary_url, pgcli_podman_binary_url,
pgcli_download_mirror, pgcli_images_http_url) and every inventory
private_ip to pgcli_no_proxy.
Add other internal endpoints by exact IP or hostname. Python (Ansible
get_url/uri) and apt do not understand CIDR entries in no_proxy; a range
such as 10.0.0.0/8 only helps curl and Go clients. Running a LAN mirror and
an egress proxy together is fine — the mirror hosts are added automatically.
Using it without Ansible
In an SSH shell, export the same variables before running pg:
pg and the podman commands it runs inherit them. Three caveats:
sudoresets the environment by default — usesudo -E,sudo env HTTP_PROXY=... pg ..., orenv_keepin sudoers.- The exports cover only that shell and its children;
pg start --autostartand other boot-time paths do not see them. - Containers created by pgcli still get
--http-proxy=false; the proxy is never passed into a long-running service.
Security
Prefer Privoxy client ACLs to a user:pass@ URL: credentials embedded in the
proxy URL are visible in process environments (/proc/<pid>/environ) and in
verbose Ansible logs. Keep the listener on the private network and the ACL
whitelist narrow.
Verify the whole path
-
From each managed host, fetch an external URL through the proxy with
curl -xas shown above. -
Run one extension install against a test instance:
The build must reach
repo.pigsty.io,apt.postgresql.organddeb.debian.org. Watchpg logs addon privoxy --name egress(logfile /dev/stdout) or capture port 8118 while it runs. -
Confirm the recreated container is clean:
If the extension build bypasses the proxy, check that the process running
pg extension install actually has the variables (Ansible sets them on the
install play). Internal requests that unexpectedly hit the proxy usually mean
the exact IP or hostname is missing from NO_PROXY.