[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:
@@ -33,8 +33,8 @@ fn allowed_lists_exactly_the_allowing_roads() {
|
||||
);
|
||||
assert_eq!(
|
||||
ids(&home, 3, &Place::Device(key(2))),
|
||||
["7tq0mz", "k3f9q2"],
|
||||
"a service road reaches part of the device"
|
||||
["k3f9q2"],
|
||||
"photos has its own address (QA F-01): its road reaches that, not the device's own address"
|
||||
);
|
||||
assert_eq!(ids(&home, 1, &subnet("192.168.100.0/24")), ["h2x8vd"]);
|
||||
assert_eq!(
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
{ "key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI", "name": "home-server", "owner": "mark", "address": "100.96.0.2", "exit": true, "relay": true,
|
||||
"routes": ["192.168.100.0/24"],
|
||||
"services": [
|
||||
{ "host": "photos.home.arpa", "ports": ["tcp/443"] },
|
||||
{ "host": "photos.home.arpa", "ports": ["tcp/443"], "address": "100.96.1.2" },
|
||||
{ "host": "git.home.arpa", "ports": ["tcp/443", "tcp/22"] }
|
||||
] },
|
||||
{ "key": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM", "name": "jana-phone", "owner": "jana", "address": "100.96.0.3" },
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"device": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY",
|
||||
"name": "friend-node",
|
||||
"address": "100.96.0.6",
|
||||
"services": [],
|
||||
"classic": false,
|
||||
"expires": null,
|
||||
"peers": [
|
||||
|
||||
+64
-2
@@ -3,6 +3,12 @@
|
||||
"device": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI",
|
||||
"name": "home-server",
|
||||
"address": "100.96.0.2",
|
||||
"services": [
|
||||
{
|
||||
"host": "photos.home.arpa",
|
||||
"address": "100.96.1.2"
|
||||
}
|
||||
],
|
||||
"classic": false,
|
||||
"expires": "2026-11-29T22:59:59Z",
|
||||
"peers": [
|
||||
@@ -76,6 +82,16 @@
|
||||
"k3f9q2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"direction": "in",
|
||||
"src": "100.96.0.1/32",
|
||||
"dst": "100.96.1.2/32",
|
||||
"proto": "any",
|
||||
"ports": null,
|
||||
"roads": [
|
||||
"k3f9q2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"direction": "in",
|
||||
"src": "100.96.0.3/32",
|
||||
@@ -89,7 +105,17 @@
|
||||
{
|
||||
"direction": "in",
|
||||
"src": "100.96.0.3/32",
|
||||
"dst": "100.96.0.2/32",
|
||||
"dst": "100.96.1.2/32",
|
||||
"proto": "any",
|
||||
"ports": null,
|
||||
"roads": [
|
||||
"k3f9q2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"direction": "in",
|
||||
"src": "100.96.0.3/32",
|
||||
"dst": "100.96.1.2/32",
|
||||
"proto": "tcp",
|
||||
"ports": [
|
||||
443,
|
||||
@@ -112,7 +138,17 @@
|
||||
{
|
||||
"direction": "in",
|
||||
"src": "100.96.0.4/32",
|
||||
"dst": "100.96.0.2/32",
|
||||
"dst": "100.96.1.2/32",
|
||||
"proto": "any",
|
||||
"ports": null,
|
||||
"roads": [
|
||||
"k3f9q2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"direction": "in",
|
||||
"src": "100.96.0.4/32",
|
||||
"dst": "100.96.1.2/32",
|
||||
"proto": "tcp",
|
||||
"ports": [
|
||||
443,
|
||||
@@ -148,6 +184,32 @@
|
||||
"r8m2tg"
|
||||
]
|
||||
},
|
||||
{
|
||||
"direction": "in",
|
||||
"src": "100.96.0.5/32",
|
||||
"dst": "100.96.1.2/32",
|
||||
"proto": "tcp",
|
||||
"ports": [
|
||||
22,
|
||||
22
|
||||
],
|
||||
"roads": [
|
||||
"r8m2tg"
|
||||
]
|
||||
},
|
||||
{
|
||||
"direction": "in",
|
||||
"src": "100.96.0.5/32",
|
||||
"dst": "100.96.1.2/32",
|
||||
"proto": "udp",
|
||||
"ports": [
|
||||
53,
|
||||
53
|
||||
],
|
||||
"roads": [
|
||||
"r8m2tg"
|
||||
]
|
||||
},
|
||||
{
|
||||
"direction": "forward",
|
||||
"src": "100.96.0.1/32",
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"device": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ",
|
||||
"name": "jana-laptop",
|
||||
"address": "100.96.0.4",
|
||||
"services": [],
|
||||
"classic": false,
|
||||
"expires": "2026-11-29T22:59:59Z",
|
||||
"peers": [
|
||||
@@ -12,7 +13,8 @@
|
||||
"address": "100.96.0.2",
|
||||
"classic": false,
|
||||
"allowed_ips": [
|
||||
"100.96.0.2/32"
|
||||
"100.96.0.2/32",
|
||||
"100.96.1.2/32"
|
||||
],
|
||||
"via": null,
|
||||
"roads": [
|
||||
@@ -28,7 +30,7 @@
|
||||
"dns": [
|
||||
{
|
||||
"host": "photos.home.arpa",
|
||||
"address": "100.96.0.2",
|
||||
"address": "100.96.1.2",
|
||||
"roads": [
|
||||
"7tq0mz"
|
||||
]
|
||||
@@ -41,7 +43,8 @@
|
||||
"app": "steam",
|
||||
"subnet": "0.0.0.0/0",
|
||||
"except": [
|
||||
"100.96.0.2/32"
|
||||
"100.96.0.2/32",
|
||||
"100.96.1.2/32"
|
||||
],
|
||||
"roads": [
|
||||
"e5yj1s"
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"device": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM",
|
||||
"name": "jana-phone",
|
||||
"address": "100.96.0.3",
|
||||
"services": [],
|
||||
"classic": false,
|
||||
"expires": "2026-11-29T22:59:59Z",
|
||||
"peers": [
|
||||
@@ -12,7 +13,8 @@
|
||||
"address": "100.96.0.2",
|
||||
"classic": false,
|
||||
"allowed_ips": [
|
||||
"100.96.0.2/32"
|
||||
"100.96.0.2/32",
|
||||
"100.96.1.2/32"
|
||||
],
|
||||
"via": null,
|
||||
"roads": [
|
||||
@@ -28,7 +30,7 @@
|
||||
"dns": [
|
||||
{
|
||||
"host": "photos.home.arpa",
|
||||
"address": "100.96.0.2",
|
||||
"address": "100.96.1.2",
|
||||
"roads": [
|
||||
"7tq0mz"
|
||||
]
|
||||
@@ -41,7 +43,8 @@
|
||||
"app": "steam",
|
||||
"subnet": "0.0.0.0/0",
|
||||
"except": [
|
||||
"100.96.0.2/32"
|
||||
"100.96.0.2/32",
|
||||
"100.96.1.2/32"
|
||||
],
|
||||
"roads": [
|
||||
"e5yj1s"
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"device": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE",
|
||||
"name": "mark-pc",
|
||||
"address": "100.96.0.1",
|
||||
"services": [],
|
||||
"classic": false,
|
||||
"expires": null,
|
||||
"peers": [
|
||||
@@ -14,6 +15,7 @@
|
||||
"allowed_ips": [
|
||||
"0.0.0.0/0",
|
||||
"100.96.0.2/32",
|
||||
"100.96.1.2/32",
|
||||
"192.168.100.0/24",
|
||||
"::/0"
|
||||
],
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"device": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc",
|
||||
"name": "petr-phone",
|
||||
"address": "100.96.0.7",
|
||||
"services": [],
|
||||
"classic": false,
|
||||
"expires": null,
|
||||
"peers": [
|
||||
|
||||
+5
-2
@@ -3,6 +3,7 @@
|
||||
"device": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU",
|
||||
"name": "router",
|
||||
"address": "100.96.0.5",
|
||||
"services": [],
|
||||
"classic": true,
|
||||
"expires": null,
|
||||
"peers": [
|
||||
@@ -12,7 +13,8 @@
|
||||
"address": "100.96.0.2",
|
||||
"classic": false,
|
||||
"allowed_ips": [
|
||||
"100.96.0.2/32"
|
||||
"100.96.0.2/32",
|
||||
"100.96.1.2/32"
|
||||
],
|
||||
"via": null,
|
||||
"roads": [
|
||||
@@ -32,7 +34,8 @@
|
||||
"app": "steam",
|
||||
"subnet": "0.0.0.0/0",
|
||||
"except": [
|
||||
"100.96.0.2/32"
|
||||
"100.96.0.2/32",
|
||||
"100.96.1.2/32"
|
||||
],
|
||||
"roads": [
|
||||
"e5yj1s"
|
||||
|
||||
@@ -75,3 +75,6 @@ devices route-link-local.devices.json devices.route devices[1].routes[0]
|
||||
devices route-overlap.devices.json devices.overlap devices.friend-node.routes
|
||||
devices service-host.devices.json devices.service devices[1].services[0].host
|
||||
devices service-no-ports.devices.json devices.ports devices[1].services[0].ports
|
||||
devices service-address-twice.devices.json devices.address devices[1].services[0].address
|
||||
devices service-address-public.devices.json devices.address devices[1].services[0].address
|
||||
devices service-address-in-route.devices.json devices.address devices.home-server.address
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format": 1,
|
||||
"devices": [
|
||||
{ "key": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE", "name": "mark-pc", "owner": "mark", "address": "100.96.0.1" },
|
||||
{ "key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI", "name": "home-server", "owner": "mark", "address": "100.96.0.2", "exit": true, "relay": true,
|
||||
"routes": ["192.168.100.0/24"],
|
||||
"services": [
|
||||
{ "host": "photos.home.arpa", "ports": ["tcp/443"], "address": "192.168.100.9" },
|
||||
{ "host": "git.home.arpa", "ports": ["tcp/443", "tcp/22"] }
|
||||
] },
|
||||
{ "key": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM", "name": "jana-phone", "owner": "jana", "address": "100.96.0.3" },
|
||||
{ "key": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ", "name": "jana-laptop", "owner": "jana", "address": "100.96.0.4" },
|
||||
{ "key": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU", "name": "router", "address": "100.96.0.5", "classic": true },
|
||||
{ "key": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY", "name": "friend-node", "owner": "petr", "address": "100.96.0.6", "exit": true },
|
||||
{ "key": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc", "name": "petr-phone", "owner": "petr", "address": "100.96.0.7" }
|
||||
]
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format": 1,
|
||||
"devices": [
|
||||
{ "key": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE", "name": "mark-pc", "owner": "mark", "address": "100.96.0.1" },
|
||||
{ "key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI", "name": "home-server", "owner": "mark", "address": "100.96.0.2", "exit": true, "relay": true,
|
||||
"routes": ["192.168.100.0/24"],
|
||||
"services": [
|
||||
{ "host": "photos.home.arpa", "ports": ["tcp/443"], "address": "203.0.114.9" },
|
||||
{ "host": "git.home.arpa", "ports": ["tcp/443", "tcp/22"] }
|
||||
] },
|
||||
{ "key": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM", "name": "jana-phone", "owner": "jana", "address": "100.96.0.3" },
|
||||
{ "key": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ", "name": "jana-laptop", "owner": "jana", "address": "100.96.0.4" },
|
||||
{ "key": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU", "name": "router", "address": "100.96.0.5", "classic": true },
|
||||
{ "key": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY", "name": "friend-node", "owner": "petr", "address": "100.96.0.6", "exit": true },
|
||||
{ "key": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc", "name": "petr-phone", "owner": "petr", "address": "100.96.0.7" }
|
||||
]
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format": 1,
|
||||
"devices": [
|
||||
{ "key": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE", "name": "mark-pc", "owner": "mark", "address": "100.96.0.1" },
|
||||
{ "key": "AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI", "name": "home-server", "owner": "mark", "address": "100.96.0.2", "exit": true, "relay": true,
|
||||
"routes": ["192.168.100.0/24"],
|
||||
"services": [
|
||||
{ "host": "photos.home.arpa", "ports": ["tcp/443"], "address": "100.96.0.1" },
|
||||
{ "host": "git.home.arpa", "ports": ["tcp/443", "tcp/22"] }
|
||||
] },
|
||||
{ "key": "AwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM", "name": "jana-phone", "owner": "jana", "address": "100.96.0.3" },
|
||||
{ "key": "BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ", "name": "jana-laptop", "owner": "jana", "address": "100.96.0.4" },
|
||||
{ "key": "BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU", "name": "router", "address": "100.96.0.5", "classic": true },
|
||||
{ "key": "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgY", "name": "friend-node", "owner": "petr", "address": "100.96.0.6", "exit": true },
|
||||
{ "key": "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc", "name": "petr-phone", "owner": "petr", "address": "100.96.0.7" }
|
||||
]
|
||||
}
|
||||
@@ -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".
|
||||
|
||||
@@ -8,7 +8,8 @@ use common::{Parts, at, fw_accepts, key};
|
||||
use roads::{Hostname, Place, compile, explain};
|
||||
use std::net::IpAddr;
|
||||
|
||||
const PHOTOS_HOST: &str = "100.96.0.2";
|
||||
/// photos.home.arpa's own address on the home server (QA F-01: a service road reaches only its service).
|
||||
const PHOTOS_HOST: &str = "100.96.1.2";
|
||||
|
||||
fn home_server() -> IpAddr {
|
||||
PHOTOS_HOST.parse().unwrap()
|
||||
|
||||
@@ -267,6 +267,27 @@ fn generated(baseline: &[u8]) -> BTreeSet<String> {
|
||||
c.problems
|
||||
);
|
||||
hit.insert(rules::ROAD_FAMILY.into());
|
||||
// service.shared: without its own address, photos shares home-server:443 with git (QA F-01). The road
|
||||
// grants nothing: the plans equal those of the same store without it.
|
||||
let shared = Parts::home().edit_devices(|d| d.replace(r#", "address": "100.96.1.2""#, ""));
|
||||
let c = shared.compile();
|
||||
assert!(
|
||||
c.problems
|
||||
.iter()
|
||||
.any(|p| p.path == "roads/7tq0mz-jana-photos-until-sunday.md"
|
||||
&& p.code == rules::SERVICE_SHARED
|
||||
&& p.field.as_deref() == Some("object")
|
||||
&& p.is_error()),
|
||||
"{:?}",
|
||||
c.problems
|
||||
);
|
||||
let without = shared.without_road("7tq0mz").compile();
|
||||
assert_eq!(
|
||||
plans_bytes(&c),
|
||||
plans_bytes(&without),
|
||||
"a refused service road granted"
|
||||
);
|
||||
hit.insert(rules::SERVICE_SHARED.into());
|
||||
hit
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user