feat(webserver): restrict the port rule by group or sources #57

Merged
claudiomaradonna merged 3 commits from feat/webserver-restricted-sources into main 2026-11-21 14:48:54 +01:00
Collaborator

Why

webserver's port file is the only HTTP rule firewall-apply renders, and
it always opened webserver_ports to every source. A host that runs a
forwarder on its own network (network_mode: host) for a cluster's reverse
proxy needs that port reachable from the cluster's nodes alone: today a
tenant can either open it to everyone or leave it shut, and the proxy then
answers 504.

Closes #56

What changed

Two host variables now restrict the webserver rule. webserver_from_group
admits the IPv4 addresses firewall-apply derives from that group's other
members, as swarm_peers_group does; webserver_sources admits listed
addresses or CIDRs. With either set, the chain renders
ip saddr { … } tcp dport { … }, and a group that derives nobody, with no
sources, drops the rule and shuts the ports, as every restricted rule does.

With neither set, or with webserver_sources: [] and no group, the rule
stays open to every source, exactly as before. That is a deliberate
exception to the empty-source rule of the other port files; the port file
computes open itself, so firewall-apply is unchanged.
docs/ARCHITECTURE.md § Firewall names the exception and the webserver
README owns it.

How to verify

From a checkout prepared as CONTRIBUTING
describes, render the table from tests/fixtures/firewall_render/loader.yml
on base 607ddc0 and branch 9fe0d4b, and read the webserver chain:

.venv/bin/ansible-playbook -i tests/fixtures/local.yml \
  tests/fixtures/firewall_render/loader.yml -e fixture_file=/tmp/t.nft \
  -e '{"webserver_sources": ["192.0.2.30"], "webserver_ports": [8080]}'
awk '$1=="chain" && $2=="webserver" {on=1; next} on && $1=="}" {exit} on' /tmp/t.nft
-e Base 607ddc0 Branch 9fe0d4b
webserver_sources: [192.0.2.30], webserver_ports: [8080] tcp dport { 8080 } ct state new accept ip saddr { 192.0.2.30 } tcp dport { 8080 } ct state new accept
webserver_from_group: all (only self, which is excluded) tcp dport { 80, 443 } ct state new accept no rule: dropped, reported as webserver: nothing admitted for webserver
none tcp dport { 80, 443 } ct state new accept the same

All three scenarios were run as written, on both revisions.

Checks run on the branch:

  • make check passes on every commit.
  • New regression cases fail on the base at their assertions and pass on the
    branch: in check_firewall_render.sh, webserver_sources restricting
    the rule and a group that derives nobody dropping it; in
    check_peer_derivation.sh, a grouped webserver admitting exactly the
    reachable peer. That last assertion also fails when from_group: is
    deleted from the port file.
  • The pin that webserver_sources: [] stays open passes on both
    revisions.

Not run, because podman was absent: make test, which covers the
molecule scenarios and the tag_propagation gate. That includes
firewall-apply's default scenario, which pins the unset case with
nft on a real table. Expected result: unchanged, passing.

Considerations

  • An empty webserver_sources, for example a templated list that comes
    out empty, leaves the ports open to every source rather than dropping
    the rule. This matches the base's behaviour and is the agreed semantics.
  • A restricted rule is IPv4 only, as every restricted rule is, so a
    restricted webserver admits no IPv6 client.
  • The restriction covers all of webserver_ports on a host. One host
    cannot serve 80/443 publicly and keep another port restricted.
  • Set aside from review: a low layout note on a short line in the
    README paragraph (raised in the second round).
## Why `webserver`'s port file is the only HTTP rule `firewall-apply` renders, and it always opened `webserver_ports` to every source. A host that runs a forwarder on its own network (`network_mode: host`) for a cluster's reverse proxy needs that port reachable from the cluster's nodes alone: today a tenant can either open it to everyone or leave it shut, and the proxy then answers 504. Closes #56 ## What changed Two host variables now restrict the webserver rule. `webserver_from_group` admits the IPv4 addresses `firewall-apply` derives from that group's other members, as `swarm_peers_group` does; `webserver_sources` admits listed addresses or CIDRs. With either set, the chain renders `ip saddr { … } tcp dport { … }`, and a group that derives nobody, with no sources, drops the rule and shuts the ports, as every restricted rule does. With neither set, or with `webserver_sources: []` and no group, the rule stays open to every source, exactly as before. That is a deliberate exception to the empty-source rule of the other port files; the port file computes `open` itself, so `firewall-apply` is unchanged. `docs/ARCHITECTURE.md` § Firewall names the exception and the webserver README owns it. ## How to verify From a checkout prepared as [CONTRIBUTING](CONTRIBUTING.md#setup) describes, render the table from `tests/fixtures/firewall_render/loader.yml` on base `607ddc0` and branch `9fe0d4b`, and read the `webserver` chain: ```bash .venv/bin/ansible-playbook -i tests/fixtures/local.yml \ tests/fixtures/firewall_render/loader.yml -e fixture_file=/tmp/t.nft \ -e '{"webserver_sources": ["192.0.2.30"], "webserver_ports": [8080]}' awk '$1=="chain" && $2=="webserver" {on=1; next} on && $1=="}" {exit} on' /tmp/t.nft ``` | `-e` | Base 607ddc0 | Branch 9fe0d4b | | ---- | ------------ | -------------- | | `webserver_sources: [192.0.2.30]`, `webserver_ports: [8080]` | `tcp dport { 8080 } ct state new accept` | `ip saddr { 192.0.2.30 } tcp dport { 8080 } ct state new accept` | | `webserver_from_group: all` (only `self`, which is excluded) | `tcp dport { 80, 443 } ct state new accept` | no rule: dropped, reported as `webserver: nothing admitted for webserver` | | none | `tcp dport { 80, 443 } ct state new accept` | the same | All three scenarios were run as written, on both revisions. Checks run on the branch: - `make check` passes on every commit. - New regression cases fail on the base at their assertions and pass on the branch: in `check_firewall_render.sh`, `webserver_sources` restricting the rule and a group that derives nobody dropping it; in `check_peer_derivation.sh`, a grouped webserver admitting exactly the reachable peer. That last assertion also fails when `from_group:` is deleted from the port file. - The pin that `webserver_sources: []` stays open passes on both revisions. Not run, because podman was absent: `make test`, which covers the molecule scenarios and the `tag_propagation` gate. That includes `firewall-apply`'s `default` scenario, which pins the unset case with `nft` on a real table. Expected result: unchanged, passing. ## Considerations - An empty `webserver_sources`, for example a templated list that comes out empty, leaves the ports open to every source rather than dropping the rule. This matches the base's behaviour and is the agreed semantics. - A restricted rule is IPv4 only, as every restricted rule is, so a restricted webserver admits no IPv6 client. - The restriction covers all of `webserver_ports` on a host. One host cannot serve 80/443 publicly and keep another port restricted. - Set aside from review: a low layout note on a short line in the README paragraph (raised in the second round).
With webserver_sources set to an empty list, the webserver chain admits
its ports from every source, as it does today. The restriction that
follows keeps it so: only a listed source or a group restricts the
rule.
A host that runs a forwarder on its own network for a cluster's proxy
needs its port admitted from the cluster's nodes alone, and the only
HTTP port file opened every source. webserver_from_group and
webserver_sources now restrict the rule; with neither set it stays open
to every source, as before.

Refs #56
docs(webserver): document the restricting variables
All checks were successful
check / check (pull_request) Successful in 19m52s
check / check (push) Successful in 20m24s
9fe0d4b312
claudiomaradonna deleted branch feat/webserver-restricted-sources 2026-11-21 14:49:03 +01:00
Sign in to join this conversation.
No description provided.