Skip to main content

EGR002 - Agent Cannot Run the Egress Firewall

Agent error code #EGR002 indicates that the agent does not have the privilege it needs to change the egress firewall. On Linux and OpenBSD the command is installed but the agent is not allowed to run it as root. Changing the kernel's rules requires root, and the agent runs as its own unprivileged account, so it calls the command through sudo -n (or doas -n). When neither is available, or the call is refused, every egress operation fails.

The agent cannot answer a password prompt, so a rule that asks for one counts as a refusal.

On Windows the agent changes Windows Firewall rules itself, which needs the agent service to run as LocalSystem. This code there means the service runs as some other account, or Windows Firewall could not be opened.

Common causes include:

  • No sudoers or doas rule covers the command for the knocknoc-agent account
  • The rule names a path that is not the command on this host
  • The rule requires a password
  • Neither sudo nor doas is installed
  • On Windows, the Knocknoc Agent service was changed to log on as another account

The commands the agent runs, by firewall:

Firewall Commands
nftables nft
iptables iptables, ip6tables, iptables-save, ip6tables-save, iptables-restore, ip6tables-restore
pf pfctl

Steps to Resolve

Let knocker Write the Rule

knocker enable egress installs the rule the firewall needs and checks it with visudo before keeping it: /etc/sudoers.d/knocknoc-agent_nftables for nftables, /etc/sudoers.d/knocknoc-agent_iptables for iptables (the deb and rpm packages also install that one). On OpenBSD it adds a permit nopass line for pfctl to /etc/doas.conf. Re-running it is safe.

Check the Rule by Hand

  1. List what the account may run: sudo -l -U knocknoc-agent
  2. Compare the paths in the rule with command -v for each command above. knocker's rules name both the /usr/sbin and /sbin paths.
  3. Confirm the rule is NOPASSWD (or nopass for doas)
  4. Try a read as the agent would, for example sudo -u knocknoc-agent sudo -n iptables-save -t filter

On Windows: Run the Agent as LocalSystem

  1. Open Services (services.msc) and find Knocknoc Agent
  2. On the Log On tab, choose Local System account
  3. Restart the service, or run sc stop KnocknocAgent then sc start KnocknocAgent from an elevated prompt