podinput

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package podinput is the INPUT policy of the VPN pod and the internet gateway pod.

Both pods are transparent gateways: what they forward is the business of their FORWARD rules, and nothing on the lab side may talk to the pod itself. Every lab interface (lab<N>) and every other interface that is not the uplink gets its packets that are addressed to the pod dropped, ICMP included, so the pod does not answer a ping, a port scan or a connection on its own addresses. What stays open, and only that:

  • the loopback;
  • replies to what the pod itself started (conntrack ESTABLISHED, RELATED), and the continuation of a connection that an earlier rule accepted;
  • everything from the uplink (the pod network: the kubelet, the node, the proxy that delivers WireGuard to its UDP port, which wgguard.go narrows further);
  • the VPN status page and rate-limited echo requests, from the WireGuard interface and to the tunnel address only;
  • DHCP, on the lab interfaces where the pod runs a DHCP server (AllowDHCP);
  • ping of the pod's own address on a lab interface, rate-limited, and only on the interface that owns the address (AllowPing): Linux answers for every local address on every interface, so without the -d match a device could ping the pod's address of another lab, its uplink or its tunnel address;
  • IPv6 neighbour discovery on the lab interfaces (ARP of IPv4 is not netfilter's).

The rules live in a chain of their own, jumped to from the top of INPUT. The chain gets its last rule (the drop) first and the jump last, so no moment of the installation drops what should be accepted or accepts what should be dropped.

Index

Constants

View Source
const Chain = "CICE_INPUT"

Chain is the chain of the policy.

View Source
const ConntrackHelpers = "/proc/sys/net/netfilter/nf_conntrack_helper"

ConntrackHelpers is the switch of automatic conntrack helpers (FTP, SIP, ...): a helper makes a RELATED connection out of a payload, which the ESTABLISHED,RELATED accept of the FORWARD chain would let through.

View Source
const LabIfaces = "lab+"

LabIfaces matches every lab interface of a pod (lab<N>).

Variables

This section is empty.

Functions

func AllowDHCP

func AllowDHCP(ipt Filter, iface string) error

AllowDHCP opens DHCP on one lab interface; DenyDHCP closes it again. Both are idempotent. The policy must be installed.

func AllowPing

func AllowPing(ipt Filter, iface, addr string) error

AllowPing lets a lab ping the pod's address on its own interface (the answer is the pod's own output, which is not filtered); DenyPing takes it away with the interface. Both are idempotent. The policy must be installed. The two rules stand before the ESTABLISHED accept (they go to the top of the chain), the drop of the over-limit requests first so the accept is never alone.

func DHCPRule

func DHCPRule(iface string) []string

DHCPRule accepts DHCP requests that arrive on one lab interface.

func DenyDHCP

func DenyDHCP(ipt Filter, iface string)

func DenyPing

func DenyPing(ipt Filter, iface, addr string)

func EnsureOff

func EnsureOff(paths []string) error

EnsureOff is IPv6Off for the given switches.

func IPv6Off

func IPv6Off() error

IPv6Off makes sure the pod's network namespace has no IPv6 (the pod's own interfaces carry none, so nothing reaches the pod over IPv6). A namespace without an IPv6 stack (the switch is absent) counts as off. The write is tried first (a privileged or pod-spec-configured namespace allows it); a container's /proc/sys is normally read-only, so what counts is the value read back: anything but "1" is an error, and the caller must not start.

func Install

func Install(ipt Filter, p Policy, ipv6 bool) error

Install builds the chain and jumps to it from INPUT. It is idempotent (a container restart in a pod whose network namespace outlives the process finds the rules in place). Run it before any interface of the pod comes up.

func NoConntrackHelpers

func NoConntrackHelpers(path string) error

NoConntrackHelpers makes sure no conntrack helper is assigned automatically (the default of kernels since 4.7; the file is absent when conntrack is not loaded yet, which is fine). It tries to switch the helpers off when they are on.

func PingRule

func PingRule(iface, addr string) []string

PingRule accepts echo requests that arrive on one lab interface and are addressed to that interface's own address.

func ProtectIPv6

func ProtectIPv6(v6 Table, p Policy, ensureOff func() error) (filtered bool, err error)

ProtectIPv6 closes the pod to IPv6: when the pod has a working ip6tables the INPUT policy and the FORWARD DROP policy are installed for IPv6 and the result is true; otherwise IPv6 must be off (ensureOff), and the result is false. Any step that fails is an error: a pod that can neither filter nor switch off IPv6 must not start. v6 is nil when the pod has no ip6tables.

func Remove

func Remove(ipt Filter)

Remove takes the policy off: the jump first, then the chain.

func Rules

func Rules(p Policy, ipv6 bool) [][]string

Rules are the accepts of the chain, in the order they stand, for IPv4 or IPv6. The drop of everything else is the last rule of the chain and is not in the list.

Types

type Filter

type Filter interface {
	ChainExists(table, chain string) (bool, error)
	ClearChain(table, chain string) error
	ClearAndDeleteChain(table, chain string) error
	Exists(table, chain string, rulespec ...string) (bool, error)
	Insert(table, chain string, pos int, rulespec ...string) error
	Append(table, chain string, rulespec ...string) error
	Delete(table, chain string, rulespec ...string) error
}

Filter is the part of go-iptables the policy uses (a fake stands in for it in the tests).

type Policy

type Policy struct {
	// Uplink is the pod network interface (eth0): everything from it is accepted.
	Uplink string
	// Probe is the VPN status page; nil for a pod that has none (the gateway).
	Probe *Probe
}

Policy is what the pod needs.

type Probe

type Probe struct {
	Iface string
	Addr  string
	Port  int
}

Probe is the connection check a participant may reach: a TCP port and rate-limited ping of the tunnel address, from the tunnel interface.

type Table

type Table interface {
	Filter
	ChangePolicy(table, chain, target string) error
}

Table is Filter with the policy switch of a built-in chain.

Jump to

Keyboard shortcuts

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