ipv6fence

package
v0.6.13 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package ipv6fence keeps IPv6 off the node's sandbox networks.

Sandboxes are IPv4-only, and every host rule that keeps one sandbox off another and off the node is IPv4: netrules' floor and node chains, the Firecracker isolation chain, the egress gateway. With IPv6 up inside two sandboxes on one bridge, one reached the other's listener at fe80::…%eth0 while the IPv4 address timed out (cluster-3-mixed-routing, containerd, pooled netns). The runtimes now start every sandbox with IPv6 off (hostnet.SandboxIPv6Sysctls, netns.Host.Realize, the Firecracker ipv6.disable_ipv6=1 boot argument, the TAP's host end). This package is the second layer, which holds whatever a sandbox does to its own stack: a gVisor sentry or a VM guest has a network stack of its own, and root in a guest owns its kernel.

Two nftables tables named TableName, both independent of iptables, netrules and the operator's file:

  • bridge family: drop every IPv6 frame (ethertype 0x86dd) forwarded between two ports of a sandbox bridge, delivered from one to the host, or sent by the host into one. The bridge family sees bridged frames whether or not br_netfilter hands them to ip6tables.
  • ip6 family: drop IPv6 into the host (input), through it (forward) and out of it (output) on the sandbox bridges and the Firecracker TAPs (routed, not bridged).

Each Apply replaces both tables in one netlink transaction, so there is never a moment with half a fence; Check reads them back so a supervisor can put back a fence a firewall reload or a flush took away.

Index

Constants

View Source
const (
	FamilyBridge = "bridge"
	FamilyIP6    = "ip6"
)

Families of the two tables.

View Source
const (
	ChainForward = "forward"
	ChainInput   = "input"
	ChainOutput  = "output"
)

Chains of each table; each is a base chain on the hook of the same name.

View Source
const (
	MatchInBridge  = "ibrname"
	MatchOutBridge = "obrname"
	MatchIn        = "iifname"
	MatchOut       = "oifname"
)

What a rule matches on: the bridge a frame came in on or goes out on (bridge family), or the interface a packet came in on or goes out on (ip6 family).

View Source
const ReassertInterval = 30 * time.Second

ReassertInterval paces the check that the fence is still in the kernel, matching the host firewall chains' re-assert (pkg/daemon chainReassertInterval).

View Source
const TableName = "aerolvm_ipv6"

TableName names the fence's table in the bridge and ip6 families (`nft list table bridge aerolvm_ipv6`, `nft list table ip6 aerolvm_ipv6`).

Variables

View Source
var ErrNotSynced = errors.New("ipv6 fence: not installed yet")

ErrNotSynced is what Ready answers before the first Sync.

View Source
var ErrUnsupported = errors.New("ipv6 fence: nftables is not available on this platform")

ErrUnsupported means this platform has no nftables.

Functions

func ChainRules

func ChainRules(rules []Rule) map[string][]Rule

ChainRules groups rules by family/chain in plan order: what each chain must hold, including empty chains.

Types

type Backend

type Backend interface {
	// Apply replaces both tables with exactly rules, in one transaction.
	Apply(rules []Rule) error
	// Check reports whether the kernel holds exactly rules: both tables,
	// every chain on its hook and priority, and each chain's rules in
	// order. A chain something else inserted a rule into reads as missing,
	// since an accept above a drop would let traffic past it.
	Check(rules []Rule) (bool, error)
}

Backend installs and reads back the fence.

func NewBackend

func NewBackend() Backend

NewBackend returns the netlink backend.

type NFTBackend

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

NFTBackend drives the two TableName tables over netlink.

func (*NFTBackend) Apply

func (b *NFTBackend) Apply(rules []Rule) error

Apply implements Backend: both tables if the kernel takes them, else the ip6 table with br_netfilter on (see bridgeLayer).

func (*NFTBackend) Check

func (b *NFTBackend) Check(rules []Rule) (bool, error)

Check implements Backend, for the tables the last Apply installed.

func (*NFTBackend) Layers

func (b *NFTBackend) Layers() string

Layers says which tables hold the fence, for the supervisor's log.

type Rule

type Rule struct {
	Family string
	Chain  string
	Match  string
	// Name is a bridge or interface name; a trailing "*" is a prefix.
	Name string
}

Rule is one drop of the fence, in the form the backend and the tests share.

func Plan

func Plan(spec Spec) []Rule

Plan is every rule the fence needs for spec (normalized first), grouped by table and chain in a fixed order.

func (Rule) Comment

func (r Rule) Comment() string

Comment is what the rule carries in the kernel: the operator sees it in `nft list ruleset`, and Check compares it to find a rule that went missing or changed.

type Source

type Source struct {
	Runtime string
	Spec    func(ctx context.Context) (Spec, error)
}

Source names, for one runtime, the host interfaces its sandboxes sit on. Spec may fail (dockerd not answering yet): that runtime's creates are refused until a later sync gets it.

type Spec

type Spec struct {
	// Bridges are the Linux bridges sandboxes are attached to: the
	// containerd CNI bridge, the docker sandbox network's bridge.
	Bridges []string
	// Links are routed sandbox interfaces on the host. A trailing "*"
	// matches every interface with that prefix, as in nft: "fctap*" is
	// every Firecracker TAP, including ones created after the fence.
	Links []string
}

Spec is what the fence covers.

func (Spec) Empty

func (s Spec) Empty() bool

Empty reports whether the spec covers nothing.

func (Spec) Key

func (s Spec) Key() string

Key is a stable string for a normalized spec, for logs and change checks.

func (Spec) Merge

func (s Spec) Merge(o Spec) Spec

Merge returns the union of s and o (not normalized).

func (Spec) Normalize

func (s Spec) Normalize() (Spec, error)

Normalize validates every name and returns the spec sorted and without duplicates, so two equal specs have equal keys.

type Supervisor

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

Supervisor installs the fence for every source and keeps it there. The create gate asks Ready; the daemon runs Sync once at boot, before the API serves, then Run.

func NewSupervisor

func NewSupervisor(be Backend, logger *slog.Logger, sources ...Source) *Supervisor

NewSupervisor returns a supervisor for sources over be.

func (*Supervisor) Ready

func (s *Supervisor) Ready(runtime string) error

Ready reports whether the fence covers runtime's sandboxes: nil when it does, or when runtime is not one this supervisor fences (WASM and isolate sandboxes have no interface on the node).

func (*Supervisor) Run

func (s *Supervisor) Run(ctx context.Context, tick time.Duration)

Run syncs every tick until ctx ends: a failed install is retried within tick, a changed spec (dockerd's bridge came up) is applied, and every ReassertInterval the kernel is checked and the fence put back if something took it away.

func (*Supervisor) Sync

func (s *Supervisor) Sync(ctx context.Context, force bool)

Sync installs the fence when it is new, changed or failed last time (force: always), and checks it when the reassert is due.

Jump to

Keyboard shortcuts

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