From 3214772a20218c00707448f71418d5cb3756df66 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 27 Nov 2026 08:34:34 +0000 Subject: [PATCH 01/12] fix(ci): merge update PRs with a separate App from the auto-merge environment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The automatic merge of update PRs never succeeded: the Main ruleset refused the updater App's merge call with HTTP 405 (two reviews, code owner review, Hadolint results), because the App is no bypass actor. Making the updater App one would let any same-repository PR merge without review, since entry-pr-translate.yml mints a token from the same key on pull_request. The merge job now runs in the auto-merge environment, restricted to main, and mints its token from MERGE_APP_CLIENT_ID and MERGE_APP_PRIVATE_KEY of a separate App that alone gets the ruleset bypass. The docs describe the setup. ๐ŸŽฏ Fix: 85 % ๐Ÿ’ฅ Break: 3 % ๐Ÿ’ธ Tokens: 108 % โฑ๏ธ Velocity: 115 % ๐Ÿ›ก๏ธ Security: 100 % ๐Ÿ† Score: 66 ๐Ÿšฆ Gate: โ›” fix 85 % < 90; tokens 108 % > 100, velocity 115 % > 100: ask the operator before the commit Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 --- .../workflows/entry-pr-green-update-merge.yml | 5 +++-- .../tools/github/actions/configuration.md | 2 +- .../tools/github/actions/secrets.md | 21 ++++++++++++++++--- .../tools/github/actions/workflows.md | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/.github/workflows/entry-pr-green-update-merge.yml b/.github/workflows/entry-pr-green-update-merge.yml index 9091ebb92b..b1f401dea4 100644 --- a/.github/workflows/entry-pr-green-update-merge.yml +++ b/.github/workflows/entry-pr-green-update-merge.yml @@ -19,6 +19,7 @@ jobs: || startsWith(github.event.workflow_run.head_branch, 'dependabot/')) runs-on: ubuntu-26.04 timeout-minutes: 15 + environment: auto-merge permissions: actions: read checks: read @@ -56,8 +57,8 @@ jobs: id: app-token uses: actions/create-github-app-token@v3 with: - client-id: ${{ secrets.BOT_APP_CLIENT_ID }} - private-key: ${{ secrets.BOT_APP_PRIVATE_KEY }} + client-id: ${{ secrets.MERGE_APP_CLIENT_ID }} + private-key: ${{ secrets.MERGE_APP_PRIVATE_KEY }} - name: ๐Ÿ”€ Merge the update PR at its tested head if: steps.gate.outputs.merge == 'true' diff --git a/docs/contributing/tools/github/actions/configuration.md b/docs/contributing/tools/github/actions/configuration.md index 4b9e8eb3b7..3c865c76fe 100644 --- a/docs/contributing/tools/github/actions/configuration.md +++ b/docs/contributing/tools/github/actions/configuration.md @@ -172,7 +172,7 @@ An update PR merges itself only when all of these hold; otherwise the job prints 3. Every latest check run on its head commit completed as `success`, `skipped` or `neutral`, and every commit status is `success`. A check still running counts as not green; no later run retries the merge. 4. Every role under `roles//` the PR changes appears in the `role` column of a `role-runtimes-*` artifact of that run. A PR that changes no role needs no artifact; a missing artifact proves nothing. -The merge goes through `PUT /repos/{owner}/{repo}/pulls/{number}/merge` with `merge_method=merge` and the tested head `sha`, so a commit pushed after the run makes it fail instead of merging untested code. `gh pr merge` is not used because it refuses a PR the ruleset still blocks before the server can apply the App's bypass. The App MUST be a bypass actor of the `Main` ruleset in `pull_request` mode; without that the merge step fails and the PR stays open. +The merge goes through `PUT /repos/{owner}/{repo}/pulls/{number}/merge` with `merge_method=merge` and the tested head `sha`, so a commit pushed after the run makes it fail instead of merging untested code. `gh pr merge` is not used because it refuses a PR the ruleset still blocks before the server can apply the App's bypass. The token comes from the separate merge App in the `auto-merge` environment, which MUST be a bypass actor of the `Main` ruleset in `pull_request` mode; without that the merge step fails and the PR stays open. Setup: [secrets.md](secrets.md#merge_app_client_id-and-merge_app_private_key-). ## `INFINITO_PLAYWRIGHT_KEEP` ๐ŸŽฌ diff --git a/docs/contributing/tools/github/actions/secrets.md b/docs/contributing/tools/github/actions/secrets.md index 816df5a001..ebf8110ff2 100644 --- a/docs/contributing/tools/github/actions/secrets.md +++ b/docs/contributing/tools/github/actions/secrets.md @@ -8,8 +8,10 @@ Repository secrets MUST be set under **Settings โ†’ Secrets and variables โ†’ Ac | Secret | Workflow | Purpose | Required when | |---|---|---|---| -| `BOT_APP_CLIENT_ID` | [cron-update.yml](../../../../../.github/workflows/cron-update.yml), [entry-pr-green-update-merge.yml](../../../../../.github/workflows/entry-pr-green-update-merge.yml) | GitHub App Client ID (OAuth-style `Ivโ€ฆ` identifier shown on the App's General page) used to mint a short-lived installation token for the update PR and for its automatic merge. | `CI_ENABLE_AUTO_UPDATES == 'true'` | -| `BOT_APP_PRIVATE_KEY` | [cron-update.yml](../../../../../.github/workflows/cron-update.yml), [entry-pr-green-update-merge.yml](../../../../../.github/workflows/entry-pr-green-update-merge.yml) | PEM-encoded private key of the same GitHub App. Used to sign the JWT that exchanges for the installation token. | `CI_ENABLE_AUTO_UPDATES == 'true'` | +| `BOT_APP_CLIENT_ID` | [cron-update.yml](../../../../../.github/workflows/cron-update.yml) | GitHub App Client ID (OAuth-style `Ivโ€ฆ` identifier shown on the App's General page) used to mint a short-lived installation token for the update PR. | `CI_ENABLE_AUTO_UPDATES == 'true'` | +| `BOT_APP_PRIVATE_KEY` | [cron-update.yml](../../../../../.github/workflows/cron-update.yml) | PEM-encoded private key of the same GitHub App. Used to sign the JWT that exchanges for the installation token. | `CI_ENABLE_AUTO_UPDATES == 'true'` | +| `MERGE_APP_CLIENT_ID` | [entry-pr-green-update-merge.yml](../../../../../.github/workflows/entry-pr-green-update-merge.yml) | Client ID of the separate merge App, an **environment** secret of `auto-merge`, never a repository secret. | `CI_ENABLE_AUTO_UPDATES == 'true'` | +| `MERGE_APP_PRIVATE_KEY` | [entry-pr-green-update-merge.yml](../../../../../.github/workflows/entry-pr-green-update-merge.yml) | PEM private key of the merge App, an environment secret of `auto-merge`. | `CI_ENABLE_AUTO_UPDATES == 'true'` | | `API_OPENAI_KEY` | [call-test-deploy.yml](../../../../../.github/workflows/call-test-deploy.yml) | Publishes the `openai/*` models on the LiteLLM gateway and lets the CLI test exercise the route. | Never. Unset leaves the route unpublished. | | `API_ANTHROPIC_KEY` | [call-test-deploy.yml](../../../../../.github/workflows/call-test-deploy.yml) | Publishes the `anthropic/*` models. | Never. | | `API_OPENROUTER_KEY` | [call-test-deploy.yml](../../../../../.github/workflows/call-test-deploy.yml) | Publishes `openrouter/auto`. | Never. | @@ -99,7 +101,7 @@ A classic personal access token MAY be used as a fallback for unrelated automati Each PR-opening job in [cron-update.yml](../../../../../.github/workflows/cron-update.yml) runs an `actions/create-github-app-token@v2` step gated on `steps.diff.outputs.changed == 'true'`, then forwards the minted token as `GH_TOKEN` and the resolved `APP_SLUG` to the subsequent PR step. The job's `permissions:` block keeps the workflow-provided `GITHUB_TOKEN` read-only; write access is provided exclusively by the App token, scoped to the App's repository permissions. -[entry-pr-green-update-merge.yml](../../../../../.github/workflows/entry-pr-green-update-merge.yml) mints the App token only after its merge gate passed, and uses it for the merge call alone; the gate itself reads with the read-only `GITHUB_TOKEN`. Merging needs the App's `Contents` and `Pull requests` write permissions plus a bypass of the `Main` ruleset; a PR that changes `.github/workflows/` additionally needs `Workflows`: **Read and write**, or its merge fails and it stays open. +This App MUST NOT be a bypass actor of the `Main` ruleset: [entry-pr-translate.yml](../../../../../.github/workflows/entry-pr-translate.yml) mints its token on `pull_request`, where a same-repository PR can change the workflow and read the key. ### Commit identity propagation ๐Ÿชช @@ -119,6 +121,19 @@ A missing secret resolves to an empty string in workflow expressions. The workfl The behaviour is fail-loud by design. Missing or mistyped secret names MUST surface as a failed workflow run rather than as a PR with an unintended author. +## `MERGE_APP_CLIENT_ID` and `MERGE_APP_PRIVATE_KEY` ๐Ÿ”€ + +[entry-pr-green-update-merge.yml](../../../../../.github/workflows/entry-pr-green-update-merge.yml) merges a proven update PR with a second GitHub App that does nothing else. It is the only bypass actor of the `Main` ruleset besides the admins, so its key MUST be reachable from the default branch alone. + +### How to set it up ๐Ÿ› ๏ธ + +1. Create the App as in [How to generate the App](#how-to-generate-the-app-), with `Contents` and `Pull requests`: **Read and write**, plus `Workflows`: **Read and write** so a PR that changes `.github/workflows/` can merge too. Install it on the `core` repository only. +2. Go to **Settings โ†’ Environments โ†’ New environment**, name it `auto-merge`, and under **Deployment branches and tags** choose **Selected branches and tags** with the single rule `main`. A run on any other ref, a pull request included, cannot read its secrets. +3. Add `MERGE_APP_CLIENT_ID` (the `Ivโ€ฆ` Client ID) and `MERGE_APP_PRIVATE_KEY` (the full PEM) as **environment secrets** of `auto-merge`, never as repository secrets. +4. In **Settings โ†’ Rules โ†’ Rulesets โ†’ Main**, add the App under **Bypass list** with **For pull requests only**. + +The job mints the App token only after its merge gate passed and uses it for the merge call alone; the gate reads with the read-only `GITHUB_TOKEN`. The job runs on `workflow_run`, which always runs on the default branch, so the environment's branch rule admits it. Without the bypass, the merge call fails with `Repository rule violations found` (HTTP 405) and the PR stays open. + ## Related ๐Ÿ”— - [configuration.md](configuration.md): repository variables that gate the same workflows. diff --git a/docs/contributing/tools/github/actions/workflows.md b/docs/contributing/tools/github/actions/workflows.md index 2f4fcf3352..68a6eedbb7 100644 --- a/docs/contributing/tools/github/actions/workflows.md +++ b/docs/contributing/tools/github/actions/workflows.md @@ -87,7 +87,7 @@ Trigger column legend: **auto** = fires automatically (push, pull_request, sched | [entry-pr-translate.yml](../../../../../.github/workflows/entry-pr-translate.yml): `๐ŸŒ Translate catalogs` | Merges the source strings of the `core` and `docs` domains into `locale/`, then machine-translates what a pull request leaves empty or fuzzy, one runner per language LibreTranslate supports. Each runner opens its own PR against the head branch of the triggering PR. Gated behind the `CI_ENABLE_AUTO_TRANSLATIONS` repository variable, see [configuration.md](configuration.md); pull requests from a fork are skipped. Requires the `BOT_APP_CLIENT_ID` and `BOT_APP_PRIVATE_KEY` repository secrets, see [secrets.md](secrets.md). | auto (`pull_request` against `main`: opened, synchronize, reopened) | none | | [entry-pr-open-dependabot-close.yml](../../../../../.github/workflows/entry-pr-open-dependabot-close.yml): `๐Ÿšซ Dependabot: Close while auto-updates disabled` | Auto-closes Dependabot PRs while `CI_ENABLE_AUTO_UPDATES` is not set to `true`, so Dependabot honours the same gate as the workflow-driven update jobs. See [configuration.md](configuration.md). | auto (`pull_request_target`: opened, reopened) | none | | [entry-pr-change-dependabot-label.yml](../../../../../.github/workflows/entry-pr-change-dependabot-label.yml): `๐Ÿ”„ Dependabot: Label update level` | Labels every Dependabot PR `โฌ†๏ธ update` plus exactly one of `๐Ÿ”ด major`, `๐ŸŸก minor` and `๐ŸŸข patch`, read from the `update-type` of `dependabot/fetch-metadata`; a type that names no semver level counts as `major`. Creates a missing label, adds only labels the PR lacks and checks out the base branch only. Gated behind `CI_ENABLE_AUTO_UPDATES`, see [configuration.md](configuration.md). | auto (`pull_request_target`: opened, reopened, synchronize) | none | -| [entry-pr-green-update-merge.yml](../../../../../.github/workflows/entry-pr-green-update-merge.yml): `๐Ÿ”„ Update: Merge proven PRs` | Runs when a `๐Ÿ”€ Pull Request` run of the `pull_request` event succeeds on an `update/*` or `dependabot/*` branch. [cli.contributing.update.merge](../../../../../cli/contributing/update/merge/__main__.py) merges the PR only when the `infinito-nexus-updater[bot]` App or `dependabot[bot]` opened it, it carries `โฌ†๏ธ update`, every check run and commit status on its head is green, and the run's `role-runtimes-*` artifacts list every role the PR changes. Otherwise it prints why and the PR stays open for a manual merge. The merge pins the tested head and uses the App token, so the App MUST be a bypass actor of the `Main` ruleset. Gated behind `CI_ENABLE_AUTO_UPDATES`, see [configuration.md](configuration.md); requires the `BOT_APP_CLIENT_ID` and `BOT_APP_PRIVATE_KEY` repository secrets, see [secrets.md](secrets.md). | auto (`workflow_run` of `๐Ÿ”€ Pull Request`: completed) | none | +| [entry-pr-green-update-merge.yml](../../../../../.github/workflows/entry-pr-green-update-merge.yml): `๐Ÿ”„ Update: Merge proven PRs` | Runs when a `๐Ÿ”€ Pull Request` run of the `pull_request` event succeeds on an `update/*` or `dependabot/*` branch. [cli.contributing.update.merge](../../../../../cli/contributing/update/merge/__main__.py) merges the PR only when the `infinito-nexus-updater[bot]` App or `dependabot[bot]` opened it, it carries `โฌ†๏ธ update`, every check run and commit status on its head is green, and the run's `role-runtimes-*` artifacts list every role the PR changes. Otherwise it prints why and the PR stays open for a manual merge. The merge pins the tested head and uses the token of a separate merge App, which MUST be a bypass actor of the `Main` ruleset. Gated behind `CI_ENABLE_AUTO_UPDATES`, see [configuration.md](configuration.md); requires the `MERGE_APP_CLIENT_ID` and `MERGE_APP_PRIVATE_KEY` secrets of the `auto-merge` environment, see [secrets.md](secrets.md). | auto (`workflow_run` of `๐Ÿ”€ Pull Request`: completed) | none | ## Changing workflows โœ๏ธ From faeffe8d0d93052c7981cc8d955af031bf737478 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 27 Nov 2026 09:37:57 +0000 Subject: [PATCH 02/12] fix(ci): narrow the merge App token and correct the auto-merge branch rule docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CodeRabbit review on PR 3066: the merge token inherited every installation permission (zizmor github-app); it is now minted with contents, pull-requests and workflows write only. The docs claimed no pull-request run can read the auto-merge secrets, but pull_request_target and workflow_run jobs run with the base branch as their ref and pass the main rule; they now say so and forbid any job that declares the environment from running pull-request code. ๐ŸŽฏ Fix: 90 % ๐Ÿ’ฅ Break: 2 % ๐Ÿ’ธ Tokens: 98 % โฑ๏ธ Velocity: 94 % ๐Ÿ›ก๏ธ Security: 100 % ๐Ÿ† Score: 96 ๐Ÿšฆ Gate: โœ… 90/5, tokens and velocity <= 100, security 100 % Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 --- .github/workflows/entry-pr-green-update-merge.yml | 3 +++ docs/contributing/tools/github/actions/secrets.md | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/entry-pr-green-update-merge.yml b/.github/workflows/entry-pr-green-update-merge.yml index b1f401dea4..57c95027a4 100644 --- a/.github/workflows/entry-pr-green-update-merge.yml +++ b/.github/workflows/entry-pr-green-update-merge.yml @@ -59,6 +59,9 @@ jobs: with: client-id: ${{ secrets.MERGE_APP_CLIENT_ID }} private-key: ${{ secrets.MERGE_APP_PRIVATE_KEY }} + permission-contents: write + permission-pull-requests: write + permission-workflows: write - name: ๐Ÿ”€ Merge the update PR at its tested head if: steps.gate.outputs.merge == 'true' diff --git a/docs/contributing/tools/github/actions/secrets.md b/docs/contributing/tools/github/actions/secrets.md index ebf8110ff2..d9bfaa1906 100644 --- a/docs/contributing/tools/github/actions/secrets.md +++ b/docs/contributing/tools/github/actions/secrets.md @@ -128,11 +128,11 @@ The behaviour is fail-loud by design. Missing or mistyped secret names MUST surf ### How to set it up ๐Ÿ› ๏ธ 1. Create the App as in [How to generate the App](#how-to-generate-the-app-), with `Contents` and `Pull requests`: **Read and write**, plus `Workflows`: **Read and write** so a PR that changes `.github/workflows/` can merge too. Install it on the `core` repository only. -2. Go to **Settings โ†’ Environments โ†’ New environment**, name it `auto-merge`, and under **Deployment branches and tags** choose **Selected branches and tags** with the single rule `main`. A run on any other ref, a pull request included, cannot read its secrets. +2. Go to **Settings โ†’ Environments โ†’ New environment**, name it `auto-merge`, and under **Deployment branches and tags** choose **Selected branches and tags** with the single rule `main`. A `pull_request` run, whose ref is the pull request's merge ref, cannot read its secrets. A `pull_request_target` or `workflow_run` job runs with the base branch as its ref and passes this rule, so a job that declares `auto-merge` MUST NOT check out or execute pull-request code; only [entry-pr-green-update-merge.yml](../../../../../.github/workflows/entry-pr-green-update-merge.yml) declares it, and it runs `main`'s own code. 3. Add `MERGE_APP_CLIENT_ID` (the `Ivโ€ฆ` Client ID) and `MERGE_APP_PRIVATE_KEY` (the full PEM) as **environment secrets** of `auto-merge`, never as repository secrets. 4. In **Settings โ†’ Rules โ†’ Rulesets โ†’ Main**, add the App under **Bypass list** with **For pull requests only**. -The job mints the App token only after its merge gate passed and uses it for the merge call alone; the gate reads with the read-only `GITHUB_TOKEN`. The job runs on `workflow_run`, which always runs on the default branch, so the environment's branch rule admits it. Without the bypass, the merge call fails with `Repository rule violations found` (HTTP 405) and the PR stays open. +The job mints the App token only after its merge gate passed, narrowed to `contents`, `pull-requests` and `workflows` write, and uses it for the merge call alone; the gate reads with the read-only `GITHUB_TOKEN`. The job runs on `workflow_run`, which always runs on the default branch, so the environment's branch rule admits it. Without the bypass, the merge call fails with `Repository rule violations found` (HTTP 405) and the PR stays open. ## Related ๐Ÿ”— From bc7e20b7a2b364332fe3c6c53c0b8921177cf261 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 27 Nov 2026 10:34:11 +0000 Subject: [PATCH 03/12] docs(ci): gate the merge App bypass on updater-branch prerequisites MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Step 4 of the MERGE_APP setup in secrets.md now adds the merge App to the Main bypass list only after a new Prerequisites section holds: a ruleset on update/** and dependabot/** limited to the updater App and Dependabot, and a separate translate App with BOT_APP_* moved into a main-only environment. configuration.md and workflows.md say the same: no bypass before the prerequisites, manual merge until then. Addresses the CodeRabbit head-binding thread on PR #3066. ๐ŸŽฏ Fix: 90 % ๐Ÿ’ฅ Break: 1 % ๐Ÿ’ธ Tokens: 114 % โฑ๏ธ Velocity: 124 % ๐Ÿ›ก๏ธ Security: 100 % ๐Ÿ† Score: 63 ๐Ÿšฆ Gate: โš ๏ธ tokens 114 % > 100, velocity 124 % > 100: operator approved via hub decision 3503669213e6402e Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 --- .../tools/github/actions/configuration.md | 2 +- docs/contributing/tools/github/actions/secrets.md | 13 +++++++++++-- docs/contributing/tools/github/actions/workflows.md | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/docs/contributing/tools/github/actions/configuration.md b/docs/contributing/tools/github/actions/configuration.md index 3c865c76fe..e1b90d1b3f 100644 --- a/docs/contributing/tools/github/actions/configuration.md +++ b/docs/contributing/tools/github/actions/configuration.md @@ -172,7 +172,7 @@ An update PR merges itself only when all of these hold; otherwise the job prints 3. Every latest check run on its head commit completed as `success`, `skipped` or `neutral`, and every commit status is `success`. A check still running counts as not green; no later run retries the merge. 4. Every role under `roles//` the PR changes appears in the `role` column of a `role-runtimes-*` artifact of that run. A PR that changes no role needs no artifact; a missing artifact proves nothing. -The merge goes through `PUT /repos/{owner}/{repo}/pulls/{number}/merge` with `merge_method=merge` and the tested head `sha`, so a commit pushed after the run makes it fail instead of merging untested code. `gh pr merge` is not used because it refuses a PR the ruleset still blocks before the server can apply the App's bypass. The token comes from the separate merge App in the `auto-merge` environment, which MUST be a bypass actor of the `Main` ruleset in `pull_request` mode; without that the merge step fails and the PR stays open. Setup: [secrets.md](secrets.md#merge_app_client_id-and-merge_app_private_key-). +The merge goes through `PUT /repos/{owner}/{repo}/pulls/{number}/merge` with `merge_method=merge` and the tested head `sha`, so a commit pushed after the run makes it fail instead of merging untested code. `gh pr merge` is not used because it refuses a PR the ruleset still blocks before the server can apply the App's bypass. The token comes from the separate merge App in the `auto-merge` environment, which becomes a bypass actor of the `Main` ruleset in `pull_request` mode only once the [prerequisites](secrets.md#prerequisites-for-the-bypass-) hold; until then the merge step fails and the PR stays open for a manual merge. Setup: [secrets.md](secrets.md#merge_app_client_id-and-merge_app_private_key-). ## `INFINITO_PLAYWRIGHT_KEEP` ๐ŸŽฌ diff --git a/docs/contributing/tools/github/actions/secrets.md b/docs/contributing/tools/github/actions/secrets.md index d9bfaa1906..2942585626 100644 --- a/docs/contributing/tools/github/actions/secrets.md +++ b/docs/contributing/tools/github/actions/secrets.md @@ -123,14 +123,23 @@ The behaviour is fail-loud by design. Missing or mistyped secret names MUST surf ## `MERGE_APP_CLIENT_ID` and `MERGE_APP_PRIVATE_KEY` ๐Ÿ”€ -[entry-pr-green-update-merge.yml](../../../../../.github/workflows/entry-pr-green-update-merge.yml) merges a proven update PR with a second GitHub App that does nothing else. It is the only bypass actor of the `Main` ruleset besides the admins, so its key MUST be reachable from the default branch alone. +[entry-pr-green-update-merge.yml](../../../../../.github/workflows/entry-pr-green-update-merge.yml) merges a proven update PR with a second GitHub App that does nothing else. Once enabled, it is the only bypass actor of the `Main` ruleset besides the admins, so its key MUST be reachable from the default branch alone. ### How to set it up ๐Ÿ› ๏ธ 1. Create the App as in [How to generate the App](#how-to-generate-the-app-), with `Contents` and `Pull requests`: **Read and write**, plus `Workflows`: **Read and write** so a PR that changes `.github/workflows/` can merge too. Install it on the `core` repository only. 2. Go to **Settings โ†’ Environments โ†’ New environment**, name it `auto-merge`, and under **Deployment branches and tags** choose **Selected branches and tags** with the single rule `main`. A `pull_request` run, whose ref is the pull request's merge ref, cannot read its secrets. A `pull_request_target` or `workflow_run` job runs with the base branch as its ref and passes this rule, so a job that declares `auto-merge` MUST NOT check out or execute pull-request code; only [entry-pr-green-update-merge.yml](../../../../../.github/workflows/entry-pr-green-update-merge.yml) declares it, and it runs `main`'s own code. 3. Add `MERGE_APP_CLIENT_ID` (the `Ivโ€ฆ` Client ID) and `MERGE_APP_PRIVATE_KEY` (the full PEM) as **environment secrets** of `auto-merge`, never as repository secrets. -4. In **Settings โ†’ Rules โ†’ Rulesets โ†’ Main**, add the App under **Bypass list** with **For pull requests only**. +4. Only after every prerequisite below holds: in **Settings โ†’ Rules โ†’ Rulesets โ†’ Main**, add the App under **Bypass list** with **For pull requests only**. Check the live bypass list first; it MUST NOT hold the updater App. + +### Prerequisites for the bypass ๐Ÿ”’ + +The merge gate checks who opened the PR, not who pushed its head commit, so the head of an `update/*` or `dependabot/*` branch MUST be writable by the updater App and Dependabot alone, and the updater key MUST be out of reach of every pull request: + +1. A branch ruleset on `update/**` and `dependabot/**` restricts creation, updates and deletion, with only the updater App and Dependabot on its bypass list. +2. [entry-pr-translate.yml](../../../../../.github/workflows/entry-pr-translate.yml) mints its token from an App of its own, and `BOT_APP_CLIENT_ID` and `BOT_APP_PRIVATE_KEY` move into an environment restricted to `main`, so no `pull_request` run can read them. + +With both in place, pushing a head the gate accepts needs the updater key, which only workflows on `main` can read. Until then the merge App stays off the bypass list, the merge call fails with HTTP 405, and update PRs wait for a manual merge. The job mints the App token only after its merge gate passed, narrowed to `contents`, `pull-requests` and `workflows` write, and uses it for the merge call alone; the gate reads with the read-only `GITHUB_TOKEN`. The job runs on `workflow_run`, which always runs on the default branch, so the environment's branch rule admits it. Without the bypass, the merge call fails with `Repository rule violations found` (HTTP 405) and the PR stays open. diff --git a/docs/contributing/tools/github/actions/workflows.md b/docs/contributing/tools/github/actions/workflows.md index 68a6eedbb7..6aee59b383 100644 --- a/docs/contributing/tools/github/actions/workflows.md +++ b/docs/contributing/tools/github/actions/workflows.md @@ -87,7 +87,7 @@ Trigger column legend: **auto** = fires automatically (push, pull_request, sched | [entry-pr-translate.yml](../../../../../.github/workflows/entry-pr-translate.yml): `๐ŸŒ Translate catalogs` | Merges the source strings of the `core` and `docs` domains into `locale/`, then machine-translates what a pull request leaves empty or fuzzy, one runner per language LibreTranslate supports. Each runner opens its own PR against the head branch of the triggering PR. Gated behind the `CI_ENABLE_AUTO_TRANSLATIONS` repository variable, see [configuration.md](configuration.md); pull requests from a fork are skipped. Requires the `BOT_APP_CLIENT_ID` and `BOT_APP_PRIVATE_KEY` repository secrets, see [secrets.md](secrets.md). | auto (`pull_request` against `main`: opened, synchronize, reopened) | none | | [entry-pr-open-dependabot-close.yml](../../../../../.github/workflows/entry-pr-open-dependabot-close.yml): `๐Ÿšซ Dependabot: Close while auto-updates disabled` | Auto-closes Dependabot PRs while `CI_ENABLE_AUTO_UPDATES` is not set to `true`, so Dependabot honours the same gate as the workflow-driven update jobs. See [configuration.md](configuration.md). | auto (`pull_request_target`: opened, reopened) | none | | [entry-pr-change-dependabot-label.yml](../../../../../.github/workflows/entry-pr-change-dependabot-label.yml): `๐Ÿ”„ Dependabot: Label update level` | Labels every Dependabot PR `โฌ†๏ธ update` plus exactly one of `๐Ÿ”ด major`, `๐ŸŸก minor` and `๐ŸŸข patch`, read from the `update-type` of `dependabot/fetch-metadata`; a type that names no semver level counts as `major`. Creates a missing label, adds only labels the PR lacks and checks out the base branch only. Gated behind `CI_ENABLE_AUTO_UPDATES`, see [configuration.md](configuration.md). | auto (`pull_request_target`: opened, reopened, synchronize) | none | -| [entry-pr-green-update-merge.yml](../../../../../.github/workflows/entry-pr-green-update-merge.yml): `๐Ÿ”„ Update: Merge proven PRs` | Runs when a `๐Ÿ”€ Pull Request` run of the `pull_request` event succeeds on an `update/*` or `dependabot/*` branch. [cli.contributing.update.merge](../../../../../cli/contributing/update/merge/__main__.py) merges the PR only when the `infinito-nexus-updater[bot]` App or `dependabot[bot]` opened it, it carries `โฌ†๏ธ update`, every check run and commit status on its head is green, and the run's `role-runtimes-*` artifacts list every role the PR changes. Otherwise it prints why and the PR stays open for a manual merge. The merge pins the tested head and uses the token of a separate merge App, which MUST be a bypass actor of the `Main` ruleset. Gated behind `CI_ENABLE_AUTO_UPDATES`, see [configuration.md](configuration.md); requires the `MERGE_APP_CLIENT_ID` and `MERGE_APP_PRIVATE_KEY` secrets of the `auto-merge` environment, see [secrets.md](secrets.md). | auto (`workflow_run` of `๐Ÿ”€ Pull Request`: completed) | none | +| [entry-pr-green-update-merge.yml](../../../../../.github/workflows/entry-pr-green-update-merge.yml): `๐Ÿ”„ Update: Merge proven PRs` | Runs when a `๐Ÿ”€ Pull Request` run of the `pull_request` event succeeds on an `update/*` or `dependabot/*` branch. [cli.contributing.update.merge](../../../../../cli/contributing/update/merge/__main__.py) merges the PR only when the `infinito-nexus-updater[bot]` App or `dependabot[bot]` opened it, it carries `โฌ†๏ธ update`, every check run and commit status on its head is green, and the run's `role-runtimes-*` artifacts list every role the PR changes. Otherwise it prints why and the PR stays open for a manual merge. The merge pins the tested head and uses the token of a separate merge App, which becomes a bypass actor of the `Main` ruleset only once the prerequisites in [secrets.md](secrets.md#prerequisites-for-the-bypass-) hold; until then the PR waits for a manual merge. Gated behind `CI_ENABLE_AUTO_UPDATES`, see [configuration.md](configuration.md); requires the `MERGE_APP_CLIENT_ID` and `MERGE_APP_PRIVATE_KEY` secrets of the `auto-merge` environment, see [secrets.md](secrets.md). | auto (`workflow_run` of `๐Ÿ”€ Pull Request`: completed) | none | ## Changing workflows โœ๏ธ From 7fea39f2ad77aa10690f478c85fc769c3eed5ec9 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 27 Nov 2026 10:51:47 +0000 Subject: [PATCH 04/12] docs(ci): name the Restrict updates rule and fence the updater environment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without the bypass the merge call fails because the Main ruleset's update rule (Restrict updates) lets only bypass actors move main, pull-request merges included, whatever reviews the PR holds. Prerequisite 2 now also requires that no job declaring the updater environment checks out or executes pull-request code, pull_request_target and workflow_run jobs included, checked per workflow before the bypass is added. Second CodeRabbit round on PR #3066. ๐ŸŽฏ Fix: 90 % ๐Ÿ’ฅ Break: 1 % ๐Ÿ’ธ Tokens: 105 % โฑ๏ธ Velocity: 107 % ๐Ÿ›ก๏ธ Security: 100 % ๐Ÿ† Score: 79 ๐Ÿšฆ Gate: โš ๏ธ tokens 105 % > 100, velocity 107 % > 100: operator approved via hub decision e76bab9b144d01cd Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 --- docs/contributing/tools/github/actions/secrets.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/contributing/tools/github/actions/secrets.md b/docs/contributing/tools/github/actions/secrets.md index 2942585626..7c821178e9 100644 --- a/docs/contributing/tools/github/actions/secrets.md +++ b/docs/contributing/tools/github/actions/secrets.md @@ -137,9 +137,9 @@ The behaviour is fail-loud by design. Missing or mistyped secret names MUST surf The merge gate checks who opened the PR, not who pushed its head commit, so the head of an `update/*` or `dependabot/*` branch MUST be writable by the updater App and Dependabot alone, and the updater key MUST be out of reach of every pull request: 1. A branch ruleset on `update/**` and `dependabot/**` restricts creation, updates and deletion, with only the updater App and Dependabot on its bypass list. -2. [entry-pr-translate.yml](../../../../../.github/workflows/entry-pr-translate.yml) mints its token from an App of its own, and `BOT_APP_CLIENT_ID` and `BOT_APP_PRIVATE_KEY` move into an environment restricted to `main`, so no `pull_request` run can read them. +2. [entry-pr-translate.yml](../../../../../.github/workflows/entry-pr-translate.yml) mints its token from an App of its own, and `BOT_APP_CLIENT_ID` and `BOT_APP_PRIVATE_KEY` move into an environment restricted to `main`, so no `pull_request` run can read them. As with `auto-merge`, a `pull_request_target` or `workflow_run` job passes that branch rule, so no job that declares the environment may check out or execute pull-request code; list every workflow that declares it and confirm this before step 4. -With both in place, pushing a head the gate accepts needs the updater key, which only workflows on `main` can read. Until then the merge App stays off the bypass list, the merge call fails with HTTP 405, and update PRs wait for a manual merge. +With both in place, pushing a head the gate accepts needs the updater key, which only workflows on `main` can read. Until then the merge App stays off the bypass list, the merge call fails with HTTP 405, and update PRs wait for a manual merge: the ruleset's `update` rule (Restrict updates) lets only bypass actors move `main`, pull-request merges included, whatever reviews the PR holds. The job mints the App token only after its merge gate passed, narrowed to `contents`, `pull-requests` and `workflows` write, and uses it for the merge call alone; the gate reads with the read-only `GITHUB_TOKEN`. The job runs on `workflow_run`, which always runs on the default branch, so the environment's branch rule admits it. Without the bypass, the merge call fails with `Repository rule violations found` (HTTP 405) and the PR stays open. From c578f3111a2bfc9729c6b9029c59569d3101c003 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 27 Nov 2026 11:20:27 +0000 Subject: [PATCH 05/12] fix(ci): keep the updater key out of pull-request runs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit entry-pr-translate.yml ran the pull request's own code and then minted a token from BOT_APP_PRIVATE_KEY in the same job, so any same-repository PR could read the updater key. Translation now uses a separate App (TRANSLATE_APP_CLIENT_ID, TRANSLATE_APP_PRIVATE_KEY) that sits on no bypass list. Every job that mints an updater token (seven in cron-update.yml, one in cron-collection-source.yml) declares environment: updater, restricted to main, so BOT_APP_* can live as environment secrets only. secrets.md, configuration.md and workflows.md document the new secrets, the second updater workflow and the admin role on the update-branch ruleset. ๐ŸŽฏ Fix: 90 % ๐Ÿ’ฅ Break: 3 % ๐Ÿ’ธ Tokens: 104 % โฑ๏ธ Velocity: 108 % ๐Ÿ›ก๏ธ Security: 100 % ๐Ÿ† Score: 78 ๐Ÿšฆ Gate: โš ๏ธ tokens 104 % > 100, velocity 108 % > 100: operator approved via hub decision 4b87e2f7793bdb4b Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 --- .github/workflows/cron-collection-source.yml | 1 + .github/workflows/cron-update.yml | 7 ++++ .github/workflows/entry-pr-translate.yml | 4 +-- .../tools/github/actions/configuration.md | 2 +- .../tools/github/actions/secrets.md | 36 ++++++++++++------- .../tools/github/actions/workflows.md | 4 +-- 6 files changed, 37 insertions(+), 17 deletions(-) diff --git a/.github/workflows/cron-collection-source.yml b/.github/workflows/cron-collection-source.yml index 877415b27e..ff4cd1e953 100644 --- a/.github/workflows/cron-collection-source.yml +++ b/.github/workflows/cron-collection-source.yml @@ -19,6 +19,7 @@ jobs: name: โš–๏ธ Time Galaxy against the git fallback if: vars.CI_ENABLE_AUTO_UPDATES == 'true' runs-on: ubuntu-26.04 + environment: updater env: HISTORY_PATH: build/collection-source-history.json steps: diff --git a/.github/workflows/cron-update.yml b/.github/workflows/cron-update.yml index e4ae9aebff..4f175076d6 100644 --- a/.github/workflows/cron-update.yml +++ b/.github/workflows/cron-update.yml @@ -22,6 +22,7 @@ jobs: name: ๐Ÿณ Update Docker image versions if: vars.CI_ENABLE_AUTO_UPDATES == 'true' runs-on: ubuntu-26.04 + environment: updater steps: - name: โฌ‡๏ธ Checkout uses: actions/checkout@v7.0.0 @@ -69,6 +70,7 @@ jobs: name: ๐Ÿณ Update compose file image versions if: vars.CI_ENABLE_AUTO_UPDATES == 'true' runs-on: ubuntu-26.04 + environment: updater steps: - name: โฌ‡๏ธ Checkout uses: actions/checkout@v7.0.0 @@ -116,6 +118,7 @@ jobs: name: ๐Ÿ”– Update declared version sources if: vars.CI_ENABLE_AUTO_UPDATES == 'true' runs-on: ubuntu-26.04 + environment: updater steps: - name: โฌ‡๏ธ Checkout uses: actions/checkout@v7.0.0 @@ -163,6 +166,7 @@ jobs: name: ๐Ÿ Update pinned pip requirements if: vars.CI_ENABLE_AUTO_UPDATES == 'true' runs-on: ubuntu-26.04 + environment: updater steps: - name: โฌ‡๏ธ Checkout uses: actions/checkout@v7.0.0 @@ -210,6 +214,7 @@ jobs: name: ๐ŸŒŒ Update pinned Ansible collections if: vars.CI_ENABLE_AUTO_UPDATES == 'true' runs-on: ubuntu-26.04 + environment: updater steps: - name: โฌ‡๏ธ Checkout uses: actions/checkout@v7.0.0 @@ -257,6 +262,7 @@ jobs: name: ๐ŸŒฟ Update repository refs if: vars.CI_ENABLE_AUTO_UPDATES == 'true' runs-on: ubuntu-26.04 + environment: updater steps: - name: โฌ‡๏ธ Checkout uses: actions/checkout@v7.0.0 @@ -304,6 +310,7 @@ jobs: name: ๐Ÿƒ Update GitHub-hosted runner labels if: vars.CI_ENABLE_AUTO_UPDATES == 'true' runs-on: ubuntu-26.04 + environment: updater steps: - name: โฌ‡๏ธ Checkout uses: actions/checkout@v7.0.0 diff --git a/.github/workflows/entry-pr-translate.yml b/.github/workflows/entry-pr-translate.yml index 79654def5f..fe64b9a75e 100644 --- a/.github/workflows/entry-pr-translate.yml +++ b/.github/workflows/entry-pr-translate.yml @@ -126,8 +126,8 @@ jobs: id: app-token uses: actions/create-github-app-token@v3 with: - client-id: ${{ secrets.BOT_APP_CLIENT_ID }} - private-key: ${{ secrets.BOT_APP_PRIVATE_KEY }} + client-id: ${{ secrets.TRANSLATE_APP_CLIENT_ID }} + private-key: ${{ secrets.TRANSLATE_APP_PRIVATE_KEY }} - name: ๐Ÿ“‚ Open PR for the translated catalogs if: steps.diff.outputs.changed == 'true' diff --git a/docs/contributing/tools/github/actions/configuration.md b/docs/contributing/tools/github/actions/configuration.md index e1b90d1b3f..4eb8a758fc 100644 --- a/docs/contributing/tools/github/actions/configuration.md +++ b/docs/contributing/tools/github/actions/configuration.md @@ -127,7 +127,7 @@ The gate is applied inside [push_ci_policy.sh](../../../../../scripts/meta/resol Controls whether automated update PRs are created. Covers both the workflow-driven jobs in [cron-update.yml](../../../../../.github/workflows/cron-update.yml) (Docker image versions, agent skills) and PRs opened by Dependabot (gated via [entry-pr-open-dependabot-close.yml](../../../../../.github/workflows/entry-pr-open-dependabot-close.yml), which auto-closes them). -The workflow-driven jobs additionally require the `BOT_APP_CLIENT_ID` and `BOT_APP_PRIVATE_KEY` repository secrets, see [secrets.md](secrets.md). Without those secrets, runs fail at the token-minting step and no PR is opened. +The workflow-driven jobs additionally require the `BOT_APP_CLIENT_ID` and `BOT_APP_PRIVATE_KEY` secrets of the `updater` environment, see [secrets.md](secrets.md). Without those secrets, runs fail at the token-minting step and no PR is opened. **Default behaviour (variable not set or set to any value other than `true`):** The `update-docker-image-versions` job is skipped. Dependabot PRs are auto-closed on open with a comment pointing to this variable. diff --git a/docs/contributing/tools/github/actions/secrets.md b/docs/contributing/tools/github/actions/secrets.md index 7c821178e9..d81abc8528 100644 --- a/docs/contributing/tools/github/actions/secrets.md +++ b/docs/contributing/tools/github/actions/secrets.md @@ -2,14 +2,16 @@ This page lists every repository secret that GitHub Actions workflows in this repository consume, and documents the failure mode when a secret is missing. For repository **variables** see [configuration.md](configuration.md). For the workflow catalog see [workflows.md](workflows.md). -Repository secrets MUST be set under **Settings โ†’ Secrets and variables โ†’ Actions โ†’ Secrets**. +Repository secrets MUST be set under **Settings โ†’ Secrets and variables โ†’ Actions โ†’ Secrets**; environment secrets under **Settings โ†’ Environments โ†’ `` โ†’ Environment secrets**. ## Secrets ๐Ÿ“‹ | Secret | Workflow | Purpose | Required when | |---|---|---|---| -| `BOT_APP_CLIENT_ID` | [cron-update.yml](../../../../../.github/workflows/cron-update.yml) | GitHub App Client ID (OAuth-style `Ivโ€ฆ` identifier shown on the App's General page) used to mint a short-lived installation token for the update PR. | `CI_ENABLE_AUTO_UPDATES == 'true'` | -| `BOT_APP_PRIVATE_KEY` | [cron-update.yml](../../../../../.github/workflows/cron-update.yml) | PEM-encoded private key of the same GitHub App. Used to sign the JWT that exchanges for the installation token. | `CI_ENABLE_AUTO_UPDATES == 'true'` | +| `BOT_APP_CLIENT_ID` | [cron-update.yml](../../../../../.github/workflows/cron-update.yml), [cron-collection-source.yml](../../../../../.github/workflows/cron-collection-source.yml) | GitHub App Client ID (OAuth-style `Ivโ€ฆ` identifier shown on the App's General page) used to mint a short-lived installation token for the update PR. An **environment** secret of `updater`, never a repository secret. | `CI_ENABLE_AUTO_UPDATES == 'true'` | +| `BOT_APP_PRIVATE_KEY` | [cron-update.yml](../../../../../.github/workflows/cron-update.yml), [cron-collection-source.yml](../../../../../.github/workflows/cron-collection-source.yml) | PEM-encoded private key of the same GitHub App. Used to sign the JWT that exchanges for the installation token. An environment secret of `updater`. | `CI_ENABLE_AUTO_UPDATES == 'true'` | +| `TRANSLATE_APP_CLIENT_ID` | [entry-pr-translate.yml](../../../../../.github/workflows/entry-pr-translate.yml) | Client ID of the translation App that opens the machine-translation PRs. A repository secret, readable by same-repository pull requests. | `CI_ENABLE_AUTO_TRANSLATIONS == 'true'` | +| `TRANSLATE_APP_PRIVATE_KEY` | [entry-pr-translate.yml](../../../../../.github/workflows/entry-pr-translate.yml) | PEM private key of the translation App. | `CI_ENABLE_AUTO_TRANSLATIONS == 'true'` | | `MERGE_APP_CLIENT_ID` | [entry-pr-green-update-merge.yml](../../../../../.github/workflows/entry-pr-green-update-merge.yml) | Client ID of the separate merge App, an **environment** secret of `auto-merge`, never a repository secret. | `CI_ENABLE_AUTO_UPDATES == 'true'` | | `MERGE_APP_PRIVATE_KEY` | [entry-pr-green-update-merge.yml](../../../../../.github/workflows/entry-pr-green-update-merge.yml) | PEM private key of the merge App, an environment secret of `auto-merge`. | `CI_ENABLE_AUTO_UPDATES == 'true'` | | `API_OPENAI_KEY` | [call-test-deploy.yml](../../../../../.github/workflows/call-test-deploy.yml) | Publishes the `openai/*` models on the LiteLLM gateway and lets the CLI test exercise the route. | Never. Unset leaves the route unpublished. | @@ -92,16 +94,26 @@ A classic personal access token MAY be used as a fallback for unrelated automati ### How to hand the credentials to CI ๐Ÿ“ฅ 1. Open the repository on GitHub. -2. Go to **Settings โ†’ Secrets and variables โ†’ Actions**. -3. Stay on the **Secrets** tab. -4. Click **New repository secret** and add `BOT_APP_CLIENT_ID` with the App's Client ID (shown on the App's General page under **About**, in the `Ivโ€ฆ` format โ€” *not* the numeric App ID). -5. Click **New repository secret** and add `BOT_APP_PRIVATE_KEY` with the complete PEM content, including the `-----BEGIN PRIVATE KEY-----` and `-----END PRIVATE KEY-----` lines. +2. Go to **Settings โ†’ Environments โ†’ New environment**, name it `updater`, and under **Deployment branches and tags** choose **Selected branches and tags** with the single rule `main`. +3. Under **Environment secrets**, add `BOT_APP_CLIENT_ID` with the App's Client ID (shown on the App's General page under **About**, in the `Ivโ€ฆ` format, *not* the numeric App ID). +4. Add `BOT_APP_PRIVATE_KEY` with the complete PEM content, including the `-----BEGIN PRIVATE KEY-----` and `-----END PRIVATE KEY-----` lines. +5. Delete any repository secret of the same names under **Settings โ†’ Secrets and variables โ†’ Actions**; a repository secret would stay readable by `pull_request` runs. ### How the workflow consumes the secrets โš™๏ธ -Each PR-opening job in [cron-update.yml](../../../../../.github/workflows/cron-update.yml) runs an `actions/create-github-app-token@v2` step gated on `steps.diff.outputs.changed == 'true'`, then forwards the minted token as `GH_TOKEN` and the resolved `APP_SLUG` to the subsequent PR step. The job's `permissions:` block keeps the workflow-provided `GITHUB_TOKEN` read-only; write access is provided exclusively by the App token, scoped to the App's repository permissions. +Each PR-opening job in [cron-update.yml](../../../../../.github/workflows/cron-update.yml) and [cron-collection-source.yml](../../../../../.github/workflows/cron-collection-source.yml) declares `environment: updater` and runs an `actions/create-github-app-token@v3` step gated on `steps.diff.outputs.changed == 'true'`, then forwards the minted token as `GH_TOKEN` and the resolved `APP_SLUG` to the subsequent PR step. The job's `permissions:` block keeps the workflow-provided `GITHUB_TOKEN` read-only; write access is provided exclusively by the App token, scoped to the App's repository permissions. -This App MUST NOT be a bypass actor of the `Main` ruleset: [entry-pr-translate.yml](../../../../../.github/workflows/entry-pr-translate.yml) mints its token on `pull_request`, where a same-repository PR can change the workflow and read the key. +These jobs run on `push` to `main`, `schedule` or `workflow_dispatch` and check out `main`; a dispatch on any other branch fails at the environment's branch rule. No job that declares `updater` may check out or execute pull-request code. + +This App MUST NOT be a bypass actor of the `Main` ruleset. It is the only bypass actor of the update-branch ruleset, see [Prerequisites for the bypass](#prerequisites-for-the-bypass-). + +## `TRANSLATE_APP_CLIENT_ID` and `TRANSLATE_APP_PRIVATE_KEY` ๐ŸŒ + +[entry-pr-translate.yml](../../../../../.github/workflows/entry-pr-translate.yml) mints its token on `pull_request` after running the pull request's own code, so any same-repository pull request can read this key. It therefore belongs to an App of its own that sits on no bypass list: a leaked key grants what every writer already has, and it opens only `translate/pr-*` branches. + +1. Create the App as in [How to generate the App](#how-to-generate-the-app-), with `Contents` and `Pull requests`: **Read and write**. Install it on the `core` repository only. +2. Add `TRANSLATE_APP_CLIENT_ID` and `TRANSLATE_APP_PRIVATE_KEY` as **repository** secrets. +3. Never add this App to the bypass list of any ruleset. ### Commit identity propagation ๐Ÿชช @@ -134,10 +146,10 @@ The behaviour is fail-loud by design. Missing or mistyped secret names MUST surf ### Prerequisites for the bypass ๐Ÿ”’ -The merge gate checks who opened the PR, not who pushed its head commit, so the head of an `update/*` or `dependabot/*` branch MUST be writable by the updater App and Dependabot alone, and the updater key MUST be out of reach of every pull request: +The merge gate checks who opened the PR, not who pushed its head commit, so the head of an `update/*` or `dependabot/*` branch MUST be writable by the updater App, Dependabot and admins alone, and the updater key MUST be out of reach of every pull request: -1. A branch ruleset on `update/**` and `dependabot/**` restricts creation, updates and deletion, with only the updater App and Dependabot on its bypass list. -2. [entry-pr-translate.yml](../../../../../.github/workflows/entry-pr-translate.yml) mints its token from an App of its own, and `BOT_APP_CLIENT_ID` and `BOT_APP_PRIVATE_KEY` move into an environment restricted to `main`, so no `pull_request` run can read them. As with `auto-merge`, a `pull_request_target` or `workflow_run` job passes that branch rule, so no job that declares the environment may check out or execute pull-request code; list every workflow that declares it and confirm this before step 4. +1. A branch ruleset on `update/**` and `dependabot/**` restricts creation, updates and deletion, with only the updater App, Dependabot and the admin role on its bypass list. The admin role lets a maintainer merge a translation PR or push a fixup onto an update branch; the translation App stays off it. +2. `BOT_APP_CLIENT_ID` and `BOT_APP_PRIVATE_KEY` exist only as secrets of the `updater` environment, restricted to `main`, and no longer as repository secrets, so no `pull_request` run can read them; [entry-pr-translate.yml](../../../../../.github/workflows/entry-pr-translate.yml) uses the [translation App](#translate_app_client_id-and-translate_app_private_key-). As with `auto-merge`, a `pull_request_target` or `workflow_run` job passes that branch rule, so no job that declares the environment may check out or execute pull-request code; list every workflow that declares it and confirm this before step 4. With both in place, pushing a head the gate accepts needs the updater key, which only workflows on `main` can read. Until then the merge App stays off the bypass list, the merge call fails with HTTP 405, and update PRs wait for a manual merge: the ruleset's `update` rule (Restrict updates) lets only bypass actors move `main`, pull-request merges included, whatever reviews the PR holds. diff --git a/docs/contributing/tools/github/actions/workflows.md b/docs/contributing/tools/github/actions/workflows.md index 6aee59b383..5b7552dc29 100644 --- a/docs/contributing/tools/github/actions/workflows.md +++ b/docs/contributing/tools/github/actions/workflows.md @@ -83,8 +83,8 @@ Trigger column legend: **auto** = fires automatically (push, pull_request, sched | [call-release-version.yml](../../../../../.github/workflows/call-release-version.yml): `๐Ÿš€ Release: Version Logic` | Releases a specific version tag (build + publish). Called from `entry-push-latest.yml` on tagged pushes. | reusable, manual | `tag` (required, e.g. `v1.2.3`) | | [cron-release-highest.yml](../../../../../.github/workflows/cron-release-highest.yml): `๐Ÿš€ Release missing tag` | Scheduled backfill: finds the highest tag without a release and triggers `call-release-version.yml` for it. | auto (`schedule`: daily 00:00 UTC), manual | none | | [cron-cleanup-stale.yml](../../../../../.github/workflows/cron-cleanup-stale.yml): `๐Ÿงน Prune stale data` | Marks and closes stale issues and PRs, deletes inactive branches, and prunes old GHCR CI image versions. | auto (`schedule`: daily 00:00 UTC), manual | none | -| [cron-update.yml](../../../../../.github/workflows/cron-update.yml): `๐Ÿ”„ Update versions` | Updates Docker image versions and other pinned dependencies; opens an update PR via a GitHub App installation token so PR-lifecycle events fire on the resulting PR. Both jobs are gated behind the `CI_ENABLE_AUTO_UPDATES` repository variable, see [configuration.md](configuration.md). Requires the `BOT_APP_CLIENT_ID` and `BOT_APP_PRIVATE_KEY` repository secrets, see [secrets.md](secrets.md). | auto (`push` to `main`, `schedule`: daily 00:30 UTC), manual | none | -| [entry-pr-translate.yml](../../../../../.github/workflows/entry-pr-translate.yml): `๐ŸŒ Translate catalogs` | Merges the source strings of the `core` and `docs` domains into `locale/`, then machine-translates what a pull request leaves empty or fuzzy, one runner per language LibreTranslate supports. Each runner opens its own PR against the head branch of the triggering PR. Gated behind the `CI_ENABLE_AUTO_TRANSLATIONS` repository variable, see [configuration.md](configuration.md); pull requests from a fork are skipped. Requires the `BOT_APP_CLIENT_ID` and `BOT_APP_PRIVATE_KEY` repository secrets, see [secrets.md](secrets.md). | auto (`pull_request` against `main`: opened, synchronize, reopened) | none | +| [cron-update.yml](../../../../../.github/workflows/cron-update.yml): `๐Ÿ”„ Update versions` | Updates Docker image versions and other pinned dependencies; opens an update PR via a GitHub App installation token so PR-lifecycle events fire on the resulting PR. Both jobs are gated behind the `CI_ENABLE_AUTO_UPDATES` repository variable, see [configuration.md](configuration.md). Requires the `BOT_APP_CLIENT_ID` and `BOT_APP_PRIVATE_KEY` secrets of the `updater` environment, see [secrets.md](secrets.md). | auto (`push` to `main`, `schedule`: daily 00:30 UTC), manual | none | +| [entry-pr-translate.yml](../../../../../.github/workflows/entry-pr-translate.yml): `๐ŸŒ Translate catalogs` | Merges the source strings of the `core` and `docs` domains into `locale/`, then machine-translates what a pull request leaves empty or fuzzy, one runner per language LibreTranslate supports. Each runner opens its own PR against the head branch of the triggering PR. Gated behind the `CI_ENABLE_AUTO_TRANSLATIONS` repository variable, see [configuration.md](configuration.md); pull requests from a fork are skipped. Requires the `TRANSLATE_APP_CLIENT_ID` and `TRANSLATE_APP_PRIVATE_KEY` repository secrets of a separate App, see [secrets.md](secrets.md). | auto (`pull_request` against `main`: opened, synchronize, reopened) | none | | [entry-pr-open-dependabot-close.yml](../../../../../.github/workflows/entry-pr-open-dependabot-close.yml): `๐Ÿšซ Dependabot: Close while auto-updates disabled` | Auto-closes Dependabot PRs while `CI_ENABLE_AUTO_UPDATES` is not set to `true`, so Dependabot honours the same gate as the workflow-driven update jobs. See [configuration.md](configuration.md). | auto (`pull_request_target`: opened, reopened) | none | | [entry-pr-change-dependabot-label.yml](../../../../../.github/workflows/entry-pr-change-dependabot-label.yml): `๐Ÿ”„ Dependabot: Label update level` | Labels every Dependabot PR `โฌ†๏ธ update` plus exactly one of `๐Ÿ”ด major`, `๐ŸŸก minor` and `๐ŸŸข patch`, read from the `update-type` of `dependabot/fetch-metadata`; a type that names no semver level counts as `major`. Creates a missing label, adds only labels the PR lacks and checks out the base branch only. Gated behind `CI_ENABLE_AUTO_UPDATES`, see [configuration.md](configuration.md). | auto (`pull_request_target`: opened, reopened, synchronize) | none | | [entry-pr-green-update-merge.yml](../../../../../.github/workflows/entry-pr-green-update-merge.yml): `๐Ÿ”„ Update: Merge proven PRs` | Runs when a `๐Ÿ”€ Pull Request` run of the `pull_request` event succeeds on an `update/*` or `dependabot/*` branch. [cli.contributing.update.merge](../../../../../cli/contributing/update/merge/__main__.py) merges the PR only when the `infinito-nexus-updater[bot]` App or `dependabot[bot]` opened it, it carries `โฌ†๏ธ update`, every check run and commit status on its head is green, and the run's `role-runtimes-*` artifacts list every role the PR changes. Otherwise it prints why and the PR stays open for a manual merge. The merge pins the tested head and uses the token of a separate merge App, which becomes a bypass actor of the `Main` ruleset only once the prerequisites in [secrets.md](secrets.md#prerequisites-for-the-bypass-) hold; until then the PR waits for a manual merge. Gated behind `CI_ENABLE_AUTO_UPDATES`, see [configuration.md](configuration.md); requires the `MERGE_APP_CLIENT_ID` and `MERGE_APP_PRIVATE_KEY` secrets of the `auto-merge` environment, see [secrets.md](secrets.md). | auto (`workflow_run` of `๐Ÿ”€ Pull Request`: completed) | none | From 05d298f2177564c6634541d9bab180f0f40f1787 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 27 Nov 2026 11:39:57 +0000 Subject: [PATCH 06/12] docs(ci): require a rotated updater key before the merge bypass MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Same-repository pull requests could read the updater key through the translation workflow until c578f311, and a copy taken then stays valid after the secret moves. Prerequisite 3 now requires a regenerated updater key in the updater environment and every older key deleted on the App page before the merge App joins the Main bypass list. Third CodeRabbit finding on PR #3066. ๐ŸŽฏ Fix: 92 % ๐Ÿ’ฅ Break: 1 % ๐Ÿ’ธ Tokens: 108 % โฑ๏ธ Velocity: 112 % ๐Ÿ›ก๏ธ Security: 100 % ๐Ÿ† Score: 75 ๐Ÿšฆ Gate: โš ๏ธ tokens 108 % > 100, velocity 112 % > 100: operator approved via hub decision bfd92507d88d0a7c Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 --- docs/contributing/tools/github/actions/secrets.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/contributing/tools/github/actions/secrets.md b/docs/contributing/tools/github/actions/secrets.md index d81abc8528..a15f42158d 100644 --- a/docs/contributing/tools/github/actions/secrets.md +++ b/docs/contributing/tools/github/actions/secrets.md @@ -150,8 +150,9 @@ The merge gate checks who opened the PR, not who pushed its head commit, so the 1. A branch ruleset on `update/**` and `dependabot/**` restricts creation, updates and deletion, with only the updater App, Dependabot and the admin role on its bypass list. The admin role lets a maintainer merge a translation PR or push a fixup onto an update branch; the translation App stays off it. 2. `BOT_APP_CLIENT_ID` and `BOT_APP_PRIVATE_KEY` exist only as secrets of the `updater` environment, restricted to `main`, and no longer as repository secrets, so no `pull_request` run can read them; [entry-pr-translate.yml](../../../../../.github/workflows/entry-pr-translate.yml) uses the [translation App](#translate_app_client_id-and-translate_app_private_key-). As with `auto-merge`, a `pull_request_target` or `workflow_run` job passes that branch rule, so no job that declares the environment may check out or execute pull-request code; list every workflow that declares it and confirm this before step 4. +3. The updater App's private key was regenerated after the translation workflow stopped minting from it, the new key is the one in `updater`, and every older key is deleted under **Private keys** on the App's settings page. Same-repository pull requests could read the old key, and a copy taken then stays valid until it is revoked. -With both in place, pushing a head the gate accepts needs the updater key, which only workflows on `main` can read. Until then the merge App stays off the bypass list, the merge call fails with HTTP 405, and update PRs wait for a manual merge: the ruleset's `update` rule (Restrict updates) lets only bypass actors move `main`, pull-request merges included, whatever reviews the PR holds. +With all three in place, pushing a head the gate accepts needs the updater key, which only workflows on `main` can read. Until then the merge App stays off the bypass list, the merge call fails with HTTP 405, and update PRs wait for a manual merge: the ruleset's `update` rule (Restrict updates) lets only bypass actors move `main`, pull-request merges included, whatever reviews the PR holds. The job mints the App token only after its merge gate passed, narrowed to `contents`, `pull-requests` and `workflows` write, and uses it for the merge call alone; the gate reads with the read-only `GITHUB_TOKEN`. The job runs on `workflow_run`, which always runs on the default branch, so the environment's branch rule admits it. Without the bypass, the merge call fails with `Repository rule violations found` (HTTP 405) and the PR stays open. From 286918ecfcdb92a9b08fe9678ac7db78db155084 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 27 Nov 2026 12:06:12 +0000 Subject: [PATCH 07/12] feat(update): walk the operator through the updater key and translation App MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit python -m cli.contributing.update.apps creates the updater environment restricted to main when it is missing, stores a freshly generated updater key there, waits until the older keys are deleted, prefills the form for the separate translation App and stores its key as a repository secret, then removes repository copies of the updater key and offers to delete the downloaded PEM files. Keys reach gh on stdin only. Tests cover stdin-only key transfer, the environment check, PEM and client ID validation and the confirmation stops. ๐ŸŽฏ Fix: 90 % ๐Ÿ’ฅ Break: 1 % ๐Ÿ’ธ Tokens: 97 % โฑ๏ธ Velocity: 94 % ๐Ÿ›ก๏ธ Security: 100 % ๐Ÿ† Score: 98 ๐Ÿšฆ Gate: โœ… 90/5, tokens and velocity <= 100, security 100 % Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 --- cli/contributing/update/README.md | 11 + cli/contributing/update/apps/__init__.py | 0 cli/contributing/update/apps/__main__.py | 271 ++++++++++++++++++ .../tools/github/actions/secrets.md | 2 + .../cli/contributing/update/apps/__init__.py | 0 .../cli/contributing/update/apps/test_main.py | 144 ++++++++++ 6 files changed, 428 insertions(+) create mode 100644 cli/contributing/update/apps/__init__.py create mode 100755 cli/contributing/update/apps/__main__.py create mode 100644 tests/unit/python/cli/contributing/update/apps/__init__.py create mode 100644 tests/unit/python/cli/contributing/update/apps/test_main.py diff --git a/cli/contributing/update/README.md b/cli/contributing/update/README.md index 0b933bf733..1950be4b8e 100644 --- a/cli/contributing/update/README.md +++ b/cli/contributing/update/README.md @@ -133,3 +133,14 @@ fails `tests/lint/ansible/services/test_version_keys.py`. Run `python -m cli.contributing.update.source --dry-run` to list pending bumps; the `update-version-sources` job of `.github/workflows/cron-update.yml` opens the PRs, and `tests/external/update/source/` warns about them. + +## App credentials + +`python -m cli.contributing.update.apps --repo infinito-nexus/core --updater-slug infinito-nexus-updater --translate-slug infinito-nexus-translator` +walks the operator through the browser steps and stores the results with `gh`: +it creates the `updater` environment restricted to `main` when it is missing, +stores a freshly generated updater key there, waits until the older keys are +deleted, prefills the form for the separate translation App and stores its +key as a repository secret. Keys go to `gh` on stdin and are never printed; +`--skip-updater` resumes after the updater step. See +[secrets.md](../../../docs/contributing/tools/github/actions/secrets.md). diff --git a/cli/contributing/update/apps/__init__.py b/cli/contributing/update/apps/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cli/contributing/update/apps/__main__.py b/cli/contributing/update/apps/__main__.py new file mode 100755 index 0000000000..d9230e07c8 --- /dev/null +++ b/cli/contributing/update/apps/__main__.py @@ -0,0 +1,271 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import argparse +import re +import subprocess +import sys +from pathlib import Path +from typing import TYPE_CHECKING +from urllib.parse import urlencode + +if TYPE_CHECKING: + from collections.abc import Callable, Sequence + + Gh = Callable[[Sequence[str], bytes | None], bytes] + Ask = Callable[[str], str] + Say = Callable[[str], None] + +GH_TIMEOUT_SECONDS = 120 +UPDATER_ENVIRONMENT = "updater" +UPDATER_BRANCH = "main" +UPDATER_SECRETS = ("BOT_APP_CLIENT_ID", "BOT_APP_PRIVATE_KEY") +TRANSLATE_SECRETS = ("TRANSLATE_APP_CLIENT_ID", "TRANSLATE_APP_PRIVATE_KEY") +_CLIENT_ID = re.compile(r"Iv[0-9A-Za-z.]{8,}") + + +def run_gh(args: Sequence[str], stdin: bytes | None) -> bytes: + return subprocess.run( + ["gh", *args], + input=stdin, + capture_output=True, + check=True, + timeout=GH_TIMEOUT_SECONDS, + ).stdout + + +def lines(out: bytes) -> list[str]: + return [line for line in out.decode("utf-8").splitlines() if line.strip()] + + +def ensure_environment(gh: Gh, repo: str, say: Say) -> None: + """ + Args: + gh: runs ``gh`` with the given arguments and stdin, returns its stdout. + repo: ``owner/name``. + say: prints one line to the operator. + + Raises: + SystemExit: the environment exists with other deployment branches. + """ + path = f"repos/{repo}/environments/{UPDATER_ENVIRONMENT}" + names = lines( + gh(["api", f"repos/{repo}/environments", "--jq", ".environments[].name"], None) + ) + if UPDATER_ENVIRONMENT not in names: + gh( + [ + "api", + "--method", + "PUT", + path, + "-F", + "deployment_branch_policy[protected_branches]=false", + "-F", + "deployment_branch_policy[custom_branch_policies]=true", + ], + None, + ) + gh( + [ + "api", + "--method", + "POST", + f"{path}/deployment-branch-policies", + "-f", + f"name={UPDATER_BRANCH}", + "-f", + "type=branch", + ], + None, + ) + say( + f"created environment {UPDATER_ENVIRONMENT}, restricted to {UPDATER_BRANCH}" + ) + return + policies = lines( + gh( + [ + "api", + f"{path}/deployment-branch-policies", + "--jq", + ".branch_policies[].name", + ], + None, + ) + ) + if policies != [UPDATER_BRANCH]: + raise SystemExit( + f"environment {UPDATER_ENVIRONMENT} allows {policies or 'every branch'}, " + f"not only {UPDATER_BRANCH}: fix it under https://github.com/{repo}/settings/environments" + ) + say(f"environment {UPDATER_ENVIRONMENT} exists, restricted to {UPDATER_BRANCH}") + + +def read_private_key(path: Path) -> bytes: + """ + Args: + path: the file the App's settings page downloaded. + + Returns: + the file's bytes, never printed. + + Raises: + SystemExit: the file is missing or holds no PEM private key. + """ + if not path.is_file(): + raise SystemExit(f"no file at {path}") + data = path.read_bytes() # nocheck: cache-read + if b"-----BEGIN" not in data or b"PRIVATE KEY-----" not in data: + raise SystemExit(f"{path} holds no PEM private key") + return data + + +def ask_client_id(ask: Ask, app: str) -> str: + value = ask(f"Client ID of {app} (Iv..., on the App's General page): ").strip() + if not _CLIENT_ID.fullmatch(value): + raise SystemExit(f"{value!r} is no GitHub App Client ID; it starts with Iv") + return value + + +def confirm(ask: Ask, question: str) -> None: + if ask(f"{question} [y/N] ").strip().lower() != "y": + raise SystemExit("stopped; run again once that step is done") + + +def set_secret( + gh: Gh, repo: str, name: str, value: bytes, environment: str | None +) -> None: + """ + Args: + gh: runs ``gh`` with the given arguments and stdin. + repo: ``owner/name``. + name: the secret's name. + value: the secret's bytes. + environment: the environment holding it, ``None`` for a repository secret. + """ + scope = ["--env", environment] if environment is not None else [] + gh(["secret", "set", name, "--repo", repo, *scope], value) + + +def app_page(org: str, slug: str) -> str: + return f"https://github.com/organizations/{org}/settings/apps/{slug}" + + +def new_app_url(org: str, repo: str, name: str) -> str: + query = urlencode( + { + "name": name, + "url": f"https://github.com/{repo}", + "public": "false", + "webhook_active": "false", + "contents": "write", + "pull_requests": "write", + } + ) + return f"https://github.com/organizations/{org}/settings/apps/new?{query}" + + +def rotate_updater_key(gh: Gh, repo: str, slug: str, ask: Ask, say: Say) -> Path: + org = repo.split("/", maxsplit=1)[0] + say(f"\n1. Updater App: open {app_page(org, slug)}") + say( + " Under 'Private keys' press 'Generate a private key'; the browser downloads a .pem." + ) + client_id = ask_client_id(ask, slug) + pem = Path(ask("Path of the downloaded .pem: ").strip()).expanduser() + key = read_private_key(pem) + set_secret(gh, repo, UPDATER_SECRETS[0], client_id.encode(), UPDATER_ENVIRONMENT) + set_secret(gh, repo, UPDATER_SECRETS[1], key, UPDATER_ENVIRONMENT) + say(f" stored {', '.join(UPDATER_SECRETS)} in environment {UPDATER_ENVIRONMENT}") + say( + f" Now delete every OLDER key on {app_page(org, slug)}; keep only the one just made." + ) + confirm(ask, " Only the new updater key is left?") + return pem + + +def create_translate_app(gh: Gh, repo: str, slug: str, ask: Ask, say: Say) -> Path: + org = repo.split("/", maxsplit=1)[0] + say(f"\n2. Translation App: open {new_app_url(org, repo, slug)}") + say( + " The form is prefilled (no webhook, Contents and Pull requests write); press 'Create GitHub App'." + ) + say(" Then 'Generate a private key', and install it on the core repository only:") + say(f" https://github.com/apps/{slug}/installations/new") + confirm(ask, f" {slug} is created and installed on {repo} alone?") + client_id = ask_client_id(ask, slug) + pem = Path(ask("Path of the downloaded .pem: ").strip()).expanduser() + key = read_private_key(pem) + set_secret(gh, repo, TRANSLATE_SECRETS[0], client_id.encode(), None) + set_secret(gh, repo, TRANSLATE_SECRETS[1], key, None) + say( + f" stored {', '.join(TRANSLATE_SECRETS)} as repository secrets; never add {slug} to a bypass list" + ) + return pem + + +def drop_repository_copies(gh: Gh, repo: str, say: Say) -> None: + names = lines( + gh( + ["secret", "list", "--repo", repo, "--json", "name", "--jq", ".[].name"], + None, + ) + ) + for name in UPDATER_SECRETS: + if name in names: + gh(["secret", "delete", name, "--repo", repo], None) + say(f" deleted repository secret {name}; pull_request runs could read it") + + +def main(argv: Sequence[str] | None, gh: Gh, ask: Ask, say: Say) -> int: + """ + Args: + argv: command-line arguments; ``None`` reads ``sys.argv``. + gh: runs ``gh`` with the given arguments and stdin, returns its stdout. + ask: reads one answer from the operator. + say: prints one line to the operator. + + Returns: + 0 once every secret is in place. + """ + parser = argparse.ArgumentParser( + description=( + "Rotate the updater App key into the main-only updater environment and " + "set up the separate translation App, through gh and the browser." + ) + ) + parser.add_argument("--repo", required=True, help="owner/name") + parser.add_argument("--updater-slug", required=True, help="Slug of the updater App") + parser.add_argument( + "--translate-slug", required=True, help="Slug for the translation App" + ) + parser.add_argument( + "--skip-updater", action="store_true", help="Updater key already rotated" + ) + args = parser.parse_args(argv) + + gh(["auth", "status"], None) + ensure_environment(gh, args.repo, say) + pems = [] + if not args.skip_updater: + pems.append(rotate_updater_key(gh, args.repo, args.updater_slug, ask, say)) + pems.append(create_translate_app(gh, args.repo, args.translate_slug, ask, say)) + say("\n3. Repository copies of the updater key") + drop_repository_copies(gh, args.repo, say) + say("\n4. Downloaded keys") + for pem in pems: + if ask(f" Delete {pem}? [y/N] ").strip().lower() == "y": + pem.unlink() + say(f" deleted {pem}") + say( + "\nDone. Merge the pull request that moves the workflows to these secrets next;" + ) + say( + "the merge App joins the Main bypass list only after its prerequisites in secrets.md hold." + ) + return 0 + + +if __name__ == "__main__": + sys.exit(main(None, run_gh, input, print)) diff --git a/docs/contributing/tools/github/actions/secrets.md b/docs/contributing/tools/github/actions/secrets.md index a15f42158d..8bf830b217 100644 --- a/docs/contributing/tools/github/actions/secrets.md +++ b/docs/contributing/tools/github/actions/secrets.md @@ -93,6 +93,8 @@ A classic personal access token MAY be used as a fallback for unrelated automati ### How to hand the credentials to CI ๐Ÿ“ฅ +`python -m cli.contributing.update.apps --repo infinito-nexus/core --updater-slug infinito-nexus-updater --translate-slug infinito-nexus-translator` walks through the steps below and the [translation App](#translate_app_client_id-and-translate_app_private_key-) through `gh`, passing every key on stdin. Done by hand: + 1. Open the repository on GitHub. 2. Go to **Settings โ†’ Environments โ†’ New environment**, name it `updater`, and under **Deployment branches and tags** choose **Selected branches and tags** with the single rule `main`. 3. Under **Environment secrets**, add `BOT_APP_CLIENT_ID` with the App's Client ID (shown on the App's General page under **About**, in the `Ivโ€ฆ` format, *not* the numeric App ID). diff --git a/tests/unit/python/cli/contributing/update/apps/__init__.py b/tests/unit/python/cli/contributing/update/apps/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/unit/python/cli/contributing/update/apps/test_main.py b/tests/unit/python/cli/contributing/update/apps/test_main.py new file mode 100644 index 0000000000..7acd3b6aea --- /dev/null +++ b/tests/unit/python/cli/contributing/update/apps/test_main.py @@ -0,0 +1,144 @@ +from __future__ import annotations + +import tempfile +import unittest +from pathlib import Path + +import cli.contributing.update.apps.__main__ as apps + +REPO = "infinito-nexus/core" +KEY = b"-----BEGIN RSA PRIVATE KEY-----\nabc\n-----END RSA PRIVATE KEY-----\n" +UPDATER_ID = "Iv23liUpdater01" +TRANSLATE_ID = "Iv23liTranslate1" + + +class FakeGh: + def __init__(self, environments: str, policies: str, repo_secrets: str) -> None: + self.calls: list[tuple[list[str], bytes | None]] = [] + self.outputs = { + f"repos/{REPO}/environments": environments, + f"repos/{REPO}/environments/updater/deployment-branch-policies": policies, + } + self.repo_secrets = repo_secrets + + def __call__(self, args, stdin): + self.calls.append((list(args), stdin)) + if args[:2] == ["secret", "list"]: + return self.repo_secrets.encode() + if args[0] == "api" and len(args) > 1: + return self.outputs.get(args[1], "").encode() + return b"" + + def secrets_set(self): + return [ + (a[2], a[a.index("--env") + 1] if "--env" in a else None, s) + for a, s in self.calls + if a[:2] == ["secret", "set"] + ] + + +class AppsMainTest(unittest.TestCase): + def setUp(self) -> None: + holder = tempfile.TemporaryDirectory() + self.addCleanup(holder.cleanup) + self.tmp = Path(holder.name) + self.updater_pem = self.tmp / "updater.pem" + self.translate_pem = self.tmp / "translate.pem" + self.updater_pem.write_bytes(KEY) + self.translate_pem.write_bytes(KEY) + self.said: list[str] = [] + + def run_main(self, gh, answers, *extra): + replies = iter(answers) + return apps.main( + [ + "--repo", + REPO, + "--updater-slug", + "infinito-nexus-updater", + "--translate-slug", + "infinito-nexus-translator", + *extra, + ], + gh=gh, + ask=lambda _prompt: next(replies), + say=self.said.append, + ) + + def full_answers(self): + return [ + UPDATER_ID, + str(self.updater_pem), + "y", + "y", + TRANSLATE_ID, + str(self.translate_pem), + "y", + "y", + ] + + def test_keys_reach_gh_through_stdin_only(self) -> None: + gh = FakeGh("updater\n", "main\n", "") + self.assertEqual(self.run_main(gh, self.full_answers()), 0) + self.assertEqual( + gh.secrets_set(), + [ + ("BOT_APP_CLIENT_ID", "updater", UPDATER_ID.encode()), + ("BOT_APP_PRIVATE_KEY", "updater", KEY), + ("TRANSLATE_APP_CLIENT_ID", None, TRANSLATE_ID.encode()), + ("TRANSLATE_APP_PRIVATE_KEY", None, KEY), + ], + ) + for args, _stdin in gh.calls: + self.assertNotIn(KEY.decode(), " ".join(args)) + self.assertNotIn(KEY.decode(), "\n".join(self.said)) + self.assertFalse(self.updater_pem.exists()) + self.assertFalse(self.translate_pem.exists()) + + def test_missing_environment_is_created_main_only(self) -> None: + gh = FakeGh("auto-merge\n", "", "") + self.run_main(gh, self.full_answers()) + api = [a for a, _ in gh.calls if a[0] == "api" and "--method" in a] + self.assertEqual(api[0][2:4], ["PUT", f"repos/{REPO}/environments/updater"]) + self.assertIn("name=main", api[1]) + + def test_environment_open_to_other_branches_stops_before_any_secret(self) -> None: + gh = FakeGh("updater\n", "main\nfeature/*\n", "") + with self.assertRaises(SystemExit): + self.run_main(gh, self.full_answers()) + self.assertEqual(gh.secrets_set(), []) + + def test_file_without_private_key_stops_before_any_secret(self) -> None: + self.updater_pem.write_bytes(b"not a key") + gh = FakeGh("updater\n", "main\n", "") + with self.assertRaises(SystemExit): + self.run_main(gh, self.full_answers()) + self.assertEqual(gh.secrets_set(), []) + + def test_unconfirmed_old_key_deletion_stops_before_translation(self) -> None: + gh = FakeGh("updater\n", "main\n", "") + answers = [UPDATER_ID, str(self.updater_pem), "n"] + with self.assertRaises(SystemExit): + self.run_main(gh, answers) + self.assertEqual( + [n for n, _, _ in gh.secrets_set()], + ["BOT_APP_CLIENT_ID", "BOT_APP_PRIVATE_KEY"], + ) + + def test_repository_copies_of_the_updater_key_are_deleted(self) -> None: + gh = FakeGh("updater\n", "main\n", "BOT_APP_PRIVATE_KEY\nDOCKERHUB_TOKEN\n") + answers = ["y", TRANSLATE_ID, str(self.translate_pem), "n"] + self.run_main(gh, answers, "--skip-updater") + deleted = [a[2] for a, _ in gh.calls if a[:2] == ["secret", "delete"]] + self.assertEqual(deleted, ["BOT_APP_PRIVATE_KEY"]) + self.assertTrue(self.translate_pem.exists()) + + def test_client_id_must_be_an_app_client_id(self) -> None: + gh = FakeGh("updater\n", "main\n", "") + with self.assertRaises(SystemExit): + self.run_main(gh, ["12345", str(self.updater_pem)]) + self.assertEqual(gh.secrets_set(), []) + + +if __name__ == "__main__": + unittest.main() From 6c24f07359771c2f9f5ba3c7d4bc9d52915fa7a8 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 27 Nov 2026 12:31:14 +0000 Subject: [PATCH 08/12] fix(update): name the secret-name constants after their content MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CodeQL py/clear-text-logging-sensitive-data (alerts 1312-1314 on PR #3066) read UPDATER_SECRETS and TRANSLATE_SECRETS as secret values because of their names, so every status line printing them looked like a leak. They hold only the secret names; UPDATER_NAMES and TRANSLATE_NAMES say so. Keys still reach gh on stdin only. ๐ŸŽฏ Fix: 92 % ๐Ÿ’ฅ Break: 1 % ๐Ÿ’ธ Tokens: 98 % โฑ๏ธ Velocity: 96 % ๐Ÿ›ก๏ธ Security: 100 % ๐Ÿ† Score: 97 ๐Ÿšฆ Gate: โœ… 90/5, tokens and velocity <= 100, security 100 % Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 --- cli/contributing/update/apps/__main__.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cli/contributing/update/apps/__main__.py b/cli/contributing/update/apps/__main__.py index d9230e07c8..e070212389 100755 --- a/cli/contributing/update/apps/__main__.py +++ b/cli/contributing/update/apps/__main__.py @@ -19,8 +19,8 @@ if TYPE_CHECKING: GH_TIMEOUT_SECONDS = 120 UPDATER_ENVIRONMENT = "updater" UPDATER_BRANCH = "main" -UPDATER_SECRETS = ("BOT_APP_CLIENT_ID", "BOT_APP_PRIVATE_KEY") -TRANSLATE_SECRETS = ("TRANSLATE_APP_CLIENT_ID", "TRANSLATE_APP_PRIVATE_KEY") +UPDATER_NAMES = ("BOT_APP_CLIENT_ID", "BOT_APP_PRIVATE_KEY") +TRANSLATE_NAMES = ("TRANSLATE_APP_CLIENT_ID", "TRANSLATE_APP_PRIVATE_KEY") _CLIENT_ID = re.compile(r"Iv[0-9A-Za-z.]{8,}") @@ -175,9 +175,9 @@ def rotate_updater_key(gh: Gh, repo: str, slug: str, ask: Ask, say: Say) -> Path client_id = ask_client_id(ask, slug) pem = Path(ask("Path of the downloaded .pem: ").strip()).expanduser() key = read_private_key(pem) - set_secret(gh, repo, UPDATER_SECRETS[0], client_id.encode(), UPDATER_ENVIRONMENT) - set_secret(gh, repo, UPDATER_SECRETS[1], key, UPDATER_ENVIRONMENT) - say(f" stored {', '.join(UPDATER_SECRETS)} in environment {UPDATER_ENVIRONMENT}") + set_secret(gh, repo, UPDATER_NAMES[0], client_id.encode(), UPDATER_ENVIRONMENT) + set_secret(gh, repo, UPDATER_NAMES[1], key, UPDATER_ENVIRONMENT) + say(f" stored {', '.join(UPDATER_NAMES)} in environment {UPDATER_ENVIRONMENT}") say( f" Now delete every OLDER key on {app_page(org, slug)}; keep only the one just made." ) @@ -197,10 +197,10 @@ def create_translate_app(gh: Gh, repo: str, slug: str, ask: Ask, say: Say) -> Pa client_id = ask_client_id(ask, slug) pem = Path(ask("Path of the downloaded .pem: ").strip()).expanduser() key = read_private_key(pem) - set_secret(gh, repo, TRANSLATE_SECRETS[0], client_id.encode(), None) - set_secret(gh, repo, TRANSLATE_SECRETS[1], key, None) + set_secret(gh, repo, TRANSLATE_NAMES[0], client_id.encode(), None) + set_secret(gh, repo, TRANSLATE_NAMES[1], key, None) say( - f" stored {', '.join(TRANSLATE_SECRETS)} as repository secrets; never add {slug} to a bypass list" + f" stored {', '.join(TRANSLATE_NAMES)} as repository secrets; never add {slug} to a bypass list" ) return pem @@ -212,7 +212,7 @@ def drop_repository_copies(gh: Gh, repo: str, say: Say) -> None: None, ) ) - for name in UPDATER_SECRETS: + for name in UPDATER_NAMES: if name in names: gh(["secret", "delete", name, "--repo", repo], None) say(f" deleted repository secret {name}; pull_request runs could read it") From ffe28a77c2a391799b649619e17293ddebefd30e Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 27 Nov 2026 12:55:18 +0000 Subject: [PATCH 09/12] feat(update): guide each browser step of the app credentials CLI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The CLI named a 'Private keys' section GitHub no longer shows. Each step is now numbered and names the current menus: Credentials, Key pairs, Generate a private key for the key, General, About for the Client ID, Install App, Only select repositories for the installation. It waits for Enter after every browser step, and with --downloads it offers the .pem that appeared there during that step, ignoring older files. README and secrets.md show the new call. ๐ŸŽฏ Fix: 90 % ๐Ÿ’ฅ Break: 2 % ๐Ÿ’ธ Tokens: 89 % โฑ๏ธ Velocity: 77 % ๐Ÿ›ก๏ธ Security: 100 % ๐Ÿ† Score: 100 ๐Ÿšฆ Gate: โœ… 90/5, tokens and velocity <= 100, security 100 % Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 --- cli/contributing/update/README.md | 6 +- cli/contributing/update/apps/__main__.py | 110 ++++++++++++++---- .../tools/github/actions/secrets.md | 2 +- .../cli/contributing/update/apps/test_main.py | 52 ++++++++- 4 files changed, 137 insertions(+), 33 deletions(-) diff --git a/cli/contributing/update/README.md b/cli/contributing/update/README.md index 1950be4b8e..7c508a8e15 100644 --- a/cli/contributing/update/README.md +++ b/cli/contributing/update/README.md @@ -136,8 +136,10 @@ the PRs, and `tests/external/update/source/` warns about them. ## App credentials -`python -m cli.contributing.update.apps --repo infinito-nexus/core --updater-slug infinito-nexus-updater --translate-slug infinito-nexus-translator` -walks the operator through the browser steps and stores the results with `gh`: +`python -m cli.contributing.update.apps --repo infinito-nexus/core --updater-slug infinito-nexus-updater --translate-slug infinito-nexus-translator --downloads ~/Downloads` +walks the operator through the browser steps and stores the results with `gh`. +It names each menu entry to click, waits for Enter after every browser step and +offers the `.pem` that appeared in `--downloads` during that step: it creates the `updater` environment restricted to `main` when it is missing, stores a freshly generated updater key there, waits until the older keys are deleted, prefills the form for the separate translation App and stores its diff --git a/cli/contributing/update/apps/__main__.py b/cli/contributing/update/apps/__main__.py index e070212389..9e1d6e8ab8 100755 --- a/cli/contributing/update/apps/__main__.py +++ b/cli/contributing/update/apps/__main__.py @@ -5,6 +5,7 @@ import argparse import re import subprocess import sys +import time from pathlib import Path from typing import TYPE_CHECKING from urllib.parse import urlencode @@ -121,8 +122,11 @@ def read_private_key(path: Path) -> bytes: return data -def ask_client_id(ask: Ask, app: str) -> str: - value = ask(f"Client ID of {app} (Iv..., on the App's General page): ").strip() +def ask_client_id(ask: Ask, say: Say, app: str) -> str: + say( + f" In the left menu of {app} open 'General'; under 'About' copy the 'Client ID'." + ) + value = ask(" Client ID (starts with Iv): ").strip() if not _CLIENT_ID.fullmatch(value): raise SystemExit(f"{value!r} is no GitHub App Client ID; it starts with Iv") return value @@ -133,6 +137,43 @@ def confirm(ask: Ask, question: str) -> None: raise SystemExit("stopped; run again once that step is done") +def wait(ask: Ask, what: str) -> None: + ask(f" {what} Press Enter when done.") + + +def newest_pem(downloads: Path, since: float) -> Path | None: + """ + Args: + downloads: the directory the browser saves into. + since: epoch seconds; older files are ignored. + + Returns: + the most recently modified ``*.pem`` saved at or after *since*, or + ``None`` when there is none. + """ + fresh = [p for p in downloads.glob("*.pem") if p.stat().st_mtime >= since] + return max(fresh, key=lambda p: p.stat().st_mtime) if fresh else None + + +def ask_pem(ask: Ask, say: Say, downloads: Path | None, since: float) -> Path: + found = newest_pem(downloads, since) if downloads is not None else None + if found is None: + return Path(ask(" Path of the downloaded .pem: ").strip()).expanduser() + say(f" Found the new key {found}") + typed = ask(" Press Enter to use it, or type another path: ").strip() + return Path(typed).expanduser() if typed else found + + +def generate_key(ask: Ask, say: Say, page: str) -> float: + since = time.time() + say(f" Open {page}") + say( + " In the left menu open 'Credentials', tab 'Key pairs', press 'Generate a private key'." + ) + wait(ask, "The browser downloads a .pem file.") + return since + + def set_secret( gh: Gh, repo: str, name: str, value: bytes, environment: str | None ) -> None: @@ -166,37 +207,45 @@ def new_app_url(org: str, repo: str, name: str) -> str: return f"https://github.com/organizations/{org}/settings/apps/new?{query}" -def rotate_updater_key(gh: Gh, repo: str, slug: str, ask: Ask, say: Say) -> Path: +def rotate_updater_key( + gh: Gh, repo: str, slug: str, downloads: Path | None, ask: Ask, say: Say +) -> Path: org = repo.split("/", maxsplit=1)[0] - say(f"\n1. Updater App: open {app_page(org, slug)}") - say( - " Under 'Private keys' press 'Generate a private key'; the browser downloads a .pem." - ) - client_id = ask_client_id(ask, slug) - pem = Path(ask("Path of the downloaded .pem: ").strip()).expanduser() + say(f"\nStep 1 of 4: new key for the updater App {slug}") + since = generate_key(ask, say, app_page(org, slug)) + pem = ask_pem(ask, say, downloads, since) key = read_private_key(pem) + client_id = ask_client_id(ask, say, slug) set_secret(gh, repo, UPDATER_NAMES[0], client_id.encode(), UPDATER_ENVIRONMENT) set_secret(gh, repo, UPDATER_NAMES[1], key, UPDATER_ENVIRONMENT) say(f" stored {', '.join(UPDATER_NAMES)} in environment {UPDATER_ENVIRONMENT}") - say( - f" Now delete every OLDER key on {app_page(org, slug)}; keep only the one just made." - ) + say(" Back in 'Credentials', tab 'Key pairs': delete every key except the newest") + say(" one (the one created just now, see its date).") confirm(ask, " Only the new updater key is left?") return pem -def create_translate_app(gh: Gh, repo: str, slug: str, ask: Ask, say: Say) -> Path: +def create_translate_app( + gh: Gh, repo: str, slug: str, downloads: Path | None, ask: Ask, say: Say +) -> Path: org = repo.split("/", maxsplit=1)[0] - say(f"\n2. Translation App: open {new_app_url(org, repo, slug)}") + say(f"\nStep 2 of 4: create the translation App {slug}") + say(f" Open {new_app_url(org, repo, slug)}") say( - " The form is prefilled (no webhook, Contents and Pull requests write); press 'Create GitHub App'." + " The form is prefilled: no webhook, Contents and Pull requests read and write." ) - say(" Then 'Generate a private key', and install it on the core repository only:") - say(f" https://github.com/apps/{slug}/installations/new") - confirm(ask, f" {slug} is created and installed on {repo} alone?") - client_id = ask_client_id(ask, slug) - pem = Path(ask("Path of the downloaded .pem: ").strip()).expanduser() + wait(ask, "Scroll down and press 'Create GitHub App'.") + since = generate_key(ask, say, app_page(org, slug)) + pem = ask_pem(ask, say, downloads, since) key = read_private_key(pem) + client_id = ask_client_id(ask, say, slug) + say( + " In the left menu open 'Install App', press 'Install' next to the organization," + ) + say( + f" choose 'Only select repositories', pick {repo.split('/', maxsplit=1)[1]}, press 'Install'." + ) + confirm(ask, f" {slug} is installed on {repo} alone?") set_secret(gh, repo, TRANSLATE_NAMES[0], client_id.encode(), None) set_secret(gh, repo, TRANSLATE_NAMES[1], key, None) say( @@ -243,17 +292,30 @@ def main(argv: Sequence[str] | None, gh: Gh, ask: Ask, say: Say) -> int: parser.add_argument( "--skip-updater", action="store_true", help="Updater key already rotated" ) + parser.add_argument( + "--downloads", + type=Path, + help="Directory the browser saves into; the newest .pem there is offered", + ) args = parser.parse_args(argv) gh(["auth", "status"], None) ensure_environment(gh, args.repo, say) pems = [] if not args.skip_updater: - pems.append(rotate_updater_key(gh, args.repo, args.updater_slug, ask, say)) - pems.append(create_translate_app(gh, args.repo, args.translate_slug, ask, say)) - say("\n3. Repository copies of the updater key") + pems.append( + rotate_updater_key( + gh, args.repo, args.updater_slug, args.downloads, ask, say + ) + ) + pems.append( + create_translate_app( + gh, args.repo, args.translate_slug, args.downloads, ask, say + ) + ) + say("\nStep 3 of 4: repository copies of the updater key") drop_repository_copies(gh, args.repo, say) - say("\n4. Downloaded keys") + say("\nStep 4 of 4: downloaded keys") for pem in pems: if ask(f" Delete {pem}? [y/N] ").strip().lower() == "y": pem.unlink() diff --git a/docs/contributing/tools/github/actions/secrets.md b/docs/contributing/tools/github/actions/secrets.md index 8bf830b217..a96e3396d1 100644 --- a/docs/contributing/tools/github/actions/secrets.md +++ b/docs/contributing/tools/github/actions/secrets.md @@ -93,7 +93,7 @@ A classic personal access token MAY be used as a fallback for unrelated automati ### How to hand the credentials to CI ๐Ÿ“ฅ -`python -m cli.contributing.update.apps --repo infinito-nexus/core --updater-slug infinito-nexus-updater --translate-slug infinito-nexus-translator` walks through the steps below and the [translation App](#translate_app_client_id-and-translate_app_private_key-) through `gh`, passing every key on stdin. Done by hand: +`python -m cli.contributing.update.apps --repo infinito-nexus/core --updater-slug infinito-nexus-updater --translate-slug infinito-nexus-translator --downloads ~/Downloads` walks through the steps below and the [translation App](#translate_app_client_id-and-translate_app_private_key-) through `gh`, passing every key on stdin. Done by hand: 1. Open the repository on GitHub. 2. Go to **Settings โ†’ Environments โ†’ New environment**, name it `updater`, and under **Deployment branches and tags** choose **Selected branches and tags** with the single rule `main`. diff --git a/tests/unit/python/cli/contributing/update/apps/test_main.py b/tests/unit/python/cli/contributing/update/apps/test_main.py index 7acd3b6aea..130521f468 100644 --- a/tests/unit/python/cli/contributing/update/apps/test_main.py +++ b/tests/unit/python/cli/contributing/update/apps/test_main.py @@ -1,5 +1,6 @@ from __future__ import annotations +import os import tempfile import unittest from pathlib import Path @@ -67,12 +68,15 @@ class AppsMainTest(unittest.TestCase): def full_answers(self): return [ - UPDATER_ID, + "", str(self.updater_pem), + UPDATER_ID, "y", - "y", - TRANSLATE_ID, + "", + "", str(self.translate_pem), + TRANSLATE_ID, + "y", "y", "y", ] @@ -117,7 +121,7 @@ class AppsMainTest(unittest.TestCase): def test_unconfirmed_old_key_deletion_stops_before_translation(self) -> None: gh = FakeGh("updater\n", "main\n", "") - answers = [UPDATER_ID, str(self.updater_pem), "n"] + answers = ["", str(self.updater_pem), UPDATER_ID, "n"] with self.assertRaises(SystemExit): self.run_main(gh, answers) self.assertEqual( @@ -127,7 +131,7 @@ class AppsMainTest(unittest.TestCase): def test_repository_copies_of_the_updater_key_are_deleted(self) -> None: gh = FakeGh("updater\n", "main\n", "BOT_APP_PRIVATE_KEY\nDOCKERHUB_TOKEN\n") - answers = ["y", TRANSLATE_ID, str(self.translate_pem), "n"] + answers = ["", "", str(self.translate_pem), TRANSLATE_ID, "y", "n"] self.run_main(gh, answers, "--skip-updater") deleted = [a[2] for a, _ in gh.calls if a[:2] == ["secret", "delete"]] self.assertEqual(deleted, ["BOT_APP_PRIVATE_KEY"]) @@ -136,9 +140,45 @@ class AppsMainTest(unittest.TestCase): def test_client_id_must_be_an_app_client_id(self) -> None: gh = FakeGh("updater\n", "main\n", "") with self.assertRaises(SystemExit): - self.run_main(gh, ["12345", str(self.updater_pem)]) + self.run_main(gh, ["", str(self.updater_pem), "12345"]) self.assertEqual(gh.secrets_set(), []) + def test_downloads_offers_only_the_key_generated_during_the_step(self) -> None: + downloads = self.tmp / "downloads" + downloads.mkdir() + stale = downloads / "old.pem" + stale.write_bytes(b"stale") + os.utime(stale, (1, 1)) + fresh = downloads / "infinito-nexus-updater.private-key.pem" + replies = iter(["", UPDATER_ID, "n"]) + prompts: list[str] = [] + + def ask(prompt: str) -> str: + prompts.append(prompt) + if "Press Enter when done" in prompt: + fresh.write_bytes(KEY) + return next(replies) + + gh = FakeGh("updater\n", "main\n", "") + with self.assertRaises(SystemExit): + apps.main( + [ + "--repo", + REPO, + "--updater-slug", + "infinito-nexus-updater", + "--translate-slug", + "infinito-nexus-translator", + "--downloads", + str(downloads), + ], + gh=gh, + ask=lambda p: "" if "use it" in p else ask(p), + say=self.said.append, + ) + self.assertIn(f" Found the new key {fresh}", self.said) + self.assertEqual(gh.secrets_set()[1], ("BOT_APP_PRIVATE_KEY", "updater", KEY)) + if __name__ == "__main__": unittest.main() From 455666865c8af631ffd4ee9123450e1e55b08666 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 27 Nov 2026 13:44:41 +0000 Subject: [PATCH 10/12] fix(update): refuse tag policies and unusable keys, retire pre-rotation heads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The updater environment check now requires exactly one deployment policy of type branch named main, so a tag policy named main no longer passes. The downloaded PEM is parsed with cryptography before any secret is written: truncated, encrypted and non-RSA keys are refused. secrets.md adds prerequisite 4: open update and dependabot pull requests whose head predates the key rotation are closed before the bypass, since the gate checks who opened a pull request, not who pushed its head. Fourth CodeRabbit round on PR #3066. ๐ŸŽฏ Fix: 92 % ๐Ÿ’ฅ Break: 2 % ๐Ÿ’ธ Tokens: 168 % โฑ๏ธ Velocity: 215 % ๐Ÿ›ก๏ธ Security: 100 % ๐Ÿ† Score: 25 ๐Ÿšฆ Gate: โš ๏ธ tokens 168 % > 100, velocity 215 % > 100: operator approved via hub decision 63c0fc40b08ee94d Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 --- cli/contributing/update/apps/__main__.py | 18 +++++--- .../tools/github/actions/secrets.md | 7 ++-- .../cli/contributing/update/apps/test_main.py | 42 ++++++++++++++----- 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/cli/contributing/update/apps/__main__.py b/cli/contributing/update/apps/__main__.py index 9e1d6e8ab8..3fbb8d5e60 100755 --- a/cli/contributing/update/apps/__main__.py +++ b/cli/contributing/update/apps/__main__.py @@ -10,6 +10,10 @@ from pathlib import Path from typing import TYPE_CHECKING from urllib.parse import urlencode +from cryptography.exceptions import UnsupportedAlgorithm +from cryptography.hazmat.primitives.asymmetric import rsa +from cryptography.hazmat.primitives.serialization import load_pem_private_key + if TYPE_CHECKING: from collections.abc import Callable, Sequence @@ -90,12 +94,12 @@ def ensure_environment(gh: Gh, repo: str, say: Say) -> None: "api", f"{path}/deployment-branch-policies", "--jq", - ".branch_policies[].name", + '.branch_policies[] | "\\(.type):\\(.name)"', ], None, ) ) - if policies != [UPDATER_BRANCH]: + if policies != [f"branch:{UPDATER_BRANCH}"]: raise SystemExit( f"environment {UPDATER_ENVIRONMENT} allows {policies or 'every branch'}, " f"not only {UPDATER_BRANCH}: fix it under https://github.com/{repo}/settings/environments" @@ -112,13 +116,17 @@ def read_private_key(path: Path) -> bytes: the file's bytes, never printed. Raises: - SystemExit: the file is missing or holds no PEM private key. + SystemExit: the file is missing or holds no unencrypted RSA private key. """ if not path.is_file(): raise SystemExit(f"no file at {path}") data = path.read_bytes() # nocheck: cache-read - if b"-----BEGIN" not in data or b"PRIVATE KEY-----" not in data: - raise SystemExit(f"{path} holds no PEM private key") + try: + key = load_pem_private_key(data, password=None) + except (ValueError, TypeError, UnsupportedAlgorithm) as exc: + raise SystemExit(f"{path} holds no unencrypted PEM private key") from exc + if not isinstance(key, rsa.RSAPrivateKey): + raise SystemExit(f"{path} holds no RSA private key") return data diff --git a/docs/contributing/tools/github/actions/secrets.md b/docs/contributing/tools/github/actions/secrets.md index a96e3396d1..cf74b4cbf4 100644 --- a/docs/contributing/tools/github/actions/secrets.md +++ b/docs/contributing/tools/github/actions/secrets.md @@ -107,7 +107,7 @@ Each PR-opening job in [cron-update.yml](../../../../../.github/workflows/cron-u These jobs run on `push` to `main`, `schedule` or `workflow_dispatch` and check out `main`; a dispatch on any other branch fails at the environment's branch rule. No job that declares `updater` may check out or execute pull-request code. -This App MUST NOT be a bypass actor of the `Main` ruleset. It is the only bypass actor of the update-branch ruleset, see [Prerequisites for the bypass](#prerequisites-for-the-bypass-). +This App MUST NOT be a bypass actor of the `Main` ruleset. It sits on the update-branch ruleset's bypass list beside Dependabot and the admin role, see [Prerequisites for the bypass](#prerequisites-for-the-bypass-). ## `TRANSLATE_APP_CLIENT_ID` and `TRANSLATE_APP_PRIVATE_KEY` ๐ŸŒ @@ -152,9 +152,10 @@ The merge gate checks who opened the PR, not who pushed its head commit, so the 1. A branch ruleset on `update/**` and `dependabot/**` restricts creation, updates and deletion, with only the updater App, Dependabot and the admin role on its bypass list. The admin role lets a maintainer merge a translation PR or push a fixup onto an update branch; the translation App stays off it. 2. `BOT_APP_CLIENT_ID` and `BOT_APP_PRIVATE_KEY` exist only as secrets of the `updater` environment, restricted to `main`, and no longer as repository secrets, so no `pull_request` run can read them; [entry-pr-translate.yml](../../../../../.github/workflows/entry-pr-translate.yml) uses the [translation App](#translate_app_client_id-and-translate_app_private_key-). As with `auto-merge`, a `pull_request_target` or `workflow_run` job passes that branch rule, so no job that declares the environment may check out or execute pull-request code; list every workflow that declares it and confirm this before step 4. -3. The updater App's private key was regenerated after the translation workflow stopped minting from it, the new key is the one in `updater`, and every older key is deleted under **Private keys** on the App's settings page. Same-repository pull requests could read the old key, and a copy taken then stays valid until it is revoked. +3. The updater App's private key was regenerated after the translation workflow stopped minting from it, the new key is the one in `updater`, and every older key is deleted under **Credentials โ†’ Key pairs** on the App's settings page. Same-repository pull requests could read the old key, and a copy taken then stays valid until it is revoked. +4. Every open pull request on an `update/**` or `dependabot/**` branch whose head was pushed before prerequisite 3 is closed and its branch deleted; the next updater run and Dependabot open fresh ones from heads pushed after the rotation. The gate checks who opened a pull request, not who pushed its head, so a head pushed with the old key would otherwise stay mergeable through the bypass. -With all three in place, pushing a head the gate accepts needs the updater key, which only workflows on `main` can read. Until then the merge App stays off the bypass list, the merge call fails with HTTP 405, and update PRs wait for a manual merge: the ruleset's `update` rule (Restrict updates) lets only bypass actors move `main`, pull-request merges included, whatever reviews the PR holds. +With all four in place, pushing a head the gate accepts needs the updater key, which only workflows on `main` can read. Until then the merge App stays off the bypass list, the merge call fails with HTTP 405, and update PRs wait for a manual merge: the ruleset's `update` rule (Restrict updates) lets only bypass actors move `main`, pull-request merges included, whatever reviews the PR holds. The job mints the App token only after its merge gate passed, narrowed to `contents`, `pull-requests` and `workflows` write, and uses it for the merge call alone; the gate reads with the read-only `GITHUB_TOKEN`. The job runs on `workflow_run`, which always runs on the default branch, so the environment's branch rule admits it. Without the bypass, the merge call fails with `Repository rule violations found` (HTTP 405) and the PR stays open. diff --git a/tests/unit/python/cli/contributing/update/apps/test_main.py b/tests/unit/python/cli/contributing/update/apps/test_main.py index 130521f468..61258a18a7 100644 --- a/tests/unit/python/cli/contributing/update/apps/test_main.py +++ b/tests/unit/python/cli/contributing/update/apps/test_main.py @@ -5,10 +5,24 @@ import tempfile import unittest from pathlib import Path +from cryptography.hazmat.primitives import serialization +from cryptography.hazmat.primitives.asymmetric import ec, rsa + import cli.contributing.update.apps.__main__ as apps REPO = "infinito-nexus/core" -KEY = b"-----BEGIN RSA PRIVATE KEY-----\nabc\n-----END RSA PRIVATE KEY-----\n" +KEY = rsa.generate_private_key(public_exponent=65537, key_size=2048).private_bytes( + serialization.Encoding.PEM, + serialization.PrivateFormat.TraditionalOpenSSL, + serialization.NoEncryption(), +) +TRUNCATED_KEY = b"-----BEGIN RSA PRIVATE KEY-----\nabc\n-----END RSA PRIVATE KEY-----\n" +EC_KEY = ec.generate_private_key(ec.SECP256R1()).private_bytes( + serialization.Encoding.PEM, + serialization.PrivateFormat.PKCS8, + serialization.NoEncryption(), +) +BRANCH_MAIN = "branch:main\n" UPDATER_ID = "Iv23liUpdater01" TRANSLATE_ID = "Iv23liTranslate1" @@ -82,7 +96,7 @@ class AppsMainTest(unittest.TestCase): ] def test_keys_reach_gh_through_stdin_only(self) -> None: - gh = FakeGh("updater\n", "main\n", "") + gh = FakeGh("updater\n", BRANCH_MAIN, "") self.assertEqual(self.run_main(gh, self.full_answers()), 0) self.assertEqual( gh.secrets_set(), @@ -107,20 +121,28 @@ class AppsMainTest(unittest.TestCase): self.assertIn("name=main", api[1]) def test_environment_open_to_other_branches_stops_before_any_secret(self) -> None: - gh = FakeGh("updater\n", "main\nfeature/*\n", "") + gh = FakeGh("updater\n", "branch:main\nbranch:feature/*\n", "") with self.assertRaises(SystemExit): self.run_main(gh, self.full_answers()) self.assertEqual(gh.secrets_set(), []) - def test_file_without_private_key_stops_before_any_secret(self) -> None: - self.updater_pem.write_bytes(b"not a key") - gh = FakeGh("updater\n", "main\n", "") + def test_tag_policy_named_main_stops_before_any_secret(self) -> None: + gh = FakeGh("updater\n", "tag:main\n", "") with self.assertRaises(SystemExit): self.run_main(gh, self.full_answers()) self.assertEqual(gh.secrets_set(), []) + def test_file_without_usable_rsa_key_stops_before_any_secret(self) -> None: + for body in (b"not a key", TRUNCATED_KEY, EC_KEY): + with self.subTest(body=body[:30]): + self.updater_pem.write_bytes(body) + gh = FakeGh("updater\n", BRANCH_MAIN, "") + with self.assertRaises(SystemExit): + self.run_main(gh, self.full_answers()) + self.assertEqual(gh.secrets_set(), []) + def test_unconfirmed_old_key_deletion_stops_before_translation(self) -> None: - gh = FakeGh("updater\n", "main\n", "") + gh = FakeGh("updater\n", BRANCH_MAIN, "") answers = ["", str(self.updater_pem), UPDATER_ID, "n"] with self.assertRaises(SystemExit): self.run_main(gh, answers) @@ -130,7 +152,7 @@ class AppsMainTest(unittest.TestCase): ) def test_repository_copies_of_the_updater_key_are_deleted(self) -> None: - gh = FakeGh("updater\n", "main\n", "BOT_APP_PRIVATE_KEY\nDOCKERHUB_TOKEN\n") + gh = FakeGh("updater\n", BRANCH_MAIN, "BOT_APP_PRIVATE_KEY\nDOCKERHUB_TOKEN\n") answers = ["", "", str(self.translate_pem), TRANSLATE_ID, "y", "n"] self.run_main(gh, answers, "--skip-updater") deleted = [a[2] for a, _ in gh.calls if a[:2] == ["secret", "delete"]] @@ -138,7 +160,7 @@ class AppsMainTest(unittest.TestCase): self.assertTrue(self.translate_pem.exists()) def test_client_id_must_be_an_app_client_id(self) -> None: - gh = FakeGh("updater\n", "main\n", "") + gh = FakeGh("updater\n", BRANCH_MAIN, "") with self.assertRaises(SystemExit): self.run_main(gh, ["", str(self.updater_pem), "12345"]) self.assertEqual(gh.secrets_set(), []) @@ -159,7 +181,7 @@ class AppsMainTest(unittest.TestCase): fresh.write_bytes(KEY) return next(replies) - gh = FakeGh("updater\n", "main\n", "") + gh = FakeGh("updater\n", BRANCH_MAIN, "") with self.assertRaises(SystemExit): apps.main( [ From 5bf89aad2b79679051ee4f0a41e0f30c208d27e6 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 27 Nov 2026 13:51:49 +0000 Subject: [PATCH 11/12] test(update): derive the truncated key fixture at runtime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Secret scanning alert 1 flagged the literal PEM fixture (markers around the body abc) that 286918ec added to test_main.py as an RSA private key. TRUNCATED_KEY is now cut from the key the test generates, so no PEM block remains in the repository and the refusal test still covers a truncated body. ๐ŸŽฏ Fix: 95 % ๐Ÿ’ฅ Break: 1 % ๐Ÿ’ธ Tokens: 105 % โฑ๏ธ Velocity: 111 % ๐Ÿ›ก๏ธ Security: 100 % ๐Ÿ† Score: 81 ๐Ÿšฆ Gate: โš ๏ธ tokens 105 % > 100, velocity 111 % > 100: operator approved via hub decision 860710d6c3c61500 Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 --- tests/unit/python/cli/contributing/update/apps/test_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/python/cli/contributing/update/apps/test_main.py b/tests/unit/python/cli/contributing/update/apps/test_main.py index 61258a18a7..00c84da879 100644 --- a/tests/unit/python/cli/contributing/update/apps/test_main.py +++ b/tests/unit/python/cli/contributing/update/apps/test_main.py @@ -16,7 +16,7 @@ KEY = rsa.generate_private_key(public_exponent=65537, key_size=2048).private_byt serialization.PrivateFormat.TraditionalOpenSSL, serialization.NoEncryption(), ) -TRUNCATED_KEY = b"-----BEGIN RSA PRIVATE KEY-----\nabc\n-----END RSA PRIVATE KEY-----\n" +TRUNCATED_KEY = b"\n".join([*KEY.splitlines()[:2], KEY.splitlines()[-1]]) + b"\n" EC_KEY = ec.generate_private_key(ec.SECP256R1()).private_bytes( serialization.Encoding.PEM, serialization.PrivateFormat.PKCS8, From a6d002f9c44f18661c630f05746d3e1a6fca0be2 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 27 Nov 2026 15:03:03 +0000 Subject: [PATCH 12/12] fix(ci): wait out old-key tokens and drop every pre-rotation update branch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Deleting an App key does not revoke installation tokens minted from it, which live up to one hour. Prerequisite 3 now waits one hour after the old-key deletion, prerequisite 4 deletes every pre-rotation update/** and dependabot/** branch whatever its pull request state, and the CLI prints the earliest deletion time. The download-detection test pins time.time and the file mtimes. ๐ŸŽฏ Fix: 93 % ๐Ÿ’ฅ Break: 2 % ๐Ÿ’ธ Tokens: 102 % โฑ๏ธ Velocity: 102 % ๐Ÿ›ก๏ธ Security: 100 % ๐Ÿ† Score: 88 ๐Ÿšฆ Gate: โš ๏ธ tokens 102 % > 100, velocity 102 % > 100: operator approved via hub decision 85dd95b10579602b Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 --- cli/contributing/update/apps/__main__.py | 6 ++++++ docs/contributing/tools/github/actions/secrets.md | 6 +++--- .../python/cli/contributing/update/apps/test_main.py | 11 ++++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/cli/contributing/update/apps/__main__.py b/cli/contributing/update/apps/__main__.py index 3fbb8d5e60..00a4bc9b58 100755 --- a/cli/contributing/update/apps/__main__.py +++ b/cli/contributing/update/apps/__main__.py @@ -22,6 +22,7 @@ if TYPE_CHECKING: Say = Callable[[str], None] GH_TIMEOUT_SECONDS = 120 +INSTALLATION_TOKEN_SECONDS = 3600 UPDATER_ENVIRONMENT = "updater" UPDATER_BRANCH = "main" UPDATER_NAMES = ("BOT_APP_CLIENT_ID", "BOT_APP_PRIVATE_KEY") @@ -230,6 +231,11 @@ def rotate_updater_key( say(" Back in 'Credentials', tab 'Key pairs': delete every key except the newest") say(" one (the one created just now, see its date).") confirm(ask, " Only the new updater key is left?") + ready = time.strftime( + "%Y-%m-%d %H:%M", time.localtime(time.time() + INSTALLATION_TOKEN_SECONDS) + ) + say(" Tokens minted with the old keys stay valid up to one hour: delete the") + say(f" pre-rotation update/** and dependabot/** branches after {ready}.") return pem diff --git a/docs/contributing/tools/github/actions/secrets.md b/docs/contributing/tools/github/actions/secrets.md index cf74b4cbf4..df30298034 100644 --- a/docs/contributing/tools/github/actions/secrets.md +++ b/docs/contributing/tools/github/actions/secrets.md @@ -152,10 +152,10 @@ The merge gate checks who opened the PR, not who pushed its head commit, so the 1. A branch ruleset on `update/**` and `dependabot/**` restricts creation, updates and deletion, with only the updater App, Dependabot and the admin role on its bypass list. The admin role lets a maintainer merge a translation PR or push a fixup onto an update branch; the translation App stays off it. 2. `BOT_APP_CLIENT_ID` and `BOT_APP_PRIVATE_KEY` exist only as secrets of the `updater` environment, restricted to `main`, and no longer as repository secrets, so no `pull_request` run can read them; [entry-pr-translate.yml](../../../../../.github/workflows/entry-pr-translate.yml) uses the [translation App](#translate_app_client_id-and-translate_app_private_key-). As with `auto-merge`, a `pull_request_target` or `workflow_run` job passes that branch rule, so no job that declares the environment may check out or execute pull-request code; list every workflow that declares it and confirm this before step 4. -3. The updater App's private key was regenerated after the translation workflow stopped minting from it, the new key is the one in `updater`, and every older key is deleted under **Credentials โ†’ Key pairs** on the App's settings page. Same-repository pull requests could read the old key, and a copy taken then stays valid until it is revoked. -4. Every open pull request on an `update/**` or `dependabot/**` branch whose head was pushed before prerequisite 3 is closed and its branch deleted; the next updater run and Dependabot open fresh ones from heads pushed after the rotation. The gate checks who opened a pull request, not who pushed its head, so a head pushed with the old key would otherwise stay mergeable through the bypass. +3. The updater App's private key was regenerated after the translation workflow stopped minting from it, the new key is the one in `updater`, and every older key is deleted under **Credentials โ†’ Key pairs** on the App's settings page. Same-repository pull requests could read the old key, and a copy taken then stays valid until it is revoked. Deleting a key stops new installation tokens but does not revoke the ones already minted, which stay valid for up to one hour, so at least one hour passes after the deletion before prerequisite 4 starts. +4. Every `update/**` and `dependabot/**` branch whose head was pushed before that hour ended is deleted, whether its pull request is open, closed or missing, and an open one is closed; the next updater run and Dependabot open fresh ones from heads pushed afterwards. The gate checks who opened a pull request, not who pushed its head, so a head pushed with the old key would otherwise stay mergeable through the bypass, including a closed pull request that a writer reopens. -With all four in place, pushing a head the gate accepts needs the updater key, which only workflows on `main` can read. Until then the merge App stays off the bypass list, the merge call fails with HTTP 405, and update PRs wait for a manual merge: the ruleset's `update` rule (Restrict updates) lets only bypass actors move `main`, pull-request merges included, whatever reviews the PR holds. +With all four in place, and the hour of prerequisite 3 over, pushing a head the gate accepts needs the updater key, which only workflows on `main` can read. Until then the merge App stays off the bypass list, the merge call fails with HTTP 405, and update PRs wait for a manual merge: the ruleset's `update` rule (Restrict updates) lets only bypass actors move `main`, pull-request merges included, whatever reviews the PR holds. The job mints the App token only after its merge gate passed, narrowed to `contents`, `pull-requests` and `workflows` write, and uses it for the merge call alone; the gate reads with the read-only `GITHUB_TOKEN`. The job runs on `workflow_run`, which always runs on the default branch, so the environment's branch rule admits it. Without the bypass, the merge call fails with `Repository rule violations found` (HTTP 405) and the PR stays open. diff --git a/tests/unit/python/cli/contributing/update/apps/test_main.py b/tests/unit/python/cli/contributing/update/apps/test_main.py index 00c84da879..c10c41766c 100644 --- a/tests/unit/python/cli/contributing/update/apps/test_main.py +++ b/tests/unit/python/cli/contributing/update/apps/test_main.py @@ -2,7 +2,7 @@ from __future__ import annotations import os import tempfile -import unittest +import unittest.mock from pathlib import Path from cryptography.hazmat.primitives import serialization @@ -23,6 +23,7 @@ EC_KEY = ec.generate_private_key(ec.SECP256R1()).private_bytes( serialization.NoEncryption(), ) BRANCH_MAIN = "branch:main\n" +NOW = 1_800_000_000.0 UPDATER_ID = "Iv23liUpdater01" TRANSLATE_ID = "Iv23liTranslate1" @@ -170,7 +171,7 @@ class AppsMainTest(unittest.TestCase): downloads.mkdir() stale = downloads / "old.pem" stale.write_bytes(b"stale") - os.utime(stale, (1, 1)) + os.utime(stale, (NOW - 1, NOW - 1)) fresh = downloads / "infinito-nexus-updater.private-key.pem" replies = iter(["", UPDATER_ID, "n"]) prompts: list[str] = [] @@ -179,10 +180,14 @@ class AppsMainTest(unittest.TestCase): prompts.append(prompt) if "Press Enter when done" in prompt: fresh.write_bytes(KEY) + os.utime(fresh, (NOW + 1, NOW + 1)) return next(replies) gh = FakeGh("updater\n", BRANCH_MAIN, "") - with self.assertRaises(SystemExit): + with ( + unittest.mock.patch.object(apps.time, "time", return_value=NOW), + self.assertRaises(SystemExit), + ): apps.main( [ "--repo",