firewall

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package firewall is the relay's security-group model, after OpenStack Neutron's networking API: ports carry security groups, groups hold rules, rules only allow, and everything not allowed is denied.

A flow from port S to port D is allowed iff one of S's EGRESS rules allows it AND one of D's INGRESS rules allows it, as Neutron filters at each port. Groups on a port are a union and rules have no order, so the result does not depend on the order anything was added in.

Statefulness: a port is stateful unless every group on it is stateless (Neutron's "stateful" attribute). A stateful port lets replies of an allowed flow through without a rule (the relay's connection tracking). For a stateless port the reverse direction must be allowed too: a TCP connect whose source or destination port is stateless also needs D's egress and S's ingress to allow the reverse flow, and every UDP datagram is checked on its own.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParsePortRange

func ParsePortRange(s string) (uint16, uint16, error)

ParsePortRange reads a CLI port spec: "80", "8000-8080", "" or "any".

Types

type Decision

type Decision struct {
	Allowed     bool
	EgressRule  string // the rule at the source that allowed it
	IngressRule string // the rule at the destination that allowed it
	Log         bool   // one of the matching rules asked for a log line
	Reason      string // why not, when not
}

Decision says whether a flow is allowed, and by which rules.

type Direction

type Direction uint8

Direction is where a rule applies, seen from the port.

const (
	Ingress Direction = 1
	Egress  Direction = 2
)

func (Direction) String

func (d Direction) String() string

type Flow

type Flow struct {
	Protocol Protocol
	Src, Dst netip.AddrPort
}

Flow is one L4 flow from Src to Dst.

func (Flow) Reverse

func (f Flow) Reverse() Flow

Reverse is the flow of the replies.

type Group

type Group struct {
	ID          string
	Name        string
	Description string
	Stateful    bool
	Rules       []Rule
}

Group is a security group.

type Policy

type Policy struct {
	Groups map[string]*Group
	// Members returns the addresses of every port that carries the group,
	// for remote_group_id.
	Members func(groupID string) []netip.Addr
}

Policy is the set of groups of one class and the lookups a decision needs.

func (*Policy) Evaluate

func (pol *Policy) Evaluate(f Flow, src, dst *Port) Decision

Evaluate decides a flow from port src to port dst. It checks the forward direction, and for a stateless end the reverse one too (see the package comment). Replies of an already-tracked flow are not decided here.

func (*Policy) Stateful

func (pol *Policy) Stateful(p *Port) bool

Stateful reports whether p is tracked: some group on it is stateful.

type Port

type Port struct {
	ID           string
	Addr         netip.Addr
	Groups       []string // group ids
	PortSecurity bool     // false: no filtering at all (teacher only)
}

Port is one container endpoint as the firewall sees it.

type Protocol

type Protocol uint8

Protocol numbers, IANA's (as Neutron's protocol attribute accepts them).

const (
	Any  Protocol = 0
	ICMP Protocol = 1
	TCP  Protocol = 6
	UDP  Protocol = 17
)

func ParseProtocol

func ParseProtocol(s string) (Protocol, error)

ParseProtocol reads "tcp", "udp", "icmp", "any" or a number of one of them.

func (Protocol) String

func (p Protocol) String() string

type Rule

type Rule struct {
	ID           string
	GroupID      string
	Direction    Direction
	Protocol     Protocol
	PortMin      uint16
	PortMax      uint16
	RemotePrefix netip.Prefix // zero value: unset
	RemoteGroup  string
	Description  string
	Log          bool
}

Rule is one security group rule. PortMin/PortMax are a TCP/UDP port range (0,0 = every port) or, for ICMP, a type and a code (0 meaning any when AnyICMP is set). Remote is at most one of RemotePrefix and RemoteGroup; neither means any remote.

func (Rule) Validate

func (r Rule) Validate() error

Validate checks a rule the way Neutron's API does.

Jump to

Keyboard shortcuts

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