Discovery: what can be protected
Package internal/discovery. It inspects the machine and changes nothing. It
opens no network connection; its only "request" goes to the local Docker socket.
The four links
For each of SSH, Nginx and Caddy:
| Link | Question |
|---|---|
| detected | is the service on this machine? |
| source | can its events be read? |
| parser | is the format supported? |
| packet path | would a ban affect its traffic? |
Each is yes, no or unknown with a sentence of evidence. finish activates a
service only if all are yes. The one exception: for web logs the parser may be
unknown because the log is still empty; lines are still only used if they parse.
A configuration choice (disabled, or not enabled) also prevents activation, and is
listed under "to activate".
Evidence used
| Source | What |
|---|---|
systemctl show |
whether relevant units are loaded, active or enabled |
/proc/<pid> |
process name, program path, control group |
/proc/net/tcp, tcp6 |
listening sockets, matched to those processes |
| network interfaces | addresses; Tailscale and WireGuard interfaces |
journalctl |
whether the journal can be read, with recent sample messages |
| log files | readability and a format sample |
/etc/nginx |
settings that change what logged addresses mean |
| Docker socket | version, default log driver, firewall backend, published containers |
iptables --version |
which iptables variant |
| nftables | read-only table state |
A listening port is never evidence on its own.
External programs are run with argument lists (no shell), a fixed environment, a 5 second limit, output bounded to 1 MiB, only if other users cannot replace them.
SSH
| Situation | Result |
|---|---|
ssh/sshd service or socket unit active or enabled, or an sshd process on the host |
detected |
only dropbear |
detected, parser no |
journalctl fails |
source no |
| sshd processes only inside containers | path no |
| firewall unreadable | path unknown |
| table foreign or from another install | path no |
[ssh] enabled = false |
not activated |
A process is "in a container" if its control group names docker, containerd, libpod, lxc or kubepods.
Nginx
- Detected:
nginx.serviceor an nginx process. - Each configured log: read the last 64 KiB, test up to 100 complete lines. At
least half must parse (source and parser). Empty: parser
unknown. - If the default
combinedfails butmainfits, the message suggestsformat = "main". It never switches by itself. - Path: needs
clientsdeclared; then the configuration scan:
| Found | Effect |
|---|---|
set_real_ip_from or real_ip_header, without $realip_remote_addr in the format |
path no, unsafe |
log_format ... escape=none |
parser no, unsafe |
| parts of the configuration unreadable | note added |
The scan starts at /etc/nginx/nginx.conf, follows include (with wildcards),
reads at most 64 files of 256 KiB, and ignores comments.
Unsafe is stronger than not ready: a running reader is stopped and its saved position forgotten, so lines written meanwhile are never used.
Caddy
Source is a configured log file or the journal of a configured unit; without
either, no, with the reminder that Caddy logging is opt-in. File samples work as
for Nginx. For the journal, any one of 100 recent messages parsing as a JSON access
entry verifies the format, since the unit also logs other messages.
Environment notes
| Found | Note |
|---|---|
| not root | the report may understate what is available |
| no systemd | relying on process information |
| Docker | version, default log driver, firewall backend, containers; whether forwarded traffic is covered; experimental backend |
tailscale* interface |
peers are not allowlisted automatically |
| WireGuard interface | the same |
ufw enabled (from /etc/ufw/ufw.conf) |
rules unchanged |
| firewalld active | rules unchanged |
| nftables service | flush ruleset may remove the table until repaired |
When it runs
init and status (without a daemon) run it directly. The daemon runs it at start
and every 60 seconds, starting newly ready detectors and stopping unsafe ones.
Testing
discovery_test.go uses a fake System, covering each row above.
system_linux_test.go checks the real readers against the test machine.