Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
9644e08
feat(sessions): accept the four egress fields on own- and host-addres…
minimal-foundry[bot] Sep 25, 2026
fcc7882
feat(minimald): log egress rule counts at session start; none box rej…
minimal-foundry[bot] Sep 25, 2026
7651faf
feat(minimal-tui): show host-address egress and deny subnets in the d…
minimal-foundry[bot] Sep 25, 2026
8329d14
feat(min): accept egress flags on activate; show effective rules in s…
minimal-foundry[bot] Sep 25, 2026
9929237
docs(min): document the egress flags and the policy output
minimal-foundry[bot] Sep 25, 2026
0030672
style: rustfmt the egress rendering changes
minimal-foundry[bot] Sep 25, 2026
a56aa16
Merge remote-tracking branch 'origin/main' into agent/1617-accept-the…
minimal-foundry[bot] Sep 25, 2026
707049b
Merge remote-tracking branch 'origin/main' into agent/1617-accept-the…
norrietaylor Sep 25, 2026
18006e1
fix(min): cite the current network spellings in the egress flag help
minimal-foundry[bot] Sep 25, 2026
4742b2f
fix(min): omit the ingress block for host-address sessions in policy
minimal-foundry[bot] Sep 25, 2026
015aa65
Merge remote-tracking branch 'origin/main' into agent/1617-accept-the…
minimal-foundry[bot] Sep 25, 2026
6608718
fix(min): print the no-network note for none sessions in policy
minimal-foundry[bot] Sep 25, 2026
8d8e32d
style: rustfmt the none-session policy test
minimal-foundry[bot] Sep 25, 2026
ffe5ad1
Merge remote-tracking branch 'origin/main' into agent/1617-accept-the…
minimal-foundry[bot] Sep 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 40 additions & 22 deletions crates/minimal-tui/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,14 @@ fn render_policy(model: &Model, key: &SessionKey, frame: &mut Frame, area: Rect)
fn policy_lines(model: &Model, key: &SessionKey) -> Vec<Line<'static>> {
let detail = model.details.get(key);
let record = detail.and_then(|d| d.record.as_ref());
let network = record.map(|r| r.network);
let mut lines: Vec<Line> = Vec::new();

if record.is_some() && record.map(|r| r.network) != Some(sessions::NetworkMode::OwnIp) {
if network == Some(sessions::NetworkMode::NoNet) {
// A none box has no network, so it can carry no egress or ingress
// declaration at all — nothing here would describe anything real.
lines.push(Line::styled(
"No network policy (HostNet/NoNet)",
"No network policy (NoNet)",
Style::default().fg(Color::Gray),
));
} else {
Expand Down Expand Up @@ -517,28 +520,43 @@ fn policy_lines(model: &Model, key: &SessionKey) -> Vec<Line<'static>> {
.join(", ")
))),
}
// The denied ranges are subtractive — carved out of
// what the allow fields admit — so unlike the allow
// fields an unset row means "nothing denied", not
// "allow all".
match &egress.deny_subnets {
None => lines.push(Line::raw(" deny subnets (none)")),
Some(subnets) => lines
.push(Line::raw(format!(" deny subnets {}", subnets.join(", ")))),
}
}
}
lines.push(Line::styled(
"ingress",
Style::default().add_modifier(Modifier::BOLD),
));
match &policy.ingress {
None => lines.push(Line::raw(" deny all")),
Some(ingress) => {
if ingress.port_mappings.is_empty()
&& ingress.dynamic_allowed_range.is_none()
{
lines.push(Line::raw(" deny all"));
}
for mapping in &ingress.port_mappings {
lines.push(Line::raw(format!(
" {} :{} → :{}",
mapping.proto, mapping.external_port, mapping.internal_port
)));
}
if let Some((lo, hi)) = ingress.dynamic_allowed_range {
lines.push(Line::raw(format!(" dynamic ports {lo}–{hi}")));
// Ingress is an own-address surface: the switch's static
// forwarder is the only per-session ingress minimald applies,
// and a host-address box shares its host's namespace, so
// there is no per-session ingress policy to show for it.
if network != Some(sessions::NetworkMode::HostNet) {
Comment thread
minimal-foundry[bot] marked this conversation as resolved.
Resolved
lines.push(Line::styled(
"ingress",
Style::default().add_modifier(Modifier::BOLD),
));
match &policy.ingress {
None => lines.push(Line::raw(" deny all")),
Some(ingress) => {
if ingress.port_mappings.is_empty()
&& ingress.dynamic_allowed_range.is_none()
{
lines.push(Line::raw(" deny all"));
}
for mapping in &ingress.port_mappings {
lines.push(Line::raw(format!(
" {} :{} → :{}",
mapping.proto, mapping.external_port, mapping.internal_port
)));
}
if let Some((lo, hi)) = ingress.dynamic_allowed_range {
lines.push(Line::raw(format!(" dynamic ports {lo}–{hi}")));
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/minimal-tui/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ fn detail_pane_with_policy() {
allow_subnets: Some(vec!["10.0.0.0/8".to_string()]),
allow_dns_hosts: None,
allow_protocols: None,
deny_subnets: Some(vec!["192.168.0.0/16".to_string()]),
}),
Some(sessions::IngressPolicy {
port_mappings: vec![sessions::PortMapping {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/minimal-tui/tests/snapshots.rs
assertion_line: 230
expression: render(&mut model)
---
"┌──────────────────────────────┐┌ api-staging · 00000000 ──────────────────────────────────────────┐"
Expand All @@ -12,6 +13,7 @@ expression: render(&mut model)
"│ ││ subnets 10.0.0.0/8 │"
"│ ││ dns hosts allow all │"
"│ ││ protocols allow all │"
"│ ││ deny subnets 192.168.0.0/16 │"
"│ ││ ingress │"
"│ ││ tcp :8080 → :80 │"
"│ ││ ─ Preview (live screen snapshot) ─────────────────────────────── │"
Expand All @@ -29,6 +31,5 @@ expression: render(&mut model)
"│ ││ │"
"│ ││ │"
"│ ││ │"
"│ ││ │"
"└──────────────────────────────┘└──────────────────────────────────────────────────────────────────┘"
" ↑↓ move · / filter · enter attach · d destroy · r rename · n new · q quit "
35 changes: 35 additions & 0 deletions crates/minimal/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,26 @@ pub struct ActivateArgs {
/// tcp). Repeatable. Requires `--network own_ip`.
#[arg(long = "ingress", value_name = "EXT:INT[/PROTO]")]
pub ingress: Vec<String>,
/// Allowed destination subnets in CIDR form (`egress.allow_subnets`),
/// e.g. `10.0.0.0/8`. Repeatable; unset means allow-all subnets. Valid on
/// an own-address (`--network own_ip`) or host-address
/// (`--network host_ip`) box; a none box rejects the whole egress
/// declaration.
#[arg(long = "allow-subnets", value_name = "CIDR")]
pub allow_subnets: Vec<String>,
/// Allowed destination DNS hostnames (`egress.allow_dns_hosts`), e.g.
/// `github.com`. Repeatable; unset means allow-all hosts.
#[arg(long = "allow-dns-hosts", value_name = "HOST")]
pub allow_dns_hosts: Vec<String>,
/// Allowed outbound transport protocols (`egress.allow_protocols`):
/// tcp, udp, or icmp. Repeatable; unset means allow all protocols.
#[arg(long = "allow-protocols", value_name = "PROTO")]
pub allow_protocols: Vec<String>,
/// Denied destination subnets in CIDR form (`egress.deny_subnets`),
/// subtracted from the allowed set. Repeatable; unset means nothing is
/// denied.
#[arg(long = "deny-subnets", value_name = "CIDR")]
pub deny_subnets: Vec<String>,
/// Apply the named loadout from `<config>/minimal/loadouts/<NAME>.toml`.
/// Repeatable. If any `--loadout` is specified, defaults from
/// `[loadouts].default_loadouts` in the client config are ignored.
Expand Down Expand Up @@ -610,6 +630,21 @@ pub(crate) fn parse_ingress_proto(proto: &str) -> Result<sessions::IpProto, anyh
}
}

/// Parse an `--allow-protocols <PROTO>` spec into an [`sessions::IpProto`].
/// Egress rules name any transport the policy type carries, so unlike the
/// ingress parser (whose vocabulary is gvproxy's static forwarder's), icmp is
/// accepted here.
pub(crate) fn parse_egress_proto(proto: &str) -> Result<sessions::IpProto, anyhow::Error> {
match proto.to_ascii_lowercase().as_str() {
"tcp" => Ok(sessions::IpProto::Tcp),
"udp" => Ok(sessions::IpProto::Udp),
"icmp" => Ok(sessions::IpProto::Icmp),
other => Err(anyhow::anyhow!(
"egress: unsupported protocol '{other}' (use tcp, udp, or icmp)"
)),
}
}

#[derive(Debug, Args)]
pub struct AttachArgs {
/// Session identifier (UUID or session name). When omitted, `min session attach`
Expand Down
4 changes: 4 additions & 0 deletions crates/minimal/src/cmd/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ pub(crate) fn bare_activate_args() -> ActivateArgs {
sync: None,
network: CliNetworkMode::HostNet,
ingress: Vec::new(),
allow_subnets: Vec::new(),
allow_dns_hosts: Vec::new(),
allow_protocols: Vec::new(),
deny_subnets: Vec::new(),
loadout: Vec::new(),
no_loadouts: false,
no_hooks: false,
Expand Down
129 changes: 124 additions & 5 deletions crates/minimal/src/cmd/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,25 @@ pub(crate) async fn activate_session(
let mapping = parse_ingress_mapping(spec)?;
port_mappings.push(mapping);
}
let mut allow_protocols = Vec::with_capacity(args.allow_protocols.len());
for spec in &args.allow_protocols {
allow_protocols.push(parse_egress_proto(spec)?);
}
// Any egress flag makes the declaration; a field with no values stays
// `None` — its allow-all/none-denied default — so `--deny-subnets` alone
// records an allow-all policy that denies one range.
let has_egress = !args.allow_subnets.is_empty()
|| !allow_protocols.is_empty()
|| !args.allow_dns_hosts.is_empty()
|| !args.deny_subnets.is_empty();
let egress = has_egress.then_some(sessions::EgressPolicy {
allow_subnets: (!args.allow_subnets.is_empty()).then(|| args.allow_subnets.clone()),
allow_dns_hosts: (!args.allow_dns_hosts.is_empty()).then(|| args.allow_dns_hosts.clone()),
allow_protocols: (!allow_protocols.is_empty()).then_some(allow_protocols),
deny_subnets: (!args.deny_subnets.is_empty()).then(|| args.deny_subnets.clone()),
});
let policy = sessions::SessionPolicy {
egress: None,
egress,
ingress: (!port_mappings.is_empty()).then_some(sessions::IngressPolicy {
port_mappings,
dynamic_allowed_range: None,
Expand Down Expand Up @@ -747,6 +764,10 @@ pub(crate) async fn activate_new_for_attach(global: &GlobalArgs) -> Result<(), a
sync: None,
network: CliNetworkMode::HostNet,
ingress: Vec::new(),
allow_subnets: Vec::new(),
allow_dns_hosts: Vec::new(),
allow_protocols: Vec::new(),
deny_subnets: Vec::new(),
loadout: Vec::new(),
no_loadouts: false,
no_hooks: false,
Expand Down Expand Up @@ -857,7 +878,7 @@ pub(crate) fn exit_code_of(status: std::process::ExitStatus) -> i32 {
.unwrap_or(1)
}

/// Print the effective networking policy for a session as JSON.
/// Print the effective networking rules for a session.
pub async fn cmd_session_policy(
global: &GlobalArgs,
args: PolicyArgs,
Expand All @@ -866,6 +887,12 @@ pub async fn cmd_session_policy(

let mut client = connect_daemon(global).await?;

// The policy reply carries only the rules, but the ingress block is
// suppressed for host-address sessions (see [`format_policy`]), so the
// command also resolves the record the policy rides on for its network
// mode.
let record = resolve_session(&mut client, &args.session).await?;

use minimald_rpc::{GetSessionPolicy, GetSessionPolicyRequest};
let lookup: GetSessionPolicyRequest = SessionLookup::parse(&args.session).into();

Expand All @@ -876,9 +903,9 @@ pub async fn cmd_session_policy(

match resp {
minimald_rpc::Errorable::Ok(policy) => {
let json =
serde_json_lenient::to_string(&policy).context("Failed to serialize policy")?;
println!("{json}");
let mut out = std::io::stdout();
format_policy(&mut out, &policy, record.network)?;
out.flush().context("Failed to write policy")?;
Ok(())
}
minimald_rpc::Errorable::Err { error } => {
Expand All @@ -887,6 +914,98 @@ pub async fn cmd_session_policy(
}
}

/// Render a session policy as its effective rules: each egress dimension
/// resolved to its list or its default (`allow all`; `deny subnets` reads
/// `(none)` when nothing is denied), the ingress mappings spelled out.
/// `network` is the session's network mode, and the modes without a surface
/// to describe are held to the TUI's detail pane: a none box has no network
/// at all, so it prints the pane's one-line note in place of both blocks
/// (`allow all` egress would claim a reach a box with no network does not
/// have), and a host-address session shares its host's namespace, so it has
/// no per-session ingress policy to show and the block is omitted entirely.
/// Shared by `min session policy`'s printer and the integration
/// test that pins the rendering (NET-061).
pub fn format_policy(
out: &mut impl std::io::Write,
policy: &sessions::SessionPolicy,
network: sessions::NetworkMode,
) -> Result<(), anyhow::Error> {
// A none box has no network, so it can carry no egress or ingress
// declaration at all — nothing the blocks print would describe anything
// real (the same case the TUI's detail pane replaces with this note).
if network == sessions::NetworkMode::NoNet {
writeln!(out, "No network policy (NoNet)")?;
return Ok(());
}
writeln!(out, "egress")?;
match &policy.egress {
None => writeln!(out, " allow all")?,
Some(egress) => {
write_rules(out, "subnets", egress.allow_subnets.as_ref(), "allow all")?;
write_rules(
out,
"dns hosts",
egress.allow_dns_hosts.as_ref(),
"allow all",
)?;
match &egress.allow_protocols {
None => writeln!(out, " protocols allow all")?,
Some(protos) => writeln!(
out,
" protocols {}",
protos
.iter()
.map(|p| p.to_string())
.collect::<Vec<_>>()
.join(", ")
)?,
}
write_rules(out, "deny subnets", egress.deny_subnets.as_ref(), "(none)")?;
}
}
// Ingress is an own-address surface: the switch's static forwarder is the
// only per-session ingress minimald applies, and a host-address box
// shares its host's namespace, so there is no per-session ingress policy
// to show for it — "deny all" there would claim a deny-rule exists.
if network != sessions::NetworkMode::HostNet {
writeln!(out, "ingress")?;
match &policy.ingress {
None => writeln!(out, " deny all")?,
Some(ingress) => {
if ingress.port_mappings.is_empty() && ingress.dynamic_allowed_range.is_none() {
writeln!(out, " deny all")?;
}
for mapping in &ingress.port_mappings {
writeln!(
out,
" {} :{} → :{}",
mapping.proto, mapping.external_port, mapping.internal_port
)?;
}
if let Some((lo, hi)) = ingress.dynamic_allowed_range {
writeln!(out, " dynamic ports {lo}–{hi}")?;
}
}
}
}
Ok(())
}
Comment thread
norrietaylor marked this conversation as resolved.
Resolved

/// One egress rule row: the CIDR or hostname list, or the default the policy
/// resolves to when the dimension is unset.
fn write_rules(
out: &mut impl std::io::Write,
label: &str,
rules: Option<&Vec<String>>,
default: &str,
) -> Result<(), anyhow::Error> {
match rules {
None => writeln!(out, " {label} {default}")?,
Some(rules) => writeln!(out, " {label} {}", rules.join(", "))?,
}
Ok(())
}

/// Register a session as an SSH remote in Zed's `settings.json`.
///
/// Zed drives its own `ssh` for remote projects, so the entry has to carry the
Expand Down
Loading
Loading