Skip to content

Commit 2700b1a

Browse files
2000krysztofjohntmyers
authored andcommitted
fix(policy): reject unknown endpoint security modes
Closes NVIDIA#3046 Validate TLS, enforcement, and access values across policy and provider profile ingress, and prevent runtime parsing from falling back to audit for unknown enforcement values. Signed-off-by: Krzysztof Malczuk <[email protected]>
1 parent 473d1e9 commit 2700b1a

8 files changed

Lines changed: 158 additions & 14 deletions

File tree

‎architecture/security-policy.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ connection metadata agrees. When request paths overlap, a path endpoint with a
241241
higher specificity rank deterministically overrides broader request-processing
242242
metadata. Equally specific overlapping endpoints must agree.
243243

244+
Endpoint `tls`, `enforcement`, `access`, and `protocol` strings are validated
245+
before persistence or activation. The supervisor also refuses unknown endpoint
246+
modes defensively; an unrecognized enforcement value never falls back to audit.
247+
244248
Gateway mutation paths validate the complete effective candidate before
245249
persistence when the affected sandbox scope is known. Direct replacements,
246250
incremental merges and approvals, provider attachment, and profile fanout reject

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,30 @@ mod agent_transport_tests {
107107
}
108108
}
109109

110+
/// Validate the security-sensitive endpoint fields whose public representation
111+
/// is currently a string. Empty values preserve the documented defaults.
112+
pub fn validate_endpoint_modes(tls: &str, enforcement: &str, access: &str) -> Vec<String> {
113+
let mut errors = Vec::new();
114+
115+
if !matches!(tls, "" | "skip" | "terminate" | "passthrough") {
116+
errors.push(format!(
117+
"unknown tls value '{tls}' (expected skip, terminate, or passthrough)"
118+
));
119+
}
120+
if !matches!(enforcement, "" | "enforce" | "audit") {
121+
errors.push(format!(
122+
"unknown enforcement value '{enforcement}' (expected enforce or audit)"
123+
));
124+
}
125+
if !matches!(access, "" | "read-only" | "read-write" | "full") {
126+
errors.push(format!(
127+
"unknown access value '{access}' (expected read-only, read-write, or full)"
128+
));
129+
}
130+
131+
errors
132+
}
133+
110134
/// Fields extracted from an endpoint definition needed for L7 semantic
111135
/// validation. Both profile lint and the runtime validator construct this
112136
/// from their own data representation.
@@ -250,6 +274,27 @@ mod tests {
250274
assert!(errors.is_empty(), "expected no errors, got: {errors:?}");
251275
}
252276

277+
#[test]
278+
fn endpoint_modes_reject_unknown_values() {
279+
let errors = validate_endpoint_modes("skp", "enforc", "read-wirte");
280+
281+
assert_eq!(errors.len(), 3);
282+
assert!(errors[0].contains("unknown tls value 'skp'"));
283+
assert!(errors[1].contains("unknown enforcement value 'enforc'"));
284+
assert!(errors[2].contains("unknown access value 'read-wirte'"));
285+
}
286+
287+
#[test]
288+
fn endpoint_modes_accept_documented_values_and_defaults() {
289+
for tls in ["", "skip", "terminate", "passthrough"] {
290+
for enforcement in ["", "enforce", "audit"] {
291+
for access in ["", "read-only", "read-write", "full"] {
292+
assert!(validate_endpoint_modes(tls, enforcement, access).is_empty());
293+
}
294+
}
295+
}
296+
}
297+
253298
#[test]
254299
fn rejects_unknown_protocol() {
255300
let ep = L7EndpointFields {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub use compose::{
3737
is_provider_rule_name, provider_rule_name, strip_provider_rule_names,
3838
};
3939
pub use l7_validate::{
40-
L7EndpointFields, L7Protocol, agent_authored_transport_rejection,
40+
L7EndpointFields, L7Protocol, agent_authored_transport_rejection, validate_endpoint_modes,
4141
validate_explicit_tcp_additional_fields, validate_l7_endpoint_semantics,
4242
};
4343
pub use merge::{
@@ -1524,6 +1524,11 @@ fn validate_sandbox_policy_with_mcp_presence(
15241524
.unwrap_or(false),
15251525
};
15261526
let mut l7_errors = validate_l7_endpoint_semantics(&fields);
1527+
l7_errors.extend(validate_endpoint_modes(
1528+
&ep.tls,
1529+
&ep.enforcement,
1530+
&ep.access,
1531+
));
15271532
let mut explicit_tcp_fields = Vec::new();
15281533
if !ep.enforcement.is_empty() {
15291534
explicit_tcp_fields.push("enforcement");

‎crates/openshell-providers/src/profiles.rs‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use openshell_core::proto::{
1414
};
1515
use openshell_core::secrets::uses_reserved_revision_namespace;
1616
use openshell_policy::{
17-
L7EndpointFields, L7Protocol, validate_explicit_tcp_additional_fields,
17+
L7EndpointFields, L7Protocol, validate_endpoint_modes, validate_explicit_tcp_additional_fields,
1818
validate_l7_endpoint_semantics,
1919
};
2020
use serde::{Deserialize, Deserializer, Serialize, Serializer, de};
@@ -2550,6 +2550,16 @@ pub fn validate_profile_set(
25502550
msg,
25512551
));
25522552
}
2553+
for msg in
2554+
validate_endpoint_modes(&endpoint.tls, &endpoint.enforcement, &endpoint.access)
2555+
{
2556+
diagnostics.push(ProfileValidationDiagnostic::error(
2557+
source,
2558+
profile_id,
2559+
format!("endpoints[{index}]"),
2560+
msg,
2561+
));
2562+
}
25532563
for msg in validate_explicit_tcp_additional_fields(
25542564
&endpoint.protocol,
25552565
&additional_l7_profile_fields(endpoint),
@@ -6295,6 +6305,35 @@ credentials:
62956305

62966306
// -- L7 endpoint semantic validation (shared with runtime) ----------------
62976307

6308+
#[test]
6309+
fn validate_rejects_unknown_security_sensitive_endpoint_values() {
6310+
let profile = parse_profile_yaml(
6311+
r"
6312+
id: invalid-modes
6313+
display_name: Invalid modes
6314+
endpoints:
6315+
- host: api.example.com
6316+
port: 443
6317+
protocol: rest
6318+
tls: skp
6319+
enforcement: enforc
6320+
access: read-wirte
6321+
",
6322+
)
6323+
.expect("string values should parse before semantic validation");
6324+
6325+
let diagnostics = validate_profile_set(&[("profile.yaml".to_string(), profile)]);
6326+
let message = diagnostics
6327+
.iter()
6328+
.map(|diagnostic| diagnostic.message.as_str())
6329+
.collect::<Vec<_>>()
6330+
.join("\n");
6331+
6332+
assert!(message.contains("unknown tls value 'skp'"));
6333+
assert!(message.contains("unknown enforcement value 'enforc'"));
6334+
assert!(message.contains("unknown access value 'read-wirte'"));
6335+
}
6336+
62986337
#[test]
62996338
fn validate_rejects_protocol_without_rules_or_access() {
63006339
let profile = parse_profile_yaml(

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,6 +2152,35 @@ mod tests {
21522152
assert!(err.message().contains("TLD wildcard"));
21532153
}
21542154

2155+
#[test]
2156+
fn validate_policy_safety_reports_unknown_enforcement() {
2157+
use openshell_core::proto::{NetworkEndpoint, NetworkPolicyRule};
2158+
2159+
let mut policy = openshell_policy::restrictive_default_policy();
2160+
policy.network_policies.insert(
2161+
"github_api".into(),
2162+
NetworkPolicyRule {
2163+
name: "github-api-readonly".into(),
2164+
endpoints: vec![NetworkEndpoint {
2165+
host: "api.github.com".into(),
2166+
port: 443,
2167+
protocol: "rest".into(),
2168+
enforcement: "enforc".into(),
2169+
access: "read-only".into(),
2170+
..Default::default()
2171+
}],
2172+
..Default::default()
2173+
},
2174+
);
2175+
2176+
let err = validate_policy_safety(&policy).unwrap_err();
2177+
2178+
assert_eq!(err.code(), Code::InvalidArgument);
2179+
assert!(err.message().contains("endpoint 0"));
2180+
assert!(err.message().contains("unknown enforcement value 'enforc'"));
2181+
assert!(err.message().contains("expected enforce or audit"));
2182+
}
2183+
21552184
#[test]
21562185
fn validate_policy_safety_rejects_invalid_middleware_before_acceptance() {
21572186
use openshell_core::proto::{MiddlewareEndpointSelector, NetworkMiddlewareConfig};

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

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ use openshell_core::endpoint_status::{
2828
use openshell_core::mcp::McpProtocolVersion;
2929
pub use openshell_policy::L7Protocol;
3030
use openshell_policy::{
31-
L7EndpointFields, validate_explicit_tcp_additional_fields, validate_l7_endpoint_semantics,
31+
L7EndpointFields, validate_endpoint_modes, validate_explicit_tcp_additional_fields,
32+
validate_l7_endpoint_semantics,
3233
};
3334
use std::sync::{Arc, Mutex};
3435

@@ -297,9 +298,16 @@ pub fn parse_l7_config(val: &regorus::Value) -> Option<L7EndpointConfig> {
297298
let protocol_val = get_object_str(val, "protocol")?;
298299
let protocol = L7Protocol::parse(&protocol_val)?;
299300

300-
let tls = match get_object_str(val, "tls").as_deref() {
301-
Some("skip") => TlsMode::Skip,
302-
Some("terminate") => {
301+
let tls_value = get_object_str(val, "tls").unwrap_or_default();
302+
let enforcement_value = get_object_str(val, "enforcement").unwrap_or_default();
303+
let access_value = get_object_str(val, "access").unwrap_or_default();
304+
if !validate_endpoint_modes(&tls_value, &enforcement_value, &access_value).is_empty() {
305+
return None;
306+
}
307+
308+
let tls = match tls_value.as_str() {
309+
"skip" => TlsMode::Skip,
310+
"terminate" => {
303311
let event = openshell_ocsf::NetworkActivityBuilder::new(openshell_ocsf::ctx::ctx())
304312
.activity(openshell_ocsf::ActivityId::Other)
305313
.severity(openshell_ocsf::SeverityId::Medium)
@@ -311,7 +319,7 @@ pub fn parse_l7_config(val: &regorus::Value) -> Option<L7EndpointConfig> {
311319
openshell_ocsf::ocsf_emit!(event);
312320
TlsMode::Auto
313321
}
314-
Some("passthrough") => {
322+
"passthrough" => {
315323
let event = openshell_ocsf::NetworkActivityBuilder::new(openshell_ocsf::ctx::ctx())
316324
.activity(openshell_ocsf::ActivityId::Other)
317325
.severity(openshell_ocsf::SeverityId::Medium)
@@ -323,12 +331,14 @@ pub fn parse_l7_config(val: &regorus::Value) -> Option<L7EndpointConfig> {
323331
openshell_ocsf::ocsf_emit!(event);
324332
TlsMode::Auto
325333
}
326-
_ => TlsMode::Auto,
334+
"" => TlsMode::Auto,
335+
_ => unreachable!("endpoint modes were validated above"),
327336
};
328337

329-
let enforcement = match get_object_str(val, "enforcement").as_deref() {
330-
Some("enforce") => EnforcementMode::Enforce,
331-
_ => EnforcementMode::Audit,
338+
let enforcement = match enforcement_value.as_str() {
339+
"enforce" => EnforcementMode::Enforce,
340+
"" | "audit" => EnforcementMode::Audit,
341+
_ => unreachable!("endpoint modes were validated above"),
332342
};
333343

334344
let allow_encoded_slash = get_object_bool(val, "allow_encoded_slash").unwrap_or(false);
@@ -2230,6 +2240,16 @@ mod tests {
22302240
assert!(EndpointObserver::begin(Some(&sender), &config).is_none());
22312241
}
22322242

2243+
#[test]
2244+
fn parse_l7_config_rejects_unknown_enforcement() {
2245+
let val = regorus::Value::from_json_str(
2246+
r#"{"protocol": "rest", "enforcement": "enforc", "access": "read-only", "host": "api.example.com", "port": 443}"#,
2247+
)
2248+
.unwrap();
2249+
2250+
assert!(parse_l7_config(&val).is_none());
2251+
}
2252+
22332253
#[test]
22342254
fn parse_credential_signing_sigv4() {
22352255
let val = regorus::Value::from_json_str(

‎docs/providers/profiles.mdx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,8 @@ environment value under the actual environment variable key.
446446

447447
`endpoints` contains the same endpoint object shape as sandbox network policy. A profile can use access presets, protocol-specific allow rules, deny rules, WebSocket credential rewriting, request body credential rewriting, GraphQL fields, and SSRF IP allowlists. Because profile credentials are not mapped to individual endpoints, OpenShell conservatively treats every endpoint in a profile that declares credentials as credentialed. Such endpoints require L7 inspection and cannot use `tls: skip` unless the profile explicitly sets `allow_uninspected_credentials: true`.
448448

449+
Profile validation rejects unknown `tls`, `enforcement`, and `access` values before the profile can contribute policy to a sandbox.
450+
449451
`binaries` contains the executable paths allowed to reach the profile endpoints when the profile contributes policy to a sandbox. Write each binary as a scalar path. OpenShell also accepts the transitional object form `- path: /usr/bin/example` and exports it as a scalar. The removed `harness` property is rejected; delete it from profiles created before 0.1.0.
450452

451453
`inference_capable` is informational metadata that marks profiles intended for

‎docs/reference/policy-schema.mdx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ Each endpoint defines a reachable destination and optional inspection rules.
212212
| `port` | integer | Yes | TCP port number. |
213213
| `path` | string | No | Optional HTTP path glob used to select between L7 endpoints that share the same host and port. Empty means all paths. Use this when REST and GraphQL live under the same host, such as `/repos/**` and `/graphql`. |
214214
| `protocol` | string | No | Set to `tcp` with a valid DNS hostname to allow native TCP clients through policy DNS and transparent capture without payload inspection. Omit the field for L4 passthrough through an explicit proxy, including legacy hostless `allowed_ips` endpoints. Set to `rest` for HTTP method/path inspection, `websocket` for RFC 6455 upgrade and client text-message inspection, `graphql` for GraphQL-over-HTTP operation inspection, `mcp` for MCP Streamable HTTP request inspection, or `json-rpc` for generic JSON-RPC-over-HTTP method inspection. WebSocket endpoints can also use GraphQL operation rules for GraphQL-over-WebSocket traffic. Provider-credentialed endpoints require an inspected protocol unless `allow_uninspected_credentials` is explicitly set. |
215-
| `tls` | string | No | TLS handling mode. The proxy auto-detects TLS by peeking the first bytes of each connection and terminates it for inspected HTTPS traffic, so this field is optional in most cases. Set to `skip` to disable auto-detection for edge cases such as client-certificate mTLS or non-standard protocols. Provider-credentialed endpoints reject `tls: skip` unless `allow_uninspected_credentials` is explicitly set. The values `terminate` and `passthrough` are deprecated and log a warning; they are still accepted for backward compatibility but have no effect on behavior. |
216-
| `enforcement` | string | No | `enforce` actively blocks disallowed requests. `audit` logs violations but allows traffic through. |
217-
| `access` | string | No | Access preset. One of `read-only`, `read-write`, or `full`. Mutually exclusive with `rules`. Not valid on `protocol: mcp` or `protocol: json-rpc`; MCP uses explicit rules unless `mcp.allow_all_known_mcp_methods: true` enables the endpoint method profile, and JSON-RPC always uses explicit rules. |
215+
| `tls` | string | No | TLS handling mode. The proxy auto-detects TLS by peeking the first bytes of each connection and terminates it for inspected HTTPS traffic, so this field is optional in most cases. Set to `skip` to disable auto-detection for edge cases such as client-certificate mTLS or non-standard protocols. Provider-credentialed endpoints reject `tls: skip` unless `allow_uninspected_credentials` is explicitly set. The values `terminate` and `passthrough` are deprecated and log a warning; they are still accepted for backward compatibility but have no effect on behavior. Other values are rejected before activation. |
216+
| `enforcement` | string | No | `enforce` actively blocks disallowed requests. `audit` logs violations but allows traffic through. Other values are rejected before activation rather than interpreted as audit mode. |
217+
| `access` | string | No | Access preset. One of `read-only`, `read-write`, or `full`; other values are rejected before activation. Mutually exclusive with `rules`. Not valid on `protocol: mcp` or `protocol: json-rpc`; MCP uses explicit rules unless `mcp.allow_all_known_mcp_methods: true` enables the endpoint method profile, and JSON-RPC always uses explicit rules. |
218218
| `rules` | list of allow rule objects | No | Fine-grained protocol-specific allow rules. Mutually exclusive with `access`. |
219219
| `deny_rules` | list of deny rule objects | No | L7 deny rules that block specific requests even when allowed by `access` or `rules`. Deny rules take precedence over allow rules. |
220220
| `allowed_ips` | list of string | No | CIDR or IP allowlist for SSRF override. Exact user-declared hostname endpoints may resolve to RFC 1918 private addresses without this field, but wildcard, hostless, and policy-advisor-proposed endpoints still require `allowed_ips` for private resolved IPs. A hostless allowlist is valid only for the legacy proxy path and cannot be combined with `protocol: tcp`. Entries overlapping loopback (`127.0.0.0/8`), link-local (`169.254.0.0/16`), or unspecified (`0.0.0.0`) are rejected at load time. |

0 commit comments

Comments
 (0)