Skip to content

Commit c4ea03e

Browse files
committed
feat(sandbox): add --permissive flag for audit2allow-style policy discovery
Add permissive mode to sandboxes, enabling a single-pass onboarding workflow for discovering what network policy a workload needs. When `openshell sandbox create --permissive` is used, the proxy logs but does not enforce network policy denials at both L4 (TCP connect) and L7 (HTTP method/path) layers. Denied connections succeed with full credential injection, and each denial feeds the existing DenialAggregator → mechanistic mapper → draft proposal pipeline. Users review all discovered endpoints at once with `openshell policy draft get`, approve them, and export the learned policy. Filesystem (Landlock) restrictions are skipped in permissive mode. Seccomp, process identity, and SSRF guards remain enforced. Permissive mode is threaded through all enforcement paths: CONNECT L4, forward-proxy L4, single-route and multi-route L7 relay, forward-proxy L7 path selection, and WebSocket/GraphQL message-level inspection. The permissive flag flows from SandboxSpec (proto) through the gateway's GetSandboxConfigResponse to the sandbox supervisor, which sets it on ProxyPolicy and L7EvalContext. Closes NVIDIA#1839 Signed-off-by: Russell Bryant <[email protected]>
1 parent e3d26dd commit c4ea03e

19 files changed

Lines changed: 1209 additions & 351 deletions

File tree

‎crates/openshell-cli/src/main.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,14 @@ enum SandboxCommands {
13291329
#[arg(long = "env", value_name = "KEY=VALUE")]
13301330
envs: Vec<String>,
13311331

1332+
/// Run in permissive mode: log but do not enforce network policy denials.
1333+
/// Connections that would be blocked are allowed through and logged as
1334+
/// draft policy proposals. Filesystem (Landlock) restrictions are skipped.
1335+
/// Seccomp and process-identity controls remain enforced.
1336+
/// Use with --policy to provide protocol hints for richer L7 learning.
1337+
#[arg(long)]
1338+
permissive: bool,
1339+
13321340
/// Approval mode for agent-authored policy proposals.
13331341
///
13341342
/// `manual` (default): every proposal lands in the draft inbox for
@@ -2622,6 +2630,7 @@ async fn main() -> Result<()> {
26222630
no_auto_providers,
26232631
labels,
26242632
envs,
2633+
permissive,
26252634
approval_mode,
26262635
command,
26272636
} => {
@@ -2709,6 +2718,7 @@ async fn main() -> Result<()> {
27092718
labels: labels_map,
27102719
environment: env_map,
27112720
approval_mode: &approval_mode,
2721+
permissive,
27122722
},
27132723
&tls,
27142724
))

‎crates/openshell-cli/src/run.rs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,7 @@ pub struct SandboxCreateConfig<'a> {
17891789
pub labels: HashMap<String, String>,
17901790
pub environment: HashMap<String, String>,
17911791
pub approval_mode: &'a str,
1792+
pub permissive: bool,
17921793
}
17931794

17941795
impl Default for SandboxCreateConfig<'_> {
@@ -1812,6 +1813,7 @@ impl Default for SandboxCreateConfig<'_> {
18121813
labels: HashMap::new(),
18131814
environment: HashMap::new(),
18141815
approval_mode: "manual",
1816+
permissive: false,
18151817
}
18161818
}
18171819
}
@@ -1842,6 +1844,7 @@ pub async fn sandbox_create(
18421844
labels,
18431845
environment,
18441846
approval_mode,
1847+
permissive,
18451848
} = config;
18461849

18471850
if editor.is_some() && !command.is_empty() {
@@ -1899,6 +1902,27 @@ pub async fn sandbox_create(
18991902
.await?;
19001903

19011904
let policy = load_sandbox_policy(policy)?;
1905+
1906+
if permissive {
1907+
let has_protocol_endpoints = policy.as_ref().is_some_and(|p| {
1908+
p.network_policies
1909+
.values()
1910+
.any(|rule| rule.endpoints.iter().any(|ep| !ep.protocol.is_empty()))
1911+
});
1912+
if !has_protocol_endpoints {
1913+
eprintln!(
1914+
"\n{} Permissive mode: no HTTP endpoints declared in policy.\n \
1915+
L7 audit will be limited to host:port only.\n \
1916+
To capture HTTP method/path detail, add endpoint protocol hints:\n\n \
1917+
endpoints:\n \
1918+
- host: api.example.com\n \
1919+
port: 443\n \
1920+
protocol: rest\n",
1921+
"⚠".yellow(),
1922+
);
1923+
}
1924+
}
1925+
19021926
let resource_limits = build_sandbox_resource_limits(cpu, memory)?;
19031927
let driver_config = driver_config_json
19041928
.map(parse_driver_config_json)
@@ -1924,6 +1948,7 @@ pub async fn sandbox_create(
19241948
policy,
19251949
providers: configured_providers,
19261950
template,
1951+
permissive,
19271952
..SandboxSpec::default()
19281953
}),
19291954
name: name.unwrap_or_default().to_string(),

‎crates/openshell-core/src/grpc_client.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,8 @@ pub struct SettingsPollResult {
749749
/// When `policy_source` is `Global`, the version of the global policy revision.
750750
pub global_policy_version: u32,
751751
pub provider_env_revision: u64,
752+
/// When true, the sandbox logs but does not enforce network policy denials.
753+
pub permissive: bool,
752754
}
753755

754756
fn settings_poll_result(inner: crate::proto::GetSandboxConfigResponse) -> SettingsPollResult {
@@ -762,6 +764,7 @@ fn settings_poll_result(inner: crate::proto::GetSandboxConfigResponse) -> Settin
762764
settings: inner.settings,
763765
global_policy_version: inner.global_policy_version,
764766
provider_env_revision: inner.provider_env_revision,
767+
permissive: inner.permissive,
765768
}
766769
}
767770

‎crates/openshell-core/src/policy.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ pub enum NetworkMode {
6969
pub struct ProxyPolicy {
7070
/// TCP address for a local HTTP proxy (loopback-only).
7171
pub http_addr: Option<SocketAddr>,
72+
/// When true, log but do not enforce policy denials (audit2allow mode).
73+
pub permissive: bool,
7274
}
7375

7476
#[derive(Debug, Clone, Default)]
@@ -104,7 +106,10 @@ impl TryFrom<ProtoSandboxPolicy> for SandboxPolicy {
104106
// can be evaluated by OPA and `inference.local` is always addressable.
105107
let network = NetworkPolicy {
106108
mode: NetworkMode::Proxy,
107-
proxy: Some(ProxyPolicy { http_addr: None }),
109+
proxy: Some(ProxyPolicy {
110+
http_addr: None,
111+
permissive: false,
112+
}),
108113
};
109114

110115
Ok(Self {

‎crates/openshell-sandbox/src/lib.rs‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,10 @@ fn process_policy_for_topology(
960960
let proxy = process_policy
961961
.network
962962
.proxy
963-
.get_or_insert(ProxyPolicy { http_addr: None });
963+
.get_or_insert(ProxyPolicy {
964+
http_addr: None,
965+
permissive: false,
966+
});
964967
if proxy.http_addr.is_none() {
965968
proxy.http_addr = Some(SIDECAR_PROCESS_PROXY_ADDR.parse().into_diagnostic()?);
966969
}
@@ -1656,7 +1659,10 @@ mod baseline_tests {
16561659
},
16571660
network: NetworkPolicy {
16581661
mode: NetworkMode::Proxy,
1659-
proxy: Some(ProxyPolicy { http_addr: None }),
1662+
proxy: Some(ProxyPolicy {
1663+
http_addr: None,
1664+
permissive: false,
1665+
}),
16601666
},
16611667
landlock: LandlockPolicy::default(),
16621668
process: ProcessPolicy::default(),
@@ -1811,7 +1817,10 @@ async fn load_policy(
18111817
filesystem: config.filesystem,
18121818
network: NetworkPolicy {
18131819
mode: NetworkMode::Proxy,
1814-
proxy: Some(ProxyPolicy { http_addr: None }),
1820+
proxy: Some(ProxyPolicy {
1821+
http_addr: None,
1822+
permissive: false,
1823+
}),
18151824
},
18161825
landlock: config.landlock,
18171826
process: config.process,
@@ -1943,14 +1952,22 @@ async fn load_policy(
19431952
}
19441953
};
19451954

1946-
let policy = match SandboxPolicy::try_from(proto_policy.clone()) {
1955+
let mut policy = match SandboxPolicy::try_from(proto_policy.clone()) {
19471956
Ok(policy) => policy,
19481957
Err(e) => {
19491958
report_initial_policy_failure(endpoint, id, loaded_policy_revision.as_ref(), &e)
19501959
.await;
19511960
return Err(e);
19521961
}
19531962
};
1963+
if snapshot.permissive {
1964+
if let Some(ref mut proxy) = policy.network.proxy {
1965+
proxy.permissive = true;
1966+
}
1967+
info!(
1968+
"Sandbox running in permissive mode: policy denials will be logged but not enforced"
1969+
);
1970+
}
19541971
return Ok((
19551972
policy,
19561973
opa_engine,
@@ -2761,7 +2778,10 @@ mod tests {
27612778
filesystem: FilesystemPolicy::default(),
27622779
network: NetworkPolicy {
27632780
mode: NetworkMode::Proxy,
2764-
proxy: Some(ProxyPolicy { http_addr }),
2781+
proxy: Some(ProxyPolicy {
2782+
http_addr,
2783+
permissive: false,
2784+
}),
27652785
},
27662786
landlock: LandlockPolicy::default(),
27672787
process: ProcessPolicy::default(),
@@ -3008,6 +3028,7 @@ filesystem_policy:
30083028
settings: std::collections::HashMap::new(),
30093029
global_policy_version: 0,
30103030
provider_env_revision: 0,
3031+
permissive: false,
30113032
}
30123033
}
30133034

‎crates/openshell-server/src/grpc/policy.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,8 @@ pub(super) async fn handle_get_sandbox_config(
12511251
let provider_env_revision =
12521252
compute_provider_env_revision(state.store.as_ref(), &sandbox_provider_names).await?;
12531253

1254+
let permissive = sandbox.spec.as_ref().is_some_and(|s| s.permissive);
1255+
12541256
Ok(Response::new(GetSandboxConfigResponse {
12551257
policy,
12561258
version,
@@ -1260,6 +1262,7 @@ pub(super) async fn handle_get_sandbox_config(
12601262
policy_source: policy_source.into(),
12611263
global_policy_version,
12621264
provider_env_revision,
1265+
permissive,
12631266
}))
12641267
}
12651268

‎crates/openshell-supervisor-network/src/l7/graphql.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,8 @@ network_policies:
804804
activity_tx: None,
805805
dynamic_credentials: None,
806806
token_grant_resolver: None,
807+
permissive: false,
808+
denial_tx: None,
807809
};
808810
let request_info = crate::l7::L7RequestInfo {
809811
action: req.action,

0 commit comments

Comments
 (0)