networkfilter

package
v1.418.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ProxyPort is the port the forward proxy listens on.
	// It serves both HTTP forward proxy requests and HTTP CONNECT tunnels.
	// Transparent iptables-redirected connections (port 80/443) are also accepted here.
	ProxyPort = 3128
)
View Source
const SidecarUID = 0

SidecarUID is the UID the network-filter sidecar container runs as. filter OUTPUT rules accept all traffic from this UID unconditionally so the sidecar can reach real upstreams without being self-blocked.

Variables

This section is empty.

Functions

func PeekSNI

func PeekSNI(r io.Reader) (string, []byte, error)

PeekSNI reads a TLS ClientHello from r and returns the SNI hostname. It does not consume bytes beyond what it reads; use a bufio.Reader or bytes.Buffer so the caller can replay the bytes to the upstream connection. Returns an error if the record is not a valid TLS ClientHello or has no SNI.

func SetupIPTables

func SetupIPTables() error

SetupIPTables configures iptables rules to enforce network isolation for the session Pod, following the same strategy as NemoClaw / NVIDIA OpenShell:

  • All outbound TCP is REJECT-ed by default.
  • Traffic from the network-filter sidecar (UID 0) is exempted so it can reach real upstreams without looping back through itself.
  • The proxy port (127.0.0.1:3128) is explicitly allowed for the main container to reach the sidecar.
  • Established / related packets (TCP replies, ICMP unreachables) are let through so the proxy's upstream connections work normally.
  • UDP is left unrestricted to avoid breaking DNS and other infrastructure; add explicit UDP rules here if stricter UDP isolation is required.

Primary mechanism: HTTP_PROXY / HTTPS_PROXY environment variables (injected by the session manager) make proxy-aware clients (curl, Go http.Client, npm, pip, etc.) use CONNECT tunnels for ALL ports, not just 80/443. The REJECT rules below ensure non-proxy-aware direct TCP connections are also blocked.

Must be called with CAP_NET_ADMIN — from the network-filter-setup init container.

Types

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

Filter decides whether a given host should be blocked. When allowedDomains is non-empty, only those domains pass (allowlist mode). Otherwise, deniedDomains are blocked (denylist mode). bypassDomains are always allowed regardless of mode.

func NewAllowlistFilter added in v1.414.0

func NewAllowlistFilter(allowedDomains []string) *Filter

NewAllowlistFilter creates an allowlist filter: only listed domains are permitted.

func NewFilter

func NewFilter(deniedDomains []string) *Filter

NewFilter creates a denylist filter.

func (*Filter) Check added in v1.414.0

func (f *Filter) Check(host string) FilterResult

Check returns the FilterResult for the given host. host may include a port suffix (host:port); it is stripped before matching.

func (*Filter) IsDenied

func (f *Filter) IsDenied(host string) bool

IsDenied returns true when host should be blocked.

type FilterResult added in v1.414.0

type FilterResult int

FilterResult describes the outcome of a filter check.

const (
	FilterResultAllowed  FilterResult = iota // passed allowlist/denylist check
	FilterResultBypassed                     // always-allow bypass domain
	FilterResultBlocked                      // denied by allowlist or denylist
)

func (FilterResult) String added in v1.414.0

func (r FilterResult) String() string

type Proxy

type Proxy struct {
	// contains filtered or unexported fields
}

Proxy is a forward proxy that enforces a domain deny-list. It handles three types of incoming connections on a single port:

  1. HTTP CONNECT tunnels — sent by proxy-aware HTTPS clients (via HTTP_PROXY env var)
  2. HTTP forward requests — sent by proxy-aware HTTP clients (via HTTP_PROXY env var)
  3. Transparent TCP — redirected by iptables from port 80/443 - port 80: parsed as an HTTP request (Host header) - port 443: TLS ClientHello SNI peek

func NewProxy

func NewProxy(filter *Filter) *Proxy

NewProxy creates a Proxy with the given deny-list filter.

func (*Proxy) Run

func (p *Proxy) Run(lis net.Listener) error

Run starts the proxy on the given listener. It blocks until lis is closed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL