fix(vm-provision): quote the cloud-init snippet path in its root command
driver / standard (pull_request) Successful in 17s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Successful in 1m4s
driver / test (3.12) (pull_request) Successful in 1m8s
driver / test (3.13) (pull_request) Successful in 1m4s
driver / lowest (pull_request) Successful in 39s
driver / build (pull_request) Successful in 33s
driver / security (pull_request) Successful in 1m21s
CI / driver (pull_request) Successful in 3m1s
driver / publish (pull_request) Skipped
driver / standard (pull_request) Successful in 17s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Successful in 1m4s
driver / test (3.12) (pull_request) Successful in 1m8s
driver / test (3.13) (pull_request) Successful in 1m4s
driver / lowest (pull_request) Successful in 39s
driver / build (pull_request) Successful in 33s
driver / security (pull_request) Successful in 1m21s
CI / driver (pull_request) Successful in 3m1s
driver / publish (pull_request) Skipped
_write_snippet put the snippet storage's path and the snippet's file name unquoted into the command that writes the snippet as root on the node; a space, ; or $(...) in either was acted on by the shell. Both now go through shlex.quote, and a file name that is not one plain name (a path, a shell character) is refused before anything runs. Closes #47
This commit is contained in:
1 parent
b3fe5009c8
commit
dffb19e3df
3 files changed
+40
-2
No files matched your search
@@ -1501,3 +1501,30 @@ def test_a_checksum_algorithm_outside_the_known_ones_is_refused():
|
||||
)
|
||||
|
||||
assert not any("reboot" in c.args[0] for c in mixin._run_node_command.call_args_list)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# The cloud-init snippet's path in a root shell command (#47)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_a_snippet_storage_path_stays_one_argument(tmp_path, monkeypatch):
|
||||
storage = tmp_path / "a b;reboot;$(reboot)"
|
||||
mixin = _hostile_shell(tmp_path, monkeypatch)
|
||||
|
||||
mixin._write_snippet(str(storage), "101-user-data.yaml", "#cloud-config\n")
|
||||
|
||||
assert not (tmp_path / "injected").exists()
|
||||
assert (storage / "snippets" / "101-user-data.yaml").read_text() == "#cloud-config\n"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"filename", ["x;reboot;.yaml", "../../etc/cron.d/x", "a b.yaml", "$(reboot).yaml", ""]
|
||||
)
|
||||
def test_a_snippet_name_that_is_not_a_plain_file_name_is_refused(filename):
|
||||
mixin = ProxmoxVMProvisionMixin()
|
||||
mixin._run_node_command = MagicMock(return_value="")
|
||||
|
||||
with pytest.raises(ValueError, match="snippet"):
|
||||
mixin._write_snippet("/var/lib/vz", filename, "#cloud-config\n")
|
||||
mixin._run_node_command.assert_not_called()
|
||||
Reference in new issue
Block a user