Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ ADR 0015 supersedes [ADR 0002](0002-roadmap-jobs-act-as-a-machine-account.md).

Amended on 2026-10-28 ([#2454](https://github.com/dan-petty/devops-cli/issues/2454)): the owner made the App as `devops-cli-service`, with read and write on every repository permission, for planned repository-management work.

Amended on 2026-10-28 ([#2473](https://github.com/dan-petty/devops-cli/issues/2473)): each installation token asks only for the permissions that the roadmap jobs use, whatever the App grants.

ADR 0002 gave the roadmap jobs a machine account with a classic token, because only a classic token can reach a project board that a personal account owns. GitHub suspended that machine account on 2026-10-11 ([#1562](https://github.com/dan-petty/devops-cli/issues/1562)). Since then, no roadmap job can call GitHub without a person, and `deployment/roadmap-service` stays at `replicas: 0`.

On 2026-10-28 the owner decided that the repositories and the board stay on the personal account, and that no organization is made. The owner also said: "roadmap should perform all expected functionality even if project board is unavailable for the repository".
Expand All @@ -12,7 +14,7 @@ On 2026-10-28 the owner decided that the repositories and the board stay on the

- **The jobs act as a GitHub App.** The personal account owns the App `devops-cli-service` and installs it on its managed repositories. The roadmap jobs need these repository permissions: Issues read and write, Pull requests read and write, Contents read and write, Checks read, Actions read and Metadata read. The owner gave the App read and write on every repository permission, for planned repository-management work. It has no webhook and no user authorization.
- **The private key selects the App.** A process whose environment holds the App's private key, `DEVOPS_CLI_SERVICE_GITHUB_APP_PRIVATE_KEY`, acts as the App. Secret `devops/devops-cli` gives the key to the Service and to each cluster Job. A workstation keeps the key only in the OS keyring, for `devops k8s push-secrets`, so a workstation run keeps the gh login of its person. gh applies the same rule to `GH_TOKEN`: a token in the environment takes precedence over a stored login.
- **gidgethub mints the token.** The process signs a JWT with the key and exchanges it for an installation token with `gidgethub.apps.get_installation_access_token`. An installation token expires one hour after GitHub makes it, and the process mints a new one when less than ten minutes are left. Each gh and git child gets the current token as `GH_TOKEN`. git gets it through `gh auth git-credential`.
- **gidgethub mints the token.** gidgethub's `GitHubAPI` signs a JWT with the key, and the process exchanges it for an installation token at `POST /app/installations/<id>/access_tokens`. The request body asks for the roadmap jobs' permissions only, from `CONST_GITHUB_APP_TOKEN_PERMISSIONS`: `issues`, `pull_requests` and `contents` write, and `checks`, `actions` and `metadata` read. `gidgethub.apps.get_installation_access_token` sends no body, so the process does not use it. An installation token expires one hour after GitHub makes it, and the process mints a new one when less than ten minutes are left. Each gh and git child gets the current token as `GH_TOKEN`. git gets it through `gh auth git-credential`.
- **The installation is the identity.** The quota ledger and the GitHub session are keyed by the installation, so each new token keeps them. The session reads the current token for each request.
- **The login is the bot's.** An installation token cannot read `GET /user`, so the login is `<slug>[bot]`, from `service.github_app.slug`. The job clone commits as that login, with the email `<id>+<login>@users.noreply.github.com`. The ID comes from `GET /users/<login>`. The roadmap's webhook consumer refuses a delivery whose sender is that login.
- **The settings.** `service.github_app.app_id`, `service.github_app.installation_id` and `service.github_app.slug` go into ConfigMap `devops-cli-config`. The private key is the managed credential `service.github_app.private_key`, which a person stores with `devops config set --from-file`. The settings `service.machine_account` and `k8s.github_account` are removed.
Expand All @@ -28,6 +30,6 @@ On 2026-10-28 the owner decided that the repositories and the board stay on the
## Consequences

- An installation token cannot read or write the project board of a personal account, because GitHub gives Apps the "Projects" permission only for an organization. [ADR 0016](0016-labels-hold-the-roadmap-items-fields.md) moves the roadmap state to labels and milestones, so that the roadmap works without the board. `deployment/roadmap-service` stays at `replicas: 0` until a person moves the board's values to labels one time and pushes the App's key.
- The App's private key is in Secret `devops/devops-cli`. It reaches only the installed repositories, and each token that it mints expires after one hour. With read and write on every repository permission, the key can also change repository settings, Actions secrets and variables, environments and workflows, which AGENTS.md leaves to a person, and a key that leaks reaches all of that until it is rotated. A permission that no job uses can go from the App with no change to the code.
- The App's private key is in Secret `devops/devops-cli`. It reaches only the installed repositories, and each token that it mints expires after one hour. Each token is scoped to the roadmap jobs' permissions, whatever the App grants: a token that a bug, a prompt injection or a leak reaches cannot change repository settings, Actions secrets and variables, environments or workflows, which AGENTS.md leaves to a person. The key itself is not scoped: with read and write on every repository permission, a key that leaks can mint a token with all of them until it is rotated. A permission that no job uses can go from the App with no change to the code. If the installation does not grant one of the token's permissions, GitHub refuses the token with HTTP 422 and does not say which permission is missing, so the error names each permission that the token asks for. A later feature that needs more permissions asks for a token with its own set.
- The App's writes show as `devops-cli-service[bot]`, so a person can tell them from their own writes.
- The webhooks of each repository stay. The App's own webhook can replace them in a later item.
2 changes: 1 addition & 1 deletion k8s/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ kubectl -n devops logs -f job/<name>

> **Held at `replicas: 0`.** The Service acts as GitHub App `devops-cli-service`, which the personal account owns ([ADR 0015](../docs/adr/0015-roadmap-jobs-act-as-a-github-app-on-the-personal-account.md)). Labels and milestones hold the roadmap state ([ADR 0016](../docs/adr/0016-labels-hold-the-roadmap-items-fields.md)). `deployment/roadmap-service` stays at `replicas: 0` until a person moves the board's values to labels one time and steps 1 to 3 are done. Do not scale the deployment until then, and keep each managed repository's webhook disabled.

1. Create the GitHub App on the personal account (Settings > Developer settings > GitHub Apps > New GitHub App): name `devops-cli-service`, webhook off, "Only on this account". The roadmap jobs need these repository permissions: Issues read and write, Pull requests read and write, Contents read and write, Checks read, Actions read, Metadata read. The owner's App has read and write on every repository permission ([ADR 0015](../docs/adr/0015-roadmap-jobs-act-as-a-github-app-on-the-personal-account.md) records the risk). Install it on each managed repository, and generate a private key. The App page shows the App ID, and the installation's settings page has the installation ID at the end of its URL.
1. Create the GitHub App on the personal account (Settings > Developer settings > GitHub Apps > New GitHub App): name `devops-cli-service`, webhook off, "Only on this account". The roadmap jobs need these repository permissions: Issues read and write, Pull requests read and write, Contents read and write, Checks read, Actions read, Metadata read. The owner's App has read and write on every repository permission ([ADR 0015](../docs/adr/0015-roadmap-jobs-act-as-a-github-app-on-the-personal-account.md) records the risk). Each installation token that the Service and the Jobs mint is scoped to the permissions above, whatever the App grants, so the App must grant at least those: GitHub refuses a token with HTTP 422 when the installation does not grant one of them. Install it on each managed repository, and generate a private key. The App page shows the App ID, and the installation's settings page has the installation ID at the end of its URL.
2. `uv run devops config set service.repos <owner/name>` (each repository the service works for), then `uv run devops config set service.webhook_secrets` (hidden prompt; a JSON object mapping `owner/name` to its secret). Set the App with `uv run devops config set service.github_app.app_id <app-id>`, `service.github_app.installation_id <installation-id>`, `service.github_app.slug devops-cli-service` and `service.github_app.private_key --from-file <key.pem>`, then delete the downloaded key file. deploy-stack refuses the devops stack until `service.repos` and the App's settings are set.
3. `uv run devops k8s push-secrets --stack devops`. It writes the App's private key to Secret `devops/devops-cli`. deploy-stack also pushes it once namespace `devops` exists.
4. Check that the GHCR `service` package is public (#741 made it so): `DOCKER_CONFIG=$(mktemp -d) docker pull ghcr.io/dan-petty/devops-cli/service:<tag>`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-10-28
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Design

## Context

The Service and the cluster Jobs act as GitHub App `devops-cli-service` (ADR 0015). `mint_installation_token` exchanges the App's JWT for an installation token over the session's client, and `core.process` gives the token to every gh and git child. The installation grants read and write on every repository permission. Without a `permissions` body, GitHub gives each token all of them.

## Decisions

- **One constant holds the token's permissions.** `CONST_GITHUB_APP_TOKEN_PERMISSIONS` maps each permission that the roadmap jobs use to its level. The token request sends it as `permissions`. A later feature that needs more asks for a token with its own set. The App's grant stays the owner's setting.
- **gidgethub's `GitHubAPI` posts the request.** gidgethub 6.0.0's `get_installation_access_token` posts an empty body. `GitHubAPI` takes the App's ID and key, signs the JWT, and posts a JSON body, so the request still goes through gidgethub and the session's client, to GitHub's API origin only.
- **The log names the granted permissions only.** After a token is minted, one INFO record names the permissions of GitHub's reply, sorted, with no level and no token. A reply that grants more than the request asks for is no error: GitHub decides what the token carries, and the log shows it.
- **A 422 names each permission that the token asks for.** `classify_http_error` gives the status of the refusal. On HTTP 422 the reason adds each permission of the request with its level, after GitHub's text. Any other refusal keeps its reason as before.

## Rejected Alternatives

- **Read the installation's permissions after a 422 and name only the missing ones.** `GET /app/installations/{installation_id}` gives the installation's `permissions`. But the read is a second request after a refusal, it can fail too, and its failure would hide the 422 or need its own error path. GitHub's 422 also answers a request that the endpoint thinks is spam ("Validation failed, or the endpoint has been spammed"), so a 422 alone does not prove a missing permission. The six names in the error are enough for a person to compare with the App's settings page.
- **Keep `gidgethub.apps.get_installation_access_token`.** It posts `data=b""` and takes no `permissions` argument (gidgethub 6.0.0, `gidgethub/apps.py`), so it cannot scope the token.
- **Also scope the token to `service.repos` with `repositories`.** The issue asks for permissions only. The App is installed only on the managed repositories (`k8s/README.md`, "Roadmap service", step 1), so the installation already limits which repositories a token reaches.
- **Fail when the reply grants more than the request asks for.** The issue's acceptance criteria say that such a reply is no error. The token's permissions are GitHub's decision; the log shows them, so a person can see a difference.

## Risks

- A roadmap job that starts to use a permission outside the set fails at the request that needs it, with GitHub's 403. The fix is to add the permission to the constant, in a pull request that says why.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Proposal

## Why

Issue #2473: on 2026-10-28 the owner gave GitHub App `devops-cli-service` read and write on every repository permission, for planned repository-management work (ADR 0015, #2454). `src/devops_cli/github/app_installation.py` minted each installation token with no request body, so each token got every permission of the installation: Administration, Secrets, Variables, Environments and Workflows too, which AGENTS.md leaves to a person. A bug, a prompt injection that reaches a write, or a token that leaks could use all of them. The roadmap jobs use only Issues, Pull requests and Contents read and write, and Checks, Actions and Metadata read (`k8s/README.md`, "Roadmap service", step 1).

## What Changes

- One constant, `CONST_GITHUB_APP_TOKEN_PERMISSIONS` in `src/devops_cli/config/constants.py`, holds the token's permissions: `issues`, `pull_requests` and `contents` write, and `checks`, `actions` and `metadata` read.
- The token request sends `{"permissions": CONST_GITHUB_APP_TOKEN_PERMISSIONS}` as its body. gidgethub's `GitHubAPI` signs the App's JWT and posts the request over the session's client, as before. The process no longer calls `gidgethub.apps.get_installation_access_token`, which sends no body.
- The process logs the names of the permissions in GitHub's reply, without their levels and without the token. A reply that grants more than the request asks for is no error.
- When GitHub refuses the request with HTTP 422, the error names each permission that the token asks for, with GitHub's status and reply text. GitHub's reply does not say which permission the installation does not grant.
- ADR 0015, the "Roadmap service" text of `k8s/README.md` and the knowledge base's GitHub CLI page say that each token is scoped to these permissions, whatever the App grants.
- The change alters the request that the Service and the cluster Jobs send to GitHub, an error message and a log line, so it carries a spec delta: an ADDED requirement in `github-app-identity`.
- This change fits one pull request.

## Capabilities

### Modified Capabilities

- `github-app-identity`: each installation token carries only the permissions that the roadmap jobs use.

## Impact

- `src/devops_cli/github/app_installation.py`, `src/devops_cli/config/constants.py`, `src/devops_cli/lang/en/errors.py`.
- `tests/test_github_app_identity.py`.
- `docs/adr/0015-roadmap-jobs-act-as-a-github-app-on-the-personal-account.md`, `k8s/README.md`, `src/devops_cli/ai/knowledge_base/it_domains/tools/github_cli.md`.

## Feasibility

- GitHub's REST documentation, "Create an installation access token for an app" (`POST /app/installations/{installation_id}/access_tokens`, API version 2022-11-28), lists the body parameters `repositories`, `repository_ids` and `permissions`. It says: "If permissions is not specified, the installation access token will have all of the permissions" of the installation, and "The installation access token cannot be granted permissions that the app was not granted." The keys `issues`, `pull_requests`, `contents`, `checks`, `actions` and `metadata` each take `read` or `write`. The answers are 201, 401, 403, 404 and 422, and the 201 reply holds the token's `permissions`.
- The documentation names no error for a permission that the installation does not grant. Public reports show that GitHub answers HTTP 422 with "The permissions requested are not granted to this installation." and does not say which permission is missing: `actions/create-github-app-token` in ScottCooper92/binge-companions#235, and Renovate in MikaelSiidorow/systems#77. So the issue's premise that the error can name the missing permission fails as written. The error names each permission that the token asks for, and GitHub's status and text. The design records why the change does not read the installation's permissions after a refusal.
- gidgethub 6.0.0, as installed: `gidgethub/apps.py` `get_installation_access_token(gh, *, installation_id, app_id, private_key)` posts `data=b""` and takes no permissions and no body. `gidgethub.abc.GitHubAPI.__init__` takes `app_id` and `private_key` and signs an RS256 JWT whose issuer is the App ID (`_get_app_jwt`), and `GitHubAPI.post(url, *, data)` sends `data` as a JSON body. So the change posts the request through the same `gidgethub.httpx.GitHubAPI` over `session_client()` that the code already used.
- On `origin/main` 960e3573, the three new tests failed: the exchange's body was empty (`JSONDecodeError`), no log record named the permissions, and the 422 error named no permission.

## Existing Tool Considered

GitHub's documented `permissions` body parameter of the token endpoint, sent through gidgethub's `GitHubAPI.post`, which signs the App's JWT. Nothing is built. The change deletes the call to `gidgethub.apps.get_installation_access_token`, which cannot send a body.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## ADDED Requirements

### Requirement: Each installation token asks only for the roadmap jobs' permissions
A process that acts as the App SHALL send the body `{"permissions": CONST_GITHUB_APP_TOKEN_PERMISSIONS}` with each exchange at `POST /app/installations/<installation_id>/access_tokens`. The constant SHALL give `issues`, `pull_requests` and `contents` the level `write`, and `checks`, `actions` and `metadata` the level `read`.

#### Scenario: The token request names the roadmap jobs' permissions
- **WHEN** the process acts as App 1001 on installation 42 and mints a token
- **THEN** the body of `POST /app/installations/42/access_tokens` is `{"permissions": {"issues": "write", "pull_requests": "write", "contents": "write", "checks": "read", "actions": "read", "metadata": "read"}}`

### Requirement: The log names the minted token's permissions only
After GitHub gives a token, the process SHALL log the names of the permissions in GitHub's reply, sorted, without their levels and without the token. It SHALL use the token when the reply grants more permissions than the request asks for.

#### Scenario: GitHub's reply grants one more permission
- **WHEN** GitHub's reply gives the token `ghs_first` with the six permissions and `administration: write`
- **THEN** the token is `ghs_first`, and one log record ends with `actions, administration, checks, contents, issues, metadata, pull_requests` and holds no `ghs_first`, `write` or `read`

### Requirement: A refused permission names each permission that the token asks for
When GitHub answers the exchange with HTTP 422, the `GitHubUnauthenticatedError` SHALL name each permission that the token asks for, with its level, because GitHub's reply does not say which permission the installation does not grant.

#### Scenario: The installation does not grant a permission that the token asks for
- **WHEN** GitHub answers the exchange with HTTP 422 and "The permissions requested are not granted to this installation."
- **THEN** the token lookup raises `GitHubUnauthenticatedError` whose message holds `devops-roadmap[bot]`, `HTTP 422` and `actions (read), checks (read), contents (write), issues (write), metadata (read), pull_requests (write)`
Loading
Loading