Watch
0
0
Fork
You've already forked hyperhive
0

squid blocks a runtime deny list from the controller in every egress mode, ahead of the allow list

This commit is contained in:
atlas 2026-11-04 22:00:42 +01:00 • committed by mara
commit dd5fde848f

View file

@ -18,6 +18,20 @@ pub const TOLERANT_PERMISSIONS: &str = "tolerant-permissions";
/// into a custom one only on a hive that advertises it.
pub const NO_CONFIG_CHECKOUT: &str = "no-config-checkout";
/// The snapshot field holding the revision of the egress deny list
/// (`crate::egress_allow::DENY_KEY`) the hive last rendered into its squid
/// include, `0` when the swarm has no deny list. A hive that predates the
/// field publishes none.
pub const EGRESS_DENY_APPLIED: &str = "egress_deny_applied";
/// The deny-list revision a stored snapshot says its hive rendered: `None` for
/// a snapshot without the field (an older hive, or one that has not read the
/// list yet) or with one that is not a number.
#[must_use]
pub fn egress_deny_applied(snapshot: &serde_json::Value) -> Option<u64> {
snapshot.get(EGRESS_DENY_APPLIED)?.as_u64()
}
/// The part of a hive's status snapshot this module describes.
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct Capabilities {
@ -66,6 +80,21 @@ mod tests {
assert!(!Capabilities::of_snapshot(&new).has("other"));
}
#[test]
fn the_applied_deny_revision_is_read_only_when_it_is_a_number() {
let at = |v: serde_json::Value| {
egress_deny_applied(&serde_json::json!({ EGRESS_DENY_APPLIED: v }))
};
assert_eq!(at(serde_json::json!(7)), Some(7));
assert_eq!(at(serde_json::json!(0)), Some(0));
assert_eq!(at(serde_json::json!("7")), None);
assert_eq!(
egress_deny_applied(&serde_json::json!({"status": "ok"})),
None
);
assert_eq!(egress_deny_applied(&serde_json::json!(null)), None);
}
/// A snapshot that is not an object, or whose field is mistyped, grants
/// nothing rather than failing the read.
#[test]