[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:
@@ -1 +1 @@
|
||||
f16046353b91971cb181e7453b6631a4b38c08adb5fcc5ef603e3c7514c65699
|
||||
bfcecb172d2f1edc0ea152e1f0e05ad7b89a05ad14b27e22651a5ee6379e0917
|
||||
|
||||
+68
-12
@@ -245,6 +245,32 @@ fn check(
|
||||
format!("{h} serves only {}", served.join(", ")),
|
||||
));
|
||||
}
|
||||
// A firewall sees an address and a port, never a hostname. If another service answers on the
|
||||
// same address and one of the same ports, a rule for this one opens that one too: refuse, and
|
||||
// name it, rather than grant more than the road says (QA F-01).
|
||||
let wanted = road.ports.as_deref().unwrap_or(&s.ports);
|
||||
let mut shared: Vec<String> = d
|
||||
.services
|
||||
.iter()
|
||||
.filter(|o| {
|
||||
o.host != *h
|
||||
&& o.endpoint(d) == s.endpoint(d)
|
||||
&& ports::overlaps(Some(wanted), Some(&o.ports))
|
||||
})
|
||||
.map(|o| o.host.to_string())
|
||||
.collect();
|
||||
if !shared.is_empty() {
|
||||
shared.sort();
|
||||
out.push(p(
|
||||
"object",
|
||||
r::SERVICE_SHARED,
|
||||
format!(
|
||||
"{h} shares {} and its ports with {}, so a rule for it would open them too; give {h} its own `address` in devices.json, narrow `ports`, or write a device: road",
|
||||
s.endpoint(d),
|
||||
shared.join(", ")
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
},
|
||||
Some(Place::Subnet(n)) if road.verb == Verb::CanReach => match devs.router_of(n) {
|
||||
@@ -408,7 +434,7 @@ pub fn compile(store: &Store, now: Instant) -> Compiled {
|
||||
let ports = road.ports.clone().unwrap_or_else(|| s.ports.clone());
|
||||
(
|
||||
d.key.clone(),
|
||||
Net::host(d.address.0),
|
||||
Net::host(s.endpoint(d).0),
|
||||
false,
|
||||
Some(ports),
|
||||
Some(h.clone()),
|
||||
@@ -423,6 +449,16 @@ pub fn compile(store: &Store, now: Instant) -> Compiled {
|
||||
),
|
||||
Place::Exit(_) => unreachable!("the parser refuses exit objects for can-reach"),
|
||||
};
|
||||
// A device road reaches the whole device: its own address and those of the services it hosts on
|
||||
// an address of their own (same family as the sender only).
|
||||
let extra: Vec<Net> = match object {
|
||||
Place::Device(k) => devs.devices[k]
|
||||
.services
|
||||
.iter()
|
||||
.filter_map(|s| s.address.map(|a| Net::host(a.0)))
|
||||
.collect(),
|
||||
_ => Vec::new(),
|
||||
};
|
||||
let mut other_family: Vec<&str> = Vec::new();
|
||||
for from in subject.iter().filter(|d| **d != host) {
|
||||
// A device has one mesh address. From an IPv4 address to an IPv6 place (or the other way)
|
||||
@@ -434,16 +470,24 @@ pub fn compile(store: &Store, now: Instant) -> Compiled {
|
||||
touch(from, road);
|
||||
effects += 1;
|
||||
touch(&host, road);
|
||||
out.grants.push(Grant::Reach {
|
||||
road: road.id.clone(),
|
||||
from: from.clone(),
|
||||
host: host.clone(),
|
||||
dst,
|
||||
forward,
|
||||
ports: ports.clone(),
|
||||
dns: dns.clone(),
|
||||
via: road.via.clone(),
|
||||
});
|
||||
let family = devs.devices[from].address.0.is_ipv4();
|
||||
for d in std::iter::once(dst).chain(
|
||||
extra
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|n| n.inner().addr().is_ipv4() == family),
|
||||
) {
|
||||
out.grants.push(Grant::Reach {
|
||||
road: road.id.clone(),
|
||||
from: from.clone(),
|
||||
host: host.clone(),
|
||||
dst: d,
|
||||
forward,
|
||||
ports: ports.clone(),
|
||||
dns: dns.clone(),
|
||||
via: road.via.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
if !other_family.is_empty() {
|
||||
other_family.sort();
|
||||
@@ -738,7 +782,9 @@ fn build_plan(
|
||||
p.vias.insert(via.clone());
|
||||
if let Some(h) = host_name {
|
||||
dns.entry(h.clone())
|
||||
.or_insert_with(|| (addr(host), BTreeSet::new()))
|
||||
.or_insert_with(|| {
|
||||
(crate::net::Addr(dst.inner().addr()), BTreeSet::new())
|
||||
})
|
||||
.1
|
||||
.insert(road.clone());
|
||||
}
|
||||
@@ -830,6 +876,16 @@ fn build_plan(
|
||||
device: me.clone(),
|
||||
name: dev.name.clone(),
|
||||
address: dev.address,
|
||||
services: dev
|
||||
.services
|
||||
.iter()
|
||||
.filter_map(|s| {
|
||||
s.address.map(|address| plan::ServiceAddress {
|
||||
host: s.host.clone(),
|
||||
address,
|
||||
})
|
||||
})
|
||||
.collect(),
|
||||
classic: dev.classic,
|
||||
expires: expiry.map(|e| e.to_string()),
|
||||
peers: peers
|
||||
|
||||
@@ -24,7 +24,7 @@ pub fn explain(
|
||||
let (dst, want_ports): (Option<Net>, Option<Vec<PortSpec>>) = match place {
|
||||
Place::Device(k) => (devs.devices.get(k).map(|d| Net::host(d.address.0)), None),
|
||||
Place::Service(h) => match devs.service(h) {
|
||||
Some((d, s)) => (Some(Net::host(d.address.0)), Some(s.ports.clone())),
|
||||
Some((d, s)) => (Some(Net::host(s.endpoint(d).0)), Some(s.ports.clone())),
|
||||
None => (None, None),
|
||||
},
|
||||
Place::Subnet(n) => (Some(*n), None),
|
||||
|
||||
@@ -15,6 +15,8 @@ pub struct Plan {
|
||||
pub device: DeviceKey,
|
||||
pub name: String,
|
||||
pub address: Addr,
|
||||
/// The services this device hosts on an address of their own: it answers on these too (sorted by host).
|
||||
pub services: Vec<ServiceAddress>,
|
||||
/// This device is a classic WireGuard peer: not post-quantum.
|
||||
pub classic: bool,
|
||||
/// The earliest `until` of the roads this plan was built from, UTC: compile again by then.
|
||||
@@ -105,6 +107,13 @@ pub struct Rule {
|
||||
pub roads: Vec<RoadId>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ServiceAddress {
|
||||
pub host: Hostname,
|
||||
pub address: Addr,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Dns {
|
||||
|
||||
@@ -34,6 +34,7 @@ pub const UNTIL_FORMAT: &str = "until.format";
|
||||
pub const CREATED_FORMAT: &str = "created.format";
|
||||
pub const PORTS_FORMAT: &str = "ports.format";
|
||||
pub const PORTS_NOT_SERVED: &str = "ports.not-served";
|
||||
pub const SERVICE_SHARED: &str = "service.shared";
|
||||
pub const VIA_FORMAT: &str = "via.format";
|
||||
pub const VIA_UNKNOWN: &str = "via.unknown";
|
||||
pub const VIA_NOT_RELAY: &str = "via.not-relay";
|
||||
@@ -104,6 +105,7 @@ pub const ALL: &[&str] = &[
|
||||
CREATED_FORMAT,
|
||||
PORTS_FORMAT,
|
||||
PORTS_NOT_SERVED,
|
||||
SERVICE_SHARED,
|
||||
VIA_FORMAT,
|
||||
VIA_UNKNOWN,
|
||||
VIA_NOT_RELAY,
|
||||
|
||||
@@ -45,6 +45,17 @@ pub struct Directory {
|
||||
pub struct Service {
|
||||
pub host: Hostname,
|
||||
pub ports: Vec<PortSpec>,
|
||||
/// The service's own mesh address on its device, if it has one. A firewall sees addresses and ports, not
|
||||
/// hostnames, so only a service with its own address (or alone on its ports) can be granted by itself
|
||||
/// (QA F-01).
|
||||
pub address: Option<Addr>,
|
||||
}
|
||||
|
||||
impl Service {
|
||||
/// Where a road to this service sends traffic: its own address, or its device's.
|
||||
pub fn endpoint(&self, device: &Device) -> Addr {
|
||||
self.address.unwrap_or(device.address)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -79,9 +90,15 @@ impl Devices {
|
||||
.find_map(|d| d.services.iter().find(|s| &s.host == host).map(|s| (d, s)))
|
||||
}
|
||||
|
||||
/// Every mesh address: each device's own. Never goes direct (QA F-02).
|
||||
/// Every mesh address: each device's own and its services' own. Never goes direct (QA F-02).
|
||||
pub fn mesh_addresses(&self) -> impl Iterator<Item = (&Device, Addr)> {
|
||||
self.devices.values().map(|d| (d, d.address))
|
||||
self.devices.values().flat_map(|d| {
|
||||
std::iter::once((d, d.address)).chain(
|
||||
d.services
|
||||
.iter()
|
||||
.filter_map(move |s| s.address.map(|a| (d, a))),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/// The one device whose routes cover `net`.
|
||||
@@ -148,6 +165,8 @@ struct RawDevice {
|
||||
struct RawService {
|
||||
host: String,
|
||||
ports: Vec<String>,
|
||||
#[serde(default)]
|
||||
address: Option<String>,
|
||||
}
|
||||
|
||||
fn read_json<T: for<'de> Deserialize<'de>>(path: &str, bytes: &[u8]) -> Result<T, Vec<Problem>> {
|
||||
@@ -172,6 +191,22 @@ fn read_json<T: for<'de> Deserialize<'de>>(path: &str, bytes: &[u8]) -> Result<T
|
||||
})
|
||||
}
|
||||
|
||||
/// A mesh address: one canonical IP address, never loopback, link-local, multicast, IPv4-embedding IPv6 or an
|
||||
/// internet address, so an exit's `internet` rule can never cover a device or service of the mesh (QA F-08).
|
||||
fn mesh_address(text: &str) -> Option<Addr> {
|
||||
let a = text.parse::<std::net::IpAddr>().ok()?;
|
||||
let n = Net::host(a);
|
||||
(a.to_string() == text && !n.is_special() && !n.embeds_ipv4() && !n.reaches_internet())
|
||||
.then_some(Addr(a))
|
||||
}
|
||||
|
||||
fn not_mesh(text: &str) -> String {
|
||||
format!(
|
||||
"`{}` is not one private IP address (a mesh address is never loopback, link-local, multicast, embedded IPv4 or on the internet; use 100.64.0.0/10 or a ULA)",
|
||||
clip(text)
|
||||
)
|
||||
}
|
||||
|
||||
fn good_name(s: &str) -> bool {
|
||||
let n = s.chars().count();
|
||||
(1..=100).contains(&n) && !s.chars().any(is_hidden_char) && s.trim() == s
|
||||
@@ -399,33 +434,19 @@ impl Devices {
|
||||
}
|
||||
},
|
||||
};
|
||||
let address = match d.address.parse::<std::net::IpAddr>() {
|
||||
// A mesh address is never an internet address, so an exit's `internet` rule can never
|
||||
// cover another device of the mesh (QA F-08).
|
||||
Ok(a)
|
||||
if a.to_string() == d.address
|
||||
&& !Net::host(a).is_special()
|
||||
&& !Net::host(a).embeds_ipv4()
|
||||
&& !Net::host(a).reaches_internet() =>
|
||||
{
|
||||
if !addresses.insert(a) {
|
||||
let address = match mesh_address(&d.address) {
|
||||
Some(a) => {
|
||||
if !addresses.insert(a.0) {
|
||||
e(
|
||||
f("address"),
|
||||
r::DEVICES_ADDRESS,
|
||||
format!("{a} is used by two devices"),
|
||||
format!("{a} is used twice"),
|
||||
);
|
||||
}
|
||||
Some(Addr(a))
|
||||
Some(a)
|
||||
}
|
||||
_ => {
|
||||
e(
|
||||
f("address"),
|
||||
r::DEVICES_ADDRESS,
|
||||
format!(
|
||||
"`{}` is not one private IP address (a mesh address is never loopback, link-local, multicast, embedded IPv4 or on the internet; 100.64.0.0/10 or a ULA)",
|
||||
clip(&d.address)
|
||||
),
|
||||
);
|
||||
None => {
|
||||
e(f("address"), r::DEVICES_ADDRESS, not_mesh(&d.address));
|
||||
None
|
||||
}
|
||||
};
|
||||
@@ -496,7 +517,29 @@ impl Devices {
|
||||
"a service lists the ports it serves".into(),
|
||||
);
|
||||
}
|
||||
services.push(Service { host, ports });
|
||||
let field = format!("devices[{i}].services[{j}].address");
|
||||
let address = match s.address.as_deref().map(mesh_address) {
|
||||
None => None,
|
||||
Some(Some(a)) => {
|
||||
if !addresses.insert(a.0) {
|
||||
e(field, r::DEVICES_ADDRESS, format!("{a} is used twice"));
|
||||
}
|
||||
Some(a)
|
||||
}
|
||||
Some(None) => {
|
||||
e(
|
||||
field,
|
||||
r::DEVICES_ADDRESS,
|
||||
not_mesh(s.address.as_deref().unwrap_or_default()),
|
||||
);
|
||||
None
|
||||
}
|
||||
};
|
||||
services.push(Service {
|
||||
host,
|
||||
ports,
|
||||
address,
|
||||
});
|
||||
}
|
||||
services.sort_by(|a, b| a.host.cmp(&b.host));
|
||||
let Some(address) = address else { continue };
|
||||
@@ -535,15 +578,12 @@ impl Devices {
|
||||
);
|
||||
}
|
||||
}
|
||||
for d in out.devices.values() {
|
||||
if na.contains_addr(&d.address.0) {
|
||||
for (d, a) in out.mesh_addresses() {
|
||||
if na.contains_addr(&a.0) {
|
||||
e(
|
||||
format!("devices.{}.address", d.name),
|
||||
r::DEVICES_ADDRESS,
|
||||
format!(
|
||||
"{} of {} is inside the route {na} of {}",
|
||||
d.address, d.name, da.name
|
||||
),
|
||||
format!("{a} of {} is inside the route {na} of {}", d.name, da.name),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -57,7 +57,7 @@ is not `key: value`, or a bad quoted string, is `yaml.syntax`.
|
||||
| `id` | yes | 6 characters of `0123456789abcdefghjkmnpqrstvwxyz` (no `i l o u`), random | `id.format`; must equal the file name's prefix (`id.file-name`); unique in the store (`id.duplicate`, both files grant nothing) |
|
||||
| `subject` | yes | a reference (below): `person:`, `group:`, `device:` or `app:` | `ref.format`, `subject.kind` (not allowed for the verb), `subject.unknown` (not in the snapshots) |
|
||||
| `verb` | yes | `can-reach`, `exits-through`, `goes-direct`, `never-online-without`, `custom` | `verb.unknown` |
|
||||
| `object` | yes, except `custom` (where it is not allowed) | a reference: `device:`, `subnet:`, `service:` or `exit:` | `ref.format`, `object.kind`, `object.unknown`, `object.not-exit`, `subnet.not-canonical`, `subnet.unrouted`; a `goes-direct` subnet other than `/0` that holds a mesh address is `direct.mesh` (mesh traffic never goes direct, QA F-02) |
|
||||
| `object` | yes, except `custom` (where it is not allowed) | a reference: `device:`, `subnet:`, `service:` or `exit:` | `ref.format`, `object.kind`, `object.unknown`, `object.not-exit`, `subnet.not-canonical`, `subnet.unrouted`, `service.shared` (a service that shares its address and a port with another: its rule would open both, QA F-01); a `goes-direct` subnet other than `/0` that holds a mesh address is `direct.mesh` (mesh traffic never goes direct, QA F-02) |
|
||||
| `until` | no | RFC 3339 with an offset: `2026-11-29T23:59:59+01:00` or `…Z`; exclusive | `until.format`; `until <= now` makes the road *inactive* (`road.expired`) |
|
||||
| `ports` | no; only `can-reach` | a list of `tcp/443`, `udp/53`, `tcp/8000-8100`, `tcp`, `udp`, `icmp`; absent means all traffic | `ports.format`; for a service, every port must be one it serves (`ports.not-served`) |
|
||||
| `via` | no; only `can-reach` | `device:<key>` of a device with `relay` or `exit` | `via.format`, `via.unknown`, `via.not-relay` |
|
||||
@@ -184,6 +184,7 @@ what makes the snapshot unreadable: bad JSON, a wrong format, a malformed or dup
|
||||
| `routes` | `[]` | canonical subnets this device routes for the mesh: private only, so not `/0`, nothing that reaches the internet (use an exit), nothing loopback, link-local, multicast, reserved or IPv4-embedding; no overlap with another device's (`devices.route`, `devices.overlap`). This is also why two peers of one device can never hold the same prefix |
|
||||
| `services[].host` | — | an Ianitor hostname, unique across devices (`devices.service`) |
|
||||
| `services[].ports` | — | a non-empty port list (`devices.ports`) |
|
||||
| `services[].address` | none | the service's own mesh address on this device, under the same rules as a device `address` and unique among all of them (`devices.address`). A firewall sees addresses and ports, not hostnames: a road to a service compiles to its own address when it has one, else to the device's, and a road to a service that shares that address **and** a port with another service is refused (`service.shared`, QA F-01), because its rule would open the other one too |
|
||||
|
||||
## The plan
|
||||
|
||||
@@ -195,6 +196,7 @@ entry.
|
||||
|:--|:--|
|
||||
| `format` | `1` |
|
||||
| `device`, `name`, `address`, `classic` | this device |
|
||||
| `services[]` | `{host, address}`: the services this device hosts on an address of their own; it must answer on each (QA F-01). A road to such a service reaches that address only; a `device:` road reaches the device's address and all of these |
|
||||
| `expires` | the earliest `until` (UTC, `Z`) of every road this plan was built from, on the subject's plan and on the serving device's alike; the engine must stop applying the plan at that instant even if nothing recompiles (QA R-26); `null` if none |
|
||||
| `peers[]` | `key`, `name`, `address`, `classic` (*not post-quantum* when true), `allowed_ips` (sorted CIDRs), `via` (a path hint or `null`), `roads` |
|
||||
| `firewall.default` | always `"deny"` |
|
||||
|
||||
Reference in New Issue
Block a user