diff --git a/.gitea/workflows/renovate.yml b/.gitea/workflows/renovate.yml index cee1964..6514296 100644 --- a/.gitea/workflows/renovate.yml +++ b/.gitea/workflows/renovate.yml @@ -2,9 +2,12 @@ name: Renovate # Dependency updates for this repository (renovate.json). Runs on the Collection's own runner # (label kamino-docker, the untrusted side), never in the production cluster: code from this -# repository must not run there. The only credential is the job token (secrets.GITHUB_TOKEN); -# no org secret is referenced (only image.yml may). Unauthenticated GitHub lookups for the -# github.com pre-commit hooks may hit rate limits: best effort, no RENOVATE_GITHUB_COM_TOKEN exists. +# repository must not run there. The credential is the token of a Kamino-only bot user, held as +# the repository secret RENOVATE_BOT_TOKEN (not an org secret: only image.yml may reference those). +# The job token cannot be used: Renovate filters every pull request lookup by its own username, +# which is the virtual user gitea-actions with the job token, and Gitea answers 400 "user does not +# exist" (dry run 2445). Unauthenticated GitHub lookups for the github.com pre-commit hooks may +# hit rate limits: best effort, no RENOVATE_GITHUB_COM_TOKEN exists. # # Dry run: Actions > Renovate > Run workflow, dry_run=true (the default for a manual run), then # read the debug log. The schedule runs live. @@ -22,10 +25,9 @@ on: # yamllint disable-line rule:truthy - "false" default: "true" +# The job token is not used for Renovate (see above): read-only is enough for the job itself. permissions: - contents: write - pull-requests: write - issues: write + contents: read # Never two runs at once; a running one is not cancelled (it may be mid-push). concurrency: @@ -34,7 +36,7 @@ concurrency: jobs: renovate: - # Only in this repository (a copy elsewhere would run with its own job token). + # Only in this repository (a copy elsewhere has no such secret). if: github.repository == 'mortis/kamino' || github.repository == 'Mortis/Kamino' runs-on: kamino-docker timeout-minutes: 30 @@ -49,7 +51,7 @@ jobs: RENOVATE_PLATFORM: gitea RENOVATE_ENDPOINT: ${{ github.server_url }}/api/v1/ RENOVATE_REPOSITORIES: ${{ github.repository }} - RENOVATE_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RENOVATE_TOKEN: ${{ secrets.RENOVATE_BOT_TOKEN }} # Git auth: see the run block. The host the header is scoped to. GIT_HOST_URL: ${{ github.server_url }}/ RENOVATE_GIT_AUTHOR: "Renovate Bot " @@ -66,10 +68,14 @@ jobs: # exactly the string "false" (an empty input from an API or CLI dispatch stays a dry run). DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run != 'false' && 'true' || 'false' }} run: | - # Git over HTTPS with the job token. Renovate's own rewrite puts the token in the URL + if [ -z "$RENOVATE_TOKEN" ]; then + echo "::error::The repository secret RENOVATE_BOT_TOKEN is not set (token of the Kamino-only bot user)" + exit 1 + fi + # Git over HTTPS with the bot token. Renovate's own rewrite puts the token in the URL # (https://@host/...), which git drops when the server redirects, and Gitea # redirected the clone (dry run 2439). The header is sent on every request to the host, - # as lint.yml does. Renovate does not pass GIT_CONFIG_* from its environment to git + # as lint.yml does with its token. Renovate does not pass GIT_CONFIG_* from its environment to git # (only an allowlist, util/exec/env.js), but it does pass HOME, so a global git config # is the path that reaches its git children. The token is read from the environment. git config --global "http.${GIT_HOST_URL}.extraheader" "AUTHORIZATION: bearer ${RENOVATE_TOKEN}" diff --git a/CLAUDE.md b/CLAUDE.md index 903a04f..3371b9a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -95,9 +95,14 @@ protection, or create tags: those are the operator's. `.gitea/workflows` mentions `git.rkdr.net/defame1297/`. - **Where Renovate runs:** `.gitea/workflows/renovate.yml`, a daily cron (03:17 UTC) plus `workflow_dispatch`, on the `kamino-runner` (`kamino-docker`): the untrusted side, so code from this - repository never runs in the production cluster (ADR 0004). It authenticates with the workflow's own - job token (`secrets.GITHUB_TOKEN`): no new account, no secret, and no org secret (only `image.yml` may - reference those). The job container is `renovate/renovate:-full@sha256:...` from Docker Hub + repository never runs in the production cluster (ADR 0004). It authenticates as a Kamino-only bot user + (write access to this repository only, no admin, no other repository) whose token is the repository + secret `RENOVATE_BOT_TOKEN` (scopes `write:repository`, `write:issue`, `read:user`; not an org secret: + only `image.yml` may reference those). Never reuse the in-cluster Renovate user's token here: it + reaches the production repository. The workflow's own job token does not work: Renovate filters + its pull request lookups by its own username, which is the virtual user `gitea-actions`, and Gitea + answers `400 user does not exist` (dry run 2445). The bot user must not be able to push to `main` + or merge past the required checks (branch protection). The job container is `renovate/renovate:-full@sha256:...` from Docker Hub (the `-full` flavour for `python3`), same version as the cluster's CronJob, hand-bumped (renovate.json disables updates for the workflow file). Lookups of the github.com pre-commit hooks are unauthenticated (no `RENOVATE_GITHUB_COM_TOKEN` exists) and may hit rate limits: best effort. @@ -109,22 +114,19 @@ protection, or create tags: those are the operator's. A first good dry run shows a clone (no `external-host-error`, no `could not read Username`). - **Open item: the first live run (do not enable automerge for bot PRs until one has shown it gets Lint and Build).** The dry run proves the READS (lookups, config, branch plan) and, from the Renovate 44.161.0 - source (confirm by the log line for the post-upgrade task), also runs `postUpgradeTasks`. Only the first - LIVE run proves the writes: (1) that the job token can push a branch and open a PR. Git auth: Renovate - puts the token in the clone URL, which git drops on a redirect (dry run 2439 failed so: `could not read - Username`). `renovate.yml` therefore writes a global git config `http./.extraheader` - (`AUTHORIZATION: bearer `, like `lint.yml`); Renovate does not pass `GIT_CONFIG_*` from its - environment to git but does pass `HOME`. Unproven until a run clones. (2) That PRs opened with the job token trigger the PR workflows: Gitea, like GitHub, may not - start workflows for events created by the job token, in which case the required `Lint` and `Build` - checks never run and automerge cannot work. If so, the decision is the operator's: either push the PR - with a user token held as a repo secret from a Kamino-only user, or have `renovate.yml` dispatch lint - against the branch; until then bot PRs need a manual run. (3) That bot PRs are held by `main`'s required - status checks (check the branch protection). Also confirm in the log: Renovate clones blobless with full - history, so `origin/main` exists for the script (source-based); `python3` is in the image; the - `permissions:` block is enforced on this Gitea; `github.head_ref` is populated (the gate fails closed - on an empty one, via `EVENT_NAME`). Safety net: a failing or disallowed post-upgrade command opens the - PR WITHOUT the bump plus a red `renovate/artifacts` status, and `check_image_versions.py bump` then - fails lint. + source (confirm by the log line for the post-upgrade task), also runs `postUpgradeTasks`. Dry run 2445 + already showed that git over HTTPS works with the global `http./.extraheader` + (`AUTHORIZATION: bearer `, like `lint.yml`; Renovate does not pass `GIT_CONFIG_*` from its + environment to git but does pass `HOME`), which fixed the redirect failure of run 2439. Still unproven + until a run with the bot token: (1) that the bearer header is accepted for a personal access token (if + not, use basic auth with the bot user name); (2) that the first LIVE run can push a branch and open a + PR; (3) that PRs opened by the bot user trigger the PR workflows (it is a normal user, so they should; if + the required `Lint` and `Build` never start, automerge cannot work); (4) that bot PRs are held by + `main`'s required status checks (check the branch protection). Also confirm in the log: Renovate clones + blobless with full history, so `origin/main` exists for the script (source-based); `python3` is in the + image; `github.head_ref` is populated (the gate fails closed on an empty one, via `EVENT_NAME`). Safety + net: a failing or disallowed post-upgrade command opens the PR WITHOUT the bump plus a red + `renovate/artifacts` status, and `check_image_versions.py bump` then fails lint. - **The workflow holds the runner's slot:** the `kamino-runner` host has a single slot (the label is `kamino-docker`), and the Renovate job may run up to 30 minutes (`timeout-minutes`) from 03:17 UTC, so Lint, Build and Molecule checks queue behind it. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index feb1483..3ebf6bd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -35,11 +35,11 @@ bumps the version and tags. - `renovate.json` configures dependency bumps (minor and patch automerge, majors by hand). Renovate runs for this repository in `.gitea/workflows/renovate.yml` (daily cron on the Collection's own - runner, with the workflow's job token; no cluster code involved). To dry-run after changing the + runner, as a Kamino-only bot user (repository secret `RENOVATE_BOT_TOKEN`); no cluster code involved). To dry-run after changing the config: Actions > Renovate > Run workflow with `dry_run=true`, then read the debug log (the job fails on a failed clone or an ERROR problem). The dry run - proves reads (and runs the post-upgrade task); whether the job token can push and open a pull + proves reads (and runs the post-upgrade task); whether the bot can push and open a pull request, and whether such pull requests start the PR workflows, only the first live run shows - (open item, see CLAUDE.md); until then they may need a manual lint run. Pull requests from `renovate/` branches must pass + (open item, see CLAUDE.md). Pull requests from `renovate/` branches must pass `scripts/check_bot_pr_diff.py`, which only allows version, tag, digest and pin lines. - Workflows must not mention `git.rkdr.net/defame1297/` (the production image set); the `Check image pins` step fails if they do.