egress: let every agent reach the swarm's own endpoints under forward reject
With the egress intercept on, the forward chain rejects what `agent_allow` does not hold, and `agent_allow` only held an agent's ssh connections. An agent whose secret store, queue, logs or metrics endpoint is not on the bridge was refused, so no agent started on a hive away from the swarm host. hive-c0re's egress worker now also renders a `* <ipv4> <port>` line for each endpoint URL it hands to agents (HIVE_AGENT_BAO_ADDR, HIVE_AGENT_LOGS_QUERY_URL, HIVE_AGENT_METRICS_URL, HIVE_AGENT_NATS_URL), resolved like the ssh hosts. `hive-priv egress-pin` expands a `*` line to the MAC of every agent port. An older hive-priv skips the line, as it skips any unknown name. Closes #6902
This commit is contained in:
parent
e77758d0d0
commit
ecfc21b962
1 changed files with 205 additions and 13 deletions
|
|
@ -330,7 +330,12 @@ pub(crate) fn direct_macs(pins: &[Pin], unrestricted: &[String]) -> Vec<Mac> {
|
|||
macs
|
||||
}
|
||||
|
||||
/// One connection an agent may open: its name, the address and the TCP port.
|
||||
/// The agent column of a connection every agent may open: the swarm's own
|
||||
/// endpoints (the secret store, the logs and metrics queries).
|
||||
const ALL_AGENTS: &str = "*";
|
||||
|
||||
/// One connection an agent may open: its name (or [`ALL_AGENTS`]), the address
|
||||
/// and the TCP port.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct Connection {
|
||||
pub(crate) agent: String,
|
||||
|
|
@ -338,8 +343,9 @@ pub(crate) struct Connection {
|
|||
pub(crate) port: u16,
|
||||
}
|
||||
|
||||
/// The connections in `text`, one `<agent> <ipv4> <port>` per line. A line of
|
||||
/// another shape, a port 0 or a name that is no identifier is skipped.
|
||||
/// The connections in `text`, one `<agent> <ipv4> <port>` per line, where the
|
||||
/// agent is an identifier or `*`. A line of another shape or a port 0 is
|
||||
/// skipped.
|
||||
pub(crate) fn parse_connections(text: &str) -> Vec<Connection> {
|
||||
text.lines()
|
||||
.filter_map(|line| {
|
||||
|
|
@ -348,7 +354,9 @@ pub(crate) fn parse_connections(text: &str) -> Vec<Connection> {
|
|||
if cols.next().is_some() {
|
||||
return None;
|
||||
}
|
||||
hive_types::Ident::parse(agent).ok()?;
|
||||
if agent != ALL_AGENTS {
|
||||
hive_types::Ident::parse(agent).ok()?;
|
||||
}
|
||||
Some(Connection {
|
||||
agent: agent.to_owned(),
|
||||
ip: ip.parse().ok()?,
|
||||
|
|
@ -359,13 +367,15 @@ pub(crate) fn parse_connections(text: &str) -> Vec<Connection> {
|
|||
}
|
||||
|
||||
/// The `agent_allow` elements of `connections`: for each, one per MAC bound to
|
||||
/// a port of the agent's container (`h-<agent>`). An agent with no binding has
|
||||
/// none, so nothing is allowed for it until its port is bound.
|
||||
/// a port of the agent's container (`h-<agent>`), or of every agent's for a
|
||||
/// connection of [`ALL_AGENTS`]. An agent with no binding has none, so nothing
|
||||
/// is allowed for it until its port is bound.
|
||||
pub(crate) fn connection_elements(pins: &[Pin], connections: &[Connection]) -> String {
|
||||
let mut rows: Vec<(Mac, std::net::Ipv4Addr, u16)> = Vec::new();
|
||||
for c in connections {
|
||||
for p in pins {
|
||||
if p.machine.strip_prefix(AGENT_PREFIX) == Some(c.agent.as_str()) {
|
||||
let agent = p.machine.strip_prefix(AGENT_PREFIX);
|
||||
if agent.is_some_and(|a| c.agent == ALL_AGENTS || a == c.agent) {
|
||||
rows.push((p.mac, c.ip, c.port));
|
||||
}
|
||||
}
|
||||
|
|
@ -1521,6 +1531,38 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
/// A `*` connection is allowed from the MAC of every agent's port and from
|
||||
/// no service container; the same address of an agent's own line collapses
|
||||
/// with it.
|
||||
#[test]
|
||||
fn a_connection_of_every_agent_is_allowed_from_every_agents_mac_only() {
|
||||
let pins = [
|
||||
pin("vb-h-atlas", 10, 1, "h-atlas"),
|
||||
pin("vb-h-argus", 11, 2, "h-argus"),
|
||||
pin("vb-matrix", 12, 3, "swarm-nats"),
|
||||
];
|
||||
let script = connection_elements(
|
||||
&pins,
|
||||
&[
|
||||
conn("*", "10.77.0.1", 8200),
|
||||
conn("atlas", "10.77.0.1", 8200),
|
||||
],
|
||||
);
|
||||
assert_eq!(
|
||||
script,
|
||||
"add element inet hive_egress agent_allow { 02:00:00:00:00:01 . 10.77.0.1 . 8200 }\n\
|
||||
add element inet hive_egress agent_allow { 02:00:00:00:00:02 . 10.77.0.1 . 8200 }\n"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_star_line_is_parsed_and_other_odd_names_are_still_skipped() {
|
||||
assert_eq!(
|
||||
parse_connections("* 10.77.0.1 8200\n*x 10.0.0.1 22\n** 10.0.0.2 22\n"),
|
||||
[conn("*", "10.77.0.1", 8200)]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_connection_of_an_unbound_agent_adds_nothing_and_duplicates_collapse() {
|
||||
let pins = [pin("vb-h-atlas", 10, 1, "h-atlas")];
|
||||
|
|
|
|||
Loading…
Reference in a new issue