Skip to content

Capture connections from other container namespaces#132

Closed
Reaster0 wants to merge 1 commit into
olalie:mainfrom
Reaster0:feature/cross-netns-capture
Closed

Capture connections from other container namespaces#132
Reaster0 wants to merge 1 commit into
olalie:mainfrom
Reaster0:feature/cross-netns-capture

Conversation

@Reaster0

@Reaster0 Reaster0 commented Jun 8, 2026

Copy link
Copy Markdown

Problem

TapMap's psutil backend only reads the network namespace it runs in. Run as a Docker container with --network host --pid host, it sees the host namespace (and host-network containers), but bridged containers' connections are invisible — each lives in its own netns.

Change

New opt-in backend NetNsNetInfo (TAPMAP_CAPTURE_ALL_NETNS=1, Linux + pid: host) that aggregates connections across every namespace:

  • Delegates to PsutilNetInfo for the host namespace (unchanged process attribution), then reads /proc/<pid>/net/{tcp,tcp6,udp,udp6} for each other namespace, discovered by grouping host PIDs by their /proc/<pid>/ns/net inode.
  • Skips the host namespace (psutil owns it) to avoid double counting.
  • Parses hex IPv4/IPv6 (incl. IPv4-mapped) addresses and TCP state codes into the existing record shape, so geo-enrichment, the map, and open-ports work unchanged.
  • Labels rows by container: friendly names via a read-only mounted Docker socket, falling back to docker:<short-id>, then netns:<inode>.
  • Degrades to host-only on any scan error. Default-off — existing behavior preserved when the env var is unset.

Backend reported as psutil+netns.

Usage

environment:
  TAPMAP_CAPTURE_ALL_NETNS: "1"
volumes:
  - /var/run/docker.sock:/var/run/docker.sock:ro   # optional: friendly names

Testing

  • New tests/test_netinfo_netns.py (19 tests): address/line parsing, IPv4-mapped demapping, state-code table, allowed_statuses filter, cgroup→name labeling + fallbacks, graceful degradation. Full netinfo suite (22) green.
  • Verified live against a real multi-container host: host processes keep real names; container connections (conduwuit, nginx-proxy-manager, vpn-router, jellyfin, sonarr, transmission peers) captured and labeled by container.

🤖 Generated with Claude Code

By default TapMap's psutil backend only sees the network namespace it
runs in, so connections inside other bridged Docker containers are
invisible even with `--network host --pid host`.

Add an opt-in backend (TAPMAP_CAPTURE_ALL_NETNS=1, Linux + pid:host)
that aggregates connections across every network namespace:

- delegates to PsutilNetInfo for the host namespace (unchanged process
  attribution), then reads /proc/<pid>/net/{tcp,tcp6,udp,udp6} for each
  other namespace discovered via /proc/<pid>/ns/net inodes
- skips the host namespace to avoid double counting
- parses hex IPv4/IPv6 (incl. IPv4-mapped) and TCP state codes into the
  existing record shape, so geo-enrichment, the map, and open-ports work
  unchanged
- labels rows by container: friendly names via a read-only mounted Docker
  socket, falling back to docker:<short-id>, then netns:<inode>
- degrades to the host-only result on any scan error

Reports the active backend as "psutil+netns". Default-off; existing
behavior is preserved when the env var is unset.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Reaster0 Reaster0 closed this by deleting the head repository Jun 15, 2026
@olalie

olalie commented Jun 20, 2026

Copy link
Copy Markdown
Owner

I missed your PR.

I've archived the proposal locally and opened issue #134.

Thanks for the implementation, tests and documentation.

@Reaster0

Copy link
Copy Markdown
Author

hi, sorry to have deleted the fork, i had a lot of never merged fork for a long time and i cleaned a lot of them, the tapmap was taken by the sweep haha

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.

2 participants