diff --git a/architecture/security-policy.md b/architecture/security-policy.md index a5245bccc5..99fcbdfd86 100644 --- a/architecture/security-policy.md +++ b/architecture/security-policy.md @@ -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. diff --git a/crates/openshell-core/src/gateway_channels.rs b/crates/openshell-core/src/gateway_channels.rs index 8025d369dc..7023e47594 100644 --- a/crates/openshell-core/src/gateway_channels.rs +++ b/crates/openshell-core/src/gateway_channels.rs @@ -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 diff --git a/crates/openshell-driver-kubernetes/src/driver.rs b/crates/openshell-driver-kubernetes/src/driver.rs index e9f4ac506f..df77f67e5e 100644 --- a/crates/openshell-driver-kubernetes/src/driver.rs +++ b/crates/openshell-driver-kubernetes/src/driver.rs @@ -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 @@ -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 @@ -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 @@ -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) diff --git a/crates/openshell-policy/src/ambiguity.rs b/crates/openshell-policy/src/ambiguity.rs index 0a3fa5c522..d10678bec6 100644 --- a/crates/openshell-policy/src/ambiguity.rs +++ b/crates/openshell-policy/src/ambiguity.rs @@ -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 @@ -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()) + ); + } } diff --git a/crates/openshell-policy/src/lib.rs b/crates/openshell-policy/src/lib.rs index fc10b72e6c..68264dbc8a 100644 --- a/crates/openshell-policy/src/lib.rs +++ b/crates/openshell-policy/src/lib.rs @@ -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()); } @@ -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!( diff --git a/crates/openshell-server/src/grpc/policy.rs b/crates/openshell-server/src/grpc/policy.rs index 3ea1c9f3d7..a26e903dcf 100644 --- a/crates/openshell-server/src/grpc/policy.rs +++ b/crates/openshell-server/src/grpc/policy.rs @@ -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; diff --git a/crates/openshell-supervisor-network/src/opa.rs b/crates/openshell-supervisor-network/src/opa.rs index 88b4a5e4ec..d5faf28510 100644 --- a/crates/openshell-supervisor-network/src/opa.rs +++ b/crates/openshell-supervisor-network/src/opa.rs @@ -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(); diff --git a/crates/openshell-supervisor-network/src/policy_local.rs b/crates/openshell-supervisor-network/src/policy_local.rs index a478bf1cbd..68da665c34 100644 --- a/crates/openshell-supervisor-network/src/policy_local.rs +++ b/crates/openshell-supervisor-network/src/policy_local.rs @@ -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. /// @@ -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", @@ -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] @@ -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")); } diff --git a/crates/openshell-supervisor-network/src/proxy.rs b/crates/openshell-supervisor-network/src/proxy.rs index 77a5bff7f1..f9405a9296 100644 --- a/crates/openshell-supervisor-network/src/proxy.rs +++ b/crates/openshell-supervisor-network/src/proxy.rs @@ -2233,21 +2233,11 @@ async fn handle_tcp_connection( let tls_result = async { let mut tls_client = crate::l7::tls::tls_terminate_client(client, tls, &host_lc).await?; - let endpoint_ca = decision - .endpoint - .policy_configs - .first() - .and_then(|config| match config { - regorus::Value::Object(fields) => { - fields.get(®orus::Value::String("upstream_ca_pem".into())) - } - _ => None, - }) - .and_then(|value| match value { - regorus::Value::String(value) => Some(value.as_ref()), - _ => None, - }) - .unwrap_or(""); + // A broad allow rule may also contribute connection metadata. + // The validated exact-host CA augmentation must win regardless + // of policy iteration order; ambiguity validation ensures any + // other matching nonempty CA has the same value. + let endpoint_ca = supplemental_ca_from_configs(&decision.endpoint.policy_configs); let upstream_config = tls.endpoint_upstream_config(endpoint_ca)?; let mut tls_upstream = crate::l7::tls::tls_connect_upstream(upstream, &host_lc, &upstream_config) @@ -4246,11 +4236,14 @@ fn query_allowed_ips(decision: &EgressDecision) -> Vec { return vec![]; } - decision - .endpoint - .policy_configs - .first() + explicit_allowed_ips_from_configs(&decision.endpoint.policy_configs) +} + +fn explicit_allowed_ips_from_configs(configs: &[regorus::Value]) -> Vec { + configs + .iter() .map(|config| endpoint_config_string_array(config, "allowed_ips")) + .find(|allowed_ips| !allowed_ips.is_empty()) .unwrap_or_default() } @@ -6362,6 +6355,22 @@ async fn refuse_connect_when_tls_unavailable( Ok(true) } +fn supplemental_ca_from_configs(configs: &[regorus::Value]) -> &str { + configs + .iter() + .filter_map(|config| match config { + regorus::Value::Object(fields) => { + fields.get(®orus::Value::String("upstream_ca_pem".into())) + } + _ => None, + }) + .find_map(|value| match value { + regorus::Value::String(value) if !value.is_empty() => Some(value.as_ref()), + _ => None, + }) + .unwrap_or("") +} + /// Check if a miette error represents a benign connection close. /// /// TLS handshake EOF, missing `close_notify`, connection resets, and broken @@ -6396,6 +6405,28 @@ mod tests { use tokio::io::{AsyncRead, AsyncReadExt, AsyncWriteExt}; use tokio::net::{TcpListener, TcpStream}; + #[test] + fn supplemental_ca_wins_over_broad_config_without_ca() { + let broad = regorus::Value::from_json_str(r#"{"allowed_ips":["0.0.0.0/0"]}"#).unwrap(); + let exact = regorus::Value::from_json_str(r#"{"upstream_ca_pem":"reviewed-ca"}"#).unwrap(); + assert_eq!(supplemental_ca_from_configs(&[broad, exact]), "reviewed-ca"); + } + + #[test] + fn ca_only_config_preserves_explicit_baseline_ip_restriction() { + let ca = regorus::Value::from_json_str(r#"{"upstream_ca_pem":"reviewed-ca"}"#).unwrap(); + let baseline = regorus::Value::from_json_str(r#"{"allowed_ips":["11.0.0.0/8"]}"#).unwrap(); + for configs in [ + vec![ca.clone(), baseline.clone()], + vec![baseline.clone(), ca.clone()], + ] { + assert_eq!( + explicit_allowed_ips_from_configs(&configs), + vec!["11.0.0.0/8"] + ); + } + } + struct DenyWebSocketPreflight; #[tonic::async_trait] diff --git a/crates/openshell-supervisor-process/src/skills.rs b/crates/openshell-supervisor-process/src/skills.rs index 13e1da025d..801a154fe8 100644 --- a/crates/openshell-supervisor-process/src/skills.rs +++ b/crates/openshell-supervisor-process/src/skills.rs @@ -15,7 +15,7 @@ const POLICY_ADVISOR_SKILL_CONTENT: &str = include_str!("skills/policy-advisor/S const AGENTS_FILE: &str = "AGENTS.md"; const AGENTS_CONTENT: &str = r"# OpenShell Sandbox Guidance -When you see `policy_denied`, do not treat it as final if the user task still needs that request. Read `/etc/openshell/skills/policy_advisor.md` and use `http://policy.local` to submit the narrowest policy proposal, then wait for approval before retrying. +When you see `policy_denied`, do not treat it as final if the user task still needs that request. Read `/etc/openshell/skills/policy_advisor.md` or `$HOME/.claude/skills/policy-advisor/policy_advisor.md` and use `http://policy.local` to submit the narrowest policy proposal, then wait for approval before retrying. "; #[derive(Debug, Clone, PartialEq, Eq)] @@ -26,10 +26,42 @@ pub struct InstalledSkills { } pub fn install_static_skills() -> Result { - install_static_skills_at(Path::new("/")) + let home = std::env::var_os("HOME").map(PathBuf::from); + match install_static_skills_at_with_home(Path::new("/"), home.as_deref()) { + Ok(installed) => Ok(installed), + Err(system_error) => { + let Some(home) = home.as_deref() else { + return Err(system_error); + }; + install_static_skills_in_home(home).map_err(|home_error| { + miette::miette!( + "system skill install failed ({system_error}); home skill install failed ({home_error})" + ) + }) + } + } +} + +fn install_static_skills_in_home(home: &Path) -> Result { + let skill_dir = home.join(".claude/skills").join(POLICY_ADVISOR_SKILL_DIR); + std::fs::create_dir_all(&skill_dir).into_diagnostic()?; + let policy_advisor = skill_dir.join(POLICY_ADVISOR_FILE); + let policy_advisor_skill = skill_dir.join(POLICY_ADVISOR_SKILL_FILE); + write_readonly(&policy_advisor, POLICY_ADVISOR_CONTENT)?; + write_readonly(&policy_advisor_skill, POLICY_ADVISOR_SKILL_CONTENT)?; + Ok(InstalledSkills { + policy_advisor, + policy_advisor_skill, + agents: install_optional_agents_pointer(home), + }) } +#[cfg(test)] fn install_static_skills_at(root: &Path) -> Result { + install_static_skills_at_with_home(root, None) +} + +fn install_static_skills_at_with_home(root: &Path, home: Option<&Path>) -> Result { let skills_dir = root.join(SKILLS_RELATIVE_DIR); std::fs::create_dir_all(&skills_dir).into_diagnostic()?; @@ -40,6 +72,16 @@ fn install_static_skills_at(root: &Path) -> Result { std::fs::create_dir_all(&policy_advisor_skill_dir).into_diagnostic()?; let policy_advisor_skill = policy_advisor_skill_dir.join(POLICY_ADVISOR_SKILL_FILE); write_readonly(&policy_advisor_skill, POLICY_ADVISOR_SKILL_CONTENT)?; + write_readonly( + &policy_advisor_skill_dir.join(POLICY_ADVISOR_FILE), + POLICY_ADVISOR_CONTENT, + )?; + + // Claude discovers skills below HOME. The canonical /etc copy remains + // available to other agents and to the policy_denied response guidance. + if let Some(home) = home { + install_optional_claude_skill_pointer(home, &policy_advisor_skill_dir)?; + } let agents = install_optional_agents_pointer(root); @@ -50,7 +92,24 @@ fn install_static_skills_at(root: &Path) -> Result { }) } +fn install_optional_claude_skill_pointer(home: &Path, target: &Path) -> Result<()> { + let skills_dir = home.join(".claude/skills"); + std::fs::create_dir_all(&skills_dir).into_diagnostic()?; + let link = skills_dir.join(POLICY_ADVISOR_SKILL_DIR); + if std::fs::symlink_metadata(&link).is_ok() { + return Ok(()); + } + #[cfg(unix)] + std::os::unix::fs::symlink(target, link).into_diagnostic()?; + Ok(()) +} + fn write_readonly(path: &Path, contents: &str) -> Result<()> { + #[cfg(unix)] + if path.exists() { + use std::os::unix::fs::PermissionsExt as _; + std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o644)).into_diagnostic()?; + } std::fs::write(path, contents).into_diagnostic()?; #[cfg(unix)] @@ -128,6 +187,39 @@ mod tests { assert!(agents_content.contains("policy.local")); } + #[cfg(unix)] + #[test] + fn install_static_skills_exposes_claude_skill_in_home() { + let dir = tempfile::tempdir().unwrap(); + let home = dir.path().join("sandbox"); + let installed = install_static_skills_at_with_home(dir.path(), Some(&home)).unwrap(); + let discovered = home.join(".claude/skills/policy-advisor/SKILL.md"); + assert_eq!( + std::fs::read_to_string(discovered).unwrap(), + std::fs::read_to_string(installed.policy_advisor_skill).unwrap() + ); + install_static_skills_at_with_home(dir.path(), Some(&home)).unwrap(); + } + + #[test] + fn install_static_skills_in_home_contains_complete_guidance() { + let dir = tempfile::tempdir().unwrap(); + let installed = install_static_skills_in_home(dir.path()).unwrap(); + assert!(installed.policy_advisor_skill.starts_with(dir.path())); + assert!( + std::fs::read_to_string(&installed.policy_advisor_skill) + .unwrap() + .contains("policy_denied") + ); + assert!( + std::fs::read_to_string(&installed.policy_advisor) + .unwrap() + .contains("/v1/proposals/{chunk_id}/wait") + ); + assert_eq!(installed.agents, Some(dir.path().join("AGENTS.md"))); + install_static_skills_in_home(dir.path()).unwrap(); + } + #[test] fn install_static_skills_at_does_not_overwrite_existing_agents_file() { let dir = tempfile::tempdir().unwrap(); diff --git a/crates/openshell-supervisor-process/src/skills/policy-advisor/SKILL.md b/crates/openshell-supervisor-process/src/skills/policy-advisor/SKILL.md index 81a9f598e1..5e2b9a924f 100644 --- a/crates/openshell-supervisor-process/src/skills/policy-advisor/SKILL.md +++ b/crates/openshell-supervisor-process/src/skills/policy-advisor/SKILL.md @@ -5,6 +5,8 @@ description: Use when an OpenShell sandbox returns policy_denied, mentions polic # OpenShell Policy Advisor -When a request fails with `policy_denied`, do not treat the denial as final if the user task still needs the request. Read `/etc/openshell/skills/policy_advisor.md`, inspect `http://policy.local/v1/policy/current`, submit the narrowest proposal to `http://policy.local/v1/proposals`, wait on `/v1/proposals/{chunk_id}/wait?timeout=300`, and retry only after approval with `policy_reloaded: true`. +When a request fails with `policy_denied`, do not treat the denial as final if the user task still needs the request. Read `policy_advisor.md` beside this skill (also available at `/etc/openshell/skills/policy_advisor.md` on writable system installs), inspect `http://policy.local/v1/policy/current`, submit the narrowest proposal to `http://policy.local/v1/proposals`, wait on `/v1/proposals/{chunk_id}/wait?timeout=300`, and retry only after approval with `policy_reloaded: true`. For a self-signed internal HTTPS service, an endpoint proposal may include `upstream_ca_pem` containing the service owner's PEM CA certificate bundle. Scope it to the exact host and port. This requires developer review even in auto mode. + +If an explicit proxy returns `200 Connection established` and the TLS handshake then resets, the destination may have an untrusted upstream certificate. Ask the user or service owner for the CA PEM; do not disable TLS verification or copy an unverified certificate from the failed connection. Once supplied, propose an exact host:port rule with `upstream_ca_pem`, wait for approval and policy reload, then retry without `--cacert` or `--insecure`. diff --git a/crates/openshell-supervisor-process/src/skills/policy_advisor.md b/crates/openshell-supervisor-process/src/skills/policy_advisor.md index eb3d622563..db2737e6c7 100644 --- a/crates/openshell-supervisor-process/src/skills/policy_advisor.md +++ b/crates/openshell-supervisor-process/src/skills/policy_advisor.md @@ -46,6 +46,12 @@ the service owner; never submit a private key. Keep normal TLS inspection enabled. A supplemental CA always requires developer review, including in auto mode. Retry only after approval and `policy_reloaded: true`. +An explicit proxy may return `200 Connection established` before the TLS +handshake resets. This can mean the supervisor could not verify the upstream +certificate. Ask the user or service owner for the CA PEM before proposing +trust. Do not use `--insecure`, `-k`, or an unverified certificate copied from +the failed connection. After approval and reload, retry without `--cacert`. + ## Workflow 1. Read the denial response body. Use `layer`, `method`, `path`, `host`, diff --git a/docs/sandboxes/policy-advisor.mdx b/docs/sandboxes/policy-advisor.mdx index 24ea08d43d..5911b32fb5 100644 --- a/docs/sandboxes/policy-advisor.mdx +++ b/docs/sandboxes/policy-advisor.mdx @@ -91,8 +91,8 @@ Only `manual` and `auto` are accepted; typos like `autom` are rejected at config When policy advisor is enabled, the sandbox supervisor turns on three agent-facing surfaces: -- It installs `/etc/openshell/skills/policy_advisor.md` inside the sandbox. -- It also installs `/etc/openshell/skills/policy-advisor/SKILL.md` as a short Codex/generic-agent pointer, and writes a root `/AGENTS.md` pointer only when the image does not already provide one. +- It installs the advisor guide and skill under `/etc/openshell/skills` when that directory is writable. For non-root agent containers, it installs both files under `$HOME/.claude/skills/policy-advisor` instead, where Claude can discover the skill. +- On writable system installs it also writes a root `/AGENTS.md` pointer only when the image does not already provide one. - It serves `http://policy.local` from inside the sandbox. - It adds `agent_guidance` and `next_steps` to L7 `policy_denied` response bodies so the agent can find the skill and local API. @@ -144,6 +144,8 @@ For example, a GitHub provider can explicitly declare `api.github.com:443` for r Provenance does not hide a real endpoint conflict. The same two declarations still fail validation if they disagree on connection or request-processing behavior that must have one value, such as TLS mode, `allowed_ips`, an equally specific L7 protocol or parser contract, credential binding, or enforcement mode. Authorization fields such as compatible allow and deny rules can combine. +An exact-host `upstream_ca_pem` rule may augment a broader allow rule that has no supplemental CA, including a public HTTPS allow rule on port 443. If the CA rule omits `allowed_ips`, the existing explicit IP allowlist still applies. The gateway rejects two different CAs or different explicit IP allowlists for one destination, and every supplemental CA requires human review. If a proxy CONNECT succeeds but the TLS handshake resets, ask the service owner for the CA PEM before proposing the exact host and port; do not disable certificate verification. + Exact-host SSRF trust requires an exact endpoint and the matching binary identity to be explicit in the same rule. An advisor-only endpoint or binary does not create that stronger trust. For example: - A provider rule that explicitly declares both `/usr/bin/gh` and `api.github.com:443` already establishes exact-host trust for that pair. A later advisor proposal does not create or broaden that trust.