Skip to content

feat(github): check the App grant at start and record the App identity #5252

Open

Description

@dan-petty

Problem or Motivation

Child 13 of the ADR modernization (#5233). Decision (owner decision 3). It waits until the owner has changed the App settings.

The review of each record that this item changes:

  • ADR 0015 (amend now; supersede after owner decision 3): The App identity holds. The six amendment notes become Status History, and the permission sets live in constants.py and the github-app-identity spec. The cut of the grant and the App webhook need the owner.

Proposed Solution & Architectural Design

At Service start, a JWT read of GET /app/installations/{id} compares the granted permissions with the two token sets and names each missing permission. A new record supersedes 0015: least privilege for each token, the two sets in constants.py and the spec, the App webhook with one secret, and the key never in Actions secrets. 22 citation lines move. #4417 and #4560 stay separate PRs.

Owner decision 3 of 2026-11-12: All three GitHub settings, in this order: (1) cut the App grant to the 9 permissions that the code asks for; (2) after #4417, turn on the App webhook (Issues only) and delete the 7 repository hooks in the same hour; (3) bind the 3 required checks of the ruleset to the GitHub Actions app.

Rules of the ADR process (docs/adr/README.md, #5225) that apply:

  • Supersession: the new record sets 'supersedes', and the same PR sets status and 'superseded-by' on the old record. The test fails on a link that goes only one way. The new record restates each rule and each rejected option that still holds, because the alternatives check drops superseded records. Never amend a superseded record. After a third amendment, or when a body contradicts the code, the next change is a supersession.
  • Length: the body of a new record has 1,000 words or fewer, its title has 10 words or fewer, and its slug has 60 characters or fewer. Designs, catalogues, row tables, cutover plans, caps and measurements go to OpenSpec changes and specs, to settings or to docs, with a link under More Information.
  • Use one Considered Options section. Each bullet ends with 'chosen.', 'rejected, because .' or 'deferred until .'. 'Deferred' does not match the rejected regex (adr.py:49), so the check stops refusing on a premise that changed. Each record has a Confirmation section that names its test, CI row or metric, and an optional tracker key.
  • Code, tests and workflows cite the record in force. A test fails on a citation of a superseded record in src/, tests/ and .github/ (archived changes and CHANGELOG.md are history). Each superseding PR moves the citations of the records that it supersedes. Rename sweeps do not change docs/adr/.
  • Merge ADR changes in batches. Each change of the ADR set changes adr_hash (alternatives.py:634-644, 1006) and makes every checked item due again. So all pure status changes go in docs(adr): add MADR front matter, a Status History and the ADR rules #5225, and the record PRs merge one at a time in the planned order.
  • Keep the fix(roadmap): the ADRs in force fill the alternatives ADR budget #5049 budget test. A new record must fit in the tokens that the records it supersedes free. Short option bullets keep the budget, because options are 6,883 of the 8,464 tokens today.

The owner merges this pull request.

Target Subsystem

src/devops_cli/server/, src/devops_cli/config/constants.py, docs/adr/.

Existing Tool Considered

GitHub REST GET /app/installations/{installation_id} with the App JWT, through gidgethub (in use). No new tool.

Acceptance Criteria

Dependencies

Owner decision 3 of 2026-11-12 is made. The owner changes the App settings (tracker owner steps 3 and 4) before this item merges.

Related

Source: #5233

Alternatives check of 2026-11-22: in-use.
The repository already uses this tool.
Tool: gidgethub/gidgethub (https://github.com/gidgethub/gidgethub), Apache-2.0, last activity 2026-11-20, maintained.
Reason: The searches found only gidgethub, the GitHub transport that ADR 0006 chose and the issue names as in use; it sends the signed App JWT installation read, but the permission comparison, error naming and fail-start logic are the project's own code.

Covers:

  • Signs the App JWT for the installation read
  • Sends GET /app/installations/{id} over the checked transport
  • Async GitHub client already used for the token exchange

Lacks:

  • Comparison of the granted permissions with the two constants
  • Naming each missing or insufficient permission
  • Stopping Service start with status 1
  • ADR 0015 supersession and citation move

Proposed design

Problem statement

The Service starts without a check that its GitHub App installation grants the permissions that its two token sets need. A missing permission appears only when a later token request fails. ADR 0015 is six amendments old, and the permission sets now live in constants.py and the github-app-identity spec. The change adds a start-up grant read, records the App identity in a new ADR that supersedes 0015, and moves the citations to the new record.

Acceptance criteria

Requirement: Start-up App grant check

The Service SHALL read GET /app/installations/{installation_id} with the App JWT at start and SHALL compare the granted permissions with the permissions that CONST_GITHUB_APP_TOKEN_PERMISSIONS and CONST_GITHUB_APP_METRICS_TOKEN_PERMISSIONS ask for.

Scenario: Missing metrics permission

  • WHEN A test gives the start-up check a recorded GET /app/installations/42 answer whose permissions lack administration: read.
  • THEN The check raises ValueError with a message that names administration, and the Service start exits with status 1.

Requirement: Grant level comparison

The start-up check SHALL name each permission whose granted level is below the level that the two constants ask for.

Scenario: Read grant where write is required

  • WHEN A test gives the check a recorded answer that grants contents: read while the constants ask for contents: write.
  • THEN The error message names contents.

Requirement: Failed installation read stops start

A refused or failed GET /app/installations/{installation_id} SHALL stop the Service start and SHALL name the request path and the status, without the private key.

Scenario: GitHub refuses the JWT read

  • WHEN A test gives the check a recorded HTTP 401 answer for the installation read.
  • THEN The check raises ValueError whose message holds /app/installations/42 and 401, and does not hold the private key.

Requirement: Permission sets from constants

The start-up check SHALL take both permission sets from src/devops_cli/config/constants.py and SHALL ask for no permission outside their union.

Scenario: Union of the two sets

  • WHEN A test compares the required permissions of the check with the merged CONST_GITHUB_APP_TOKEN_PERMISSIONS and CONST_GITHUB_APP_METRICS_TOKEN_PERMISSIONS.
  • THEN The two mappings are equal.

Requirement: ADR 0015 supersession

A new ADR SHALL supersede ADR 0015, and the same change SHALL set status: superseded and superseded-by on ADR 0015 and add its Superseded by line.

Scenario: Two-way supersession link

  • WHEN uv run devops ci test tests/invariants/test_adr_records.py runs on the changed tree.
  • THEN The command reports no problem: the new record names ADR 0015, ADR 0015 names the new record, and both records keep the front matter, body-hash and length rules.

Requirement: Restated options and confirmation

The new ADR SHALL restate each rule and each rejected option of ADR 0015 that stays in force in one Considered Options section, with each bullet ending in chosen., rejected, because <reason>. or deferred until <condition>., and SHALL name its test in a Confirmation section.

Scenario: Restated options pass the record rules

  • WHEN A test reads the new ADR and compares its Considered Options bullets with the rejected options of ADR 0015.
  • THEN The test finds each rejected option of ADR 0015 and each bullet ends in one of the three allowed forms, and the Confirmation section names a test.

Requirement: Citation move

The change SHALL move every citation of ADR 0015 in src/, tests/ and .github/ to the new record.

Scenario: No stale citation

  • WHEN uv run devops ci test tests/invariants/test_adr_superseded_citations.py runs on the changed tree.
  • THEN The command passes: no file in src/, tests/ or .github/ cites ADR 0015.

Requirement: ADR index and token cap

The new ADR SHALL fit in the tokens that ADR 0015 frees, and the ADR index SHALL list it.

Scenario: Index and token cap pass

  • WHEN uv run devops ci test tests/invariants/test_adr_records.py tests/roadmap/test_roadmap_adr.py and uv run devops docs check run on the changed tree.
  • THEN Both commands pass: the index lists the new record, no generated document is stale, and the token cap test accepts the new record.

Existing Tool Considered

gidgethub (https://github.com/gidgethub/gidgethub), Apache-2.0, last activity 2026-09-25, maintained: the alternatives check in the issue body gives the verdict in-use and records what it covers and lacks. gidgethub signs the App JWT and sends GET /app/installations/{installation_id}. The project adds the comparison of the granted permissions with the two token sets and the naming of each missing or insufficient permission in src/devops_cli/server/ and src/devops_cli/config/constants.py. The project also adds the ADR supersession and the citation move in docs/adr/. Cost to build and test the comparison: about 20,000 tokens and about 2 hours. Cost to keep: about 1,000 tokens at each change of a permission set. A wrong level fails the named start-up test.

Key questions

  • Which client sends the App JWT read of GET /app/installations/{id}?: gidgethub, through GitHubAPI with app_id and private_key. ADR 0006 makes it the GitHub transport. (best practice) [sources: docs/adr/0006-github-session-requests-go-through-gidgethub.md, src/devops_cli/github/app_installation.py]
    • Chosen: gidgethub. ADR 0006 makes it the transport, and it already signs the App JWT for the token exchange.
    • Rejected: A new direct HTTP client. It adds a second transport and a second auth path with no new capability.
    • Rejected: PyGithub. It adds a dependency that no code uses and a second GitHub client.
  • Does a missing permission stop the Service start or only log a warning?: It stops the start and names each missing or insufficient permission. (best practice) [sources: openspec/specs/github-app-identity/spec.md, docs/adr/0015-roadmap-jobs-act-as-a-github-app-on-the-personal-account.md]
    • Chosen: Fail the start and name each missing or insufficient permission. The Service cannot do its work with a token that lacks a permission. The spec makes a missing App setting stop the start with status 1.
    • Rejected: Log a warning and continue. The Service runs with a token that cannot do its work, and a later request fails without naming the permission.
    • Rejected: Retry the read with backoff. A grant does not change during a restart. A retry delays the same failure.
  • Does the check compare permission names only, or names and levels?: It compares names and levels. A grant of contents: read where the constants ask contents: write is reported as missing. (best practice) [sources: src/devops_cli/config/constants.py:1670, src/devops_cli/config/constants.py:1682, src/devops_cli/github/app_installation.py]
    • Chosen: Names and levels. The constants hold a level for each name, and a read grant cannot do a write.
    • Rejected: Names only. It would pass a grant that cannot do the work.
  • How does the change record the App identity in the ADR set?: A new ADR supersedes ADR 0015. It sets supersedes: ["0015"] and restates each live rule and rejected option. The same change sets status: superseded and superseded-by on ADR 0015 and adds its Superseded by line. (best practice) [sources: docs/adr/README.md, docs/adr/0015-roadmap-jobs-act-as-a-github-app-on-the-personal-account.md]
    • Chosen: A new ADR that supersedes ADR 0015. The README requires a supersession after the third amendment or when the body contradicts the code. ADR 0015 has six amendment notes.
    • Rejected: Amend ADR 0015 in place. The README forbids an edit of the body of an accepted record.
    • Rejected: Add a Status History line only. The rules changed: the two permission sets, the App webhook and the start-up check are not a dated fact.
  • Which test proves that the citations of ADR 0015 moved?: tests/invariants/test_adr_superseded_citations.py scans src/, tests/ and .github/ for ADR NNNN and fails on a citation of a superseded record. It checks no count. The criterion is that no citation remains. The issue gives no source for 22. [sources: tests/invariants/test_adr_superseded_citations.py:17, tests/invariants/test_adr_superseded_citations.py:62]
  • Which GitHub App settings does the owner change, and in what order?: Owner decision 3 of 2026-11-12 names all three settings in this order. (1) Cut the App grant to the 9 permissions that the code asks for. (2) After feat(service): verify GitHub App webhooks with one secret #4417, turn on the App webhook for Issues only and delete the 7 repository hooks in the same hour. (3) Bind the 3 required checks of the ruleset to the GitHub Actions app. The 9 permissions are the 7 in CONST_GITHUB_APP_TOKEN_PERMISSIONS and the 2 in CONST_GITHUB_APP_METRICS_TOKEN_PERMISSIONS. [sources: src/devops_cli/config/constants.py:1670, src/devops_cli/config/constants.py:1682]

Fit

Fits in one pull request.

Suspected block

The owner must cut the GitHub App grant and turn on the App webhook under owner decision 3 of 2026-11-12 before this item merges.

Dependencies

#5250, #4417

Activity

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

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

    @devops-cli-service
    Contributor

    Alternatives check: in-use

    Reason: The searches turned up no dedicated tool that verifies a GitHub App's granted permissions at startup; that check is project logic. The issue itself already names the tool it uses — the GitHub REST call GET /app/installations/{id} with the App JWT, through gidgethub — and says "No new tool." gidgethub is open, maintained and already the project's chosen GitHub transport (ADR 0006), so it covers the tool need and no ADR rejects it.

    The repository already uses this tool.

    Tool: gidgethub/gidgethub (https://github.com/gidgethub/gidgethub)

    • License: Apache-2.0
    • Last activity: 2026-09-25
    • Maintained: yes

    Covers:

    • App-JWT-authenticated GitHub REST calls, including the installation endpoints such as GET /app/installations/{installation_id}
    • The HTTP transport and session the Service start-up check would use (already the project's chosen transport in ADR 0006)

    Lacks:

    • The comparison of the granted permissions with the two token sets and the naming of each missing permission (project code in src/devops_cli/server/ and constants.py)
    • The new ADR record that supersedes ADR 0015 and the moving of the 22 citation lines (docs/adr/ work, not a tool capability)

    Tools considered:

    Searches run:

    • gidgethub GitHub App installation permissions python, results: 5
    • GitHub App installation granted permissions check GET /app/installations JWT, results: 5
    • gidgethub python library GitHub API, results: 5
    • verify GitHub App installation permissions match required scopes tool, results: 5
    • GitHub App least privilege permissions startup validation library, results: 5

    Sources:

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

  6. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Owner question: Does the owner change the GitHub App settings before this item merges? (a person decides)

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  7. devops-cli-service commented on Nov 21, 2026

    @devops-cli-service
    Contributor

    Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies in the section Proposed design of the body.

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/githubsource/agentstatus/newtype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions