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
- func ComputeID(namespace string, src, dst net.IP, proto string, port int) string
- func CooldApply(ctx context.Context, runner ssh.Runner, host, user string, ...) error
- func CooldRevoke(ctx context.Context, runner ssh.Runner, host, user string, ...) error
- func FetchCooldToken(ctx context.Context, runner ssh.Runner, host, user string, sshPort int) (string, error)
- func ParseDiscoverLine(line string) (id, name string, ip net.IP, ok bool)
- type AllowRule
- type Container
- func DiscoverAll(ctx context.Context, runner ssh.Runner, hosts []string, user string, port int, ...) ([]Container, []ssh.ServerResult[[]Container])
- func DiscoverAllNamespaces(ctx context.Context, runner ssh.Runner, hosts []string, user string, port int, ...) ([]Container, []ssh.ServerResult[[]Container])
- func DiscoverContainers(ctx context.Context, runner ssh.Runner, host, user string, port int, ...) ([]Container, error)
Constants ¶
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.
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.
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 ¶
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.
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.