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, 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
- func AllowDHCP(ipt Filter, iface string) error
- func AllowPing(ipt Filter, iface, addr string) error
- func DHCPRule(iface string) []string
- func DenyDHCP(ipt Filter, iface string)
- func DenyPing(ipt Filter, iface, addr string)
- func EnsureOff(paths []string) error
- func IPv6Off() error
- func Install(ipt Filter, p Policy, ipv6 bool) error
- func NoConntrackHelpers(path string) error
- func PingRule(iface, addr string) []string
- func ProtectIPv6(v6 Table, p Policy, ensureOff func() error) (filtered bool, err error)
- func Remove(ipt Filter)
- func Rules(p Policy, ipv6 bool) [][]string
- type Filter
- type Policy
- type Probe
- type Table
Constants ¶
const Chain = "CICE_INPUT"
Chain is the chain of the policy.
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.
const LabIfaces = "lab+"
LabIfaces matches every lab interface of a pod (lab<N>).
Variables ¶
This section is empty.
Functions ¶
func AllowDHCP ¶
AllowDHCP opens DHCP on one lab interface; DenyDHCP closes it again. Both are idempotent. The policy must be installed.
func AllowPing ¶
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 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 ¶
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 ¶
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 ¶
PingRule accepts echo requests that arrive on one lab interface and are addressed to that interface's own address.
func ProtectIPv6 ¶
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.
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.