[roads] QA B-3: an app road names whose devices it is for, and reaches only those

subject: app:<id> applied to every device in the mesh, so whoever could write
one road (app:steam goes-direct 0.0.0.0/0) changed the tunnel of other
people's devices, an exit and a classic router. An app road now needs the new
header key on: (a person, group or device), and reaches only those devices;
on: is forbidden on any other subject. The home fixture's steam road is on
Mark's devices, so it leaves Jana's, Petr's and the router's plans. Four
fixtures, a B-3 test (fails if app roads reach every device again), the
property generator scopes app roads to a person, and the R-55 renaming
rewrites on: like subject:.
This commit is contained in:
2026-11-25 09:04:50 +01:00
parent 69e3a9377d
commit b482e264d2
18 changed files with 179 additions and 84 deletions
+68 -4
View File
@@ -15,12 +15,12 @@ use std::fmt;
pub const MAX_FILE: usize = 256 * 1024;
pub const REQUIRED: [&str; 4] = ["id", "subject", "verb", "created"];
pub const OPTIONAL: [&str; 5] = ["object", "until", "ports", "via", "classic"];
pub const OPTIONAL: [&str; 6] = ["on", "object", "until", "ports", "via", "classic"];
/// Optional keys whose absence is their widest value; present but empty is `key.empty`.
pub const NARROWING: [&str; 2] = ["until", "ports"];
/// The canonical key order.
pub const ORDER: [&str; 9] = [
"id", "subject", "verb", "object", "until", "ports", "via", "classic", "created",
pub const ORDER: [&str; 10] = [
"id", "subject", "on", "verb", "object", "until", "ports", "via", "classic", "created",
];
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -282,6 +282,9 @@ pub struct Road {
pub path: String,
pub id: RoadId,
pub subject: Subject,
/// For an `app:` subject only: whose devices the app's road applies to (a person, a group or a device).
/// Without it an app road would change the tunnel of every device in the mesh (QA B-3).
pub on: Option<Subject>,
pub verb: Verb,
pub object: Option<Place>,
pub until: Option<Timestamp>,
@@ -310,7 +313,15 @@ impl Road {
Subject::Device(k) => format!("device:{}", dev(k)),
s => s.to_string(),
};
let mut out = format!("{subject} {}", self.verb);
let mut out = subject;
if let Some(on) = &self.on {
let on = match on {
Subject::Device(k) => format!("device:{}", dev(k)),
s => s.to_string(),
};
out.push_str(&format!(" on {on}"));
}
out.push_str(&format!(" {}", self.verb));
match &self.object {
Some(Place::Device(k)) => out.push_str(&format!(" device:{}", dev(k))),
Some(Place::Exit(k)) => out.push_str(&format!(" exit:{}", dev(k))),
@@ -351,6 +362,9 @@ impl Road {
};
field("id", self.id.to_string());
field("subject", scalar(self.subject.to_string()));
if let Some(on) = &self.on {
field("on", scalar(on.to_string()));
}
field("verb", self.verb.to_string());
if let Some(o) = &self.object {
field("object", scalar(o.to_string()));
@@ -590,6 +604,55 @@ impl Road {
}
});
// `on` belongs to an app subject, and an app subject needs it (QA B-3).
let is_app = matches!(subject, Some(Subject::App(_)));
let on = if subject.is_some() && !is_app {
if line_of.contains_key("on") {
problems.push(p(
"on",
r::KEY_FORBIDDEN,
"only an app: road takes `on`".into(),
));
}
None
} else if is_app {
match single("on", &mut problems) {
None => {
problems.push(
Problem::error(
path,
Some("on"),
r::KEY_MISSING,
"an app: road says whose devices it is for: `on: person:<id>`, `group:<id>` or `device:<key>`",
)
.at(at("on")),
);
None
}
Some(s) => match parse_ref(&s) {
Err((code, m)) => {
problems.push(p("on", code, m));
None
}
Ok(Ref::S(sub @ (Subject::Person(_) | Subject::Group(_)))) => Some(sub),
Ok(Ref::P(Place::Device(d))) => Some(Subject::Device(d)),
Ok(rf) => {
problems.push(p(
"on",
r::SUBJECT_KIND,
format!(
"`on` takes person, group or device, not {}",
rf.kind().name()
),
));
None
}
},
}
} else {
None
};
if let Some(v) = verb {
for k in OPTIONAL {
if !v.takes(k) && line_of.contains_key(k) {
@@ -782,6 +845,7 @@ impl Road {
path: path.to_string(),
id,
subject,
on,
verb,
object,
until,