firewall

package
v0.4.0-beta.6 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package firewall is a built-in app modelling a host-wide inbound/outbound firewall. Scaffold only: rules are persisted and validated, Apply is a no-op (enforcement via nftables/iptables is not wired yet).

Index

Constants

View Source
const (
	PolicyAllow = "allow"
	PolicyDeny  = "deny"

	DirInbound  = "inbound"
	DirOutbound = "outbound"
)

Variables

This section is empty.

Functions

func Apply

func Apply(cfg *Config, runner nftRunner) (enforced bool, err error)

Apply enforces the config on the host firewall, or removes FlatRun's rules when the firewall is disabled. It reports whether enforcement actually happened: when nft is unavailable (a non-Linux host, or nft not installed) the config is still saved but not enforced, which is not an error.

Before a new ruleset is loaded the current one is snapshotted, and if the load fails the snapshot is restored, so a rejected ruleset never leaves the host in a half-applied state. The generated ruleset always keeps loopback, established/related, and the active SSH port open, so a default-deny inbound policy cannot drop the operator's session.

func Plan

func Plan(cfg *Config) []string

Plan returns a human-readable description of the rules that would be enforced, so the UI and tests can exercise the shape before real enforcement exists.

func Validate

func Validate(cfg *Config) error

Validate checks the firewall config is well formed before it is saved or applied.

Types

type Config

type Config struct {
	Enabled bool `yaml:"enabled" json:"enabled"`
	// DefaultInbound / DefaultOutbound are the stance applied to traffic not matched by a
	// rule: "allow" (default) or "deny".
	DefaultInbound  string `yaml:"default_inbound,omitempty" json:"default_inbound,omitempty"`
	DefaultOutbound string `yaml:"default_outbound,omitempty" json:"default_outbound,omitempty"`
	Rules           []Rule `yaml:"rules,omitempty" json:"rules,omitempty"`
}

Config is the host firewall policy, stored globally in .flatrun/firewall.yml.

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

Plugin is the built-in Firewall app. It implements plugins.Plugin so it registers in the plugin registry and lists as an installed app.

func New

func New(store *Store) *Plugin

func (*Plugin) EnforceCurrent

func (p *Plugin) EnforceCurrent() (bool, error)

EnforceCurrent applies the stored config to the host firewall. The server calls it at startup so a saved policy takes effect again after a restart.

func (*Plugin) GetCapabilities

func (p *Plugin) GetCapabilities() []plugins.Capability

func (*Plugin) GetWidgetData

func (p *Plugin) GetWidgetData(deploymentName string) (interface{}, error)

func (*Plugin) Info

func (p *Plugin) Info() plugins.PluginInfo

func (*Plugin) RegisterRoutes

func (p *Plugin) RegisterRoutes(router *gin.RouterGroup) error

RegisterRoutes exposes the host firewall config and a read-only plan. Saving validates the config but does not yet enforce it.

type Rule

type Rule struct {
	ID        string `yaml:"id,omitempty" json:"id,omitempty"`
	Direction string `yaml:"direction" json:"direction"` // inbound | outbound
	Action    string `yaml:"action" json:"action"`       // allow | deny
	Protocol  string `yaml:"protocol,omitempty" json:"protocol,omitempty"`
	Port      int    `yaml:"port,omitempty" json:"port,omitempty"`
	// CIDR is the source for inbound rules or the destination for outbound rules.
	CIDR        string `yaml:"cidr,omitempty" json:"cidr,omitempty"`
	Description string `yaml:"description,omitempty" json:"description,omitempty"`
}

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store loads and saves the host firewall config from a flat file.

func NewStore

func NewStore(basePath string) *Store

func (*Store) Load

func (s *Store) Load() (*Config, error)

Load returns the stored config, or a disabled default when no file exists yet.

func (*Store) Save

func (s *Store) Save(cfg *Config) error

Jump to

Keyboard shortcuts

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