|
|
|
|
@ -2136,14 +2136,22 @@ def test_native_runtime_guard_rejects_inactive_unmasked_firewalld(tmp_path):
|
|
|
|
|
assert result.returncode != 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_underlay_route_path_requires_exact_selected_source(tmp_path):
|
|
|
|
|
@pytest.mark.parametrize(("distribution", "target", "source"), [
|
|
|
|
|
("debian-13-iproute2-6.15", "203.0.113.123", "203.0.113.126"),
|
|
|
|
|
("almalinux-10-iproute-6.17", "198.51.100.126", "198.51.100.123"),
|
|
|
|
|
])
|
|
|
|
|
def test_underlay_route_path_accepts_real_explicit_from_output(
|
|
|
|
|
tmp_path, distribution, target, source,
|
|
|
|
|
):
|
|
|
|
|
fake_ip = tmp_path / "ip"
|
|
|
|
|
fake_ip.write_text(
|
|
|
|
|
"#!/bin/sh\n"
|
|
|
|
|
"if [ \"${5:-}\" = from ]; then\n"
|
|
|
|
|
" printf '%s dev %s src %s\\n' \"$4\" \"$VC_FROM_DEV\" \"$VC_FROM_SRC\"\n"
|
|
|
|
|
" printf '%s from %s dev %s uid 0\\n cache\\n' "
|
|
|
|
|
"\"$4\" \"$VC_FROM_SRC\" \"$VC_FROM_DEV\"\n"
|
|
|
|
|
"else\n"
|
|
|
|
|
" printf '%s dev %s src %s\\n' \"$4\" \"$VC_PLAIN_DEV\" \"$VC_PLAIN_SRC\"\n"
|
|
|
|
|
" printf '%s dev %s src %s uid 0\\n cache\\n' "
|
|
|
|
|
"\"$4\" \"$VC_PLAIN_DEV\" \"$VC_PLAIN_SRC\"\n"
|
|
|
|
|
"fi\n",
|
|
|
|
|
encoding="utf-8",
|
|
|
|
|
)
|
|
|
|
|
@ -2153,29 +2161,123 @@ def test_underlay_route_path_requires_exact_selected_source(tmp_path):
|
|
|
|
|
f"IP='{fake_ip}'",
|
|
|
|
|
"find_tool() { for p in \"$@\"; do [ -x \"$p\" ] && { printf '%s' \"$p\"; return 0; }; done; return 1; }",
|
|
|
|
|
_FIREWALL_MODE_GUARD_SH,
|
|
|
|
|
"vc_underlay_route_path 203.0.113.2 203.0.113.1",
|
|
|
|
|
f"vc_underlay_route_path {target} {source}",
|
|
|
|
|
))
|
|
|
|
|
base_env = {
|
|
|
|
|
"PATH": "/usr/bin:/bin",
|
|
|
|
|
"VC_PLAIN_DEV": "eth0",
|
|
|
|
|
"VC_FROM_DEV": "eth0",
|
|
|
|
|
"VC_FROM_SRC": "203.0.113.1",
|
|
|
|
|
"VC_PLAIN_DEV": "br0",
|
|
|
|
|
"VC_FROM_DEV": "br0",
|
|
|
|
|
"VC_FROM_SRC": source,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
exact = subprocess.run(
|
|
|
|
|
["/bin/sh", "-c", script],
|
|
|
|
|
env={**base_env, "VC_PLAIN_SRC": source},
|
|
|
|
|
check=False, capture_output=True, text=True,
|
|
|
|
|
)
|
|
|
|
|
assert exact.returncode == 0, f"{distribution}: {exact.stderr}"
|
|
|
|
|
assert exact.stdout == f"br0|{source}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(("plain_source", "explicit_source"), [
|
|
|
|
|
("10.20.30.40", "203.0.113.1"),
|
|
|
|
|
("203.0.113.1", "10.20.30.40"),
|
|
|
|
|
])
|
|
|
|
|
def test_underlay_route_path_rejects_inexact_plain_or_explicit_source(
|
|
|
|
|
tmp_path, plain_source, explicit_source,
|
|
|
|
|
):
|
|
|
|
|
fake_ip = tmp_path / "ip"
|
|
|
|
|
fake_ip.write_text(
|
|
|
|
|
"#!/bin/sh\n"
|
|
|
|
|
"if [ \"${5:-}\" = from ]; then\n"
|
|
|
|
|
" printf '%s from %s dev eth0 uid 0\\n cache\\n' "
|
|
|
|
|
"\"$4\" \"$VC_FROM_SRC\"\n"
|
|
|
|
|
"else\n"
|
|
|
|
|
" printf '%s dev eth0 src %s uid 0\\n cache\\n' "
|
|
|
|
|
"\"$4\" \"$VC_PLAIN_SRC\"\n"
|
|
|
|
|
"fi\n",
|
|
|
|
|
encoding="utf-8",
|
|
|
|
|
)
|
|
|
|
|
fake_ip.chmod(0o700)
|
|
|
|
|
script = "\n".join((
|
|
|
|
|
"set -eu",
|
|
|
|
|
f"IP='{fake_ip}'",
|
|
|
|
|
"find_tool() { for p in \"$@\"; do [ -x \"$p\" ] && { printf '%s' \"$p\"; return 0; }; done; return 1; }",
|
|
|
|
|
_FIREWALL_MODE_GUARD_SH,
|
|
|
|
|
"vc_underlay_route_path 203.0.113.2 203.0.113.1",
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
mismatch = subprocess.run(
|
|
|
|
|
["/bin/sh", "-c", script],
|
|
|
|
|
env={**base_env, "VC_PLAIN_SRC": "10.20.30.40"},
|
|
|
|
|
env={
|
|
|
|
|
"PATH": "/usr/bin:/bin",
|
|
|
|
|
"VC_PLAIN_SRC": plain_source,
|
|
|
|
|
"VC_FROM_SRC": explicit_source,
|
|
|
|
|
},
|
|
|
|
|
check=False, capture_output=True, text=True,
|
|
|
|
|
)
|
|
|
|
|
assert mismatch.returncode != 0
|
|
|
|
|
|
|
|
|
|
exact = subprocess.run(
|
|
|
|
|
|
|
|
|
|
def _run_underlay_explicit_evidence(
|
|
|
|
|
tmp_path: Path, explicit_output: str,
|
|
|
|
|
) -> subprocess.CompletedProcess[str]:
|
|
|
|
|
fake_ip = tmp_path / "ip"
|
|
|
|
|
fake_ip.write_text(
|
|
|
|
|
"#!/bin/sh\n"
|
|
|
|
|
"if [ \"${5:-}\" = from ]; then\n"
|
|
|
|
|
" printf '%s\\n' \"$VC_EXPLICIT_OUTPUT\"\n"
|
|
|
|
|
"else\n"
|
|
|
|
|
" printf '%s\\n' '203.0.113.2 dev br0 src 203.0.113.1 uid 0'\n"
|
|
|
|
|
"fi\n",
|
|
|
|
|
encoding="utf-8",
|
|
|
|
|
)
|
|
|
|
|
fake_ip.chmod(0o700)
|
|
|
|
|
script = "\n".join((
|
|
|
|
|
"set -eu",
|
|
|
|
|
f"IP='{fake_ip}'",
|
|
|
|
|
"find_tool() { for p in \"$@\"; do [ -x \"$p\" ] && { printf '%s' \"$p\"; return 0; }; done; return 1; }",
|
|
|
|
|
_FIREWALL_MODE_GUARD_SH,
|
|
|
|
|
"vc_underlay_route_path 203.0.113.2 203.0.113.1",
|
|
|
|
|
))
|
|
|
|
|
return subprocess.run(
|
|
|
|
|
["/bin/sh", "-c", script],
|
|
|
|
|
env={**base_env, "VC_PLAIN_SRC": "203.0.113.1"},
|
|
|
|
|
env={
|
|
|
|
|
"PATH": "/usr/bin:/bin",
|
|
|
|
|
"VC_EXPLICIT_OUTPUT": explicit_output,
|
|
|
|
|
},
|
|
|
|
|
check=False, capture_output=True, text=True,
|
|
|
|
|
)
|
|
|
|
|
assert exact.returncode == 0, exact.stderr
|
|
|
|
|
assert exact.stdout == "eth0|203.0.113.1"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_underlay_route_path_accepts_matching_optional_selected_source(
|
|
|
|
|
tmp_path,
|
|
|
|
|
):
|
|
|
|
|
result = _run_underlay_explicit_evidence(
|
|
|
|
|
tmp_path,
|
|
|
|
|
"203.0.113.2 from 203.0.113.1 dev br0 "
|
|
|
|
|
"src 203.0.113.1 uid 0",
|
|
|
|
|
)
|
|
|
|
|
assert result.returncode == 0, result.stderr
|
|
|
|
|
assert result.stdout == "br0|203.0.113.1"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("explicit_output", [
|
|
|
|
|
"203.0.113.2 dev br0 uid 0",
|
|
|
|
|
"203.0.113.2 dev br0 src 203.0.113.1 uid 0",
|
|
|
|
|
"203.0.113.2 from 203.0.113.1 from 203.0.113.1 dev br0 uid 0",
|
|
|
|
|
(
|
|
|
|
|
"203.0.113.2 from 203.0.113.1 dev br0 "
|
|
|
|
|
"src 10.20.30.40 uid 0"
|
|
|
|
|
),
|
|
|
|
|
"203.0.113.2 from 203.0.113.1 dev br0 dev br0 uid 0",
|
|
|
|
|
"203.0.113.2 dev br0 src 203.0.113.1 from",
|
|
|
|
|
])
|
|
|
|
|
def test_underlay_route_path_rejects_missing_or_ambiguous_explicit_evidence(
|
|
|
|
|
tmp_path, explicit_output,
|
|
|
|
|
):
|
|
|
|
|
result = _run_underlay_explicit_evidence(tmp_path, explicit_output)
|
|
|
|
|
assert result.returncode != 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _run_native_apply_underlay_preflight(
|
|
|
|
|
@ -2213,8 +2315,8 @@ def _run_native_apply_underlay_preflight(
|
|
|
|
|
" printf '%s\\n' \"203.0.113.2 dev $VC_PLAIN_DEV "
|
|
|
|
|
"src $VC_PLAIN_SRC\" ;;\n"
|
|
|
|
|
" '-4 route get 203.0.113.2 from 203.0.113.1')\n"
|
|
|
|
|
" printf '%s\\n' \"203.0.113.2 dev $VC_FROM_DEV "
|
|
|
|
|
"src $VC_FROM_SRC\" ;;\n"
|
|
|
|
|
" printf '%s\\n' \"203.0.113.2 from $VC_FROM_SRC "
|
|
|
|
|
"dev $VC_FROM_DEV uid 0\" \" cache\" ;;\n"
|
|
|
|
|
" *) exit 91 ;;\n"
|
|
|
|
|
"esac\n",
|
|
|
|
|
encoding="utf-8",
|
|
|
|
|
@ -2268,6 +2370,7 @@ def test_native_apply_uses_local_endpoint_without_firewalld_metadata(tmp_path):
|
|
|
|
|
@pytest.mark.parametrize(("kwargs", "expected_status"), [
|
|
|
|
|
({"local_address": "192.0.2.99"}, 71),
|
|
|
|
|
({"plain_source": "192.0.2.99"}, 77),
|
|
|
|
|
({"from_source": "192.0.2.99"}, 77),
|
|
|
|
|
({"from_device": "eth1"}, 77),
|
|
|
|
|
])
|
|
|
|
|
def test_native_apply_rejects_nonlocal_or_inexact_underlay_path(
|
|
|
|
|
|