refactor(maestro): drop allow_inbound policy gate, keep JWT session binding (NAP-339)
The peer (T2) attach path had a per-pair access-control layer (`[daemon.policy].allow_inbound`): a target-side allow-list of daemon ids permitted to broker-attach, enforced inside JWT verification, hot-reloadable via SIGHUP / `POST /api/policy/reload`, with a `maestro policy` CLI. On a flat-trust perimeter (the operator's VPN/firewall is the boundary for which hosts connect) that granularity is unused, and deny-by-default made it config friction — cross-daemon attach silently failed until every peer was listed. Remove the allow-list; keep the registry-minted pair-attach JWT and ALL its binding checks (iss=registry, aud=target, sid=session, exp). The firewall gates host->port reachability; it does not stop a reachable host from attaching to a session it wasn't handed or replaying a token elsewhere — that's the JWT's job and it stays. Only the `sub in allow_inbound` check is dropped. Removed: DaemonPolicySection / [daemon.policy].allow_inbound (config + daemon), policy.rs (SIGHUP listener + GET/POST /api/policy), the `maestro policy` CLI, PairAttachVerifier's allow-list field/reload/snapshot + JwtError::NotAllowed, and the e2e broker_rejects_when_target_doesnt_allow_inbound test. The NAP-265 pre-upgrade-502 path stays covered by broker_attach_returns_502_on_perimeter_mismatch. Also dropped the unit's ExecReload=kill -HUP: with no SIGHUP handler left, default SIGHUP disposition is terminate, so wiring `systemctl reload` to it would kill the daemon. Re-introducing a per-pair gate later is a verify-time change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -513,7 +513,6 @@ async fn broker_t2_attach_through_home_daemon() {
|
||||
DaemonOptions {
|
||||
perimeter_id: Some("wg-test".into()),
|
||||
private_addr: Some(beta_bind.to_string()),
|
||||
allow_inbound: vec!["alpha".into()],
|
||||
},
|
||||
)
|
||||
.await;
|
||||
@@ -529,7 +528,6 @@ async fn broker_t2_attach_through_home_daemon() {
|
||||
DaemonOptions {
|
||||
perimeter_id: Some("wg-test".into()),
|
||||
private_addr: Some(alpha_bind.to_string()),
|
||||
allow_inbound: vec![],
|
||||
},
|
||||
)
|
||||
.await;
|
||||
@@ -621,116 +619,6 @@ async fn broker_t2_attach_through_home_daemon() {
|
||||
drop(registry);
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn broker_rejects_when_target_doesnt_allow_inbound() {
|
||||
// NAP-247: beta has an empty allow_inbound, so beta's
|
||||
// /sessions/:id/stream rejects alpha's broker JWT even though the
|
||||
// registry happily mints one (default deny is target-side only).
|
||||
let registry = Registry::spawn("e2e-shared-token").await;
|
||||
let beta_bind = std::net::SocketAddr::from((
|
||||
std::net::Ipv4Addr::LOCALHOST,
|
||||
maestro_e2e::util::free_port(),
|
||||
));
|
||||
let beta = Daemon::spawn_at(
|
||||
"beta",
|
||||
®istry.http_base(),
|
||||
"e2e-shared-token",
|
||||
beta_bind,
|
||||
DaemonOptions {
|
||||
perimeter_id: Some("wg-test".into()),
|
||||
private_addr: Some(beta_bind.to_string()),
|
||||
// Default deny — alpha not listed.
|
||||
allow_inbound: vec![],
|
||||
},
|
||||
)
|
||||
.await;
|
||||
let alpha_bind = std::net::SocketAddr::from((
|
||||
std::net::Ipv4Addr::LOCALHOST,
|
||||
maestro_e2e::util::free_port(),
|
||||
));
|
||||
let alpha = Daemon::spawn_at(
|
||||
"alpha",
|
||||
®istry.http_base(),
|
||||
"e2e-shared-token",
|
||||
alpha_bind,
|
||||
DaemonOptions {
|
||||
perimeter_id: Some("wg-test".into()),
|
||||
private_addr: Some(alpha_bind.to_string()),
|
||||
allow_inbound: vec![],
|
||||
},
|
||||
)
|
||||
.await;
|
||||
assert_eq!(beta.bind_addr, beta_bind);
|
||||
assert_eq!(alpha.bind_addr, alpha_bind);
|
||||
|
||||
let client = TestClient::new(®istry.http_base(), ®istry.ws_base());
|
||||
client.bootstrap().await.expect("bootstrap");
|
||||
wait_for_async("both daemons connected", Duration::from_secs(10), || {
|
||||
let client = client.clone();
|
||||
async move {
|
||||
client
|
||||
.list_daemons()
|
||||
.await
|
||||
.map(|ds| ds.len() >= 2)
|
||||
.unwrap_or(false)
|
||||
}
|
||||
})
|
||||
.await;
|
||||
|
||||
let cwd = TempDir::new().unwrap();
|
||||
let session = client
|
||||
.spawn_session(&create_req("beta", cwd.path(), "sleep 30"))
|
||||
.await
|
||||
.expect("spawn beta");
|
||||
|
||||
let alpha_base = format!("http://{}", alpha.bind_addr);
|
||||
let sid = session.id;
|
||||
wait_for_async(
|
||||
"alpha mirrors beta's session",
|
||||
Duration::from_secs(5),
|
||||
|| {
|
||||
let base = alpha_base.clone();
|
||||
async move {
|
||||
let resp = match reqwest::get(format!("{base}/api/sessions")).await {
|
||||
Ok(r) => r,
|
||||
Err(_) => return false,
|
||||
};
|
||||
let list: Vec<maestro_protocol::Session> = match resp.json().await {
|
||||
Ok(v) => v,
|
||||
Err(_) => return false,
|
||||
};
|
||||
list.iter().any(|s| s.id == sid)
|
||||
}
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
||||
let broker_url = format!("ws://{}/api/attach/{}", alpha.bind_addr, sid);
|
||||
// NAP-265: beta rejects the pair JWT (empty allow_inbound) pre-upgrade.
|
||||
// alpha's broker now dials the peer *before* completing the upgrade, so the
|
||||
// client's handshake fails with a structured 502 rather than succeeding and
|
||||
// then closing opaquely.
|
||||
let err = tokio_tungstenite::connect_async(broker_url)
|
||||
.await
|
||||
.expect_err("handshake must fail when the peer rejects the attach");
|
||||
match err {
|
||||
tokio_tungstenite::tungstenite::Error::Http(resp) => {
|
||||
assert_eq!(
|
||||
resp.status(),
|
||||
502,
|
||||
"expected BAD_GATEWAY from alpha's broker, got {}",
|
||||
resp.status()
|
||||
);
|
||||
}
|
||||
other => panic!("expected an HTTP 502 response, got {other:?}"),
|
||||
}
|
||||
|
||||
client.kill_session(sid).await.expect("kill");
|
||||
drop(alpha);
|
||||
drop(beta);
|
||||
drop(registry);
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn broker_attach_returns_502_on_perimeter_mismatch() {
|
||||
// NAP-270: the asymmetric-VLAN boundary. alpha and beta are on DIFFERENT
|
||||
@@ -749,7 +637,6 @@ async fn broker_attach_returns_502_on_perimeter_mismatch() {
|
||||
DaemonOptions {
|
||||
perimeter_id: Some("wg-beta".into()),
|
||||
private_addr: Some(beta_bind.to_string()),
|
||||
allow_inbound: vec!["alpha".into()],
|
||||
},
|
||||
)
|
||||
.await;
|
||||
@@ -766,7 +653,6 @@ async fn broker_attach_returns_502_on_perimeter_mismatch() {
|
||||
// Different perimeter from beta → T2 unavailable.
|
||||
perimeter_id: Some("wg-alpha".into()),
|
||||
private_addr: Some(alpha_bind.to_string()),
|
||||
allow_inbound: vec![],
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
||||
Reference in New Issue
Block a user