Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions architecture/security-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ rustls verifier, alongside its normal roots. CONNECT still terminates client
TLS and uses the parsed HTTP relay, so credential rewrite, middleware, and
redaction retain their normal boundary. Policy validation rejects this field
on `tls: skip` and `protocol: tcp` endpoints, which do not use the verifier.
It also requires an exact host. A CA-bearing rule can augment a broader
allow rule with no CA on the same port: the supervisor selects the matching
supplemental CA for the upstream handshake. When the CA rule omits
`allowed_ips`, the supervisor retains the overlapping explicit IP allowlist;
different explicit lists still conflict. Two different CAs matching the
same destination remain ambiguous and reject the policy generation.
Policy advisor may propose the same endpoint field. Its security-notes gate
requires human review even when the prover reports an empty delta; approval
then uses the normal policy merge and hot reload path.
Expand Down
3 changes: 3 additions & 0 deletions crates/openshell-core/src/gateway_channels.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

//! Gateway connections whose supervisor session is currently established.
//!
//! A supervisor multi-connects to a subset of the gateway fleet and holds one
Expand Down
30 changes: 30 additions & 0 deletions crates/openshell-driver-kubernetes/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3267,6 +3267,8 @@ const BINARY_AWARE_SIDECAR_PROXY_UID: u32 = 0;
/// local coordination in sidecar topology.
const SIDECAR_STATE_VOLUME_NAME: &str = "openshell-sidecar-state";
const SIDECAR_STATE_MOUNT_PATH: &str = openshell_core::container_paths::SIDECAR_RUN_ROOT;
const AGENT_SKILLS_VOLUME_NAME: &str = "openshell-agent-skills";
const AGENT_SKILLS_MOUNT_PATH: &str = "/etc/openshell/skills";
const SIDECAR_CONTROL_SOCKET: &str = openshell_core::container_paths::SIDECAR_CONTROL_SOCKET;
// Linux abstract socket names are scoped to the pod's shared network namespace.
// Unlike a filesystem socket in the shared state volume, the workload cannot
Expand Down Expand Up @@ -3861,6 +3863,13 @@ fn apply_supervisor_sidecar_topology(
"name": SIDECAR_TLS_VOLUME_NAME,
"emptyDir": {}
}));
// The process supervisor is non-root in sidecar topology. kubelet's
// fsGroup makes this directory writable without granting it access
// to the rest of the agent container's /etc tree.
volumes.push(serde_json::json!({
"name": AGENT_SKILLS_VOLUME_NAME,
"emptyDir": {}
}));
}

let init_containers = spec
Expand Down Expand Up @@ -3930,6 +3939,10 @@ fn apply_supervisor_sidecar_topology(
volume_mounts.push(supervisor_volume_mount());
volume_mounts.push(sidecar_state_volume_mount());
volume_mounts.push(sidecar_tls_volume_mount());
volume_mounts.push(serde_json::json!({
"name": AGENT_SKILLS_VOLUME_NAME,
"mountPath": AGENT_SKILLS_MOUNT_PATH,
}));
}

let env = container
Expand Down Expand Up @@ -7600,11 +7613,28 @@ mod tests {
.iter()
.any(|volume| volume["name"] == SIDECAR_TLS_VOLUME_NAME)
);
assert!(volumes.iter().any(|volume| {
volume["name"] == AGENT_SKILLS_VOLUME_NAME && volume["emptyDir"].is_object()
}));
assert!(volumes.iter().any(|volume| {
volume["name"] == SUPERVISOR_VOLUME_NAME && volume["image"].is_object()
}));

let containers = pod_template["spec"]["containers"].as_array().unwrap();
let agent = containers
.iter()
.find(|container| container["name"] == "agent")
.unwrap();
assert!(
agent["volumeMounts"]
.as_array()
.unwrap()
.iter()
.any(|mount| {
mount["name"] == AGENT_SKILLS_VOLUME_NAME
&& mount["mountPath"] == AGENT_SKILLS_MOUNT_PATH
})
);
let sidecar = containers
.iter()
.find(|container| container["name"] == SUPERVISOR_NETWORK_SIDECAR_NAME)
Expand Down
72 changes: 65 additions & 7 deletions crates/openshell-policy/src/ambiguity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,33 @@ fn connection_conflicts(left: &NetworkEndpoint, right: &NetworkEndpoint) -> Vec<
&normalized_tls(&left.tls),
&normalized_tls(&right.tls),
);
push_conflict(
&mut conflicts,
"allowed_ips",
&normalized_strings(&left.allowed_ips),
&normalized_strings(&right.allowed_ips),
);
if left.upstream_ca_pem != right.upstream_ca_pem {
// A CA-only augmentation leaves the existing IP restriction in force.
// The supervisor selects the matching nonempty allowed_ips regardless of
// endpoint order (see explicit_allowed_ips_from_configs in proxy.rs).
// Every other allowed_ips difference remains a conflict.
let ca_inherits_left_ips = left.upstream_ca_pem.is_empty()
&& !left.allowed_ips.is_empty()
&& !right.upstream_ca_pem.is_empty()
&& right.allowed_ips.is_empty();
let ca_inherits_right_ips = right.upstream_ca_pem.is_empty()
&& !right.allowed_ips.is_empty()
&& !left.upstream_ca_pem.is_empty()
&& left.allowed_ips.is_empty();
if !ca_inherits_left_ips && !ca_inherits_right_ips {
push_conflict(
&mut conflicts,
"allowed_ips",
&normalized_strings(&left.allowed_ips),
&normalized_strings(&right.allowed_ips),
);
}
// An endpoint with no supplemental CA contributes no trust root. A
// reviewed exact-host rule may therefore augment a broad allow rule,
// while two different roots for the same destination remain ambiguous.
if !left.upstream_ca_pem.is_empty()
&& !right.upstream_ca_pem.is_empty()
&& left.upstream_ca_pem != right.upstream_ca_pem
{
conflicts.push("upstream_ca_pem differs".to_string());
}
conflicts
Expand Down Expand Up @@ -1083,4 +1103,42 @@ mod tests {
assert!(!diagnostic.contains("private-left-pem"));
assert!(!diagnostic.contains("private-right-pem"));
}

#[test]
fn exact_ca_augments_wildcard_allow_on_443() {
let mut broad = endpoint("*.sandbox.svc", 443);
broad.allowed_ips = vec!["11.0.0.0/8".to_string()];
let mut exact = endpoint("selfsigned-443.sandbox.svc", 443);
exact.upstream_ca_pem = "reviewed-ca".to_string();
assert!(find_endpoint_ambiguities(&policy_with(broad.clone(), exact.clone())).is_empty());
assert!(find_endpoint_ambiguities(&policy_with(exact, broad)).is_empty());
}

#[test]
fn ca_augmentation_cannot_replace_explicit_ip_restriction() {
let mut broad = endpoint("*.sandbox.svc", 443);
broad.allowed_ips = vec!["11.0.0.0/8".to_string()];
let mut exact = endpoint("selfsigned-443.sandbox.svc", 443);
exact.upstream_ca_pem = "reviewed-ca".to_string();
exact.allowed_ips = vec!["12.0.0.0/8".to_string()];
assert!(
find_endpoint_ambiguities(&policy_with(broad, exact))[0]
.conflicts
.iter()
.any(|conflict| conflict.starts_with("allowed_ips"))
);
}

#[test]
fn exact_ca_conflicts_with_different_ca_on_same_destination() {
let mut first = endpoint("selfsigned-443.sandbox.svc", 443);
first.upstream_ca_pem = "first-ca".to_string();
let mut second = first.clone();
second.upstream_ca_pem = "second-ca".to_string();
assert!(
find_endpoint_ambiguities(&policy_with(first, second))[0]
.conflicts
.contains(&"upstream_ca_pem differs".to_string())
);
}
}
15 changes: 15 additions & 0 deletions crates/openshell-policy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,9 @@ fn validate_sandbox_policy_with_mcp_presence(
};
let mut l7_errors = validate_l7_endpoint_semantics(&fields);
if !ep.upstream_ca_pem.is_empty() {
if ep.host.is_empty() || ep.host.contains('*') {
l7_errors.push("upstream_ca_pem requires an exact endpoint host".to_string());
}
if ep.tls.eq_ignore_ascii_case("skip") {
l7_errors.push("upstream_ca_pem cannot be used with tls: skip".to_string());
}
Expand Down Expand Up @@ -2041,6 +2044,18 @@ mod upstream_ca_tests {
v.to_string()
.contains("upstream_ca_pem cannot be used with tls: skip")
}));
let mut wildcard = policy.clone();
wildcard.network_policies.get_mut("api").unwrap().endpoints[0].host =
"*.example.test".into();
assert!(
validate_sandbox_policy(&wildcard)
.unwrap_err()
.iter()
.any(|v| {
v.to_string()
.contains("upstream_ca_pem requires an exact endpoint host")
})
);
let mut tcp = policy;
tcp.network_policies.get_mut("api").unwrap().endpoints[0].protocol = "tcp".into();
assert!(
Expand Down
24 changes: 18 additions & 6 deletions crates/openshell-server/src/grpc/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13174,14 +13174,26 @@ mod tests {
let state = test_server_state().await;
let sandbox_id = "sb-agent-ca";
let sandbox_name = "agent-ca";
let mut baseline = ProtoSandboxPolicy::default();
baseline.network_policies.insert(
"public_https".into(),
NetworkPolicyRule {
name: "public_https".into(),
endpoints: vec![NetworkEndpoint {
host: "*.example.test".into(),
port: 443,
allowed_ips: vec!["11.0.0.5/32".into()],
..Default::default()
}],
binaries: vec![NetworkBinary {
path: "/usr/bin/curl".into(),
..Default::default()
}],
},
);
state
.store
.put_message(&test_sandbox(
sandbox_id,
sandbox_name,
ProtoSandboxPolicy::default(),
vec![],
))
.put_message(&test_sandbox(sandbox_id, sandbox_name, baseline, vec![]))
.await
.unwrap();
seed_sandbox_approval_mode(&state, sandbox_name, "auto").await;
Expand Down
52 changes: 52 additions & 0 deletions crates/openshell-supervisor-network/src/opa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4992,6 +4992,58 @@ network_policies:
);
}

#[test]
fn ca_augmentation_keeps_baseline_ip_config_available() {
let mut policy = test_proto();
let ca_pem = crate::l7::tls::SandboxCa::generate()
.unwrap()
.cert_pem()
.to_string();
policy
.network_policies
.get_mut("claude_code")
.unwrap()
.endpoints[0]
.upstream_ca_pem = ca_pem.clone();
policy.network_policies.insert(
"public_https".into(),
NetworkPolicyRule {
name: "public_https".into(),
endpoints: vec![NetworkEndpoint {
host: "api.*.com".into(),
port: 443,
allowed_ips: vec!["11.0.0.5/32".into()],
..Default::default()
}],
binaries: vec![NetworkBinary {
path: "/usr/local/bin/claude".into(),
..Default::default()
}],
},
);
let engine = OpaEngine::from_proto(&policy).unwrap();
let input = NetworkInput {
host: "api.anthropic.com".into(),
port: 443,
binary_path: PathBuf::from("/usr/local/bin/claude"),
binary_sha256: "unused".into(),
ancestors: vec![],
cmdline_paths: vec![],
};
let (configs, _) = engine
.query_endpoint_configs_with_generation(&input)
.unwrap();
assert_eq!(configs.len(), 2);
assert!(configs.iter().any(|config| {
get_str(config, "upstream_ca_pem").as_deref() == Some(ca_pem.as_str())
}));
assert!(
configs
.iter()
.any(|config| { get_str_array(config, "allowed_ips") == vec!["11.0.0.5/32"] })
);
}

#[test]
fn explicit_tcp_authorizes_as_l4_without_endpoint_config() {
let engine = l7_engine();
Expand Down
8 changes: 7 additions & 1 deletion crates/openshell-supervisor-network/src/policy_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub use openshell_core::container_paths::POLICY_ADVISOR_SKILL_PATH as SKILL_PATH

/// Human-readable guidance for agents that are more likely to follow plain
/// instructions than structured next-step JSON alone.
pub const AGENT_GUIDANCE: &str = "OpenShell blocked this request with sandbox policy. If the user's task still needs this network action, do not stop here: read /etc/openshell/skills/policy_advisor.md, submit the narrowest policy proposal to http://policy.local/v1/proposals, wait for approval and `policy_reloaded: true`, then retry the original request.";
pub const AGENT_GUIDANCE: &str = "OpenShell blocked this request with sandbox policy. If the user's task still needs this network action, do not stop here: read /etc/openshell/skills/policy_advisor.md (or $HOME/.claude/skills/policy-advisor/policy_advisor.md in a non-root sandbox), submit the narrowest policy proposal to http://policy.local/v1/proposals, wait for approval and `policy_reloaded: true`, then retry the original request.";

/// Routes served by the in-sandbox policy advisor API.
///
Expand Down Expand Up @@ -259,6 +259,7 @@ pub fn agent_next_steps(agent_proposals_enabled: bool) -> serde_json::Value {
{
"action": "read_skill",
"path": SKILL_PATH,
"alternate_path": "$HOME/.claude/skills/policy-advisor/policy_advisor.md",
},
{
"action": "inspect_policy",
Expand Down Expand Up @@ -1993,6 +1994,10 @@ mod tests {
.collect();
assert!(actions.contains(&"read_skill"));
assert!(actions.contains(&"submit_proposal"));
assert_eq!(
steps[0]["alternate_path"],
"$HOME/.claude/skills/policy-advisor/policy_advisor.md"
);
}

#[test]
Expand All @@ -2005,6 +2010,7 @@ mod tests {
let guidance = agent_guidance_for(true).expect("guidance when proposals are enabled");
assert!(guidance.contains("do not stop"));
assert!(guidance.contains("/etc/openshell/skills/policy_advisor.md"));
assert!(guidance.contains("$HOME/.claude/skills/policy-advisor/policy_advisor.md"));
assert!(guidance.contains("http://policy.local/v1/proposals"));
assert!(guidance.contains("policy_reloaded: true"));
}
Expand Down
Loading
Loading