Repository navigation
feat(policy): match GraphQL arguments and nested fields - #5996
stevenlee-oai wants to merge 1 commit into
Conversation
Signed-off-by: Steven Lee <213687449+stevenlee-oai@users.noreply.github.com>
There was a problem hiding this comment.
Thanks for picking this up. The matching model looks right to me and is consistent with the existing L7 rules:
- Allow semantics extend
fieldsnaturally (every selected occurrence must be covered by one allow rule), and deny semantics match today's "any match denies". - Arguments are correlated per occurrence, so aliased calls can't borrow each other's arguments.
- Ambiguous or unresolvable input fails closed (duplicate keys/fragments/operations, cycles, depth and size budgets, persisted markers, missing variables), and deny treats unresolved arguments as potentially matching.
- The supervisor guard via
supported_capabilitiesmirrorsPOLICY_CEDAR_V1, and the Cedar token-grant translation drops/widens rather than granting.
Main design concern: the downgrade guard in NetworkEnforcementMode
I don't think enforcement mode is the right place to signal feature support:
- It conflates two orthogonal things: what to do on a violation (deny vs log) and which selectors the endpoint uses. The next feature that needs a guard would need another pair of values.
GRAPHQL_FIELD_RULES_AUDITprotects nothing: audit allows the traffic anyway, so an older gateway droppingfield_rulesonly changes logging. The widening risk exists only under enforce.- YAML and wire forms diverge. YAML authors write
enforce, while direct protobuf/SDK clients must remember to set the marker, and reads return values older SDKs don't recognize. - The equivalence leaks into merge (
effective_enforcement,merge_endpoint),ambiguity.rs,normalize_endpoint, and a marker⇔field_rules bijection check. - It relies on
validate_endpoint_mode_valuesincidentally rejecting unknown values, and it attaches at the endpoint while the feature is per rule.
Suggested shape for this PR:
- Leave
NetworkEnforcementModeunchanged and drop the marker validation and the merge/ambiguity/normalize special cases. - Keep the supervisor check through
GetSandboxConfigRequest.supported_capabilitiesas is. That covers the common upgrade order (gateway first, older supervisors still running). - Add a note in
schema.mdxthatfield_rulesrequire a gateway and supervisor at or above the release that introduces them, because an older gateway ignores them and the allow rule becomes broader.
That leaves a newer CLI or SDK talking to an older gateway unprotected, which is the same exposure accepted when MCP params and GraphQL fields were added. How gateways should advertise policy features to clients, the supported CLI/gateway/supervisor version skew, and whether gateways should reject unknown policy fields are general API questions. I'd rather settle them in a separate issue than introduce a new mechanism here; I'll open one.
Correctness and usability
"variables": nullyields no field facts, so everyfield_rulespolicy denies it. Many clients sendnullfor no variables (inline comment)."extensions": nullcounts as a persisted-query marker, which also withholds facts and denies. This is a new false denial compared with the existing hash detection (inline comment).- Inline enum literals resolve to
Nullwhile the same value passed as a variable is a string, sostates: [OPEN]and{"states": ["OPEN"]}behave differently. Treating an inline enum as its name string is safe because the server applies the same coercion, and it would satisfy the "inline and equivalent variables" acceptance criterion. - Type conditions are dropped, so
... on Repository { name }and... on User { name }both becomenode.name/search.nodes.name. Fine to defer, but please document it alongside the existing isolation caveat. __typenamemust be listed at every path. Apollo/Relay-style clients inject it; consider allowing it implicitly (keeping__schema/__typeexplicit).- Only string arguments can match (
first: 100never does). Worth a sentence in the docs.
Smaller points
- Consider reusing
L7QueryMatcher(addingoptional string exact) instead of a third matcher type, so RESTquery, MCPparamsand GraphQLargumentsshare one shape, withglob/anyrejected for GraphQL for now. If the separate type is deliberate, a sentence explaining why would help. - The sandbox conformance run is still listed as pending.
| NETWORK_ENFORCEMENT_MODE_AUDIT = 2; | ||
| // Same behavior as ENFORCE, but required when field_rules is present. An | ||
| // older gateway rejects this unknown enum instead of dropping field_rules. | ||
| NETWORK_ENFORCEMENT_MODE_GRAPHQL_FIELD_RULES_ENFORCE = 3; |
There was a problem hiding this comment.
See the review summary: I'd keep NetworkEnforcementMode limited to deny/log behaviour and drop these variants. The supervisor supported_capabilities check already guards enforcement, and client-to-gateway feature signalling is better designed separately, together with a version skew policy. The _AUDIT variant in particular guards nothing, because audit allows the traffic regardless.
| let empty_variables = Map::new(); | ||
| let variables = match obj.get("variables") { | ||
| None => Some(&empty_variables), | ||
| Some(value) => value.as_object(), |
There was a problem hiding this comment.
"variables": null lands here as None, so no field occurrences are produced and every field_rules policy denies the request. Could null be treated like an omitted variables (an empty map)?
| fn has_persisted_marker(extensions: &Value) -> bool { | ||
| extensions | ||
| .as_object() | ||
| .is_none_or(|extensions| extensions.contains_key("persistedQuery")) |
There was a problem hiding this comment.
is_none_or makes "extensions": null (or any non-object) count as a persisted-query marker, which withholds field facts and denies. null should probably be treated as absent; a non-null non-object could still fail closed.
| } | ||
| // Enum literals are distinct from strings. The string matcher treats | ||
| // both enum and null literals as non-string values. | ||
| cst::Value::EnumValue(_) | cst::Value::NullValue(_) => { |
There was a problem hiding this comment.
Mapping inline enum literals to Null means states: [OPEN] never matches, while the same value supplied through a variable is the string "OPEN" and does. Resolving an enum literal to its name string seems safe, since the server coerces both forms identically, and it would make inline and variable forms equivalent as the issue's acceptance criteria ask.
| self.collect(children, &path, depth + 1)?; | ||
| } | ||
| } | ||
| cst::Selection::InlineFragment(fragment) => { |
There was a problem hiding this comment.
The type condition is dropped here, so selections on polymorphic fields (node, nodes, search.nodes) merge across types. Not necessarily for this PR, but worth documenting next to the repository-isolation caveat in schema.mdx.
Summary
Add
field_rulesfor GraphQL over HTTP. Policies can require exact string arguments and restrict nested schema fields. This lets an operator distinguish repository queries and mutations that share one HTTP endpoint.Related Issue
Closes #5986
Changes
fieldsfor root-field matching.Testing
Focused parser, schema, and Regorus checks passed. They cover correlated occurrences, nested argument matching, missing facts, batch limits, and deny behavior.
Formatting, protobuf descriptor inventories, and docs navigation passed.
The conformance test compiled with its checked-in lockfile. It verifies that the upstream recorder sees credentials only on the admitted queries and mutation. The sandbox conformance run remains pending.
The local registry does not provide the workspace's locked
serde_with3.25.0. The Gateway, Supervisor, CLI, and policy test targets passed type checking with 3.24.0 in a disposable checkout. The PR retains the checked-in lockfile.Checks appropriate to the affected code and behavior pass
Unit tests added or updated
Conformance test added
Checklist