Skip to content

Support GraphQL argument matching and nested field restrictions in network policies #5986

Backlog

Description

@stevenlee-oai

User Story

I use OpenShell to run agents with repository-specific GitHub access. I want those agents to use the stock gh CLI, including GraphQL queries and mutations, while allowing each agent only its approved repositories and operations.

Problem Statement

GraphQL rules can match operation type, operation name and top-level fields, but cannot constrain field arguments or nested selections. GitHub sends different repository requests to the same POST /graphql endpoint, so method/path and root-field matching cannot express a repository-specific policy.

Impact / Why This Matters

gh pr create queries repository(owner: $owner, name: $name), then uses createPullRequest(input: $input) with a repository node ID. We want to permit these operations for one repository while denying them for another, and control which nested fields may be returned. Today that requires a custom enforcement extension or narrower provider credentials. Our public captured gh request fixture illustrates the requests; it is synthetic evidence, not qualification of the proposed feature.

Proposed Design

Extend GraphQL policy rules with generic field-path and resolved-argument matching. For example (illustrative syntax, not currently supported):

protocol: graphql
path: /graphql
rules:
  - allow:
      operation_type: query
      field_rules:
        - path: repository
          arguments:
            owner: { exact: acme }
            name: { exact: project }
        - path: repository.name
        - path: repository.pullRequests
        - path: repository.pullRequests.nodes
        - path: repository.pullRequests.nodes.title
  - allow:
      operation_type: mutation
      field_rules:
        - path: createPullRequest
          arguments:
            input.repositoryId: { exact: R_APPROVED }
        - path: createPullRequest.pullRequest
        - path: createPullRequest.pullRequest.url

Match actual schema field names and arguments, regardless of aliases or whether arguments are inline or supplied through variables. Apply nested selection restrictions at every selected path, with explicit subtree allowances if supported. Keep argument combinations correlated per field occurrence and reject unsupported or unresolved constrained values. This should be GraphQL-generic, with no GitHub-specific parsing in OpenShell.

Acceptance Criteria

  • A permitted repository query succeeds with inline arguments and equivalent variables; a different owner/name is denied.
  • A permitted mutation succeeds for an approved input.repositoryId; the same mutation against another ID is denied.
  • A permitted nested selection succeeds; adding an unapproved nested field is denied.
  • Aliases, fragments, repeated field occurrences, multiple operations and batches cannot bypass restrictions; all executed selections must satisfy policy before forwarding or credential injection.
  • Define behavior for variable defaults, missing or malformed variables, persisted operations and unsupported value shapes; refuse requests whose constrained arguments cannot be established.
  • Existing GraphQL policies retain their documented semantics.

Alternatives Considered

HTTP policy cannot distinguish GraphQL body semantics. Existing GraphQL presets and root-field rules are too broad for this workflow. Middleware or interceptors could implement a custom body-aware check, but would duplicate GraphQL parsing and policy management; provider-side downscoping helps with GitHub repository limits but does not provide generic nested-field controls.

Agent Investigation

Source inspection found that GraphQL classification already parses documents and expands root fragments, but does not retain resolved arguments or nested selections. GraphqlOperationInfo passes root field names to policy evaluation. The existing parser and GraphQL policy rules appear to be the natural extension point. This was source inspection only; no prototype or runtime tests were run.

Checklist

  • I've reviewed existing issues and the published docs.
  • This is a design proposal, not a request without a design.

Activity

  1. added
    state:triage-needed
    on Nov 26, 2026
  2. added
    state:accepted
    and removed
    state:triage-needed
    on Nov 26, 2026
  3. Sudeep72 commented on Nov 30, 2026

    @Sudeep72

    Hi @stevenlee-oai , I'm interested in contributing to OpenShell and came across this issue. I noticed that #5996 is already in progress. Are there any additional security tests or smaller follow-up tasks I could take up as a first-time contributor?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    state:accepted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions