Service and privileges
The one privilege
Section titled “The one privilege”The agent sends ICMP echo requests from a raw socket, and on Linux sends its ARP sweep from a packet socket. Both need CAP_NET_RAW. Nothing else it does needs any privilege.
Without it, the ping sweep cannot run and the ARP sweep falls back to reading the kernel’s neighbour table: hardware addresses and manufacturers still appear, but a host that answers ARP and nothing else is never found.
The service
Section titled “The service”Both install paths — the script and the .deb / .rpm — run the agent as a dedicated unprivileged account under a systemd sandbox:
[Service]ExecStart=/usr/bin/infrality-agent daemonRestart=on-failureRestartSec=10
User=infrality-agentGroup=infrality-agentAmbientCapabilities=CAP_NET_RAWCapabilityBoundingSet=CAP_NET_RAWNoNewPrivileges=true
ProtectSystem=strictProtectHome=truePrivateTmp=truePrivateDevices=trueProtectKernelTunables=trueProtectKernelModules=trueProtectControlGroups=trueRestrictNamespaces=trueRestrictSUIDSGID=trueRestrictRealtime=trueLockPersonality=trueMemoryDenyWriteExecute=trueRestrictAddressFamilies=AF_INET AF_INET6 AF_NETLINK AF_PACKET
StateDirectory=infrality-agentWorkingDirectory=/var/lib/infrality-agentReadWritePaths=-/etc/infrality-agentAmbientCapabilitiesdelivers the capability to a non-root process;CapabilityBoundingSetmeans it can never acquire another one.NoNewPrivilegesandProtectSystem=strictmake the rest of the filesystem read-only to it, except its state directory and its configuration folder.RestrictAddressFamilies: IP for the probes and the API, netlink to list the machine’s interfaces, andAF_PACKETfor the ARP sweep.
The script’s unit names /usr/local/bin, the packages’ /usr/bin; otherwise they are identical, and the agent’s test suite fails if they drift.
Check what is running:
systemctl show infrality-agent -p User -p AmbientCapabilitiesWhat the install changes on the host
Section titled “What the install changes on the host”| Change | Why |
|---|---|
A system account infrality-agent |
No login, no home directory, no shell |
/etc/infrality-agent/ — owner the account, mode 0750 |
Settings chosen on the dashboard are written back to the file there |
/etc/infrality-agent/config.yaml — mode 0600 |
It holds the API key; nobody else may read it |
/var/lib/infrality-agent/ |
Created by systemd for topology.json |
The binary, with cap_net_raw+ep |
So it can also be run by hand without sudo |
Everything in the unit beyond that is a per-process restriction applied at start, gone when the service stops.
Running it by hand
Section titled “Running it by hand”setcap is a file attribute, not a system change, and lets any user run the agent:
sudo setcap cap_net_raw+ep /usr/local/bin/infrality-agentinfrality-agent runThat is the path for containers (grant NET_RAW, use host networking) and for testing.
On macOS, raw sockets need root: sudo infrality-agent daemon. On Windows, run it from an Administrator terminal.
The remaining sharp edge
Section titled “The remaining sharp edge”CAP_NET_RAW also permits reading and forging packets on the host’s interfaces. It is the smallest capability the kernel offers for what the agent does, but it is not nothing — which is why it is the only one, held by an account that can do nothing else. Moving the ping sweep to unprivileged ICMP sockets, which need no capability at all, is planned.