Repository navigation
feat(policy): lint authored policy files offline - #5358
johntmyers merged 4 commits into
Conversation
Compatibility review (advisory)New or updated breaking changes; see the full report for all findings. 1. api-behavior — No explicit risk acceptance foundCreateSandbox size rejections after MCP defaulting previously included BadRequest(spec.policy) and ErrorInfo(INVALID_ARGUMENT), but now return bare INVALID_ARGUMENT.
Review details
Advisory review; publication gates are unchanged. |
74dcaf5 to
b49c040
Compare
shvma
left a comment
There was a problem hiding this comment.
I ran 11 authored policies through openshell policy lint and through CreateSandbox on the in-process gateway from openshell_server::test_support. For the four built-in middleware cases I compared against MiddlewareRegistry::validate_policy_configs with the built-in services instead (see the note at the end). Lint agreed everywhere except the external middleware case, which lint skips by design, as the docs say. Two small things, both with patches below.
-
The pair order in endpoint ambiguity messages isn't stable. With two conflicting rules
aandb,openshell policy lintprinted'a' … and 'b'in 10 of 20 runs and'b' … and 'a'in the other 10.find_endpoint_ambiguitieswalks thenetwork_policiesmap without sorting. The code predates this PR, and the gateway message has the same problem. Lint makes it more visible because its output goes to CI logs and scripts. The crate already states the rule in lib.rs: "Sort rule keys so callers receive stable validation errors for equivalent policy inputs." Patch 1 sorts the keys the same way and adds a unit test that fails without the change (one run got[("mid", "alpha"), ("alpha", "zeta")]) and passes with it.cargo test -p openshell-policy --libis 300/300 and clippy with-D warningsis clean. Fine as a follow-up if you'd rather keep this PR to lint. -
authored_policy_lint_matches_gateway_file_validationcovers identity, reserved keys and credential bindings.policy_lint_integration.rscovers ambiguity on the lint side only, and I didn't find a test thatCreateSandboxrejects the same authored file. The gateway rejects an ambiguous file onCreateSandboxeven without providers, withFailedPrecondition(policy.rs), so it doesn't fit the existing loop that expectsInvalidArgument. Patch 2 adds a separate test on the same harness. It uses one rule with two endpoints, so it doesn't depend on the ordering in point 1 and works with or without Patch 1. It passes, and clippy is clean.
Not for this PR, just context for why the parity test can't cover built-in middleware: gateway_service_with_driver doesn't register the built-ins that the real gateway does (openshell-server lib.rs), so openshell/regex is always "not registered" there.
Patch 1: sort ambiguity pairs by rule key
diff --git a/crates/openshell-policy/src/ambiguity.rs b/crates/openshell-policy/src/ambiguity.rs
index efb846a..0eb9739 100644
--- a/crates/openshell-policy/src/ambiguity.rs
+++ b/crates/openshell-policy/src/ambiguity.rs
@@ -58,9 +58,12 @@ struct EndpointRef<'a> {
/// request-specific metadata) path selectors can match the same request.
#[must_use]
pub fn find_endpoint_ambiguities(policy: &SandboxPolicy) -> Vec<EndpointAmbiguity> {
- let endpoints = policy
- .network_policies
- .iter()
+ // Protobuf maps do not preserve iteration order. Sort rule keys so callers
+ // receive the same ambiguity pairs, in the same order, for equivalent input.
+ let mut network_policies: Vec<_> = policy.network_policies.iter().collect();
+ network_policies.sort_by_key(|(key, _)| *key);
+ let endpoints = network_policies
+ .into_iter()
.flat_map(|(key, rule)| {
let policy_name = if rule.name.is_empty() {
key.as_str()
@@ -775,6 +778,43 @@ mod tests {
assert!(find_endpoint_ambiguities(&policy_with(left, right)).is_empty());
}
+ #[test]
+ fn ambiguities_are_reported_in_rule_key_order() {
+ let pairs = |policy: &SandboxPolicy| {
+ find_endpoint_ambiguities(policy)
+ .into_iter()
+ .map(|ambiguity| (ambiguity.left_policy, ambiguity.right_policy))
+ .collect::<Vec<_>>()
+ };
+ let build = || {
+ let mut policy = SandboxPolicy::default();
+ for (key, tls) in [
+ ("zeta", NetworkTlsMode::Skip),
+ ("alpha", NetworkTlsMode::Unspecified),
+ ("mid", NetworkTlsMode::Skip),
+ ] {
+ let mut endpoint = endpoint("api.example.com", 443);
+ endpoint.tls = tls as i32;
+ policy.network_policies.insert(
+ key.to_string(),
+ NetworkPolicyRule {
+ endpoints: vec![endpoint],
+ ..Default::default()
+ },
+ );
+ }
+ policy
+ };
+ let expected = vec![
+ ("alpha".to_string(), "mid".to_string()),
+ ("alpha".to_string(), "zeta".to_string()),
+ ];
+ // Each map gets its own hash seed, so repeat to catch unordered iteration.
+ for _ in 0..32 {
+ assert_eq!(pairs(&build()), expected);
+ }
+ }
+
#[test]
fn compatible_request_rules_may_overlap() {
let mut left = endpoint("api.example.com", 443);Patch 2: parity test for endpoint ambiguity
diff --git a/crates/openshell-cli/tests/policy_only_process_identity_integration.rs b/crates/openshell-cli/tests/policy_only_process_identity_integration.rs
index 559534e..90b77ca 100644
--- a/crates/openshell-cli/tests/policy_only_process_identity_integration.rs
+++ b/crates/openshell-cli/tests/policy_only_process_identity_integration.rs
@@ -183,3 +183,35 @@ async fn authored_policy_lint_matches_gateway_file_validation() {
}
}
}
+
+#[tokio::test]
+async fn authored_policy_lint_matches_gateway_endpoint_ambiguity() {
+ let server = run_server().await;
+ let policy = openshell_policy::parse_sandbox_policy(
+ "version: 1\nnetwork_policies:\n conflict:\n endpoints:\n - {host: example.com, port: 443}\n - {host: example.com, port: 443, tls: skip}\n",
+ )
+ .unwrap();
+ let ambiguities = openshell_policy::find_endpoint_ambiguities(&policy);
+ assert_eq!(ambiguities.len(), 1, "{ambiguities:?}");
+ let mut client = grpc_client(&server.endpoint, &server.tls).await.unwrap();
+ let error = client
+ .create_sandbox(CreateSandboxRequest {
+ name: "ambiguity".to_string(),
+ spec: Some(SandboxSpec {
+ policy: Some(policy),
+ ..Default::default()
+ }),
+ workspace_scope: Some(openshell_core::proto::workspace_selector(
+ "default".to_string(),
+ )),
+ ..Default::default()
+ })
+ .await
+ .expect_err("an ambiguous authored file must be rejected by the gateway too");
+ assert_eq!(error.code(), tonic::Code::FailedPrecondition);
+ assert!(
+ error.message().contains(&ambiguities[0].to_string()),
+ "{error} did not report {}",
+ ambiguities[0]
+ );
+}
johntmyers
left a comment
There was a problem hiding this comment.
gator-agent
PR Review Status
The offline lint command fits validated issue #4035, and the command guide and related skills are updated. One blocking Warning remains: the new lint path expands ambiguity diagnostics before rejecting oversized policies, which can exhaust the lint process's memory.
Action required: @shiju-nv, reject oversized encoded policies before collecting ambiguity diagnostics, retaining the canonical-size recheck and aggregation for admitted files.
Blocking findings:
GATOR-41daeae1-01: enforce the size admission bound before expanding endpoint pairs; see the inline finding.
Carried findings: None.
Non-blocking suggestions: None.
Gator metadata
- Validation: implements validated offline policy-lint issue #4035; author has repository write access.
- Docs: Fern policy command guide and related public skills updated.
- Checks: current-head Branch Checks, Helm Lint, Trivy Changes and DCO passed; separate Review Readiness failures remain visible.
- E2E: standard runtime coverage requested with test:e2e; dispatch and results are tracked by supervised reconciliation.
- Head SHA:
41daeae1f755b5f7e0ef199e2097c9ee70c1a3f9 - Base SHA:
af8182f7b63da6dd8bbea8b3c313227764ee0dea - Merge base SHA:
53bf840cd22c47c7002d47af7e9f7292b19174a4 - Patch ID:
4d2192425fe91f234f37d0f7f12661a584a2f1eb - Gator payload:
13 - Review mode:
initial - Previous reviewed SHA: none
- Review budget exhausted: no
- Maintainer decision required: no
- Next state:
gator:in-review
Validate authored files before gateway selection or authentication. Share creation safety checks and report file-only violations together while deferring checks that require live gateway state. Closes ai-openshell#4035 Signed-off-by: Shiju <[email protected]>
Signed-off-by: Shiju <[email protected]>
Signed-off-by: Shiju <[email protected]>
41daeae to
6791e9f
Compare
|
/ok to test 6791e9f |
PR Review Status@shiju-nv, the latest fix checks encoded policy size before expanding ambiguity or middleware diagnostics. I checked that the canonical-size recheck and error aggregation remain for admitted files, and that the regression covers oversized input with conflicting endpoints. Blocking findings: None. Carried findings: None; The test mirror now matches the current head after Gator metadata
|
Signed-off-by: Shiju <[email protected]>
|
/ok to test 3d3edf7 |
PR Review Status@shiju-nv, I checked the standalone lockfile synchronization: all five changes add the policy crate's existing Blocking findings: None. Carried findings: None; The test mirror matches the current head after Gator metadata
|
ecce595
Monitoring CompletePR #5358 has merged. Gator monitoring is complete. Gator metadata
|
) Moves NemoClaw's OpenShell pins from v0.1.9 to v0.1.10, whose project moved to `ai-openshell/openshell` and publishes its images and chart on Quay, upgrades the bundle's OpenTofu to 1.13.10, and updates Rust crates within the workspace's constraints. A managed `kubernetes` or `openshift` gateway now reports no sandbox service URLs, because the v0.1.10 chart turns off gateway service routing. ## Problem NemoClaw pins OpenShell v0.1.9 (`ce58cf8`). v0.1.10 (`152c59d`) is the latest release, and it changes what NemoClaw pins and how a Kubernetes gateway behaves: - The repository moved from `NVIDIA/OpenShell` to `ai-openshell/openshell`. The gateway, supervisor and sandbox images and the chart publish to `quay.io/ai-openshell`, the chart is renamed `oci://quay.io/ai-openshell/charts/openshell`, and GHCR has no 0.1.10 tags. - The chart sets `enable_gateway_service_routing: false` (ai-openshell/openshell#5672), so a Helm gateway publishes no gateway-routed service URLs. - `openshell-policy`'s `PolicyViolation` gained five Cedar and endpoint-settings variants, so NemoClaw's exhaustive description of OpenShell's violations no longer compiles. - OpenShell now refreshes an expired policy DNS mapping before connecting (ai-openshell/openshell#5650), which removes the limit that an OpenClaw agent's model request failed after a DNS answer's TTL. OpenTofu 1.13.10 is a patch release built with Go 1.27.4 for GO-2026-6859. ## Change - **Pins:** the Cargo source and revision of `openshell-core`, `openshell-sdk` and `openshell-policy`, and of the vendored SDK's `openshell-core` and `openshell-crypto`; in `versions.json`, the version, revision, Linux CLI archives, the Quay gateway, supervisor and sandbox images, and the renamed chart; the managed-gateway reference, a contract test and the gateway contract module, which carry the image digests. The CLI checksums come from the release's `openshell-checksums-sha256.txt`, and the image and chart digests from Quay's `0.1.10` tags; GHCR's `0.1.9` tags match the previous pins. The OpenTofu checksums come from its GPG-signed `SHA256SUMS`. - **Vendored SDK:** upstream changed `src/client.rs`, `src/types.rs` (the new `application_service_urls` and `gateway_service_urls`) and `tests/client_mock.rs`, copied unchanged. The SDK manifest still enables `openshell-core`'s default features, including telemetry, so the manifest patch stays; `NOTICE.md` records the new source and revision. The SDK integration limits in `internal-docs/design/architecture.md` still hold at v0.1.10 and cite that revision. - **Policy violations:** NemoClaw describes the five new violations. NemoClaw writes no Cedar policy or `endpoint_settings`, so none of them arises from a NemoClaw document. - **Service URLs on Kubernetes:** NemoClaw leaves the chart's default. The Kubernetes guide says a managed gateway reports no service URLs and how to turn routing on with `enable_gateway_service_routing: true` in `spec.gateway.config`, which passes through to the chart; the external-ingress guidance and the limit for #14316 say the same. The fake gateway in the test fixtures reports each URL as gateway-routed, as a Docker gateway does. - **Limits:** the DNS TTL limit is removed. - **Docs:** OpenShell links move to `ai-openshell/openshell` at v0.1.10; each path and anchor exists there, and the three configuration line ranges in the sandbox network guide move to the same text. - **Rust crates:** `cargo update`. `url` 2.5.9 now percent-encodes `^` in a path, as WHATWG's URL standard does, so an MCP endpoint whose path holds `^` passed NemoClaw's check; the existing `mcp_endpoints_reject_paths_openshell_rewrites_before_matching` test failed, and NemoClaw now checks the URL as written. - **Release notes:** the v0.1.10 changes users see, and the service URL change as a breaking change. ## OpenShell 0.1.10 Changes Checked | Change | Decision | |---|---| | Registry and chart move, repository transfer (ai-openshell/openshell#5822, ai-openshell/openshell#5823, ai-openshell/openshell#5833) | Followed in every pin and link. | | Helm service routing off by default (ai-openshell/openshell#5672) | Kept OpenShell's default and documented the setting; NemoClaw doesn't override chart defaults it doesn't own. | | Application origins, `domain` → `base_url` (ai-openshell/openshell#4956) | No change: NemoClaw sets no app listener, and apply reports OpenShell's preferred `url`, which stays the gateway URL when no origin is configured. | | TypeScript SDK move (ai-openshell/openshell#5685) | No change: NemoClaw uses the Rust SDK. | | Kubernetes 1.33 minimum tested (ai-openshell/openshell#5646) | No change: CI's kind node runs 1.37, and OpenShell still tests Agent Sandbox 1.0.3. | | Policy DNS TTL refresh (ai-openshell/openshell#5650) | Removed the limit; NemoClaw had no workaround. | | Sandbox restart `ContainerExited`, same-name recreate on Kubernetes, multi-replica fixes, IPv6, process limits and signals, idle-connection and 502 fixes | No NemoClaw code works around them; listed in the release notes. | | Docker persistent `/sandbox` and image updates of a stopped sandbox (ai-openshell/openshell#5617) | Not adopted here: it needs `enable_sandbox_updates` and `persist_workspace`, applies only to new workspaces, and requires a numeric `USER` in the image, so it is a feature change of its own. | | Workspace secrets, GitHub App tokens, SPIFFE broker, OAuth `client_secret_basic` and `resource`, `/**` path templates, OTLP metrics, audit records, IPv6 listeners, supervisor pool sizing | Gateway or provider settings that `spec.gateway.config` or operator-managed providers can set; NemoClaw adds no wrapper. | | `openshell policy lint` (ai-openshell/openshell#5358) | No change: NemoClaw validates policies in-process with `openshell-policy`. | | Cedar policies | Development builds only; no change. | | OpenShift UID and `fsGroup` (ai-openshell/openshell#5483) | Still open, so the `openshift` target keeps nulling the chart's IDs. | | Gateway restart leaves sandboxes in `Error` (ai-openshell/openshell#4910) | Still open; the limit stays. | ## Other Pins - NeMo Fabric is already at its latest release, v0.7.0, and its OpenClaw adapter supports only OpenClaw 2026.9.34 and its Hermes adapter Hermes v0.22.7, so the harness images stay; Fabric owns the harness versions its adapters support. - The Docker and Helm providers, kind, nextest, Protocol Buffers, Rust and vLLM are at their latest releases. - Container base images, Bun, uv and Ollama move in a stacked pull request, which needs image builds of its own. - llama.cpp's server image and the NIM image stay: each update needs its own notices and a GPU run.
Summary
Add
openshell policy lint <file>to validate authored policies without a gateway. After parsing, it reports file-only semantic violations together and identifies deferred live checks.Related Issue
Closes #4035
Changes
Release Notes
openshell policy lint policy.yamlvalidates authored files offline. Success does not establish that a sandbox can start.Testing
-D warnings, Rust formatting, whitespace and SPDX checks passed on macOS with Rust 1.95.0.cargo metadata --locked --offlineafter synchronizing the policy dependency.Checklist