Skip to content

Rule templates

A rule template is a reusable set of rules and chain policies for one backend, such as “web server baseline” for iptables. Templates are built by hand, from a host’s desired rules, or from its live firewall, and applied to other hosts by appending to or replacing their desired rules.

Managing templates needs the templates.manage permission; applying one to a host needs rules.edit on it.

Templates in the sidebar lists the templates with backend, number of rules and policies, tags, description and author, filtered by backend. New template creates one by hand: name, backend, tags, description, chain policies and rules (+ Add rule). Copy duplicates a template, Del deletes it.

Changing a template’s backend clears its rules and policies, since chains differ between backends.

  1. On the host page, click Save as template.
  2. Choose what to save:
    • Desired rules (managed by FireHawk): a snapshot of the host’s desired rules.
    • Live rules (read from host over SSH): FireHawk reads the live firewall and lists every rule; tick the ones to keep.
  3. Enter Name, Tags, Description, and tick Include chain policies if wanted.
  4. Click Save template.

Rules FireHawk cannot represent in a template are listed greyed with the reason they were skipped, for example nat tables, Docker chains or firewalld services. A rule with something a template rule cannot hold (a negation, another kind of match, a multi-field set) is skipped rather than imported as a wider rule that would match more traffic.

Rules matching address sets keep them as aliases:

  • a FireHawk set fh_<alias> maps back to that alias;
  • another set becomes a new alias of the same name, filled from the host’s set contents; an existing alias with the same addresses is reused, and one with other addresses is never changed (the new alias is then named <name>_2).

The dialog lists the aliases that saving will create. Creating them needs the aliases.manage permission.

  1. On the host page, click Apply template.
  2. Choose the Template and the Mode:
    • Append to existing rules adds the template’s rules after the host’s rules;
    • Replace existing rules replaces all desired rules of the host.
  3. Tick Apply policies to also set the template’s chain policies.
  4. Click Apply to desired rules.

This only updates the host’s desired rules. Nothing is pushed to the host until you deploy. To apply a template to a whole group, see Host groups.

Templates saved from a full-mode host can contain any table, custom chains and extra matches. They only apply to full-mode hosts. Missing chains are created, and Replace existing rules only replaces the rules of the chains the template uses.

On the Templates page, select templates and click Export selected, or click Export all. FireHawk downloads a firehawk-templates JSON file (format version 2; version 1 files still import) containing the templates without ids or authors, plus the definitions of the aliases their rules use (including aliases they include). A dynamic alias is exported with its current values as a static alias.

  1. Click Import… and choose the file.
  2. The preview shows each template as new, already exists (identical), name exists, different content or invalid (with the reason). Invalid templates are not imported; the valid ones still are.
  3. For each existing name, pick Skip (default), Overwrite or Import as copy (name (2), name (3), …).
  4. Under Aliases used by these templates, check which aliases will be created.
  5. Click Import N templates.

Missing aliases are created. An alias that already exists with other values is never overwritten: it keeps its local values, and the imported rules use them.

Limits: 2 MB per file, 500 templates. Exports and imports are recorded in the audit log.