openwrt refactor & apply rules
This commit is contained in:
1 parent
c1c17ec8e6
commit
a9aaae3da9
7 files changed
+735
-149
No files matched your search
@@ -9,10 +9,18 @@ so this provides a declarative, reviewable way to push `dnsmasq.conf` and `/etc/
|
||||
|
||||
```
|
||||
openwrt/
|
||||
├── default.nix # Builds the Rust generator + the openwrt-deploy script
|
||||
└── generator/ # Rust crate (openwrt-gen) that turns a JSON config into OpenWrt files
|
||||
├── default.nix # Thin Nix wrapper: builds the generator, exports store paths as
|
||||
│ # env vars, and inlines the .sh files below via builtins.readFile
|
||||
├── skyg-apply.sh # Runs ON THE ROUTER (POSIX sh) — backup/apply/validate/restore
|
||||
├── openwrt-deploy.sh # openwrt-deploy's logic (bash) — reads $ROUTER/$GENERATOR/etc.
|
||||
├── openwrt-dry-run.sh # openwrt-dry-run's logic (bash) — reads $GENERATOR
|
||||
└── generator/ # Rust crate (openwrt-gen) that turns a JSON config into OpenWrt files
|
||||
```
|
||||
|
||||
The three `.sh` files are real, directly-editable/shellcheck-able scripts — `default.nix` only
|
||||
supplies the Nix-computed values (router address, generator/apply-script store paths) as
|
||||
exported env vars before inlining each file's content via `builtins.readFile`.
|
||||
|
||||
## How it works
|
||||
|
||||
1. The router config lives as an **agenix secret** (e.g. `secrets/glmain.json.age`).
|
||||
@@ -23,9 +31,12 @@ openwrt/
|
||||
`-> N added, M removed` summary, then lists the `skyg_*` rule names that will be
|
||||
applied, and prompts for confirmation.
|
||||
4. On the router it **backs up** the configs it overrides to `/etc/skyg-backups/` with a
|
||||
timestamp, then applies them. `dnsmasq.conf` is validated with `dnsmasq --test` and the
|
||||
firewall is committed + reloaded; **any failure auto-restores** from that timestamp's
|
||||
backups. Backups persist so you can restore later if something breaks:
|
||||
timestamp, then applies them. It also ensures `net.bridge.bridge-nf-call-iptables` /
|
||||
`-ip6tables` are enabled via a managed block in `/etc/sysctl.conf` (see Conventions below
|
||||
— required for the firewall rules to actually see LAN-to-LAN traffic). `dnsmasq.conf` is
|
||||
validated with `dnsmasq --test` and the firewall is committed + reloaded; **any failure
|
||||
auto-restores** from that timestamp's backups. Backups persist so you can restore later if
|
||||
something breaks:
|
||||
```sh
|
||||
cp /etc/skyg-backups/firewall.<ts> /etc/config/firewall
|
||||
uci commit firewall && /etc/init.d/firewall restart
|
||||
@@ -45,7 +56,7 @@ is passed as a command-line argument (default `glmain`).
|
||||
skyg openwrt --dry-run
|
||||
# → .tmp/openwrt-glmain/dnsmasq.conf
|
||||
# → .tmp/openwrt-glmain/ethers
|
||||
# → .tmp/openwrt-glmain/firewall.batch # the exact `uci batch` that would be applied
|
||||
# → .tmp/openwrt-glmain/firewall.batch # the exact `uci -m import firewall` input
|
||||
```
|
||||
|
||||
Use this to inspect what a deploy *would* do (especially the firewall rules) before running
|
||||
@@ -60,5 +71,17 @@ the real `skyg openwrt`.
|
||||
confirmation and self-reverts on a bad dnsmasq config.
|
||||
- `generator/target/` is gitignored Rust build output — ignore it.
|
||||
- Firewall rules are **managed by name**: the deploy script only touches rules named
|
||||
`skyg_*`. It deletes existing `skyg_*` rules, adds the newly generated ones, commits, and
|
||||
reloads — so deploys are idempotent and never clobber hand-written rules.
|
||||
`skyg_*`. It deletes existing `skyg_*` rules, adds the newly generated ones as real named
|
||||
UCI sections via `uci -m import firewall` (not `uci batch` — the generator's output is
|
||||
declarative `config rule 'name'` syntax, not batch commands), commits, and reloads — so
|
||||
deploys are idempotent and never clobber hand-written rules.
|
||||
- **The LAN is one flat L2 bridge, not real per-network VLANs.** `apl`, `cam`, `lab`, etc. are
|
||||
just address-range conventions within a single `br-lan` (one `/16`, all ports bridged
|
||||
together). Because of this, unicast traffic between two hosts on the bridge is normally
|
||||
switched at L2 and never reaches the router's iptables FORWARD chain — so the `skyg_*`
|
||||
internet-only DROP rules would silently never fire. `skyg-apply.sh` works around this by
|
||||
enabling `net.bridge.bridge-nf-call-iptables` / `-ip6tables` (via a managed block appended
|
||||
to `/etc/sysctl.conf`, since `/etc/sysctl.d/*.conf` ships them disabled and is reset on
|
||||
firmware upgrades) so bridged traffic is actually filtered. Confirmed live: without this,
|
||||
an `internetOnly`-flagged device's DROP rule showed 0/0 packet/byte counters in
|
||||
`iptables -L -v -n` despite matching traffic; with it enabled, blocking works as expected.
|
||||
Reference in new issue
Block a user