images / images (push) Successful in 7m6s
A pod could put any source MAC or address on the wire: weave has no layer-2 anti-spoofing, so a pod with NET_RAW could pose as another pod or as a node's bridge, on its own node (local bridging never reaches the router) and, through weave, on others. That undercut every rule that trusts a source MAC or address, including the egress holder's check of which node a tunnel packet came from. The CNI plugin now locks the host side of each pod's veth with tc ingress filters: IPv4 from the pod's MAC and address, ARP speaking for exactly those (or probing from 0.0.0.0) pass; everything else is dropped before the bridge sees it. The u32 keys follow iproute2's layout for "ether src" (-8, -4) and "ip src" (12). ADD fails if the port cannot be locked, so an unlocked pod never starts. The filters go away with the veth. Pods attached before this plugin get locked by weave-init: "weaveutil lock-ports" walks libcni's result cache (each attachment's netns, interface and address) and locks their ports, leaving locked ones alone. weave-init mounts the cache and /var/run/netns read-only for it. TestPortLockInKernel (root) builds a bridge and two pods in throwaway namespaces and checks what reaches the other pod; reweave/test/portlock runs the same against a live cluster, across nodes, after checking every port is locked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UHXzGrsxfkGk8LmwrBbHNZ
102 lines
2.8 KiB
Go
102 lines
2.8 KiB
Go
/* weaveutil: collection of operations required by weave script */
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
var commands map[string]func([]string) error
|
|
|
|
func init() {
|
|
commands = map[string]func([]string) error{
|
|
"help": help,
|
|
"netcheck": netcheck,
|
|
"docker-tls-args": dockerTLSArgs,
|
|
"detect-bridge-type": detectBridgeType,
|
|
"create-datapath": createDatapath,
|
|
"delete-datapath": deleteDatapath,
|
|
"check-datapath": checkDatapath,
|
|
"add-datapath-interface": addDatapathInterface,
|
|
"remove-plugin-network": removePluginNetwork,
|
|
"container-addrs": containerAddrs,
|
|
"process-addrs": processAddrs,
|
|
"container-id": containerID,
|
|
"container-state": containerState,
|
|
"container-fqdn": containerFQDN,
|
|
"run-container": runContainer,
|
|
"list-containers": listContainers,
|
|
"stop-container": stopContainer,
|
|
"kill-container": killContainer,
|
|
"remove-container": removeContainer,
|
|
"create-volume-container": createVolumeContainer,
|
|
"attach-container": attach,
|
|
"detach-container": detach,
|
|
"cni-net": cniNet,
|
|
"cni-ipam": cniIPAM,
|
|
"bridge-ip": bridgeIP,
|
|
"unique-id": uniqueID,
|
|
"swarm-manager-peers": swarmManagerPeers,
|
|
"is-docker-plugin-enabled": isDockerPluginEnabled,
|
|
"rewrite-etc-hosts": rewriteEtcHosts,
|
|
"get-db-flag": getDBFlag,
|
|
"set-db-flag": setDBFlag,
|
|
"lock-ports": lockPorts,
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
// If no args passed, act as CNI plugin based on executable name
|
|
switch {
|
|
case len(os.Args) == 1 && strings.HasSuffix(os.Args[0], "weave-ipam"):
|
|
cniIPAM(os.Args)
|
|
os.Exit(0)
|
|
case len(os.Args) == 1 && strings.HasSuffix(os.Args[0], "weave-net"):
|
|
cniNet(os.Args)
|
|
os.Exit(0)
|
|
}
|
|
|
|
if len(os.Args) < 2 {
|
|
usage()
|
|
os.Exit(1)
|
|
}
|
|
cmd, found := commands[os.Args[1]]
|
|
if !found {
|
|
fmt.Fprintf(os.Stderr, "%q cmd is not found\n", os.Args[1])
|
|
usage()
|
|
os.Exit(1)
|
|
}
|
|
if err := cmd(os.Args[2:]); err != nil {
|
|
if err.Error() != "" {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
}
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func help(args []string) error {
|
|
if len(args) > 0 {
|
|
cmdUsage("help", "")
|
|
}
|
|
usage()
|
|
return nil
|
|
}
|
|
|
|
func usage() {
|
|
fmt.Fprintln(os.Stderr, "usage: weaveutil <command> <arg>...")
|
|
fmt.Fprintln(os.Stderr)
|
|
fmt.Fprintln(os.Stderr, "where <command> is one of:")
|
|
fmt.Fprintln(os.Stderr)
|
|
for cmd := range commands {
|
|
fmt.Fprintln(os.Stderr, cmd)
|
|
}
|
|
fmt.Fprintln(os.Stderr)
|
|
fmt.Fprintf(os.Stderr, "Set an environment variable called DOCKER_API_VERSION to control the API version used.\nDefault is: %v\n", defaulDockerAPIVersion)
|
|
}
|
|
|
|
func cmdUsage(cmd string, usage string) {
|
|
fmt.Fprintf(os.Stderr, "usage: weaveutil %s %s\n", cmd, usage)
|
|
os.Exit(1)
|
|
}
|