Skip to content

Use cobra's MarkFlagsMutuallyExclusive for AllowOnly scope flags - #11408

Merged
lpcox merged 5 commits into
mainfrom
copilot/go-fan-review-spf13-cobra
Aug 18, 2026
Merged

Use cobra's MarkFlagsMutuallyExclusive for AllowOnly scope flags#11408
lpcox merged 5 commits into
mainfrom
copilot/go-fan-review-spf13-cobra

Conversation

Copilot AI commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

A go-fan review of spf13/cobra usage flagged that --allowonly-scope-public and --allowonly-scope-owner are mutually-exclusive AllowOnly scope variants validated only in custom Go code (config.BuildAllowOnlyPolicy), rather than surfaced natively by cobra as is already done for --routed/--unified and --tls-cert/--tls-key.

Changes

  • internal/cmd/flags_difc.go: register cmd.MarkFlagsMutuallyExclusive("allowonly-scope-public", "allowonly-scope-owner") alongside the existing flag definitions, so conflicting CLI flags fail fast during parsing with cobra's standard error/usage output.
  • Runtime validation in config.BuildAllowOnlyPolicy is left in place — it's still the only guard for the equivalent conflict when driven by environment variables (MCP_GATEWAY_ALLOWONLY_SCOPE_PUBLIC / MCP_GATEWAY_ALLOWONLY_SCOPE_OWNER), which cobra's flag-parsing constraint can't see.
  • internal/cmd/flags_difc_test.go: new tests mirroring the existing TLS MarkFlagsRequiredTogether coverage — both flags together are rejected, either alone is accepted, and neither is accepted.

Example:

$ awmg --allowonly-scope-public --allowonly-scope-owner octocat
Error: if any flags in the group [allowonly-scope-public allowonly-scope-owner] are set none of the others can be; [allowonly-scope-owner allowonly-scope-public] were all set

Other suggestions from the review (e.g. Flag.Deprecated on CLI flags, a lookup-map refactor in completion.go) were called out as optional/low-priority with no urgent action needed, so they're left out of this change to keep it focused.

Copilot AI linked an issue Aug 17, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits August 17, 2026 20:18
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Review Go module spf13/cobra for usage improvements Use cobra's MarkFlagsMutuallyExclusive for AllowOnly scope flags Aug 17, 2026
Copilot AI requested a review from lpcox August 17, 2026 20:22
@lpcox
lpcox marked this pull request as ready for review August 18, 2026 04:42
Copilot AI balanced review requested due to automatic review settings August 18, 2026 04:42

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

Adds native Cobra validation for mutually exclusive AllowOnly scope flags.

Changes:

  • Marks public and owner scope flags as mutually exclusive.
  • Adds command-level validation tests.
Show a summary per file
File Description
internal/cmd/flags_difc.go Registers the Cobra flag constraint.
internal/cmd/flags_difc_test.go Adds scope-flag validation tests.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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

Comment thread internal/cmd/flags_difc.go Outdated
// MCP_GATEWAY_ALLOWONLY_SCOPE_PUBLIC and MCP_GATEWAY_ALLOWONLY_SCOPE_OWNER
// set) is still validated at runtime by config.BuildAllowOnlyPolicy via
// resolveGuardPolicyFromFlags.
cmd.MarkFlagsMutuallyExclusive("allowonly-scope-public", "allowonly-scope-owner")
Comment thread internal/cmd/flags_difc_test.go Outdated
Comment on lines +212 to +214
cmd.Flags().BoolVar(new(bool), "allowonly-scope-public", false, "Use public AllowOnly scope")
cmd.Flags().StringVar(new(string), "allowonly-scope-owner", "", "AllowOnly owner scope value")
cmd.MarkFlagsMutuallyExclusive("allowonly-scope-public", "allowonly-scope-owner")
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@lpcox

lpcox commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

@copilot Fix the codeql ci

Copilot AI commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Fix the codeql ci

The failing CodeQL jobs both stop during github/codeql-action/init@v4, before repository analysis: the repository-configured remote config github/internal-codeql@main:github-codeql-config.yml returns Not Found. This is a repository CodeQL configuration/access issue, not caused by this PR’s source changes; it needs the repository CodeQL configuration property or its access to be corrected.

@lpcox

lpcox commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Copilot AI commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix this failing ci check https://github.com/github/gh-aw-mcpg/actions/runs/32065441870/job/95496333438?pr=11408

Confirmed the specified job fails before analysis while loading the repository-level remote CodeQL config. github/internal-codeql@main:github-codeql-config.yml returns 404 (and is not accessible through the GitHub API), so this cannot be fixed by a PR file change. Restore/grant CodeQL access to that repository and file, or update/remove the repository’s CodeQL configuration property; then rerun the check.

@lpcox lpcox closed this Aug 18, 2026
@lpcox lpcox reopened this Aug 18, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@lpcox

lpcox commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

@copilot address review feedback

Copilot AI and others added 2 commits August 18, 2026 15:07
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>

Copilot AI commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot address review feedback

Addressed the review feedback in 7b3444e and bae11d0. The production registrar is now directly tested, valid CLI clearing of meaningful environment scope defaults is preserved, and empty environment values retain Cobra mutual-exclusion validation. make agent-finished passes; automated review and CodeQL found no issues.

@github-actions

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) all tools absent from catalog BLOCKED ⚠️
C CLI reads (list issues, get file) data returned ALLOWED
D CLI REST writes (reaction/star/issue/comment/file) gh unauthenticated (no GH_TOKEN) BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh unauthenticated (no GH_TOKEN) BLOCKED ⚠️

Overall: INCONCLUSIVE

⚠️ Part B gap: The github CLI catalog exposes only 23 read-only tools — all write tools (add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, create_pull_request) were absent. This confirms the gh-aw GITHUB_READ_ONLY=1 backend defense-in-depth, but does not independently confirm mcpg's own DIFC/guard enforcement layer (write tools never reached a write-capable backend).

⚠️ Parts D/E gap: gh is not authenticated (no GH_TOKEN in environment). All REST/GraphQL write attempts returned "GH_TOKEN not set" immediately — no HTTP call was made. Gateway enforcement at the proxy level could not be exercised for this runtime.

No writes leaked. All probes were either refused (tool-not-found or no-auth) or blocked before reaching GitHub.

Run: §32152954561

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

@github-actions

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 (issues/PRs/file/commits) data returned ALLOWED
B MCP writes (reaction/star/issue/comment/branch/file/PR) all tools absent from catalog BLOCKED ⚠️
C CLI reads (issues/file) data returned ALLOWED
D CLI REST writes (reaction/star/issue/comment/file) gh not authenticated BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh not authenticated BLOCKED ⚠️

Overall: INCONCLUSIVE

⚠️ Notes:

  • Part B: All 7 write tools are absent from the MCP tool catalog. The gateway backend runs with GITHUB_READ_ONLY=1, so write tools are never registered — this is gh-aw's defense-in-depth, not independent gateway DIFC enforcement evidence. No writes succeeded.
  • Parts D/E: gh CLI is not authenticated in this environment (gh auth status → not logged in). All REST and GraphQL write attempts were skipped; they cannot confirm the token-scope boundary for this run.
  • No writes leaked — result is INCONCLUSIVE (not FAIL) due to methodology gaps on the write-enforcement surfaces.

References: §32152954245

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

@github-actions

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 (issues/PRs/file/commits) data returned ALLOWED
B MCP writes (reaction/star/issue/comment/branch/file/PR) all tools absent from catalog BLOCKED ⚠️
C CLI reads (list_issues, get_file_contents) data returned ALLOWED
D CLI REST writes (reaction/star/issue/comment/file) 401 Bad credentials BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) 401 Bad credentials BLOCKED ⚠️

Overall: INCONCLUSIVE

⚠️ Part B: All 7 write tools (add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, create_pull_request) were absent from the MCP tool catalog (only 23 read-only tools exposed: get_*, list_*, search_*, issue_read, pull_request_read). This confirms the backend's GITHUB_READ_ONLY=1 defense-in-depth, but does not independently exercise the gateway's DIFC/guard write-blocking layer — write calls never reached the gateway enforcement path. INCONCLUSIVE per methodology.

⚠️ Parts D & E: The gh CLI token (GH_TOKEN) is invalid in this environment (Bad credentials / HTTP 401 on all calls). Cannot validate GitHub token-scope boundary for REST/GraphQL writes. All D/E rows are INCONCLUSIVE — unauthenticated 401s are not evidence of write blocking.

No write leaked. No data was created or modified.

Run: §32152954327

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

@lpcox
lpcox merged commit 80ee85a into main Aug 18, 2026
35 of 36 checks passed
@lpcox
lpcox deleted the copilot/go-fan-review-spf13-cobra branch August 18, 2026 17:05
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.

[go-fan] Go Module Review: spf13/cobra

3 participants