Skip to content

feat(gh): refuse agent writes to repo and org settings routes #5316

Done

Description

@dan-petty

Problem or Motivation

No code refuses an agent POST, PATCH, PUT or DELETE through devops gh api to settings, ruleset, secret, org or transfer routes. Agents share the owner token.

Order 2 of the plan in #5311. The owner approved the plan on 2026-11-13.

Proposed Solution & Architectural Design

Add a route table in constants and a refusal for core.caller.is_agent_caller. The message names the owner step. The table covers POST repos/{o}/{r}/transfer. --dry-run still prints the request. Issue, PR, label and dispatch routes stay open.

Target Subsystem

SDLC, Git & PR Governance

Existing Tool Considered

No open tool applies. This is a refusal in the existing wrapper, with a route table in constants.

Cost: Build: about 600k tokens, 1 day, test first. Keep: about 20k tokens a month. Fix: about 100k tokens.

Acceptance Criteria

  • Tests for each route class show these results: an agent is refused, a person passes, the dry run prints and sends nothing, and open routes pass.
  • docs/commands/gh.md and SECURITY.md are updated.

Dependencies

No blocker. Part of #5311.

Source: #5311

Alternatives check of 2026-11-22: none.
Tool: none found.
Reason: Searches for a policy gate, API allowlist proxy or route-level guard over GitHub writes returned only unrelated documentation pages; no external tool classifies these routes or refuses agent callers inside the existing wrapper.

Lacks:

  • Route table for settings, rulesets, secrets, org and transfer endpoints
  • Refusal naming the matched route and the owner step
  • Caller check through core.caller.is_agent_caller
  • Dry run that prints the request and sends nothing

Proposed design

Problem statement

Agents share the owner token and can write repository and organization settings through devops gh api. No guard refuses these writes. This change adds a protected route table and refuses protected writes from agent callers. It leaves issue, pull request, label and workflow dispatch routes open.

Acceptance criteria

Requirement: Protected route table

The gh api guard SHALL classify POST, PATCH, PUT and DELETE endpoints under repository settings, rulesets, secrets, organization settings and repository transfer as protected.

Scenario: Protected route classes

  • WHEN A test passes one representative endpoint from each protected class to the route table.
  • THEN The table returns protected for each endpoint.

Requirement: Open routes

The gh api guard SHALL classify issue, pull request, label and workflow dispatch endpoints as open for agent callers.

Scenario: Agent open route

  • WHEN A test checks an agent write to POST /repos/o/r/issues, POST /repos/o/r/pulls, POST /repos/o/r/labels and POST /repos/o/r/actions/workflows/1/dispatches.
  • THEN The guard allows each request.

Requirement: Agent protected write refused

The gh api command SHALL refuse a protected write when core.caller.is_agent_caller is true.

Scenario: Agent protected write

  • WHEN A test invokes the guard with agent caller true and a protected method and endpoint.
  • THEN The guard returns a refusal that names the matched route and the owner step, and the request sender is not called.

Requirement: Person protected write allowed

The gh api command SHALL allow a protected write when core.caller.is_agent_caller is false.

Scenario: Person protected write

  • WHEN A test invokes the guard with agent caller false and a protected method and endpoint.
  • THEN The guard returns allow and the request sender is called once.

Requirement: Dry run prints protected request

The gh api command SHALL print the request and send no request for a protected route when --dry-run is set.

Scenario: Agent dry run protected write

  • WHEN A test invokes the command with agent caller true, a protected method and endpoint, and --dry-run.
  • THEN The output shows the method and endpoint, and the request sender is not called.

Requirement: Route normalization

The route table SHALL match a protected endpoint after it strips a leading slash and a query string.

Scenario: Protected endpoint with query string

  • WHEN A test passes PUT /repos/o/r/rulesets/1?force=true to the route table.
  • THEN The table returns protected.

Requirement: Documentation states refusal

The documentation SHALL name the protected route classes and the refusal behavior.

Scenario: Documentation update

  • WHEN A documentation test reads docs/commands/gh.md and SECURITY.md.
  • THEN Each file states the protected route classes and that an agent caller is refused.

Existing Tool Considered

No open, maintained tool covers the need. The alternatives check of 2026-11-16 found no policy gate or API allowlist proxy for these routes. The change builds a route table and a refusal in the existing wrapper. Cost: build about 600k tokens, 1 day; keep about 20k tokens a month; fix about 100k tokens.

Key questions

  • What does devops gh api --dry-run do?: It previews the execution plan and makes no external change. It sends no request. [sources: docs/commands/gh.md]
  • Should --dry-run print a protected request from an agent or refuse it?: It prints the request and sends nothing. The refusal applies only to a real write. (best practice) [sources: docs/commands/gh.md]
    • Chosen: Dry-run prints only. The dry-run option previews the request and makes no external change. The issue requires the print.
    • Rejected: Dry-run refuses. It hides the request that the agent must show the owner. It adds no safety because no request is sent.
  • Which routes stay open to agent callers?: Issue, pull request, label and workflow dispatch routes stay open. The refusal covers only settings, rulesets, secrets, organization and transfer routes. (best practice) [sources: docs/commands/gh.md]
    • Chosen: Keep normal work routes open. Agents need issue, pull request, label and dispatch writes. The issue names these routes as open.
    • Rejected: Refuse every write. It blocks normal roadmap work and goes beyond the issue.
  • How should the route table match an endpoint?: Strip a leading slash and a query string. Match the path segments against placeholders. Match the method in uppercase. (best practice) [sources: docs/commands/gh.md]
    • Chosen: Normalized path match. GitHub endpoints can carry a leading slash or query string. An exact string match misses them.
    • Rejected: Exact string match. It misses equivalent endpoints and is brittle.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    on Nov 13, 2026
  2. added
    type/feature
    scope/gh
    status/new
    value/high
    effort/medium
    on Nov 13, 2026
  3. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor
  4. added
    priority/p2-medium
    on Nov 13, 2026
  5. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: Searches for a policy gate, API allowlist proxy, or guard that refuses writes to GitHub settings/ruleset/secret/org/transfer routes returned no open, maintained tool — only unrelated pages. The issue needs a route-table refusal inside the existing devops gh api wrapper (agent refused, person passes, dry-run prints only), which no general tool covers.

    Tool: none found

    Lacks:

    • A route table that classifies settings, ruleset, secret, org and transfer routes as refused for agent callers
    • A refusal keyed on core.caller.is_agent_caller inside the existing gh api wrapper
    • Dry-run that still prints the request but sends nothing
    • Keeping issue, PR, label and dispatch routes open

    Searches run:

    • policy gate for GitHub CLI api calls refuse sensitive routes, results: 5
    • tool to block writes to GitHub repository settings and organization routes by agents, results: 5
    • GitHub MCP server read-only mode prevent writes to repository settings, results: 5
    • block dangerous GitHub API endpoints guard agent writes rulesets secrets transfer, results: 5
    • proxy GitHub API enforce policy allowlist endpoints, results: 5
    • Open Policy Agent GitHub API write restrictions, results: 5
    • OpenTofu GitHub provider manage repository settings as code, results: 5
    • "gh api" wrapper guard refuse destructive endpoints agent, results: 5
    • github cli extension restrict api calls to allowlist routes, results: 5

    Checked on 2026-11-16. A person decides what this means for the item. The check changes no label and closes no issue.

  6. added
    status/ready
    and removed
    status/new
    on Nov 17, 2026
  7. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at e6f5718 (see proposed design in issue body).

  8. added
    status/in-progress
    and removed
    status/ready
    on Nov 25, 2026
  9. added a commit that references this issue on Nov 25, 2026
    1b50641
  10. added
    status/in-review
    and removed
    status/in-progress
    on Nov 25, 2026
  11. removed
    status/in-review
    on Nov 25, 2026
  12. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-25 07:20 UTC

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

    effort/mediumpriority/p2-mediumscope/ghsource/agenttype/featurevalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions