firewall

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package firewall implements the `coolify firewall` command logic: per-host container discovery (SSH+podman) and the SSH-bounced REST client that drives the coold agent's firewall surface on each mesh host.

Rule-rendering and iptables IO live entirely in coold now (see the coold repo, `src/firewall/`). The CLI's job is to resolve endpoints, compute stable rule identities, and POST/DELETE/GET against coold over SSH. Rules go on the host that owns the destination IP, matching CONTROL_PLANE.md §3.

Index

Constants

View Source
const CooldAPIBasePath = "/api/v1/firewall"

CooldAPIBasePath is the path prefix the coold REST router serves under. Mirrors `src/firewall/api.rs` in the coold repo.

View Source
const CooldAPITokenPath = "/etc/coolify/api-token" //nolint:gosec // filesystem path, not a credential

CooldAPITokenPath is the remote file coold reads its bearer token from. Kept in sync with internal/services/coold.go — the CLI falls back to reading this file over SSH when the user hasn't supplied --coold-token.

View Source
const DefaultWGInterface = "wg0"

DefaultWGInterface is the WireGuard interface name the firewall CLI assumes when no override is supplied. Matches the default of `coolify init --wg-interface`.

Variables

This section is empty.

Functions

func ComputeID

func ComputeID(namespace string, src, dst net.IP, proto string, port int) string

ComputeID returns a 12-hex stable identity hash over (namespace, src, dst, proto, port). Used as the rule comment so `list` can display it and `revoke --from ... --to ... --port ...` finds the right rule without needing to parse.

Byte-compatible with coold's ComputeID_ (src/firewall/rule.rs): namespace defaults to "default" when empty, proto lowercased (empty when unset), port rendered as 0 when unset. Mixed writers (CLI + coold) produce identical IDs for identical tuples.

func CooldApply

func CooldApply(
	ctx context.Context,
	runner ssh.Runner,
	host, user string,
	sshPort, cooldPort int,
	iface, token string,
	r AllowRule,
) error

CooldApply POSTs r to coold's /allow endpoint on host. coold is reached via SSH-bounce: SSH into host, curl localhost wg0 mgmt IP. This is the transport of choice for the alpha because the CLI runs on a laptop that isn't a mesh peer — only hosts inside the wg0 network can reach coold.

func CooldRevoke

func CooldRevoke(
	ctx context.Context,
	runner ssh.Runner,
	host, user string,
	sshPort, cooldPort int,
	iface, token, id string,
) error

CooldRevoke DELETEs rule id from coold on host. coold returns 204 even when the id is unknown, so missing rules are a silent no-op.

func FetchCooldToken

func FetchCooldToken(
	ctx context.Context,
	runner ssh.Runner,
	host, user string,
	sshPort int,
) (string, error)

FetchCooldToken SSHes into host and reads the coold bearer token at CooldAPITokenPath. Each host generates its own random token at install time (see EnsureCooldAPITokenCommand), so per-host fetch is the default path when the user hasn't provided a global --coold-token override.

func ParseDiscoverLine

func ParseDiscoverLine(line string) (id, name string, ip net.IP, ok bool)

ParseDiscoverLine parses one `id|name|ip` line from discoverScript. Returns (_, false) when the line is blank or malformed.

Types

type AllowRule

type AllowRule struct {
	Host      string // host that owns Dst's container subnet
	Namespace string // e.g. "default", "alpha"
	Src       net.IP
	Dst       net.IP
	Proto     string // "tcp" | "udp" | ""
	Port      int    // 0 = any
	Comment   string // "cid:<12-hex>" stable identity for list/revoke
}

AllowRule is a single cross-host container allow entry.

The rule lives on the host that owns Dst's container subnet (the default- deny jump fires on `-d <subnet> -j COOLIFY-INTRA`). Src may belong to any host in the mesh. Proto/Port are optional; zero values mean "any".

Namespace qualifies the tuple so identical src/dst/proto/port pairs in different namespaces produce different rule IDs and are managed independently. Empty namespace is normalized to "default" at the transport boundary for legacy coold peers.

func CooldList

func CooldList(
	ctx context.Context,
	runner ssh.Runner,
	host, user string,
	sshPort, cooldPort int,
	iface, token, namespace string,
) ([]AllowRule, error)

CooldList GETs coold's /allow endpoint on host and returns the parsed rules. An empty namespace means "all namespaces"; a non-empty value is forwarded to coold as `?namespace=<ns>`. Missing coold (no wg0 interface) is treated as an empty slice so a partially-deployed mesh doesn't break `firewall list`.

func CooldListAll

func CooldListAll(
	ctx context.Context,
	runner ssh.Runner,
	hosts []string,
	user string,
	sshPort, cooldPort int,
	iface string,
	tokenFor func(host string) (string, error),
	concurrency int,
	namespace string,
) ([]AllowRule, []ssh.ServerResult[[]AllowRule])

CooldListAll fans CooldList across every host in parallel and returns a stably-sorted flattened slice plus the per-host results. tokenFor is called once per host on its worker goroutine — fail here and the host surfaces as a ServerResult.Err instead of polluting the rule slice. An empty namespace forwards `?namespace=` omitted (coold returns all).

type Container

type Container struct {
	Host      string // SSH host the container runs on
	Namespace string // mesh namespace (podman network is coolify-<ns>-mesh)
	ID        string // short (12-char) podman ID
	Name      string // podman container name
	IP        net.IP // IP on the coolify-<ns>-mesh bridge network
}

Container is a single running podman container on one mesh host and one namespace (podman bridge network).

func DiscoverAll

func DiscoverAll(
	ctx context.Context,
	runner ssh.Runner,
	hosts []string,
	user string,
	port int,
	namespace, networkName string,
	concurrency int,
) ([]Container, []ssh.ServerResult[[]Container])

DiscoverAll runs DiscoverContainers across every host in parallel. Returns a flattened, sort-stable slice plus the per-host results so callers can surface partial failures.

func DiscoverAllNamespaces

func DiscoverAllNamespaces(
	ctx context.Context,
	runner ssh.Runner,
	hosts []string,
	user string,
	port int,
	namespaces []string,
	networkFor func(ns string) string,
	concurrency int,
) ([]Container, []ssh.ServerResult[[]Container])

DiscoverAllNamespaces runs DiscoverAll for every (namespace, network) pair and merges the results. Used by `containers --all-namespaces` and by the allow/revoke resolver so references can be matched across every namespace the user might have set up on the mesh.

func DiscoverContainers

func DiscoverContainers(
	ctx context.Context,
	runner ssh.Runner,
	host, user string,
	port int,
	namespace, networkName string,
) ([]Container, error)

DiscoverContainers SSHes into host and returns every container on networkName (the podman bridge backing namespace) with its bridge IP.

Jump to

Keyboard shortcuts

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