gerberos

package module
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: MIT Imports: 20 Imported by: 2

README

gerberos

gerberos scans sources for lines matching regular expressions and containing IPv4 or IPv6 addresses and performs actions on those addresses. Possible sources are (not necessarily existant) non-directory files, systemd journals, kernel messages, and standard outputs of arbitrary processes. Addresses can be logged or added to ipsets or nft rulesets that gerberos will manage autonomously.

Minimal additional logic is applied. This is to adhere to the Unix philosophy, but impacts gerberos' out-of-the-box usefulness for specific use cases when compared to tools like fail2ban.

Requirements

ipset backend
  • ipset 6.34
  • iptables 1.6.1
nft backend
  • nftables v0.9.3 (tested on Ubuntu 20.04)
Development only
  • Go 1.18
  • GNU Make 4.3 (optional)
  • pgrep (system tests only, optional)

Build

make build

Test

Unit tests only

make test

Unit and system tests

Requires ipset, iptables, and nftables to be installed.

make test_system

Example configuration file (TOML)

See gerberos.toml.

Example systemd service file

See gerberos.service.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultChainName  = "gerberos"
	DefaultTable4Name = "gerberos4"
	DefaultTable6Name = "gerberos6"
)
View Source
var (
	ErrMissingSource            = errors.New("missing source")
	ErrEmptySource              = errors.New("empty source")
	ErrUnknownSource            = errors.New("unknown source")
	ErrMissingAction            = errors.New("missing action")
	ErrEmptyAction              = errors.New("empty action")
	ErrUnknownAction            = errors.New("unknown action")
	ErrMissingIntervalParameter = errors.New("missing interval parameter")
	ErrInvalidIntervalParameter = errors.New("failed to parse interval parameter")
	ErrMissingRegexp            = errors.New("missing regexp")
	ErrEmptyRegexp              = errors.New("empty regexp")
	ErrMissingCountParameter    = errors.New("missing count parameter")
	ErrInvalidCountParameter    = errors.New("failed to parse count parameter")
)

Functions

func NewDefaultExecutor added in v0.0.2

func NewDefaultExecutor() *defaultExecutor

func NewTestFaultyExecutor added in v0.0.3

func NewTestFaultyExecutor(output string, exitCode int, err error, name string, args ...string) *testFaultyExecutor

func RegisterAction added in v0.0.4

func RegisterAction(name string, afn func() Action)

func RegisterBackend added in v0.0.4

func RegisterBackend(name string, bfn func(*Runner) Backend)

func RegisterSource added in v0.0.4

func RegisterSource(name string, fn func() Source)

Types

type Action added in v0.0.4

type Action interface {
	Initialize(r *Rule) error
	Perform(m *Match) error
}

func NewBanAction added in v0.0.4

func NewBanAction() Action

func NewLogAction added in v0.0.4

func NewLogAction() Action

func NewTestAction added in v0.0.4

func NewTestAction() Action

type Backend added in v0.0.2

type Backend interface {
	Initialize() error
	Ban(ip string, ipv6 bool, d time.Duration) error
	Finalize() error
}

func NewIpsetBackend added in v0.0.2

func NewIpsetBackend(rn *Runner) Backend

func NewNftBackend added in v0.0.2

func NewNftBackend(rn *Runner) Backend

func NewTestBackend added in v0.0.2

func NewTestBackend(rn *Runner) Backend

type Configuration

type Configuration struct {
	Verbose      bool
	Backend      string
	SaveFilePath string
	Rules        map[string]*Rule
}

func (*Configuration) Read

func (c *Configuration) Read(r io.Reader) error

func (*Configuration) ReadFile

func (c *Configuration) ReadFile(path string) error

type Executor added in v0.0.2

type Executor interface {
	Execute(name string, args ...string) (string, int, error)
	ExecuteWithStd(stdin io.Reader, stdout io.Writer, name string, args ...string) (string, int, error)
}

type Match added in v0.0.4

type Match struct {
	Time   time.Time
	Line   string
	IP     string
	IPv6   bool
	Regexp *regexp.Regexp
}

func (Match) String added in v0.0.4

func (m Match) String() string

func (Match) StringExtended added in v0.0.4

func (m Match) StringExtended() string

type Rule added in v0.0.3

type Rule struct {
	Source      []string
	Regexp      []string
	Action      []string
	Aggregate   []string
	Occurrences []string
	// contains filtered or unexported fields
}

func (*Rule) Match added in v0.0.4

func (r *Rule) Match(line string) (*Match, error)

func (*Rule) MatchAggregate added in v0.0.4

func (r *Rule) MatchAggregate(line string) (*Match, error)

func (*Rule) MatchSimple added in v0.0.4

func (r *Rule) MatchSimple(line string) (*Match, error)

func (*Rule) ProcessScanner added in v0.0.4

func (r *Rule) ProcessScanner(name string, args ...string) (chan *Match, error)

type Runner added in v0.0.2

type Runner struct {
	Configuration *Configuration

	Executor Executor
	// contains filtered or unexported fields
}

func NewRunner

func NewRunner(c *Configuration) *Runner

func (*Runner) Ban added in v0.0.9

func (rn *Runner) Ban(ip string, ipv6 bool, d time.Duration) error

func (*Runner) Finalize added in v0.0.2

func (rn *Runner) Finalize() error

func (*Runner) Initialize added in v0.0.2

func (rn *Runner) Initialize() error

func (*Runner) Run added in v0.0.2

func (rn *Runner) Run(requeueWorkers bool)

func (*Runner) Stop added in v0.0.2

func (rn *Runner) Stop()

type Source added in v0.0.4

type Source interface {
	Initialize(r *Rule) error
	Matches() (chan *Match, error)
}

func NewFileSource added in v0.0.4

func NewFileSource() Source

func NewKernelSource added in v0.0.4

func NewKernelSource() Source

func NewProcessSource added in v0.0.4

func NewProcessSource() Source

func NewSystemdSource added in v0.0.4

func NewSystemdSource() Source

func NewTestSource added in v0.0.4

func NewTestSource() Source

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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