Skip to content

fix: grant cap_net_raw to scanner binaries for non-root execution - #35

Merged
reloadfast merged 1 commit into
mainfrom
fix/scanner-cap-net-raw-nonroot
Feb 28, 2026
Merged

reloadfast merged 1 commit into
mainfrom
fix/scanner-cap-net-raw-nonroot

Conversation

@reloadfast

Copy link
Copy Markdown
Owner

Problem

arp-scan and nmap fail with Operation not permitted even when the container is started with --cap-add=NET_RAW.

Root Cause

Linux capability model has three relevant sets:

  • Bounding set--cap-add=NET_RAW adds it here
  • Permitted set — inherited from bounding for root; for non-root, requires ambient or file caps
  • Effective set — what the kernel actually checks on each syscall

When a non-root process (uid 1000) executes a binary, the effective set starts empty. The bounding set alone is not enough — the capability must also be on the binary file via setcap, or in the ambient set.

Fix

Install libcap2-bin and apply setcap cap_net_raw+ep to both scanner binaries in the Dockerfile:

setcap cap_net_raw+ep /usr/sbin/arp-scan
setcap cap_net_raw+ep $(which nmap)

+ep = effective + permitted bits on the file. When uid 1000 executes the binary, the kernel promotes NET_RAW to the effective set. --cap-add=NET_RAW must still be present at runtime — file capabilities cannot exceed the bounding set.

--cap-add=NET_RAW at runtime places NET_RAW in the container's bounding
and permitted capability sets, but for a non-root user (uid 1000) the
capability is never promoted to the effective set unless the binary
itself has the file capability set via setcap.

Fix: install libcap2-bin and run:
  setcap cap_net_raw+ep /usr/sbin/arp-scan
  setcap cap_net_raw+ep $(which nmap)

This sets the effective+permitted bits on the binaries so the kernel
grants NET_RAW in the effective set when uid 1000 executes them.
--cap-add=NET_RAW must still be present at runtime to keep NET_RAW
within the bounding set (file caps cannot exceed the bounding set).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@reloadfast
reloadfast merged commit 071a45d into main Feb 28, 2026
5 checks passed
@reloadfast
reloadfast deleted the fix/scanner-cap-net-raw-nonroot branch February 28, 2026 15:55
@reloadfast
reloadfast restored the fix/scanner-cap-net-raw-nonroot branch March 26, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant