fix(config): import replace and rollback configs through a private temporary file (#45) #46

Merged
christianmanivong merged 2 commits from fix/config-tempfile-2446 into main 2026-11-13 09:09:25 +00:00
Owner

What was wrong: a replace commit_config() and rollback() wrote the config as root to a fixed name in /tmp (/tmp/napalm_candidate.uci, /tmp/napalm_rollback.uci) and imported it with a second command. A local account could place that file (or a symlink) beforehand, or swap it in between, and have its own config imported and committed. Found in NetOrk/netork#2446.

Fix: _uci_import_command() builds one command per import: f=$(umask 077 && mktemp) && { printf '%s' <config, shlex-quoted> > "$f" && uci import < "$f" && uci commit; rm -f "$f"; }. The file is removed whether the import worked or not; the import's output still reaches the error check.

Tests: tests/unit/test_config_import_tempfile.py — commit (replace) and rollback each send one import command through a private mktemp file, no /tmp name, with the config as one word, single quotes included (red before the fix). Checked the command in a real sh with a stand-in uci: the config arrives intact, the file is mode 600 and is gone afterwards.

Merge note: #44 (set_hostname quoting) also adds to the Unreleased ### Fixed section of the CHANGELOG; whichever goes second needs a trivial merge there.

Closes #45

**What was wrong:** a replace `commit_config()` and `rollback()` wrote the config as root to a fixed name in /tmp (`/tmp/napalm_candidate.uci`, `/tmp/napalm_rollback.uci`) and imported it with a second command. A local account could place that file (or a symlink) beforehand, or swap it in between, and have its own config imported and committed. Found in NetOrk/netork#2446. **Fix:** `_uci_import_command()` builds one command per import: `f=$(umask 077 && mktemp) && { printf '%s' <config, shlex-quoted> > "$f" && uci import < "$f" && uci commit; rm -f "$f"; }`. The file is removed whether the import worked or not; the import's output still reaches the error check. **Tests:** `tests/unit/test_config_import_tempfile.py` — commit (replace) and rollback each send one import command through a private mktemp file, no /tmp name, with the config as one word, single quotes included (red before the fix). Checked the command in a real `sh` with a stand-in `uci`: the config arrives intact, the file is mode 600 and is gone afterwards. Merge note: #44 (set_hostname quoting) also adds to the Unreleased `### Fixed` section of the CHANGELOG; whichever goes second needs a trivial merge there. Closes #45
christianmanivong added 1 commit 2026-11-12 21:33:54 +00:00
fix(config): import replace and rollback configs through a private temporary file (#45)
driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 19s
driver / types (pull_request) Successful in 57s
driver / test (3.12) (pull_request) Successful in 1m0s
driver / test (3.13) (pull_request) Successful in 51s
driver / lowest (pull_request) Successful in 29s
driver / build (pull_request) Successful in 36s
driver / security (pull_request) Successful in 1m13s
CI / driver (pull_request) Successful in 2m50s
driver / publish (pull_request) Skipped
248c87009f
A replace commit_config() and rollback() wrote the config as root to a
fixed name in /tmp (/tmp/napalm_candidate.uci, /tmp/napalm_rollback.uci)
and imported it with a second command. A local account could place that
file beforehand, or swap it in between, and have its own config imported
and committed (NetOrk/netork#2446).

Each import is now one command: a mktemp file made under umask 077, the
config written to it, `uci import < "$f" && uci commit`, then the file
removed.
christianmanivong added 1 commit 2026-11-13 08:57:39 +00:00
Merge remote-tracking branch 'origin/main' into fix/config-tempfile-2446
driver / standard (pull_request) Successful in 14s
driver / lint (pull_request) Successful in 12s
driver / types (pull_request) Successful in 53s
driver / test (3.12) (pull_request) Successful in 55s
driver / test (3.13) (pull_request) Successful in 51s
driver / lowest (pull_request) Successful in 24s
driver / build (pull_request) Successful in 26s
driver / security (pull_request) Successful in 57s
CI / driver (pull_request) Successful in 2m14s
driver / publish (pull_request) Skipped
27ca0667d8
christianmanivong merged commit de11d16749 into main 2026-11-13 09:09:25 +00:00
christianmanivong deleted branch fix/config-tempfile-2446 2026-11-13 09:09:25 +00:00
Sign in to join this conversation.