Skip to content

Commit 69ed2d0

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 27fd31c commit 69ed2d0

18 files changed

Lines changed: 1093 additions & 251 deletions

File tree

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

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

1280+
/// Run in permissive mode: log but do not enforce network policy denials.
1281+
/// Connections that would be blocked are allowed through and logged as
1282+
/// draft policy proposals. Filesystem (Landlock) restrictions are skipped.
1283+
/// Seccomp and process-identity controls remain enforced.
1284+
/// Use with --policy to provide protocol hints for richer L7 learning.
1285+
#[arg(long)]
1286+
permissive: bool,
1287+
12801288
/// Approval mode for agent-authored policy proposals.
12811289
///
12821290
/// `manual` (default): every proposal lands in the draft inbox for
@@ -2565,6 +2573,7 @@ async fn main() -> Result<()> {
25652573
no_auto_providers,
25662574
labels,
25672575
envs,
2576+
permissive,
25682577
approval_mode,
25692578
command,
25702579
} => {
@@ -2651,6 +2660,7 @@ async fn main() -> Result<()> {
26512660
&labels_map,
26522661
&env_map,
26532662
&approval_mode,
2663+
permissive,
26542664
&tls,
26552665
))
26562666
.await?;

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,7 @@ pub async fn sandbox_create(
17391739
labels: &HashMap<String, String>,
17401740
environment: &HashMap<String, String>,
17411741
approval_mode: &str,
1742+
permissive: bool,
17421743
tls: &TlsOptions,
17431744
) -> Result<()> {
17441745
if editor.is_some() && !command.is_empty() {
@@ -1798,6 +1799,27 @@ pub async fn sandbox_create(
17981799
.await?;
17991800

18001801
let policy = load_sandbox_policy(policy)?;
1802+
1803+
if permissive {
1804+
let has_protocol_endpoints = policy.as_ref().is_some_and(|p| {
1805+
p.network_policies
1806+
.values()
1807+
.any(|rule| rule.endpoints.iter().any(|ep| !ep.protocol.is_empty()))
1808+
});
1809+
if !has_protocol_endpoints {
1810+
eprintln!(
1811+
"\n{} Permissive mode: no HTTP endpoints declared in policy.\n \
1812+
L7 audit will be limited to host:port only.\n \
1813+
To capture HTTP method/path detail, add endpoint protocol hints:\n\n \
1814+
endpoints:\n \
1815+
- host: api.example.com\n \
1816+
port: 443\n \
1817+
protocol: rest\n",
1818+
"⚠".yellow(),
1819+
);
1820+
}
1821+
}
1822+
18011823
let resource_limits = build_sandbox_resource_limits(cpu, memory)?;
18021824
let driver_config = driver_config_json
18031825
.map(parse_driver_config_json)
@@ -1822,6 +1844,7 @@ pub async fn sandbox_create(
18221844
policy,
18231845
providers: configured_providers,
18241846
template,
1847+
permissive,
18251848
..SandboxSpec::default()
18261849
}),
18271850
name: name.unwrap_or_default().to_string(),

‎crates/openshell-cli/tests/sandbox_create_lifecycle_integration.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ async fn sandbox_create_keeps_command_sessions_by_default() {
797797
&HashMap::new(),
798798
&HashMap::new(),
799799
"manual",
800+
false,
800801
&tls,
801802
)
802803
.await
@@ -841,6 +842,7 @@ async fn sandbox_create_sends_cpu_and_memory_limits_only() {
841842
&HashMap::new(),
842843
&HashMap::new(),
843844
"manual",
845+
false,
844846
&tls,
845847
)
846848
.await
@@ -919,6 +921,7 @@ async fn sandbox_create_sends_driver_config_json() {
919921
&HashMap::new(),
920922
&HashMap::new(),
921923
"manual",
924+
false,
922925
&tls,
923926
)
924927
.await
@@ -994,6 +997,7 @@ async fn sandbox_create_does_not_infer_command_providers_when_v2_enabled() {
994997
&HashMap::new(),
995998
&HashMap::new(),
996999
"manual",
1000+
false,
9971001
&tls,
9981002
)
9991003
.await
@@ -1053,6 +1057,7 @@ async fn sandbox_create_returns_vm_error_without_waiting_for_timeout() {
10531057
&HashMap::new(),
10541058
&HashMap::new(),
10551059
"manual",
1060+
false,
10561061
&tls,
10571062
)
10581063
.await
@@ -1108,6 +1113,7 @@ async fn sandbox_create_keeps_waiting_while_vm_progress_arrives() {
11081113
&HashMap::new(),
11091114
&HashMap::new(),
11101115
"manual",
1116+
false,
11111117
&tls,
11121118
)
11131119
.await
@@ -1155,6 +1161,7 @@ async fn sandbox_create_times_out_when_only_logs_arrive() {
11551161
&HashMap::new(),
11561162
&HashMap::new(),
11571163
"manual",
1164+
false,
11581165
&tls,
11591166
)
11601167
.await
@@ -1198,6 +1205,7 @@ async fn sandbox_create_deletes_command_sessions_with_no_keep() {
11981205
&HashMap::new(),
11991206
&HashMap::new(),
12001207
"manual",
1208+
false,
12011209
&tls,
12021210
)
12031211
.await
@@ -1245,6 +1253,7 @@ async fn sandbox_create_deletes_shell_sessions_with_no_keep() {
12451253
&HashMap::new(),
12461254
&HashMap::new(),
12471255
"manual",
1256+
false,
12481257
&tls,
12491258
)
12501259
.await
@@ -1292,6 +1301,7 @@ async fn sandbox_create_keeps_sandbox_with_hidden_keep_flag() {
12921301
&HashMap::new(),
12931302
&HashMap::new(),
12941303
"manual",
1304+
false,
12951305
&tls,
12961306
)
12971307
.await
@@ -1339,6 +1349,7 @@ async fn sandbox_create_keeps_sandbox_with_forwarding() {
13391349
&HashMap::new(),
13401350
&HashMap::new(),
13411351
"manual",
1352+
false,
13421353
&tls,
13431354
)
13441355
.await
@@ -1382,6 +1393,7 @@ async fn sandbox_create_sends_environment_variables() {
13821393
&HashMap::new(),
13831394
&env_map,
13841395
"manual",
1396+
false,
13851397
&tls,
13861398
)
13871399
.await

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

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -546,21 +546,6 @@ async fn connect_inference(endpoint: &str) -> Result<InferenceClient<AuthedChann
546546
Ok(InferenceClient::new(channel))
547547
}
548548

549-
/// Fetch sandbox policy from `OpenShell` server via gRPC.
550-
///
551-
/// Returns `Ok(Some(policy))` when the server has a policy configured,
552-
/// or `Ok(None)` when the sandbox was created without a policy (the sandbox
553-
/// should discover one from disk or use the restrictive default).
554-
pub async fn fetch_policy(endpoint: &str, sandbox_id: &str) -> Result<Option<ProtoSandboxPolicy>> {
555-
debug!(endpoint = %endpoint, sandbox_id = %sandbox_id, "Connecting to OpenShell server");
556-
557-
let mut client = connect(endpoint).await?;
558-
559-
debug!("Connected, fetching sandbox policy");
560-
561-
fetch_policy_with_client(&mut client, sandbox_id).await
562-
}
563-
564549
/// Fetch sandbox policy using an existing client connection.
565550
async fn fetch_policy_with_client(
566551
client: &mut OpenShellClient<AuthedChannel>,
@@ -585,6 +570,33 @@ async fn fetch_policy_with_client(
585570
})?))
586571
}
587572

573+
/// Fetch sandbox policy and permissive flag from the config response.
574+
pub async fn fetch_policy_and_permissive(
575+
endpoint: &str,
576+
sandbox_id: &str,
577+
) -> Result<(Option<ProtoSandboxPolicy>, bool)> {
578+
let mut client = connect(endpoint).await?;
579+
580+
let response = client
581+
.get_sandbox_config(GetSandboxConfigRequest {
582+
sandbox_id: sandbox_id.to_string(),
583+
})
584+
.await
585+
.into_diagnostic()?;
586+
587+
let inner = response.into_inner();
588+
let permissive = inner.permissive;
589+
590+
if inner.version == 0 && inner.policy.is_none() {
591+
return Ok((None, permissive));
592+
}
593+
594+
let policy = inner
595+
.policy
596+
.ok_or_else(|| miette::miette!("Server returned non-zero version but empty policy"))?;
597+
Ok((Some(policy), permissive))
598+
}
599+
588600
/// Sync a locally-discovered policy using an existing client connection.
589601
async fn sync_policy_with_client(
590602
client: &mut OpenShellClient<AuthedChannel>,

‎crates/openshell-sandbox/src/l7/graphql.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,8 @@ network_policies:
802802
cmdline_paths: Vec::new(),
803803
secret_resolver: None,
804804
activity_tx: None,
805+
permissive: false,
806+
denial_tx: None,
805807
};
806808
let request_info = crate::l7::L7RequestInfo {
807809
action: req.action,

0 commit comments

Comments
 (0)