Skip to content

feat(gh): refuse an agent's review of a pending deployment #7534

Done

Description

@dan-petty

Problem

ADR 0041 (proposed in #7497) gates each apply of the GitHub settings with environment github-settings of dan-petty/infra, whose required reviewer is the owner. Agents use the gh login of the owner. CONST_GH_API_PROTECTED_ROUTES (src/devops_cli/config/constants.py) refuses the settings routes to an agent caller, but not POST repos/{owner}/{repo}/actions/runs/{run_id}/pending_deployments, the review of a pending deployment. So devops gh api lets an agent approve an apply in place of the owner.

Change

Add the review routes of a deployment to CONST_GH_API_PROTECTED_ROUTES: POST repos/{owner}/{repo}/actions/runs/{run_id}/pending_deployments and POST repos/{owner}/{repo}/actions/runs/{run_id}/deployment_protection_rule.

Existing tool considered

The existing guard require_gh_api_access of src/devops_cli/github/api_guard.py. This item adds two routes to its table.

Done when

  • A test of tests/github/test_gh_api_agent_guard.py shows that an agent caller gets a refusal and sends no request for each route, and that a person caller passes.

Dependencies

Source

Source: #7497

Proposed design

Problem statement

ADR 0041 (proposed in #7497) has the owner review each apply of the GitHub settings through environment github-settings of dan-petty/infra. Agents use the gh login of the owner, so they could send the review of that deployment themselves. CONST_GH_API_PROTECTED_ROUTES refuses the settings routes to an agent caller, but it holds neither route that records a deployment review. This item adds the two review routes to the table under their own route class, names that class in the help text and the documentation, and tests the refusal and the pass of a person.

Acceptance criteria

Requirement: Pending deployment review refused to an agent

The guard SHALL refuse POST repos/{owner}/{repo}/actions/runs/{run_id}/pending_deployments to an agent caller.

Scenario: Agent reviews a pending deployment

  • WHEN an agent caller calls require_gh_api_access with the method POST and the path repos/dan-petty/infra/actions/runs/241/pending_deployments
  • THEN the call raises GitHubApiAccessRefusedError, its route_class is deployment review, its details["pattern"] is repos/{owner}/{repo}/actions/runs/{run_id}/pending_deployments, and no request is sent

Requirement: Custom protection rule review refused to an agent

The guard SHALL refuse POST repos/{owner}/{repo}/actions/runs/{run_id}/deployment_protection_rule to an agent caller.

Scenario: Agent reviews a custom deployment protection rule

  • WHEN an agent caller calls require_gh_api_access with the method POST and the path repos/dan-petty/infra/actions/runs/241/deployment_protection_rule
  • THEN the call raises GitHubApiAccessRefusedError, its route_class is deployment review, its details["pattern"] is repos/{owner}/{repo}/actions/runs/{run_id}/deployment_protection_rule, and no request is sent

Requirement: The run id does not change the refusal

The guard SHALL match each review route by its path template for any run id.

Scenario: Another run id

  • WHEN an agent caller calls require_gh_api_access with the method POST and the path repos/dan-petty/infra/actions/runs/999999/pending_deployments
  • THEN the call raises GitHubApiAccessRefusedError with the pattern repos/{owner}/{repo}/actions/runs/{run_id}/pending_deployments

Requirement: Person caller passes both review routes

The guard SHALL let a person caller send either review route.

Scenario: Owner approves a pending deployment

  • WHEN a person caller calls require_gh_api_access with the method POST and the path of either review route
  • THEN each call returns None and raises no refusal

Requirement: The command sends no request for a review route

The devops gh api command SHALL send no request when an agent caller targets either review route.

Scenario: Agent command refuses before dispatch

  • WHEN a test runs devops gh api -X POST repos/dan-petty/infra/actions/runs/241/pending_deployments as an agent caller against the fake gh edge
  • THEN the command exits non-zero with the refusal naming deployment review, and the fake edge records no call

Requirement: Documentation names the deployment review class

The help text, the generated docs/commands/gh.md and docs/CLI_REFERENCE.md, and SECURITY.md SHALL name the deployment review class and its two routes.

Scenario: Documentation names the class

  • WHEN a documentation test reads docs/commands/gh.md, docs/CLI_REFERENCE.md and SECURITY.md
  • THEN each file names deployment review and both the pending_deployments and deployment_protection_rule routes

Existing Tool Considered

No alternatives check has run. No open tool covers this need: the route-level refusal of an agent's devops gh api call lives in the project's own guard require_gh_api_access (src/devops_cli/github/api_guard.py:84), which reads CONST_GH_API_PROTECTED_ROUTES (src/devops_cli/config/constants.py:3184). The change adds two entries to that table, the class name in the help text and the docs, and tests: about 10 lines of data and 6 test cases, an estimated 20k tokens and under one hour of elapsed time to build, with no upkeep beyond the table. A replacement guard would cost more tokens and time than two table entries.

Key questions

  • Which GitHub REST routes record the review of a deployment of a workflow run?: The two POST routes that the Actions REST reference documents for a workflow run: repos/{owner}/{repo}/actions/runs/{run_id}/pending_deployments reviews the pending deployments of a run, and repos/{owner}/{repo}/actions/runs/{run_id}/deployment_protection_rule reviews its custom deployment protection rules. The guard protects exactly these two, with the class deployment review. (best practice) [sources: src/devops_cli/config/constants.py:3180, src/devops_cli/github/api_guard.py:63]
    • Chosen: The two POST review routes. They are the endpoints that record a review of a pending deployment or a custom protection rule, and the table names the narrowest protected area (src/devops_cli/config/constants.py:3182).
    • Rejected: Every POST under repos/{owner}/{repo}/actions/runs/{run_id}/**. It would also refuse rerun, rerun-failed-jobs, cancel and approve requests that an agent may legitimately send, and the table's rule is the narrowest protected area (src/devops_cli/config/constants.py:3180).
    • Rejected: No change; rely on the environment gate. Agents use the owner's gh login, so an agent could approve the very deployment that the gate holds for the owner; the guard is the code that refuses it (src/devops_cli/github/api_guard.py:84).
  • Which code refuses a protected route to an agent caller, and where does the table of routes live?: require_gh_api_access in src/devops_cli/github/api_guard.py:84 refuses a protected route to an agent caller, through classify_protected_route at src/devops_cli/github/api_guard.py:63. CONST_GH_API_PROTECTED_ROUTES in src/devops_cli/config/constants.py:3184 holds the routes. tests/github/test_gh_api_agent_guard.py tests the guard. [sources: src/devops_cli/github/api_guard.py:84, src/devops_cli/github/api_guard.py:63, src/devops_cli/config/constants.py:3184, tests/github/test_gh_api_agent_guard.py:47]
  • Which route class does the refusal name, and what else changes with it?: A new class deployment review. The help text of devops gh api (src/devops_cli/lang/en/help.py:1473) and SECURITY.md:58 list the protected classes, so the change names the new class there, regenerates docs/commands/gh.md and docs/CLI_REFERENCE.md with uv run devops docs generate, and keeps tests/commands/test_gh_cmd.py on the no-request guarantee. (best practice) [sources: src/devops_cli/config/constants.py:3182, src/devops_cli/lang/en/help.py:1473, SECURITY.md:58, docs/commands/gh.md:9]
    • Chosen: A new deployment review class, with the help and the documentation. The refusal names the narrowest protected area (src/devops_cli/config/constants.py:3182), and the help text, the generated docs and SECURITY.md:58 enumerate the classes, so they would be stale otherwise.
    • Rejected: Reuse the repository settings class. A deployment review is not a write of a repository setting, and the refusal would send the owner to the wrong route class.
    • Rejected: A new class with no documentation change. The help text, docs/commands/gh.md, docs/CLI_REFERENCE.md and SECURITY.md:58 would omit the class that the refusal names.
  • Which callers do the two review routes refuse?: The two routes refuse an agent caller only. A person caller passes, because the owner must review the deployment. (best practice) [sources: src/devops_cli/github/api_guard.py:87, tests/github/test_gh_api_agent_guard.py:157]
    • Chosen: An agent caller only. The guard returns for every caller that is_agent_caller() does not report (src/devops_cli/github/api_guard.py:87), and the environment gate needs the review of the owner.
    • Rejected: Every caller. It stops the owner from approving the deployment, which the gate requires.
  • Where do the tests of the two routes go?: The classification and refusal tests go in tests/github/test_gh_api_agent_guard.py, beside the tests of the settings routes. The no-request test of the command goes in tests/commands/test_gh_cmd.py, which SECURITY.md:58 names for that guarantee and which holds the fake gh edge. (best practice) [sources: tests/github/test_gh_api_agent_guard.py:16, tests/commands/test_gh_cmd.py, SECURITY.md:58]
    • Chosen: Extend both test modules. The guard module holds the route table cases and the caller fixtures, and the command module holds the fake gh edge that shows no request is sent.
    • Rejected: A new test module. It copies the fake edge, the route table cases and the caller fixtures of the two existing modules.
  • Does this change wait on ADR 0041 and refactor(repos): replace the onboard settings rows with OpenTofu #7497?: No. ADR 0041 is still proposed (docs/adr/0041-opentofu-holds-the-repository-settings.md:2), and the change adds two entries to a table and a test that no file of refactor(repos): replace the onboard settings rows with OpenTofu #7497 touches (openspec/changes/7497-onboard-settings-opentofu/tasks.md). The body names ADR 0041 and refactor(repos): replace the onboard settings rows with OpenTofu #7497 as the reason of the gate, and the first apply of dan-petty/infra#241 waits on this item, not the reverse. (best practice) [sources: src/devops_cli/config/constants.py:3184, src/devops_cli/github/api_guard.py:84, docs/adr/0041-opentofu-holds-the-repository-settings.md:2, openspec/changes/7497-onboard-settings-opentofu/tasks.md]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-28: none.
Tool: none found.
Reason: Searches found no maintained tool that refuses specific GitHub REST routes to an agent caller; the route table is the project's own guard in devops-cli, so the change is two entries plus tests.

Lacks:

  • No external tool holds a table of refused GitHub API routes
  • No generic policy proxy knows the deployment review routes
  • No tool distinguishes an agent caller from a person caller here
  • No tool raises the refusal before the request is sent

Activity

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

    @dan-petty
    OwnerAuthor
    • Priority: A live security gap lets an agent bypass the required owner reviewer on infrastructure applies.
    • Related: feat(gh): refuse agent writes to repo and org settings routes #5316, which asks for a different change. Both add routes to CONST_GH_API_PROTECTED_ROUTES for agent refusal, but #5316 covers settings and transfer routes while the candidate adds deployment review routes.
  3. added
    priority/p1-high
    on Nov 28, 2026
  4. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Next step: the alternatives check records a verdict. See the section Proposed design of the body.

  5. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (6)

    Tools considered:

    Searches run:

    • GitHub Actions deployment protection rule require reviewer approve pending deployment API, results: 5
    • open source proxy guard GitHub API route allowlist deny agent approval deployment, results: 5
    • mitmproxy addon block GitHub API endpoint approval policy agent, results: 5
    • octo-sts GitHub App token scoping deployment approval restriction, results: 5
    • GitHub REST API pending_deployments review endpoint documentation, results: 5
    • policy engine allowlist HTTP requests to GitHub API enforce agent permissions, results: 5

    Sources:

  6. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/new
    status/in-progress
    on Nov 28, 2026
  7. removed
    status/in-review
    owner/agent
    on Nov 28, 2026
  8. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-28 17:56 UTC

  9. added a commit that references this issue on Nov 28, 2026
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/lowpriority/p1-highscope/ghsource/agenttype/featurevalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions