[roads] QA F-01: a service road grants only that service
A firewall sees an address and a port, never a hostname, so a road to photos.home.arpa compiled to home-server:443 and also opened git.home.arpa there. Rules are now per service: - devices.json services may carry their own mesh address (same rules as a device address, unique among all of them). A road to such a service compiles to that address only; the hosting device's plan lists it in the new field services[] so it answers on it, and DNS points there. - A road to a service that shares its address and a port with another service is refused (service.shared), naming the others, instead of opening both. Narrowing ports: to a port nobody else serves on that address is allowed. - A device: road reaches the whole device: its own address and its services' own addresses. No Ianitor identity check is needed for this. The home fixture gives photos its own address (100.96.1.2); tests that encoded the old host:port model are updated, three new snapshot fixtures cover the address rules, and the golden plans and pinned digest are regenerated. Mutation-checked: dropping the refusal, or ignoring the service address, each fails an F-01 test.
This commit is contained in:
@@ -29,7 +29,6 @@ fn with(parts: Parts, r: (String, String)) -> Parts {
|
||||
/// only say "Jana's address may reach 100.96.0.2 on tcp/443", and photos and git both live there on tcp/443,
|
||||
/// so "Jana can reach Photos" is also "Jana can reach Git"; `explain` admits it.
|
||||
#[test]
|
||||
#[ignore = "QA F-01 (blocker): a service road grants every service on the same host and port"]
|
||||
fn f01_a_service_road_grants_only_that_service() {
|
||||
// Without the household road, Jana's only road to the home server is 7tq0mz: photos, tcp/443.
|
||||
let parts = Parts::home().without_road("k3f9q2");
|
||||
@@ -48,6 +47,67 @@ fn f01_a_service_road_grants_only_that_service() {
|
||||
);
|
||||
}
|
||||
|
||||
/// F-01, the other half: without its own address, photos shares home-server:443 with git, and the road to
|
||||
/// photos is refused, naming git, instead of opening both. A `ports:` that avoids the shared port is allowed.
|
||||
#[test]
|
||||
fn f01_a_service_that_shares_its_address_and_port_is_refused() {
|
||||
let parts = Parts::home().edit_devices(|d| d.replace(r#", "address": "100.96.1.2""#, ""));
|
||||
let c = parts.compile();
|
||||
let p = c
|
||||
.problems
|
||||
.iter()
|
||||
.find(|p| p.path.contains("7tq0mz") && p.code == roads::rules::SERVICE_SHARED);
|
||||
assert!(
|
||||
p.is_some_and(|p| p.is_error() && p.message.contains("git.home.arpa")),
|
||||
"{:?}",
|
||||
c.problems
|
||||
);
|
||||
assert!(
|
||||
!c.plans[&key(3)]
|
||||
.dns
|
||||
.iter()
|
||||
.any(|d| d.host.as_str() == "photos.home.arpa"),
|
||||
"the refused road still granted"
|
||||
);
|
||||
// Git alone on tcp/22 shares nothing: a road narrowed to it compiles.
|
||||
let narrowed = Parts::home()
|
||||
.edit_devices(|d| d.replace(r#", "address": "100.96.1.2""#, ""))
|
||||
.with_road(
|
||||
"f01aaa-jana-git-ssh.md",
|
||||
"---\nid: f01aaa\nsubject: person:jana\nverb: can-reach\nobject: service:git.home.arpa\nports: [tcp/22]\ncreated: 2026-11-25T10:00:00Z\n---\n",
|
||||
)
|
||||
.compile();
|
||||
assert!(
|
||||
!narrowed.problems.iter().any(|p| p.path.contains("f01aaa")),
|
||||
"{:?}",
|
||||
narrowed.problems
|
||||
);
|
||||
}
|
||||
|
||||
/// F-01: with its own address, photos is granted by itself: the rule's destination is that address, the
|
||||
/// home server's plan answers on it, and Jana's DNS points there.
|
||||
#[test]
|
||||
fn f01_a_service_with_its_own_address_is_granted_alone() {
|
||||
let c = Parts::home().without_road("k3f9q2").compile();
|
||||
let server = &c.plans[&key(2)];
|
||||
assert!(server.services.iter().any(|s| s.host.as_str() == "photos.home.arpa" && s.address.to_string() == "100.96.1.2"));
|
||||
let to_photos: Vec<_> = server
|
||||
.firewall
|
||||
.rules
|
||||
.iter()
|
||||
.filter(|r| r.roads.iter().any(|id| id.as_str() == "7tq0mz"))
|
||||
.collect();
|
||||
assert!(!to_photos.is_empty());
|
||||
assert!(
|
||||
to_photos
|
||||
.iter()
|
||||
.all(|r| matches!(r.dst, Dst::Net(n) if n.to_string() == "100.96.1.2/32")),
|
||||
"{to_photos:?}"
|
||||
);
|
||||
let phone = &c.plans[&key(3)];
|
||||
assert!(phone.dns.iter().any(|d| d.host.as_str() == "photos.home.arpa" && d.address.to_string() == "100.96.1.2"));
|
||||
}
|
||||
|
||||
/// F-02. `goes-direct` may name the mesh's own addresses or a subnet the mesh routes. Then traffic that the
|
||||
/// plan also routes into the tunnel is told to bypass it, on whatever network the device is on, and the
|
||||
/// kill switch does not stop it because the subnet is "private".
|
||||
|
||||
Reference in New Issue
Block a user