[roads] QA F-03: a kill-switch road with an error fails closed, through no exit
Any check() error used to make a road grant nothing, and for never-online-without nothing meant no kill switch: an exit that stopped being one (or left devices.json) silently turned off every kill switch through it. The road is still reported as an error, but its subject's kill switch stays on through no exit (only the mesh), and going direct to the internet is still dropped. An expired kill switch ends as written. The road_file fuzz target's deny-by-default check now allows exactly that narrowing and nothing else.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
//! The compiler: roads + people directory + device list + `now` → one [`Plan`] per device.
|
||||
//!
|
||||
//! Deny by default. A road with any error grants nothing; a valid road that is expired, or whose subject has no
|
||||
//! devices, grants nothing and is reported as inactive. Without both snapshots no plan is produced at all.
|
||||
//! devices, grants nothing and is reported as inactive. Restrictions fail closed instead: a kill-switch road
|
||||
//! with an error still turns its subject's kill switch on, through no exit (only the mesh), QA F-03. Without both snapshots no plan is produced at all.
|
||||
//! Every collection on the output path is ordered, so the same input gives the same bytes.
|
||||
|
||||
use crate::id::RoadId;
|
||||
@@ -83,9 +84,17 @@ type RuleKey = (Direction, Net, Dst, Proto, Option<[u16; 2]>);
|
||||
struct Extras {
|
||||
direct: BTreeMap<DirectKey, BTreeSet<RoadId>>,
|
||||
kill: BTreeMap<DeviceKey, BTreeSet<RoadId>>,
|
||||
/// Kill-switch roads with an error: applied closed, through no exit.
|
||||
kill_closed: BTreeSet<RoadId>,
|
||||
custom: Vec<plan::Custom>,
|
||||
}
|
||||
|
||||
impl Extras {
|
||||
fn has_kill_switch(&self) -> bool {
|
||||
!self.kill.is_empty() || !self.kill_closed.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
/// The devices a subject covers: a person's are the devices they own; a group's, its members'; an app's, every
|
||||
/// device.
|
||||
pub fn subject_devices(subject: &Subject, dir: &Directory, devs: &Devices) -> BTreeSet<DeviceKey> {
|
||||
@@ -318,6 +327,27 @@ pub fn compile(store: &Store, now: Instant) -> Compiled {
|
||||
let problems = check(road, dir, devs, &subject);
|
||||
if !problems.is_empty() {
|
||||
out.problems.extend(problems);
|
||||
// "Grants nothing" is right for a grant and wrong for a restriction: a kill switch whose exit stops
|
||||
// being one, or leaves devices.json, must not switch the protection off (QA F-03). It stays on,
|
||||
// through no exit: only the mesh. An expired kill switch ends as written; one that does not parse
|
||||
// is not in the store at all (`via check` reports it).
|
||||
if road.verb == Verb::NeverOnlineWithout {
|
||||
let exit = match &road.object {
|
||||
Some(Place::Exit(k)) => Some(k),
|
||||
_ => None,
|
||||
};
|
||||
let live = road.until.as_ref().is_none_or(|u| u.at() > now);
|
||||
for d in subject.iter().filter(|d| Some(*d) != exit) {
|
||||
if live {
|
||||
touch(d, road);
|
||||
extras
|
||||
.entry(d.clone())
|
||||
.or_default()
|
||||
.kill_closed
|
||||
.insert(road.id.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let inactive = |field: Option<&str>, code, msg: String| {
|
||||
@@ -511,10 +541,18 @@ pub fn compile(store: &Store, now: Instant) -> Compiled {
|
||||
// traffic outside the tunnel, whatever a goes-direct road says (QA R-47). Going direct to a private subnet
|
||||
// (the local network) stays allowed.
|
||||
for (key, ex) in extras.iter_mut() {
|
||||
if ex.kill.is_empty() {
|
||||
if !ex.has_kill_switch() {
|
||||
continue;
|
||||
}
|
||||
let kill_roads: Vec<String> = ex.kill.values().flatten().map(|r| r.to_string()).collect();
|
||||
let kill_roads: Vec<String> = ex
|
||||
.kill
|
||||
.values()
|
||||
.flatten()
|
||||
.chain(&ex.kill_closed)
|
||||
.collect::<BTreeSet<_>>()
|
||||
.into_iter()
|
||||
.map(|r| r.to_string())
|
||||
.collect();
|
||||
let dropped: Vec<(DirectKey, BTreeSet<RoadId>)> = ex
|
||||
.direct
|
||||
.iter()
|
||||
@@ -673,8 +711,10 @@ fn build_plan(
|
||||
}
|
||||
|
||||
let extras = extras.unwrap_or_default();
|
||||
let kill_switch = (!extras.kill.is_empty()).then(|| plan::KillSwitch {
|
||||
through: if extras.kill.len() == 1 {
|
||||
let kill_switch = extras.has_kill_switch().then(|| plan::KillSwitch {
|
||||
// One exit, from valid roads only: through it. Two exits, or any kill-switch road with an error: only
|
||||
// the mesh.
|
||||
through: if extras.kill.len() == 1 && extras.kill_closed.is_empty() {
|
||||
extras.kill.keys().next().cloned()
|
||||
} else {
|
||||
None
|
||||
@@ -683,6 +723,7 @@ fn build_plan(
|
||||
.kill
|
||||
.values()
|
||||
.flatten()
|
||||
.chain(&extras.kill_closed)
|
||||
.cloned()
|
||||
.collect::<BTreeSet<_>>()
|
||||
.into_iter()
|
||||
|
||||
@@ -93,7 +93,6 @@ fn f02_going_direct_never_overlaps_what_the_tunnel_carries() {
|
||||
/// typo: the exit device stops offering itself as an exit (or leaves devices.json), and every kill switch
|
||||
/// through it silently disappears while the rest of the plan compiles.
|
||||
#[test]
|
||||
#[ignore = "QA F-03 (major): an invalid kill-switch road fails open"]
|
||||
fn f03_a_kill_switch_whose_exit_goes_away_fails_closed() {
|
||||
let parts = Parts::home().edit_devices(|d| {
|
||||
d.replace(
|
||||
@@ -109,10 +108,48 @@ fn f03_a_kill_switch_whose_exit_goes_away_fails_closed() {
|
||||
.any(|p| p.path.contains("w9c3ke") && p.is_error()),
|
||||
"the kill-switch road is reported"
|
||||
);
|
||||
let ks = c.plans[&key(1)].kill_switch.as_ref();
|
||||
assert!(
|
||||
c.plans[&key(1)].kill_switch.is_some(),
|
||||
ks.is_some(),
|
||||
"mark-pc lost its kill switch because its exit stopped being one: it now fails open"
|
||||
);
|
||||
assert_eq!(
|
||||
ks.unwrap().through,
|
||||
None,
|
||||
"closed means through no exit: only the mesh"
|
||||
);
|
||||
// Mutation guard: the same road made valid again keeps its exit.
|
||||
assert_eq!(
|
||||
Parts::home().compile().plans[&key(1)]
|
||||
.kill_switch
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.through,
|
||||
Some(key(2))
|
||||
);
|
||||
}
|
||||
|
||||
/// F-03, the other references: an unknown exit, and an exit road that has expired, which ends as written.
|
||||
#[test]
|
||||
fn f03_an_unknown_exit_fails_closed_and_an_expired_kill_switch_ends() {
|
||||
let text = Parts::home().road_text("w9c3ke");
|
||||
let unknown = text.replace(
|
||||
"exit:AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI",
|
||||
"exit:CQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQk",
|
||||
);
|
||||
let c = Parts::home().replace_road("w9c3ke", &unknown).compile();
|
||||
assert!(
|
||||
c.problems
|
||||
.iter()
|
||||
.any(|p| p.path.contains("w9c3ke") && p.is_error())
|
||||
);
|
||||
assert_eq!(c.plans[&key(1)].kill_switch.as_ref().unwrap().through, None);
|
||||
let expired = unknown.replace("created:", "until: 2026-11-01T00:00:00+01:00\ncreated:");
|
||||
let c = Parts::home().replace_road("w9c3ke", &expired).compile();
|
||||
assert!(
|
||||
c.plans[&key(1)].kill_switch.is_none(),
|
||||
"an expired kill switch ends as written"
|
||||
);
|
||||
}
|
||||
|
||||
/// F-04. Deleting a person from the directory (the upstream event, without also editing devices.json) leaves
|
||||
|
||||
Reference in New Issue
Block a user