netguard

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: BSD-3-Clause Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package netguard defines the single network-egress policy for untrusted code running on a tau node: which destinations must be blocked so a tenant WASM function or a container the node did not author cannot reach node-local services or cloud infrastructure (loopback, private networks, and the link-local metadata endpoint), while still reaching the public internet.

The same policy feeds two enforcement layers so they can never drift:

  • a net.Dialer control guard for the in-process WASM guest's HTTP client (pkg/vm-low-orbit/http) — portable Go, every OS;
  • an nftables ruleset for restricted containers (pkg/containers firewall) — Linux only, built from DeniedPrefixes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeniedPrefixes

func DeniedPrefixes() []*net.IPNet

DeniedPrefixes returns a copy of the denied networks, for building the nftables sets in the container firewall. Callers split by address family via (*net.IPNet).IP.To4().

func DialControl

func DialControl(network, address string, _ syscall.RawConn) error

DialControl is a net.Dialer.Control function that rejects a connection whose resolved address is denied. Control runs after DNS resolution, on the concrete address being dialled, so it defeats DNS-rebinding — the guard sees the real IP, not the hostname.

func InstallBridgeFilter

func InstallBridgeFilter(bridge string) error

InstallBridgeFilter programs the host firewall so containers attached to the named bridge cannot reach denied destinations. Every container on that bridge gets a veth into it, so one interface-scoped, static ruleset covers them all — install once per process. Idempotent (atomic table replace).

The caller passes the bridge of a network reserved for restricted containers, not the shared default one: the rule cannot tell containers apart, so anything else on that bridge is filtered too.

func InstallCgroupFilter

func InstallCgroupFilter(cgroupID uint64, level uint32) error

InstallCgroupFilter programs a single, static output-hook rule dropping denied-destination packets from any socket whose cgroup v2 has, at ancestor level `level`, the cgroup identified by cgroupID. Used on the containerd backend, where containers share the host network namespace (no bridge to match on) but restricted ones all run under one parent cgroup: matching that parent with a single rule covers them all, nested cgroups included, without any per-container rule churn. Install once per process against the pre-created parent cgroup.

A wrong level or id installs cleanly but matches nothing — it fails *open* — so the match is exercised end to end by TestCgroupEgressDrop_Integration: a process in a cgroup below the matched parent must be refused a loopback destination and still reach a public one. Requires kernel >= 5.13 and CAP_NET_ADMIN; the level is counted from the cgroup root, so a parent at /sys/fs/cgroup/<ns>/restricted is level 2.

func IsDenied

func IsDenied(ip net.IP) bool

IsDenied reports whether untrusted code may not connect to ip. It fails closed: a nil or unparseable address is denied.

func RestrictedDialer

func RestrictedDialer(timeout time.Duration) *net.Dialer

RestrictedDialer returns a net.Dialer that enforces the egress policy and the given connect timeout. Use its DialContext for an untrusted http.Transport.

func Uninstall

func Uninstall() error

Uninstall removes the egress table, if present. Nothing in the node calls it — the policy is static and re-asserted per container — but a test that programs the host firewall must be able to put the host back.

Types

This section is empty.

Jump to

Keyboard shortcuts

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