Skip to content

Commit 34d54ad

Browse files
committed
feat(driver-mxc): implement Pattern-C governed-egress split through the policy seam
- split_policy: SocketAddr proxy_redirect (replaces bare port), processcontainer containment guard naming MXC M1, version preserved in the trimmed proxy_policy, delegation reported as an info loss item - seam: MappedConfig carries trimmed_policy + proxy_addr; MapCtx.egress selects the split path; coarse path unchanged when egress is disabled - driver: [openshell.drivers.mxc] egress_proxy / egress_proxy_addr config, validated at create (isolation_session rejected until M1); lifecycle threads the redirect into provision and stores the trimmed policy per sandbox, emitting an EgressRedirect platform event - mxc: optional MxcNetwork block (defaultPolicy=block + proxy) in provision and one-shot configs; mock records configs for test assertions - tests: lossless-invariant suite over all example policies (validate + serialize round-trip), split lifecycle proof, M1 rejection; example gains --split --proxy-addr writing mxc-config.json / trimmed-policy.yaml / loss-report.json Signed-off-by: Giedrius Burachas <[email protected]>
1 parent cf8770a commit 34d54ad

8 files changed

Lines changed: 1113 additions & 117 deletions

File tree

‎.agents/skills/implement-openshell-policy-mapper/SKILL.md‎

Lines changed: 356 additions & 0 deletions
Large diffs are not rendered by default.

‎crates/openshell-driver-mxc/README.md‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ architectural rationale (decisions D1–D4).
1818
| Capability | MXC driver | Closing it requires |
1919
|---|---|---|
2020
| Filesystem policy (read-write / read-only grants) | ✅ provision-time AppContainer shares | — |
21-
| Governed egress (CONNECT proxy + OPA + L7) | ❌ | `implement-openshell-mxc-egress-proxy` |
22-
| Network policy | ❌ `isolation_session` rejects network config | MXC feedback item M1 + egress skill |
21+
| Governed egress (CONNECT proxy + OPA + L7) | Available behind `egress_proxy` on `process_container`; host proxy integration is the next consumer | `implement-openshell-mxc-egress-proxy` |
22+
| Network policy | Split into MXC `network.proxy` + trimmed OpenShell policy on `process_container`; `isolation_session` still rejects network config | MXC feedback item M1 for persistent sessions |
2323
| Process policy (seccomp, uid/gid) | ❌ host-side governance design; OS isolation only | not pursued |
2424
| Interactive exec/connect/forward | ❌ exec runs in-driver, no client attach | `adapt-openshell-gateway-windows` |
2525
| Bundled agent image | ❌ no OCI image; relies on Windows host install | — |
@@ -37,14 +37,23 @@ The June 15 demo proof point is **filesystem policy enforcement**:
3737
[openshell.drivers.mxc]
3838
# Path to wxc-exec.exe (required for live runs)
3939
wxc_exec_path = "C:\\path\\to\\wxc-exec.exe"
40+
# MXC backend: "isolation_session" (default) or "process_container"
41+
backend = "process_container"
4042
# MXC configurationId — never use "small" (known OS bug)
4143
default_configuration_id = "composable"
44+
# process_container-only options
45+
pc_least_privilege = false
46+
pc_capabilities = []
4247
# Agent command executed inside the sandbox
4348
agent_command = ["cmd", "/c", "echo hello > C:\\work\\demo\\hello.txt"]
4449
# Working directory for the agent (defaults to share_dir)
4550
agent_cwd = "C:\\work\\demo"
4651
# Host directory mapped read-write into the sandbox
4752
share_dir = "C:\\work\\demo"
53+
# Pattern C governed egress. Requires backend = "process_container" until
54+
# MXC M1 adds network.proxy support for isolation_session.
55+
egress_proxy = false
56+
egress_proxy_addr = ""
4857
# Enable --debug on wxc-exec invocations
4958
debug = false
5059
```
@@ -76,6 +85,13 @@ the **source of truth** for the OpenShell→MXC mapping — it was the standalon
7685
`StubPolicyMapper` is retained as a documented, compile-only fallback that only
7786
maps `share_dir`.
7887

88+
When `egress_proxy` is enabled, `EmbeddedPolicyMapper` uses `split_policy`
89+
instead: MXC receives filesystem grants plus a loopback `network.proxy`
90+
redirect, and the driver stores the trimmed network-only `SandboxPolicy` for
91+
the host CONNECT proxy. The development export surface remains the
92+
[`policy-to-mxc`](examples/policy-to-mxc.rs) example; there is no production
93+
`openshell policy export-mxc` subcommand yet.
94+
7995
Everything in this crate — including the mapper, the
8096
[`policy-to-mxc`](examples/policy-to-mxc.rs) example, and the parity tests in
8197
[`tests/policy_mapper_examples.rs`](tests/policy_mapper_examples.rs) — is
@@ -95,6 +111,6 @@ landed before moving it.
95111
## Deferred work
96112

97113
- **Interactive exec/connect/forward** → `adapt-openshell-gateway-windows`
98-
- **Governed egress / network policy** → `implement-openshell-mxc-egress-proxy`
114+
- **Governed egress proxy implementation** → `implement-openshell-mxc-egress-proxy`
99115
- **Restart durability** (deprovision orphaned sessions on startup) → follow-on
100116
- **GPU passthrough** → not pursued in host-side-governance design

‎crates/openshell-driver-mxc/examples/policy-to-mxc.rs‎

Lines changed: 83 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ fn main() {}
2323

2424
#[cfg(target_os = "windows")]
2525
mod imp {
26+
use std::net::SocketAddr;
2627
use std::path::{Path, PathBuf};
2728

2829
use anyhow::{Context, Result, anyhow, bail};
@@ -84,12 +85,17 @@ mod imp {
8485

8586
/// Run the lossless split instead of the coarse map.
8687
///
87-
/// Requires `--proxy-port`. Prints the MXC config (with proxy redirect
88-
/// and empty `allowedHosts`) and the trimmed proxy policy side-by-side.
88+
/// Requires `--proxy-addr`. Prints and writes the MXC config (with proxy
89+
/// redirect and empty `allowedHosts`) plus the trimmed proxy policy.
8990
#[arg(long)]
9091
split: bool,
9192

92-
/// Localhost port the `OpenShell` CONNECT proxy listens on (required with `--split`).
93+
/// Loopback address the `OpenShell` CONNECT proxy listens on. Accepts
94+
/// `IP:PORT`, or a bare port shorthand expanded to `127.0.0.1:PORT`.
95+
#[arg(long)]
96+
proxy_addr: Option<String>,
97+
98+
/// Deprecated shorthand for `--proxy-addr 127.0.0.1:PORT`.
9399
#[arg(long)]
94100
proxy_port: Option<u16>,
95101
}
@@ -98,9 +104,7 @@ mod imp {
98104
let args = Args::parse();
99105

100106
if args.split {
101-
let port = args
102-
.proxy_port
103-
.ok_or_else(|| anyhow!("--proxy-port is required with --split"))?;
107+
let proxy_addr = parse_proxy_addr(args.proxy_addr.as_deref(), args.proxy_port)?;
104108
let policy_path = args
105109
.policy
106110
.as_ref()
@@ -112,8 +116,8 @@ mod imp {
112116
.into_owned();
113117
let slug = args.container_id.clone().unwrap_or(stem);
114118
let mut opts = build_options(&args, &slug);
115-
opts.proxy_localhost_port = Some(port);
116-
return show_split(policy_path, &opts);
119+
opts.proxy_redirect = Some(proxy_addr);
120+
return show_split(policy_path, &args.out_dir, &opts);
117121
}
118122

119123
if let Some(examples_root) = &args.examples_root {
@@ -173,10 +177,27 @@ mod imp {
173177
env: args.env.clone(),
174178
timeout_ms: args.timeout_ms,
175179
allow_wildcards: args.allow_wildcards,
176-
proxy_localhost_port: None,
180+
proxy_redirect: None,
177181
}
178182
}
179183

184+
fn parse_proxy_addr(addr: Option<&str>, port: Option<u16>) -> Result<SocketAddr> {
185+
let Some(raw) = addr else {
186+
let port = port.ok_or_else(|| anyhow!("--proxy-addr is required with --split"))?;
187+
return format!("127.0.0.1:{port}")
188+
.parse()
189+
.context("parsing deprecated --proxy-port shorthand");
190+
};
191+
let expanded = if raw.chars().all(|c| c.is_ascii_digit()) {
192+
format!("127.0.0.1:{raw}")
193+
} else {
194+
raw.to_owned()
195+
};
196+
expanded
197+
.parse()
198+
.with_context(|| format!("parsing --proxy-addr {raw:?}"))
199+
}
200+
180201
fn convert_policy(
181202
policy_path: &Path,
182203
out_dir: &Path,
@@ -245,14 +266,15 @@ mod imp {
245266
// Lossless-split display
246267
// -----------------------------------------------------------------------
247268

248-
fn show_split(policy_path: &Path, opts: &MxcMappingOptions) -> Result<()> {
269+
fn show_split(policy_path: &Path, out_dir: &Path, opts: &MxcMappingOptions) -> Result<()> {
249270
let content = std::fs::read_to_string(policy_path)
250271
.with_context(|| format!("reading {}", policy_path.display()))?;
251272
let policy = openshell_policy::parse_sandbox_policy(&content)
252273
.map_err(|e| anyhow!("parsing {}: {e}", policy_path.display()))?;
253274

254275
let result = split_policy(&policy, opts)
255-
.ok_or_else(|| anyhow!("split_policy returned None — is --proxy-port set?"))?;
276+
.ok_or_else(|| anyhow!("split_policy returned None; is --proxy-addr set?"))?;
277+
write_split_outputs(policy_path, out_dir, opts, &result)?;
256278

257279
println!("=== MXC ContainerConfig (filesystem + proxy redirect) ===");
258280
println!("{}", serde_json::to_string_pretty(&result.mxc_config)?);
@@ -270,15 +292,35 @@ mod imp {
270292
let ports = if ep.ports.is_empty() {
271293
String::new()
272294
} else {
273-
format!(":{}", ep.ports.iter().map(|p| p.to_string()).collect::<Vec<_>>().join(","))
295+
format!(
296+
":{}",
297+
ep.ports
298+
.iter()
299+
.map(|p| p.to_string())
300+
.collect::<Vec<_>>()
301+
.join(",")
302+
)
274303
};
275304
println!(
276305
" endpoint: {}{} protocol={} tls={} access={} enforcement={}",
277-
ep.host, ports,
278-
if ep.protocol.is_empty() { "-" } else { &ep.protocol },
306+
ep.host,
307+
ports,
308+
if ep.protocol.is_empty() {
309+
"-"
310+
} else {
311+
&ep.protocol
312+
},
279313
if ep.tls.is_empty() { "-" } else { &ep.tls },
280-
if ep.access.is_empty() { "-" } else { &ep.access },
281-
if ep.enforcement.is_empty() { "-" } else { &ep.enforcement },
314+
if ep.access.is_empty() {
315+
"-"
316+
} else {
317+
&ep.access
318+
},
319+
if ep.enforcement.is_empty() {
320+
"-"
321+
} else {
322+
&ep.enforcement
323+
},
282324
);
283325
if !ep.rules.is_empty() {
284326
println!(" allow rules: {}", ep.rules.len());
@@ -296,7 +338,10 @@ mod imp {
296338

297339
if !result.loss.is_empty() {
298340
println!();
299-
println!("=== Filesystem loss items ({} item(s)) ===", result.loss.len());
341+
println!(
342+
"=== Filesystem loss items ({} item(s)) ===",
343+
result.loss.len()
344+
);
300345
for item in &result.loss {
301346
println!(" [{}] {}: {}", item.severity, item.path, item.message);
302347
}
@@ -305,6 +350,27 @@ mod imp {
305350
Ok(())
306351
}
307352

353+
fn write_split_outputs(
354+
policy_path: &Path,
355+
out_dir: &Path,
356+
options: &MxcMappingOptions,
357+
result: &openshell_driver_mxc::SplitPolicyResult,
358+
) -> Result<()> {
359+
write_outputs(
360+
policy_path,
361+
out_dir,
362+
options,
363+
&result.mxc_config,
364+
&result.loss,
365+
)?;
366+
let trimmed_path = out_dir.join("trimmed-policy.yaml");
367+
let trimmed = openshell_policy::serialize_sandbox_policy(&result.proxy_policy)
368+
.map_err(|e| anyhow!("serializing trimmed proxy policy: {e}"))?;
369+
std::fs::write(&trimmed_path, trimmed)
370+
.with_context(|| format!("writing {}", trimmed_path.display()))?;
371+
Ok(())
372+
}
373+
308374
// -----------------------------------------------------------------------
309375
// File discovery & slug helpers
310376
// -----------------------------------------------------------------------

0 commit comments

Comments
 (0)