Skip to content

πŸ› fix: apply repository scope to GraphQL writes without restricting reads - #19072

Merged
kubestellar-prow[bot] merged 4 commits into
hivecommons:v5from
mendezr:fix/graphql-repo-scope-19058
Nov 18, 2026
Merged

kubestellar-prow[bot] merged 4 commits into
hivecommons:v5from
mendezr:fix/graphql-repo-scope-19058

Conversation

@mendezr

@mendezr mendezr commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #19058

  • Apply the existing REST per-agent repository scope predicate and denial shape to resolved GraphQL mutation targets, independently of autonomy mode. Queries remain unrestricted by repository scope.
  • Parse the selected operation, arguments, variable defaults, aliases and fragments; check every resolved mutation target instead of matching arbitrary repository-looking strings in comment bodies or unused variables.
  • Learn node-ID β†’ repository mappings from upstream GraphQL lookup responses in a bounded, agent-isolated cache shared across connections. Support identity/gzip responses, preserve streaming/deadlines, bound decompression, and publish mappings before returning the final response bytes so immediate follow-up writes cannot race publication.
  • Document the compatibility policy and add a security changelog fragment.

Unresolved-target policy

Repository attribution is explicitly fail-open when unresolved, while existing mode, write-surface and auto-merge gates remain in force. Cold-cache ID-only gh api graphql calls, unsupported response shapes/encodings and evicted mappings must not become blanket write denials. This is best-effort scope enforcement, not a complete boundary against deliberately unseen IDs; token repository permissions remain necessary. Repository pause and the hive-wide REST allowlist are unchanged.

Validation

  • Added replay/integration tests for nine normalized gh GraphQL lookup/write document flows: issue create/comment/edit/close and PR create/comment/edit/close/merge. Tests use fresh connections and gzip responses, asserting unrestricted reads, in-scope writes, REST-shaped out-of-scope refusals that never reach upstream, and cold-cache compatibility.
  • Added regression coverage for direct repository arguments, cached inline node IDs, aliases/fragments, multiple targets, selected operations, defaults, unused variables/body text, live scope changes, cache isolation/bounds, malformed responses, gzip size limits and response publication timing.
  • gofmt -l on changed Go files: clean.
  • Go tests/build/lint not run locally, as required by AGENTS.md; CI is the test verdict. No claim of a local test pass.

Implementation plan/spec references: issue-19058/graphql-write-repo-scope; issue-19058#acceptance-criteria (no separate plan or Spektacular clause supplied).

-- hive: backend=pi model=openai/gpt-6.1-sol


🐝 Hive Agent: contributor | SHA: 02434bff3

Resolve mutation targets from operation arguments and upstream node-to-repo mappings, and reuse the REST per-agent scope refusal. Preserve unrestricted queries and document fail-open scope attribution for unresolved IDs. Keep streaming responses bounded and publish lookup mappings before the final bytes reach clients.

Co-authored-by: clubanderson <407614+clubanderson@users.noreply.github.com>

Hive-Run: hivecommons#19058
Hive-Plan: issue-19058/graphql-write-repo-scope
Hive-Spec: issue-19058#acceptance-criteria
Signed-off-by: mendezr <mendezr@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added dco-signoff: yes Indicates the PR's author has signed the DCO. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 18, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor

/ok-to-test

@kubestellar-prow

Copy link
Copy Markdown
Contributor

@hivecommons-hive[bot]: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/ok-to-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

needs-human: Prow has not run this fork PR's presubmits. Its author is not one of Prow's trusted users, so the trigger plugin waits for /ok-to-test; Hive posted it and Prow rejected hivecommons-hive[bot] ("Cannot trigger testing until a trusted user"). Hive will not post the command again on this PR.

A maintainer can comment /ok-to-test (plus /test all for the current head), or make hivecommons-hive[bot] a Prow trusted user so Hive's command counts.

@hivecommons-hive

hivecommons-hive Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

@mendezr this PR is back in your court (stage/072-returned-to-contributor). The hive will not merge it until the head changes.

Failing checks:

  • coverage

Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path.

Your relay could not take this as a fix-pr task (Hub is not the active polling slot); the hive will retry it from your relay fix queue.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v5

Conflicts are checked with every PR merged onto the current tip of v5, so a PR that only needs a rebase is not reported as conflicting with its siblings.

PR Title Relation Files
#19102 πŸ› Let the agent that opened a PR reply on its review threads same files src/crux/proxy/github_proxy.go
src/crux/proxy/github_proxy_mitm.go
#19007 πŸ› fix: strip hop-identity headers and table-test proxy relays same files src/crux/proxy/github_proxy_mitm.go
#19110 πŸ› Filter em-dashes on every outbound path, agent proxy writes included same files src/crux/proxy/github_proxy.go
src/crux/proxy/github_proxy_mitm.go
#19099 ✨ Session taint: observe-only recorder for what a session has read same files src/docs/security-model.md
#19098 ✨ Shadow-mode authorization decision seam for the push broker's changed-files guard same files src/docs/security-model.md

Signed-off-by: mendezr <mendezr@users.noreply.github.com>
@hivecommons-hive

Copy link
Copy Markdown
Contributor
1640e31

⚠️ Sentinel alert β€” maintainer review required

Hive flagged this PR (author @mendezr, head 1640e31467a3) because it matches behaviors that can override security controls, escalate privileges or damage the codebase. This is a heuristic, not an accusation β€” a maintainer should confirm the change is intended before it merges.

  • sensitive_path β€” changes 2 sensitive path(s) (Touches a sensitive path (OWNERS, workflows, policies, hive config, security docs, …))
    • src/crux/go.mod
    • src/crux/proxy/rules.go

Hive added the sentinel-alert label. While it is present, Hive will not approve this PR, apply LGTM/approval labels, or merge it through any auto-merge lane. Remove the label once reviewed; Hive will not re-apply it unless new commits are pushed. Tune paths and behaviors under sentinel in hive.yaml or the dashboard Security tab.

… EOF

Signed-off-by: mendezr <mendezr@users.noreply.github.com>
Use the existing test-scoped autonomy registration helper so these tests do not leak a global override into later GraphQL replay tests. Preserve the concurrent signed-off replay fixture fix.

Signed-off-by: mendezr <mendezr@users.noreply.github.com>
@mendezr

mendezr commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up on the contributor nudge: it targets the older head 1640e31. The current head is 05edefa, after the GraphQL fixture/read-denial isolation and autonomy-override cleanup fixes. The current coverage check is passing; no current checks are failing (golangci-lint and the hive image build are still in progress, and tide is pending). GitHub reports this head mergeable, not DIRTY or BEHIND. No additional code change is indicated by the outstanding comments. Leaving the sensitive-path review/approval controls intact; this follow-up does not grant approval or attempt to bypass the Prow trust gate.


🐝 Hive Agent: contributor | SHA: unknown

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style review at head 05edefa. Read the diff, issue #19058, and the existing GraphQL classifier in rules.go. No in-scope blocker; advisory notes only, all minor.

  1. Two GraphQL parsers now coexist. graphql_repo_scope.go adds gqlparser/v2 plus parseScopedGraphQL, while rules.go keeps the hand-rolled scanner (graphQLIdentRe, isGitHubGraphQLMutation, skipGraphQLString) for mode, write-surface and auto-merge gating. The two can disagree on what counts as a mutation or which operation is selected. Consider a short comment in graphQLAgentRepoScopeRefusal saying the gqlparser path is scope-only and why it was not folded into the existing classifier.
  2. Unreadable one-line key list. The case "id", "repositoryId", ... list in graphQLAgentRepoScopeRefusal is a single very long line. Hoist it to a package-level var graphQLTargetIDKeys = map[string]struct{}{...}, one key per line, so additions diff cleanly.
  3. Redundant internal-caller check. graphQLAgentRepoScopeRefusal already returns early for internalCallerName, but the call site in github_proxy_mitm.go repeats agentName != internalCallerName after the call. That is harmless but is a double guard with no comment, and the function runs first. Keep one guard (the function-internal one) and drop the call-site copy, or add agentName != internalCallerName && before the call so parsing is skipped.
  4. Cache eviction wording. graphQLRepoCache.put wipes the whole map when it reaches graphQLRepoCacheLimit. The doc comment says "bound", which is true, but "reset when full" would set maintainers' expectations correctly, since the docs describe evicted mappings.

NOTICE, the changelog fragment (security-19058-...md) and the docs are in the repo's usual shape. Out-of-scope: none that I could verify.

-- hive: agent=adjudicator-4 backend=claude model=claude-sonnet-5-5 claude=2.1.327

@hivecommons-hive

hivecommons-hive Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Hive status β€” updated in place; edits do not notify. Full history is in the Activity Monitor.

Review findings from adjudicator-5 (folded here because this head already carries its hive review):

Docs-currency review at head 05edefa: the new security-model.md section, changelog fragment, NOTICE entry and rules.go comment are accurate. Two operator-facing pages still state the opposite of what this PR ships, and #19058 item 5 asks for docs to match.

  1. src/docs/per-repo-agents.md:167-170 says scope does not cover GraphQL writes ("POST /graphql is not matched ... stay gated by ACMM mode"). This is now false for attributable mutations.
  2. src/docs/redteam.md:95-98 lists "GraphQL writes ... not by this scope check. Every scoped agent has the same gap today" as an uncovered area. The residual gap is now unresolved/cold-cache IDs (fail-open), not all GraphQL.

Suggested fix for per-repo-agents.md:

-- **Cover GraphQL writes whose target repo is only in the request body.** Repo
-  attribution reads the request *path*, so `POST /graphql` is not matched β€” the
-  same blind spot the pre-existing repo-scope filter has. Those mutations stay
-  gated by ACMM mode.
+- **Guarantee GraphQL write scope.** GraphQL mutations whose target resolves from
+  arguments or cached node IDs are scope-checked like REST. Unresolved targets
+  (cold cache, unseen IDs) are fail-open and stay gated by ACMM mode only; see
+  [GraphQL repository scope](security-model.md#graphql-repository-scope).

Similarly reword redteam.md's bullet to name the unresolved-ID residual gap and link the same section.

Advisory (out of scope): design/authorization-decision-point.md:83 and its github_proxy_mitm.go line refs are stale.

Findings not on a changed line

  • src/docs/per-repo-agents.md:167: Now false: GraphQL mutations are repo-scope checked by this PR. See summary for a replacement bullet.
  • src/docs/redteam.md:95: Now false: reword to the residual gap (unresolved/cold-cache node IDs are fail-open) and link security-model.md#graphql-repository-scope.
Review follow-ups: 2 open of 2 (below review.backlog.min_severity: P2)

Non-blocking findings below the backlog filing line, listed here instead of as issues. Tick them off as they are fixed; set review.backlog.min_severity: P3 to file every finding.

  • P3 low docs-currency β€” authorization-decision-point.md gate table out of date (src/docs/design/authorization-decision-point.md:83): Row 3 (agent repo scope) cites github_proxy_mitm.go:107-110 and AgentRepoScopeRefusal only, with no GraphQL arm; the GraphQL row 7 line range 158-182 shifts with the new graphQLAgentRepoScopeRefusal …
  • P3 low security β€” Cache attribution inherits enclosing repository and eviction is shared (src/crux/proxy/graphql_repo_scope.go:42): IDs reached through cross-repo edges under a repository(...) selection are cached against the enclosing repo, and the cache resets wholesale at 8192 entries shared across agents. Harmless while unres…

Review findings from adjudicator-2 (folded here because this head already carries its hive review):

Security review at head 05edefa. Read the diff, github_proxy_mitm.go around the GraphQL arm, and issue #19058.

The fail-open policy for unresolved targets is explicitly allowed by issue item 3, so I am not flagging it. Queries are untouched and the denial path reuses agentRepoScopeRefusal. I found one in-scope gap and one out-of-scope note, listed below.

  1. In-scope, low: the node-ID key list in graphql_repo_scope.go:180 is a hard-coded allowlist. A mutation whose target ID sits under a key that is not listed is never looked up in the cache, even when the ID is cached as out-of-scope. Examples I did not find in the list: lockableId (lockLockable/unlockLockable), contentId (addProjectV2ItemById), starrableId. Matching on the id/...Id key shape closes this without maintaining a list.
				if k := strings.ToLower(key); k == "id" || strings.HasSuffix(k, "id") {

(The case list at line 180 would be replaced by this if.)

  1. Out-of-scope, low: observeGraphQLRepos lets a node inherit repo from an enclosing repository(...) selection (graphQLRepoScope.go walk, childRepo). An ID reached through a cross-repo edge, such as a timeline cross-reference to an issue in another repo, can be cached against the wrong repository. Today this is harmless because unresolved targets are fail-open. It would matter if the policy ever moves to fail-closed. The cache also resets entirely at 8192 entries (:42), and that limit is shared across agents, so one agent can evict others' mappings. The effect is only a downgrade to fail-open.

Findings not on a changed line

  • src/crux/proxy/graphql_repo_scope.go:180: This key allowlist skips cache lookups for target keys not listed (e.g. lockableId, contentId, starrableId). Matching any id/*Id key closes the gap:
    				if k := strings.ToLower(key); k == "id" || strings.HasSuffix(k, "id") {
    

Review findings from adjudicator (folded here because this head already carries its hive review):

Correctness review at head 05edefa. No in-scope blocker found; one low advisory.

I read the diff, the GraphQL arm in github_proxy_mitm.go, and the contract in #19058. The new arm refuses only mutations that resolve to an out-of-scope repo and sends the refusal through the same DenyReasonAgentRepoScope path as REST. Queries and unresolved mutations fall through to the existing gates unchanged, which matches the fail-open policy the PR documents. Capture-before-final-bytes (graphQLRepoCapture.Read) covers both the Content-Length and EOF cases and has a test.

Advisory (low): see the inline thread on the put call. Not verified against live GitHub responses, and not blocking.

Not run: Go tests, since the PR states CI is the verdict.

Findings not on a changed line

  • src/crux/proxy/graphql_repo_scope.go:330: Low (advisory): walk passes the enclosing repo down to every descendant, and every id under it is cached to that repo. Nodes that belong to a different repo but sit under a repository(owner:,name:) selection, for example cross-reference source{... on Issue{id}} in timeline items, get attributed to the parent repo when the selection omits repository{nameWithOwner}. If the parent is in scope and the real repo is not, a later write on that ID is allowed. If it is the other way round, an in-scope write is wrongly refused. The impact is bounded because unresolved IDs fail open anyway. A cheap hardening is to cache an id only when it is the repository's own id or its object's repository was resolved from the response. Not verified against live responses.

Review findings from reviewer-2 (folded here because this head already carries its hive review):

Routing to a maintainer, not a defect finding: this PR carries the sentinel-alert label and changes a security boundary in the agent proxy.

What I verified in the diff:

  • src/crux/proxy/github_proxy_mitm.go now runs graphQLAgentRepoScopeRefusal on every GraphQL body before the existing auto-merge refusal, and wraps 200 responses in graphQLRepoCapture to learn node-ID to repo mappings.
  • src/crux/proxy/rules.go comment now states that unresolved mutations "do not reach this scope check". The PR body calls this policy "fail-open when unresolved" and says it is not a complete boundary against IDs the cache has not seen. A cold-cache ID-only gh api graphql write therefore still bypasses per-agent repo scope.
  • It adds a new module dependency (github.com/vektah/gqlparser/v2 v2.5.30 in src/crux/go.mod, plus a NOTICE entry) on a trust-boundary parser.

The one question for a person: is best-effort, fail-open repo scoping for GraphQL writes acceptable, with token repository permissions as the real boundary, or should unresolved mutation targets be denied? Everything else (parser correctness, cache isolation per agent) I have not verified line by line given the size (+1066), so I make no claim about it.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Needs a decision, not a merge:

Head: verdict requires_human @05edefa, 66/66 checks green, DCO yes, soak 10m0s elapsed.

How to release it:

  • After reading the verdict, a trusted merger can submit a GitHub Approve review for the current head and the lane clears the hold on its next pass; /hive approve replies on a PR are acknowledged but not consumed. An ordinary contributor cannot release their own PR.

Clear the cause and the hive re-evaluates on its next pass; the stage moves to stage/090-ready-for-human-merge, stage/095-pre-merge-soak or the merge queue on its own. Approval does not bypass CI, hold labels or other merge gates.

@clubanderson

Copy link
Copy Markdown
Member

/hive decision Accept that the GraphQL repository scope does not refuse a mutation whose target repository cannot be resolved (for example a cold-cache node id or an unsupported encoding): log it and pass it through, as the PR proposes, because refusing would break normal gh writes. Make sure that behavior and its limits are stated plainly in the security model. Apply the adjudicator's docs-currency findings: update src/docs/per-repo-agents.md (the lines saying GraphQL writes are not covered by the scope) and src/docs/redteam.md (the lines listing GraphQL writes as an uncovered area) so they match what this PR ships, keeping the residual gap described accurately. Keep the rest unchanged.

@clubanderson clubanderson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving head 05edefa. The swarm's open question is decided: a mutation whose target repository cannot be resolved is logged and passed through rather than refused, because refusing would break normal gh writes, and the security model states the limit. The two docs-currency items (per-repo-agents.md and redteam.md) will be handled as a small follow-up so they do not hold this change. Thank you for the thorough work.

@kubestellar-prow kubestellar-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Nov 18, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: 7e3629f1e3c53edffc2682fc2509f43b5628ecd0

@clubanderson

Copy link
Copy Markdown
Member

/lgtm

@clubanderson

Copy link
Copy Markdown
Member

/approve

@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: clubanderson

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 18, 2026
@kubestellar-prow
kubestellar-prow Bot merged commit 2b74b6c into hivecommons:v5 Nov 18, 2026
85 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has signed the DCO. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

πŸ”’ proxy: apply the repo scope check to GraphQL writes, keep reads unrestricted

2 participants