Running shld on locked-down servers

Run shld behind an HTTPS proxy: the hosts to allow, SHLD_PROXY, a Squid allowlist, apt, and the daily outbound check.

Some servers can't open connections to the internet. That limits an attacker who gets in: they can't connect back out or send data away. These servers usually reach the outside only through an HTTPS proxy that allows named hosts, such as Squid or a company proxy. shld runs on such a server when the proxy allows the shld hosts below.

The hosts

HostWho calls itWhat for
api.shld.appthe serverReports, heartbeats, shld auth login and fix requests
feed.shld.appthe serverSigned advisory data
downloads.shld.appthe serverSigned releases for shld update and automatic updates
app.shld.appyour browserThe page where you approve shld auth login

The server needs the first three, on port 443. You approve a login in your own browser, so the server never calls app.shld.app. Allow it on the proxy only if you open the login link from a browser that uses the same proxy.

All four sit behind Cloudflare. Their addresses are shared and change, so a firewall rule by IP address would open far more than shld. Allow them by name on the proxy instead.

Set the proxy

Put the proxy in /etc/shld/shld.env:

SHLD_PROXY='http://proxy.internal:3128'

Then restart the service:

sudo systemctl restart shld.service

SHLD_PROXY takes http://host:port or https://host:port. Add credentials as http://user:password@host:port, and percent-encode special characters in them. shld never prints the credentials: shld doctor shows http://proxy.internal:3128.

systemd starts shld with the variables in shld.env and nothing from your shell. shld update, the automatic update timer, shld auth login and shld doctor run as root and read SHLD_PROXY from the same file. So one line covers every command.

Without SHLD_PROXY, shld uses HTTPS_PROXY, HTTP_PROXY and NO_PROXY from its environment, the same way other Go programs do. SHLD_PROXY wins over HTTPS_PROXY. NO_PROXY still applies with SHLD_PROXY: add NO_PROXY=mirror.internal,10.0.0.0/8 to shld.env for hosts the server reaches directly. shld never sends loopback traffic, such as its local API on 127.0.0.1:8099, through a proxy.

The proxy only carries the connection. shld still checks each host's TLS certificate, and it still checks the signature on every release and feed file. A proxy that inspects TLS by re-signing certificates breaks shld, so exempt the three shld hosts from inspection.

Install through a proxy

Download the release through the proxy as Install and connect a server describes, with HTTPS_PROXY set for curl. Then pass the proxy to the installer:

sudo env HTTPS_PROXY=http://proxy.internal:3128 ./scripts/install.sh --binary ./bin/shld --systemd --root /srv/application

sudo drops most of your environment, so env sets the variable for the installer itself. When shld.env has no SHLD_PROXY line yet, the installer writes one from SHLD_PROXY or, failing that, HTTPS_PROXY. It refuses a value with quotes, spaces or $. Write that line yourself.

Check it

sudo shld doctor

The Proxy line reads Reaches shld through proxy http://proxy.internal:3128 (SHLD_PROXY in /etc/shld/shld.env): api.shld.app, feed.shld.app, downloads.shld.app. A blocked host fails the check and names the host and the proxy's answer. With no proxy set, the line reads No proxy set. If the proxy comes only from your shell's HTTPS_PROXY, doctor warns: the service doesn't see it.

Squid allowlist

A minimal Squid rule set for the shld hosts, in /etc/squid/conf.d/shld.conf:

# The servers that run shld.
acl shld_servers src 10.0.1.0/24
acl shld_hosts dstdomain api.shld.app feed.shld.app downloads.shld.app
acl shld_tls port 443
http_access allow shld_servers CONNECT shld_tls shld_hosts

Debian's default squid.conf defines the CONNECT ACL and reads conf.d before its final http_access deny all. Replace 10.0.1.0/24 with your servers' addresses. Reload Squid with sudo systemctl reload squid.

Add your package mirrors to the same proxy so the servers can still install updates.

Package updates

shld's fix helper runs apt-get, and apt has its own proxy setting. shld doesn't change it. Set it in /etc/apt/apt.conf.d/95proxy:

Acquire::http::Proxy "http://proxy.internal:3128";
Acquire::https::Proxy "http://proxy.internal:3128";

The daily outbound check

Once at start and then once a day, the agent checks whether the server can open a connection to any internet address. It tries a TCP handshake, 3 seconds at most, to two public resolvers on port 443, sends no data, and closes each connection after the handshake. The check always connects directly and never through the proxy, since it tests the firewall. The result reads restricted when every attempt fails at the network layer, unrestricted when any target connects, and unknown when the host has no network yet. The dashboard shows it as a server fact, never an incident. While the service is running, sudo shld doctor runs the same direct check on demand and includes an Outbound traffic row in text and JSON output. Set SHLD_EGRESS_CHECK=false in /etc/shld/shld.env to turn off the agent's automatic check; the server then shows "Outbound check is off".