Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
9fc8d80
feat(sessions,minimald,minvmd): static ingress, session policy state,…
gominimal-aw-bot[bot] Jun 24, 2026
f3952af
fix(minimald,sessions,minvmd): address review findings on net policy
gominimal-aw-bot[bot] Jun 24, 2026
c2cb3e6
fix(minvmd): restore thiserror dep after stale-base rebase
norrietaylor Jun 24, 2026
481bc24
feat(sessions,minimald): reject privileged ingress host ports below 1024
gominimal-aw-bot[bot] Jun 24, 2026
cc2f8a1
test(sessions): pin validate_policy check ordering on non-OwnIp ingress
gominimal-aw-bot[bot] Jun 24, 2026
423ca76
fix(minimald): bind ingress to loopback, align warn window and fields
gominimal-aw-bot[bot] Jun 24, 2026
01f4461
fix(minimald): log detach failure in ingress-apply rollback
gominimal-aw-bot[bot] Jun 24, 2026
b05b9d5
fix: restore unrelated pidfd spec deleted by stale-base (#552)
norrietaylor Jun 24, 2026
603a87d
feat(sessions,minimald): validate egress subnet CIDRs at launch
gominimal-aw-bot[bot] Jun 24, 2026
7b7f45b
feat(sessions,minimald): log policy-violation proto in snake_case
gominimal-aw-bot[bot] Jun 24, 2026
edf2aec
fix(minimald): cap gvproxy control-response read at 64 KiB
norrietaylor Jun 24, 2026
2d817af
fix(minimald): validate session policy at CreateSession time
gominimal-aw-bot[bot] Jun 24, 2026
a4c2699
fix(sessions): reject reversed ingress dynamic_allowed_range
gominimal-aw-bot[bot] Jun 24, 2026
5929edb
test(netns): raise the connect-retry deadline 10s -> 30s
norrietaylor Jun 24, 2026
56bbda1
feat(sessions,minvmd): validate dynamic-range floor and vm_egress CIDRs
gominimal-aw-bot[bot] Jun 24, 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
1 change: 1 addition & 0 deletions crates/minimal2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ async fn cmd_activate(global: &GlobalArgs, args: ActivateArgs) -> Result<(), ()>
username,
project_path: abs_path,
network: sessions::NetworkMode::default(),
policy: Default::default(),
attrs: Default::default(),
};

Expand Down
66 changes: 7 additions & 59 deletions crates/minimald-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use chrono::Utc;
use serde::{Deserialize, Serialize, de::DeserializeOwned};
use sessions::SessionId;

pub use sessions::{IpProto, NetworkMode};
pub use sessions::{EgressPolicy, IngressPolicy, IpProto, NetworkMode, PortMapping, SessionPolicy};

pub const RPC_SUBSYSTEM_PREFIX: &str = "minimald-v1-";

Expand Down Expand Up @@ -279,66 +279,14 @@ impl OneshotSshRpc for SessionAbort {

// ---------------------------------------------------------------------------
// Networking policy types (Unit 2: egress, ingress, dynamic port mapping).
//
// `PortMapping`, `EgressPolicy`, `IngressPolicy`, and `SessionPolicy` are
// defined in `sessions` and re-exported above, so the only live per-session
// store (`sessions::Record`) can carry the policy configured at launch without
// a `sessions` → `minimald-rpc` dependency cycle. The RPC method types below
// stay here, where the wire contract lives.
// ---------------------------------------------------------------------------

/// A single static ingress port mapping for an `OwnIp` PTask.
#[non_exhaustive]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct PortMapping {
/// Host-side port that forwards inbound connections into the PTask.
pub external_port: u16,
/// PTask-side port that receives forwarded connections.
pub internal_port: u16,
/// Transport protocol for this mapping.
pub proto: IpProto,
}

/// Effective egress policy for an `OwnIp` PTask.
///
/// Each field is `None` to mean allow-all for that dimension. Absent `egress`
/// config on a session is equivalent to all-`None` (allow-all).
#[non_exhaustive]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct EgressPolicy {
/// Allowed destination CIDR prefixes; `None` means allow-all subnets.
pub allow_subnets: Option<Vec<String>>,
/// Allowed destination DNS hostnames; `None` means allow-all hosts.
pub allow_dns_hosts: Option<Vec<String>>,
/// Allowed IP protocols; `None` means allow all protocols.
pub allow_protocols: Option<Vec<IpProto>>,
}

/// Effective ingress policy for an `OwnIp` PTask.
///
/// Default (empty `port_mappings`, no `dynamic_allowed_range`) is deny-all-external.
#[non_exhaustive]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct IngressPolicy {
/// Static port mappings applied at PTask launch.
pub port_mappings: Vec<PortMapping>,
/// Inclusive port range within which dynamic port-mapping requests are
/// accepted; `None` means dynamic mapping is disallowed.
pub dynamic_allowed_range: Option<(u16, u16)>,
}

/// The effective networking policy for a named session, as returned by
/// [`GetSessionPolicy`].
#[non_exhaustive]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct SessionPolicy {
/// Egress policy; `None` when the session is not `OwnIp` or no explicit
/// egress config is present (allow-all).
pub egress: Option<EgressPolicy>,
/// Ingress policy; `None` when the session is not `OwnIp`.
pub ingress: Option<IngressPolicy>,
}

impl SessionPolicy {
pub fn new(egress: Option<EgressPolicy>, ingress: Option<IngressPolicy>) -> Self {
Self { egress, ingress }
}
}

/// An RPC to read the effective networking policy for a session (R2.6).
pub struct GetSessionPolicy;

Expand Down
1 change: 1 addition & 0 deletions crates/minimald/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,7 @@ mod tests {
username: None,
project_path: HostAbsPath::try_new("/tmp").unwrap(),
network: sessions::NetworkMode::default(),
policy: Default::default(),
attrs: Default::default(),
},
})
Expand Down
21 changes: 11 additions & 10 deletions crates/minimald/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//! reuse), and R1.8 (structured tracing for every switch lifecycle event).

pub mod dns;
pub mod policy;
pub mod proxy;
pub mod switch;

Expand Down Expand Up @@ -57,16 +58,17 @@ const TERM_GRACE: Duration = Duration::from_secs(5);
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum NetError {
/// The prefix length is outside the range accepted by [`SwitchSubnet::new`].
///
/// Distinct from [`SubnetExhausted`](Self::SubnetExhausted): a prefix that
/// puts the subnet outside `8..=29` is a misconfiguration (the prefix was
/// never valid), not an exhausted valid subnet.
#[error("prefix /{0} is outside the valid range /8..=/29 for a gvproxy switch subnet")]
InvalidPrefix(u8),
/// The configured subnet has no remaining host address to hand out.
#[error("gvproxy subnet {0} is exhausted; no free PTask address remains")]
SubnetExhausted(SwitchSubnet),
/// A subnet was constructed with a prefix outside the supported `8..=29`
/// range — a configuration error, distinct from runtime address exhaustion.
#[error(
"gvproxy subnet prefix /{0} is invalid; must be in 8..=29 (narrower has \
no room for a PTask address; wider lets the high octet vary, which the \
derived MAC cannot keep collision-free)"
)]
InvalidPrefix(u8),
/// Spawning the gvproxy binary failed.
#[error("spawning gvproxy at {path:?}: {source}")]
Spawn {
Expand Down Expand Up @@ -154,7 +156,8 @@ impl SwitchSubnet {
// none, so anything narrower than /29 has no room for a PTask. The lower
// bound keeps MacAddr::for_switch_ip collision-free — it derives the MAC
// from the low three octets, so the high octet must be pinned by the
// prefix (/8 or narrower).
// prefix (/8 or narrower). An out-of-range prefix is a misconfiguration,
// not runtime exhaustion, so it is reported as InvalidPrefix.
if !(8..=29).contains(&prefix) {
return Err(NetError::InvalidPrefix(prefix));
}
Expand Down Expand Up @@ -675,8 +678,6 @@ mod tests {

#[test]
fn subnet_rejects_overly_narrow_prefix() {
// /30 is a misconfiguration (no room for a PTask), not an exhausted
// valid subnet — so the distinct InvalidPrefix error is returned.
assert!(matches!(
SwitchSubnet::new(Ipv4Addr::new(10, 0, 0, 0), 30),
Err(NetError::InvalidPrefix(30))
Expand Down
Loading
Loading