fix(setup): persist firewall rules across reboot + report errors instead of swallowing#29
Closed
NeritonDias wants to merge 1 commit into
Closed
Conversation
…f swallowing them
Reproduced on Oracle Cloud (Ubuntu 24.04 cloud image): wizard prints
"Firewall ports opened (80, 443)" but the dashboard is unreachable
from outside, and after a reboot the iptables rules vanish entirely.
Three bugs in the original one-liner:
os.system("ufw allow 80/tcp 2>/dev/null; ufw allow 443/tcp 2>/dev/null; ...")
os.system("iptables -I INPUT -p tcp --dport 80 -j ACCEPT 2>/dev/null; ...")
print("Firewall ports opened") # always prints, regardless
1. ``2>/dev/null`` swallows every error. On OCI/Ubuntu cloud images
``ufw`` isn't installed — the ufw lines all fail silently. The
iptables fallback often runs, but if it errors (permission,
nf_tables backend rejection, missing CAP_NET_ADMIN) you'd never
know.
2. Nothing calls ``netfilter-persistent save`` (or saves to
``/etc/iptables/rules.v4``). Even when iptables -I succeeds,
the next reboot reloads the persistent ruleset which doesn't
include 80/443 → dashboard offline until the operator manually
re-runs setup.
3. Re-running the wizard adds duplicate ACCEPT rules each time
(no -C check before -I).
Refactor:
* New helper ``_open_firewall_ports(ports)`` that prefers ufw when
present (it persists itself), falls back to iptables with -C
idempotency check, and PERSISTS via netfilter-persistent —
auto-installing iptables-persistent on Debian/Ubuntu if missing.
Falls back further to ``iptables-save > /etc/iptables/rules.v4``.
* Surfaces actual errors instead of silencing. Reports which
backend was used and which persistence path succeeded.
* Best-effort cloud-provider detection (OCI, AWS, GCP, Azure,
DigitalOcean, Hetzner) via /sys/class/dmi/id/* — prints a hint
that host-level firewall changes alone may not be enough; the
operator likely also needs to open the port in the cloud
Security List/Group/NSG. (No host-level command can fix the
cloud network firewall — but a clear hint saves hours of
debugging "523 Origin Unreachable" from Cloudflare.)
Translation keys: 7 new, mirrored across en-US / pt-BR / es. Bundles
remain at exact key parity (160 each).
Verified locally:
* Oracle Cloud Ubuntu 24.04: rules go in via iptables, persist via
netfilter-persistent, survive reboot. Hint about OCI Security
List shown.
* Ubuntu desktop with ufw: rules go in via ufw, persist
automatically, no extra hint shown.
* Re-running wizard: idempotent (no duplicate INPUT rules).
There was a problem hiding this comment.
Sorry @NeritonDias, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
5 tasks
Contributor
Author
|
Superseded by #28 — unified all three fixes (start-services preservation, scheduler PID dir, firewall persistence) into a single PR. They form one coherent end-to-end fix for fresh VPS installs surviving the first reboot, and bundling reduces the risk of a partial squash-merge (cf. what happened with #27). The exact firewall changes from this PR are commit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reproduced on Oracle Cloud (Ubuntu 24.04 cloud image): the wizard prints "Firewall ports opened (80, 443)" but the dashboard is unreachable from outside, and after a reboot the iptables rules vanish entirely. Cloudflare returns 523 "Origin Unreachable" for the duration.
Repro
Root cause
Three bugs in the original one-liner:
2>/dev/nullswallows every error. OCI/Ubuntu cloud images don't shipufw— every ufw line silently fails. The iptables fallback often runs, but if it errors (permission, nf_tables backend rejection, missing CAP_NET_ADMIN inside a container) you'd never know.netfilter-persistent save(or writes to/etc/iptables/rules.v4). Even when iptables -I succeeds, the next reboot reloads the persistent ruleset which doesn't include 80/443 → dashboard offline until the operator manually re-runs setup.-Ccheck before-I).Fix
New helper
_open_firewall_ports(ports):ufwwhen present (handles persistence itself).iptables, with-Cidempotency check before-I(re-runs on the same machine don't pile up duplicate rules).netfilter-persistent save— auto-installsiptables-persistentnon-interactively on Debian/Ubuntu if missing. Last-resort fallback writes/etc/iptables/rules.v4directly./sys/class/dmi/id/*— prints a hint that host-level firewall changes alone may not be enough; the operator likely also needs to open the port in the cloud Security List/Group/NSG. No host-level command can fix the cloud network firewall — but a clear hint saves hours of debugging "523 Origin Unreachable" from Cloudflare.7 new translation keys, mirrored across en-US / pt-BR / es. Bundles remain at exact key parity (160 each).
Test plan
python -c "import ast; ast.parse(open('setup.py',encoding='utf-8').read())"— clean parse.format(tool=, err=, provider=)iptables-save | grep dportshows 80 + 443 →curl -I https://<domain>/from a different machine returns 200.Breaking changes
None.
iptables-persistentis auto-installed only when iptables is the active backend ANDapt-getis available.