feat(policy): add GraphQL L7 inspection#1083
Open
johntmyers wants to merge 16 commits intomainfrom
Open
Conversation
Closes #1022 Adds GraphQL-over-HTTP classification, policy schema fields, OPA enforcement, persisted-query registry handling, tests, and documentation. Signed-off-by: John Myers <9696606+johntmyers@users.noreply.github.com>
2 tasks
|
🌿 Preview your docs: https://nvidia-preview-pr-1083.docs.buildwithfern.com/openshell |
|
Label |
Collaborator
Author
|
/ok to test 2595827 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds GraphQL-aware L7 inspection for GraphQL-over-HTTP endpoints. The sandbox can classify operation type, operation name, root fields, and persisted-query identifiers before evaluating OPA policy.
Related Issue
Closes #1022
Changes
proto/sandbox.proto,crates/openshell-policy,crates/openshell-sandbox/src/opa.rs: add GraphQL policy fields, persisted-query registry fields, YAML/proto round trips, and OPA serialization.crates/openshell-sandbox/src/l7/graphql.rs,crates/openshell-sandbox/src/l7/relay.rs: add GraphQL request parsing, bounded body buffering, batched operation classification, deny handling, and OCSF logging.crates/openshell-sandbox/data/sandbox-policy.rego: enforce GraphQL allow/deny rules with deny precedence, all-operation batch checks, field glob matching, and trusted hash-only persisted-query handling.POST.e2e/rust/tests/forward_proxy_graphql_l7.rs: cover forward-proxy and CONNECT-proxy GraphQL enforcement, duplicate GET control params, persisted queries, and chunked request bodies.architecture/anddocs/: document policy syntax, real-world service policy shapes, and saved/hash-only query behavior.Railway-Style Destructive Mutation UX
The Railway accident class was a direct GraphQL mutation against
https://backboard.railway.app/graphql/v2such as:A policy can make that failure mode explicit by allowing only known read operations and denying destructive root mutation fields before the request leaves the sandbox:
The important reviewer-facing behavior is that policy authors do not need to identify every possible mutation name. They can combine narrow allow rules with explicit high-risk deny rules, and deny rules take precedence if a batch mixes safe reads with a destructive mutation.
Real-World Network Policy Shapes
These examples are intentionally service-specific. GraphQL is not a universal verb model like REST, so the useful policy unit is the app schema's root fields plus any trusted saved-query registry. The new endpoint
pathselector is what lets a policy distinguish/graphqlfrom REST routes on the same host.GitHub mixed REST and GraphQL shape on
api.github.com:Railway destructive-operation guardrail shape:
Shopify Admin GraphQL read-first shape:
Hash-only / saved-query shape with a trusted registry:
Behavior to review:
POST https://api.github.com/graphqlis evaluated by the/graphqlGraphQL endpoint;GET https://api.github.com/repos/NVIDIA/OpenShell/issuesis evaluated by the/repos/NVIDIA/OpenShell/**REST endpoint.persisted_queries: allow_registeredis set and the hash or saved-query ID appears ingraphql_persisted_queries.Deviations from Plan
pathmatching soprotocol: restandprotocol: graphqlcan coexist under the same host and port.Testing
mise run pre-commitpassesTests added:
crates/openshell-sandbox/src/l7/graphql.rs; policy validation/access preset tests incrates/openshell-sandbox/src/l7/mod.rs; GraphQL OPA allow/deny/persisted-query tests incrates/openshell-sandbox/src/opa.rs; YAML/proto round-trip test incrates/openshell-policy/src/lib.rs.e2e/rust/tests/forward_proxy_graphql_l7.rscovers GraphQL L7 enforcement over both forward-proxy and CONNECT-proxy paths, including duplicate GET control params, persisted-query registry behavior, and chunked bodies.Checklist
Documentation updated:
architecture/sandbox.md: GraphQL classifier, endpointpath, and L7 flow updates.architecture/security-policy.md: GraphQL schema, endpointpath, and enforcement behavior.docs/reference/policy-schema.mdx: policy schema fields, including endpointpath.docs/sandboxes/policies.mdx: user policy examples, service shapes, and mixed REST/GraphQL host examples.docs/get-started/tutorials/github-sandbox.mdx: GitHub REST and GraphQL endpoints split by path.docs/security/best-practices.mdx: GraphQL L7 recommendations.