const RULES: &str = include_str!("../../../packaging/50-sysknife.rules");
fn allowed_actions() -> Vec<&'static str> {
let start = RULES
.find("allowedActions = [")
.expect("allowedActions array not found; this test would inspect nothing");
let body = &RULES[start..];
let body = &body[..body.find("];").expect("allowedActions is not closed")];
body.lines()
.map(str::trim)
.filter(|l| !l.starts_with("//"))
.filter_map(|l| l.split('"').nth(1))
.collect()
}
#[test]
fn the_sysknife_account_gets_no_unit_management_over_dbus() {
let actions = allowed_actions();
assert!(
actions.contains(&"org.freedesktop.hostname1.set-static-hostname"),
"the parser found {actions:?}, which does not include an action the rule \
is known to grant, so it is not reading the array"
);
for refused in [
"org.freedesktop.systemd1.manage-units",
"org.freedesktop.systemd1.manage-unit-files",
] {
assert!(
!actions.contains(&refused),
"{refused} is granted to the sysknife account again; it authorises \
StartTransientUnit, which is a root command line over D-Bus"
);
}
}
#[test]
fn the_sysknife_account_gets_only_unprivileged_rpm_ostree_calls_over_dbus() {
let actions = allowed_actions();
let rpm_ostree: Vec<&str> = actions
.iter()
.copied()
.filter(|a| a.starts_with("org.projectatomic.rpmostree1."))
.collect();
assert_eq!(
rpm_ostree,
[
"org.projectatomic.rpmostree1.upgrade",
"org.projectatomic.rpmostree1.rollback",
],
"the rpm-ostree polkit grants changed; every other method must go through \
sudo and the action-steps verb"
);
}