Skip to content

fix(github): keep the hooks permission out of the runner Job token #5058

Closed

Description

@dan-petty

Problem Description

Since #5017 (PR #5045, v0.118.0), each installation token of the GitHub App asks for repository_hooks: read. The runner Job tokens get it too. Only the metrics row of the Service reads hooks (src/devops_cli/github/hook_deliveries.py, called from src/devops_cli/roadmap/run.py). No step of a runner Job reads a hook.

A step of a runner Job runs model-written shell commands, and the token is in the environment of each git or gh child (k8s/README.md, Guarantees). So a prompt injection in a runner Job can now read the configuration of each hook (its URL hooks.<domain>) and the deliveries of each hook, with their payloads and response headers. ADR 0015 says: "A later feature that needs more permissions asks for a token with its own set."

Reproduction Steps

  1. src/devops_cli/config/constants.py: CONST_GITHUB_APP_TOKEN_PERMISSIONS holds "repository_hooks": "read".
  2. src/devops_cli/github/app_installation.py, _exchange: each token asks for that one set. A runner Job (service.github_app.token_repository set) only adds repositories.
  3. tests/github/test_github_app_identity.py, test_a_job_token_names_only_its_repository: the runner Job token asks for repository_hooks: read.

Expected vs Actual Behavior

Expected: a token with service.github_app.token_repository set (a runner Job) asks for the permissions of the roadmap jobs only. The token of a process with no token repository (the Service) also asks for repository_hooks: read, for the metrics row.

Actual: each token asks for repository_hooks: read.

Environment Diagnostics

devops-cli v0.118.0, the roadmap Service and the runner Jobs in the cluster.

Logs, Traces, or Terminal Output

Found in the review of PR #5045.

Source: #5045

Proposed design

Problem statement

Since v0.118.0, each GitHub App installation token asks for repository_hooks: read. Runner Job tokens get that permission too. A runner Job runs model-written shell commands, so a prompt injection can read hook URLs and deliveries. Only the Service metrics row reads hooks. The runner Job token must ask only for the roadmap job permissions.

Acceptance criteria

Requirement: Runner Job token omits hooks permission

A token minted for a process with service.github_app.token_repository set SHALL ask for CONST_GITHUB_APP_TOKEN_PERMISSIONS and SHALL NOT ask for repository_hooks.

Scenario: Runner Job token body

  • WHEN The fake GitHub App receives an exchange from a process whose service.github_app.token_repository is example-org/app.
  • THEN The request body's permissions equals CONST_GITHUB_APP_TOKEN_PERMISSIONS, has no repository_hooks key, and the body holds repositories: ["app"].

Requirement: Service token keeps hooks read

A token minted for a process with no service.github_app.token_repository SHALL ask for CONST_GITHUB_APP_SERVICE_TOKEN_PERMISSIONS, which includes repository_hooks: read.

Scenario: Service token body

  • WHEN The fake GitHub App receives an exchange from a process with no token repository.
  • THEN The request body's permissions equals CONST_GITHUB_APP_SERVICE_TOKEN_PERMISSIONS and holds repository_hooks: read.

Requirement: Permission maps are separate

CONST_GITHUB_APP_TOKEN_PERMISSIONS SHALL hold only the roadmap job permissions, and CONST_GITHUB_APP_SERVICE_TOKEN_PERMISSIONS SHALL extend it with repository_hooks: read.

Scenario: Permission maps

  • WHEN A test imports both constants from devops_cli.config.constants.
  • THEN The base map has no repository_hooks key and the service map equals the base map plus repository_hooks: read.

Requirement: Runner Job error names its permissions

The HTTP 422 error of a runner Job SHALL name the permissions of CONST_GITHUB_APP_TOKEN_PERMISSIONS and SHALL NOT name repository_hooks.

Scenario: Runner Job 422 error

  • WHEN The fake GitHub App returns HTTP 422 for a process whose service.github_app.token_repository is set.
  • THEN The raised GitHubUnauthenticatedError message lists the base permissions and does not contain repository_hooks.

Requirement: ADR records the split

ADR 0015 SHALL name the base permission map for roadmap jobs and the service permission map for the Service, with repository_hooks: read only in the service map.

Scenario: ADR text

  • WHEN A test reads docs/adr/0015-roadmap-jobs-act-as-a-github-app-on-the-personal-account.md.
  • THEN The text names CONST_GITHUB_APP_TOKEN_PERMISSIONS and CONST_GITHUB_APP_SERVICE_TOKEN_PERMISSIONS and states that repository_hooks: read is in the service map.

Existing Tool Considered

No alternatives check has run. No open, maintained tool or library covers this need: the change is to devops-cli's own GitHub App token request. Building cost is about 6,000 tokens to build, 2,000 tokens to keep, 1,000 tokens to fix, and 1 to 2 hours elapsed.

Key questions

  • Which permissions does a runner Job installation token ask for?: It asks for CONST_GITHUB_APP_TOKEN_PERMISSIONS only: issues, pull_requests, contents and workflows write, and checks, actions and metadata read. It asks for no repository_hooks permission. (best practice) [sources: docs/adr/0015-roadmap-jobs-act-as-a-github-app-on-the-personal-account.md:21, src/devops_cli/config/constants.py:1488, src/devops_cli/github/app_installation.py:187]
    • Rejected: One shared permission map with a conditional removal. The removal branch hides the security boundary and lets a later edit put hooks back into the runner token.
    • Chosen: Two permission maps selected by token_repository. ADR 0015 says a feature that needs more permissions asks with its own set, and each map stays auditable.
    • Rejected: A new setting for token permissions. It adds configuration for a fixed boundary and lets a deployment weaken the runner token.
  • How does the Service token keep repository_hooks: read for the metrics row?: CONST_GITHUB_APP_SERVICE_TOKEN_PERMISSIONS extends the base map with repository_hooks: read. _exchange selects it when service.github_app.token_repository is unset. (best practice) [sources: src/devops_cli/github/hook_deliveries.py, src/devops_cli/roadmap/run.py, src/devops_cli/config/constants.py:1488, src/devops_cli/github/app_installation.py:187]
    • Rejected: Add hooks to the base map and remove it for runner Jobs. The runner request would still carry the permission in code and a later edit can restore the leak.
    • Chosen: Add a service-only map that extends the base map. The Service keeps the read and the runner Job never asks for it.
    • Rejected: Use a second GitHub App for the metrics row. It adds a second identity and secret for one read, beyond this fix.
  • What should a 422 error name when the token's permission set is not granted?: It names the permissions of the set that the token asked for: the base set for a runner Job and the service set for the Service. A runner Job error must not name repository_hooks. (best practice) [sources: src/devops_cli/github/app_installation.py, tests/github/test_github_app_identity.py]
    • Rejected: Always name the service set. It tells a runner Job to ask for a permission that the Job must not carry.
    • Chosen: Name the selected set. The error tells the operator what to grant for that token only.
  • Should ADR 0015 record the two permission sets?: Yes. Amend ADR 0015 to name CONST_GITHUB_APP_TOKEN_PERMISSIONS for roadmap jobs and CONST_GITHUB_APP_SERVICE_TOKEN_PERMISSIONS for the Service, with repository_hooks: read only in the service set. (best practice) [sources: docs/adr/0015-roadmap-jobs-act-as-a-github-app-on-the-personal-account.md:21]
    • Rejected: Leave ADR 0015 unchanged. The ADR still implies one set covers every process and hides why the Service asks for hooks.
    • Chosen: Amend ADR 0015. The ADR is the recorded decision that the issue cites, and it should state the split.
  • Which code reads webhook hooks?: Only the metrics row of the Service reads hooks. read_delivery_failures in hook_deliveries.py calls the hooks and deliveries endpoints, and _run_metrics_adapter in roadmap/run.py calls it. No runner Job step reads a hook. [sources: src/devops_cli/github/hook_deliveries.py, src/devops_cli/roadmap/run.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    scope/github
    status/new
    value/high
    effort/low
    on Nov 12, 2026
  2. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor
  3. added
    priority/p1-high
    owner/agent
    on Nov 12, 2026
  4. added
    status/ready
    and removed
    owner/agent
    status/new
    on Nov 12, 2026
  5. devops-cli-service commented on Nov 12, 2026

    @devops-cli-service
    Contributor

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

  6. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 12, 2026
  7. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    Scope note: #4932 merged after this issue was filed and added administration: read to the same shared set, for the traffic read of the metrics row (#4757). No runner Job reads the traffic either, so PR #5064 keeps both repository_hooks: read and administration: read out of the runner Job token. The Service token keeps both.

  8. removed
    status/in-review
    on Nov 12, 2026
  9. devops-cli-service commented on Nov 12, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-12 15:46 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/lowpriority/p1-highscope/githubsource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions