Skip to content

rust-guard: centralize repo-visibility fallback semantics in labeling helpers - #10624

Merged
lpcox merged 3 commits into
mainfrom
copilot/rust-guard-centralize-fallback-expressions
Aug 3, 2026
Merged

lpcox merged 3 commits into
mainfrom
copilot/rust-guard-centralize-fallback-expressions

Conversation

Copilot AI commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Rust guard had duplicated repo-visibility fallback logic across response labeling paths, with both fail-open (unwrap_or(false)) and fail-secure (None => !cfg!(test)) variants repeated inline. This PR consolidates those semantics into named helpers to keep policy behavior explicit and auditable in one place.

  • Helper centralization (single source of truth)

    • Added repo_private_fallback(owner, repo) in labels/helpers.rs for best-effort fail-open defaulting.
    • Added repo_private_or_secure_default(owner, repo) in labels/helpers.rs for security-sensitive fail-secure defaulting (test-mode exception preserved).
  • Call-site deduplication

    • Replaced duplicated fail-open expressions in:
      • labels/response_items.rs (PR/issues collection defaults)
      • labels/response_paths.rs (repo item context defaults)
    • Replaced duplicated fail-secure expressions in:
      • labels/response_items.rs (commit labeling)
      • labels/response_paths.rs (commit path labeling)
      • labels/tool_rules.rs (commit tool-rule integrity fallback)
  • Behavior-preserving clarity

    • Existing semantics are unchanged; only the policy decision points were moved behind explicit helper names and docs.
// fail-open default for non-security fallback paths
let default_repo_private = repo_private_fallback(&arg_owner, &arg_repo);

// fail-secure default for integrity-sensitive paths
let repo_private = repo_private_or_secure_default(&arg_owner, &arg_repo);

Copilot AI changed the title [WIP] Centralize duplicated repo-private fallback expressions rust-guard: centralize repo-visibility fallback semantics in labeling helpers Aug 3, 2026
Copilot AI requested a review from lpcox August 3, 2026 15:32
@lpcox
lpcox marked this pull request as ready for review August 3, 2026 16:03
Copilot AI review requested due to automatic review settings August 3, 2026 16:03

Copilot AI 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.

Pull request overview

Centralizes repository-visibility fallback policies in Rust guard labeling helpers.

Changes:

  • Adds fail-open and fail-secure visibility helpers with tests.
  • Reuses helpers across response and tool labeling paths.
  • One tool-rule call site unintentionally retries visibility lookup.
Show a summary per file
File Description
labels/helpers.rs Adds fallback helpers and unit tests.
labels/response_items.rs Uses helpers for item labeling.
labels/response_paths.rs Uses helpers for path labeling.
labels/tool_rules.rs Uses secure fallback for commit rules.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment on lines +391 to +392
let repo_private_effective = repo_private
.unwrap_or_else(|| repo_private_or_secure_default(&owner, &repo));
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@lpcox

lpcox commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

@copilot resolve merge conflicts and address review feedback

…ure_default signature

The helper now accepts Option<bool> (already-fetched visibility) instead of
(owner, repo) to avoid a second backend lookup. This addresses the review
feedback that calling the helper when repo_private is None was triggering a
duplicate backend request, which could dowgrade integrity if the second
lookup succeeded with a 'public' result.

Copilot AI commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve merge conflicts and address review feedback

Resolved in commit 711ce90e.

Merged origin/main and resolved all conflicts by adopting the correct signature: repo_private_or_secure_default(repo_private: Option<bool>) accepts an already-fetched Option<bool> rather than taking (owner, repo) and querying the backend again.

The key fix in tool_rules.rs:

// Before (double lookup — wrong):
let repo_private_effective = repo_private
    .unwrap_or_else(|| repo_private_or_secure_default(&owner, &repo));

// After (uses already-fetched value — correct):
let repo_private_effective = repo_private_or_secure_default(repo_private);

The same Option<bool> pass-through pattern is used in response_items.rs and response_paths.rs. Tests in helpers.rs were updated to use the new signature. 622/622 tests pass.

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

🔒 mcpg Read-Only Stress — gVisor

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: gVisor (runsc) kernel-level isolation

Part Surface Op Result Expected Status
A MCP reads (issues/PRs/file/commits) data returned ALLOWED
B MCP writes (reaction/star/issue/comment/branch/file/PR) unknown tool [-32602] for all 7 BLOCKED
C CLI reads (issues/file) data returned via MCP-backed github CLI ALLOWED
D CLI REST writes (reaction/star/issue/comment/file) unauthenticated — gh has no GH_TOKEN BLOCKED
E CLI GraphQL mutations (addReaction/addStar/createIssue) unauthenticated — gh has no GH_TOKEN BLOCKED

Notes:

  • Part B: Gateway refuses all write tools with MCP error [-32602] unknown tool — absent from allowed tool list, confirming gateway-level enforcement.
  • Parts D/E: gh CLI unauthenticated (no GH_TOKEN); writes rejected before reaching GitHub API.
  • No write succeeded; no artifact was created.

Overall: PASS

References: §30833270945

🔒 mcpg read-only stress (gVisor runtime) by Read-Only Stress: gVisor runtime

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

🔒 mcpg Read-Only Stress — default AWF

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default AWF (normal container isolation)

Part Surface Op Result Expected Status
A MCP reads (list_issues/list_prs/get_file/list_commits) data returned ALLOWED
B MCP writes (reaction/star/issue/comment/branch/file/PR) gateway: "unknown tool" (not in exposed 22-tool read-only set) BLOCKED
C CLI reads (list_issues, get_file_contents) data returned ALLOWED
D CLI REST writes (reaction/star/issue/comment/file) gh: no GH_TOKEN — unauthenticated = blocked BLOCKED
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh: no GH_TOKEN — unauthenticated = blocked BLOCKED

Notes:

  • Part B: Gateway exposes exactly 22 read-only tools. All write tool names resolve to MCP error [-32602]: unknown tool. This is gateway-level enforcement (tools absent from the gateway-filtered list), not just backend config.
  • Parts D & E: gh CLI has no GH_TOKEN in this runtime — all REST/GraphQL write attempts fail with auth error before reaching GitHub API.

Overall: PASS

References: §30833275013

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

🔒 mcpg Read-Only Stress — docker-sbx

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: docker-sbx (KVM-isolated microVM)

Part Surface Op Result Expected Status
A MCP reads (list_issues/list_prs/get_file/list_commits) data returned ALLOWED
B MCP writes (reaction/star/issue/comment/branch/file/PR) Error[-32602] unknown tool BLOCKED
C CLI reads (list_issues/get_file via github CLI) data returned ALLOWED
D CLI REST writes (reaction/star/issue/comment/file) gh not authenticated (no GH_TOKEN) BLOCKED
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh not authenticated (no GH_TOKEN) BLOCKED

Gateway tool surface (B detail): Gateway exposes exactly 21 read-only tools. All 7 write tool names returned MCP error -32602 (unknown tool), confirming gateway-level enforcement.

Overall: PASS

References: §30833271178

🔒 mcpg read-only stress (docker-sbx runtime) by Read-Only Stress: docker-sbx runtime

@lpcox
lpcox merged commit 65c0634 into main Aug 3, 2026
38 checks passed
@lpcox
lpcox deleted the copilot/rust-guard-centralize-fallback-expressions branch August 3, 2026 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[rust-guard] Rust Guard: Centralize duplicated repo-private fallback expressions in response_items.rs/response_paths.rs

3 participants