Some more hardening to not process raw jinja inside salt/ansible cmd. But, I think this is the end of the road
Some checks failed
Lint / test (push) Waiting to run
CI / test (push) Successful in 57s
CI / test (almalinux, docker.io/library/almalinux:9, python3.11) (push) Has been cancelled
CI / test (debian, docker.io/library/debian:13, python3) (push) Has been cancelled

This commit is contained in:
Miguel Jacq 2026-06-22 20:26:06 +10:00
parent c3c3608049
commit d96ad3dc02
Signed by: mig5
GPG key ID: 03906B4110AAD3B8
9 changed files with 508 additions and 12 deletions

View file

@ -1408,3 +1408,72 @@ def test_manifest_puppet_user_gecos_with_newline_is_single_line(tmp_path: Path):
assert 'comment => "Real Name\\ntouch /tmp/pwned"' in init_pp
# And there must be no line that is just the injected command.
assert "\ntouch /tmp/pwned\n" not in init_pp
def _puppet_hiera_payload_state(payload: str) -> dict:
return {
"schema_version": 3,
"host": {"hostname": "test", "os": "debian", "pkg_backend": "dpkg"},
"inventory": {"packages": {}},
"roles": {
"users": {
"role_name": "users",
"users": [
{
"name": "alice",
"uid": 1000,
"gid": 1000,
"gecos": payload,
"home": "/home/alice",
"shell": "/bin/bash",
"primary_group": "alice",
"supplementary_groups": [],
}
],
"managed_dirs": [],
"managed_files": [],
"managed_links": [],
"excluded": [],
"notes": [],
},
"services": [],
"packages": [],
},
}
def test_manifest_puppet_static_quotes_template_like_harvested_values(
tmp_path: Path,
):
bundle = tmp_path / "bundle"
out = tmp_path / "puppet"
payload = "%{lookup('enroll::classes')}"
_write_state(bundle, _puppet_hiera_payload_state(payload))
manifest.manifest(str(bundle), str(out), target="puppet")
init_pp = (out / "modules" / "users" / "manifests" / "init.pp").read_text(
encoding="utf-8"
)
assert "comment => '%{lookup(\\'enroll::classes\\')}'" in init_pp
def test_manifest_puppet_hiera_escapes_harvested_interpolation_tokens(
tmp_path: Path,
):
bundle = tmp_path / "bundle"
out = tmp_path / "puppet"
payload = "%{lookup('enroll::classes')}"
_write_state(bundle, _puppet_hiera_payload_state(payload))
manifest.manifest(str(bundle), str(out), target="puppet", fqdn="node.example")
node_yaml = out / "data" / "nodes" / "node.example.yaml"
text = node_yaml.read_text(encoding="utf-8")
assert payload not in text
assert "%{literal(''%'')}{lookup(''enroll::classes'')}" in text
data = yaml.safe_load(text)
assert (
data["users::users"]["alice"]["comment"]
== "%{literal('%')}{lookup('enroll::classes')}"
)