Merge pull request 'fix(renovate): authenticate as a Kamino-only bot user, not the job token' (#22) from feat/renovate-bot-token into main
Build / build (push) Successful in 11s
Lint / lint (push) Successful in 12s

Reviewed-on: #22
This commit was merged in pull request #22.
This commit is contained in:
Defame1297 committed 2026-10-26 13:57:07 +00:00
commit c8c23687e2
3 files changed
+40 -32

No files matched your search

+16 -10
View File
@@ -2,9 +2,12 @@ name: Renovate
# Dependency updates for this repository (renovate.json). Runs on the Collection's own runner # 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 # (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); # repository must not run there. The credential is the token of a Kamino-only bot user, held as
# no org secret is referenced (only image.yml may). Unauthenticated GitHub lookups for the # the repository secret RENOVATE_BOT_TOKEN (not an org secret: only image.yml may reference those).
# github.com pre-commit hooks may hit rate limits: best effort, no RENOVATE_GITHUB_COM_TOKEN exists. # 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 # Dry run: Actions > Renovate > Run workflow, dry_run=true (the default for a manual run), then
# read the debug log. The schedule runs live. # read the debug log. The schedule runs live.
@@ -22,10 +25,9 @@ on: # yamllint disable-line rule:truthy
- "false" - "false"
default: "true" default: "true"
# The job token is not used for Renovate (see above): read-only is enough for the job itself.
permissions: permissions:
contents: write contents: read
pull-requests: write
issues: write
# Never two runs at once; a running one is not cancelled (it may be mid-push). # Never two runs at once; a running one is not cancelled (it may be mid-push).
concurrency: concurrency:
@@ -34,7 +36,7 @@ concurrency:
jobs: jobs:
renovate: 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' if: github.repository == 'mortis/kamino' || github.repository == 'Mortis/Kamino'
runs-on: kamino-docker runs-on: kamino-docker
timeout-minutes: 30 timeout-minutes: 30
@@ -49,7 +51,7 @@ jobs:
RENOVATE_PLATFORM: gitea RENOVATE_PLATFORM: gitea
RENOVATE_ENDPOINT: ${{ github.server_url }}/api/v1/ RENOVATE_ENDPOINT: ${{ github.server_url }}/api/v1/
RENOVATE_REPOSITORIES: ${{ github.repository }} 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 auth: see the run block. The host the header is scoped to.
GIT_HOST_URL: ${{ github.server_url }}/ GIT_HOST_URL: ${{ github.server_url }}/
RENOVATE_GIT_AUTHOR: "Renovate Bot <[email protected]>" RENOVATE_GIT_AUTHOR: "Renovate Bot <[email protected]>"
@@ -66,10 +68,14 @@ jobs:
# exactly the string "false" (an empty input from an API or CLI dispatch stays a dry run). # 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' }} DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run != 'false' && 'true' || 'false' }}
run: | 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://<token>@host/...), which git drops when the server redirects, and Gitea # (https://<token>@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, # 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 # (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. # 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}" git config --global "http.${GIT_HOST_URL}.extraheader" "AUTHORIZATION: bearer ${RENOVATE_TOKEN}"
+21 -19
View File
@@ -95,9 +95,14 @@ protection, or create tags: those are the operator's.
`.gitea/workflows` mentions `git.rkdr.net/defame1297/`. `.gitea/workflows` mentions `git.rkdr.net/defame1297/`.
- **Where Renovate runs:** `.gitea/workflows/renovate.yml`, a daily cron (03:17 UTC) plus - **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 `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 repository never runs in the production cluster (ADR 0004). It authenticates as a Kamino-only bot user
job token (`secrets.GITHUB_TOKEN`): no new account, no secret, and no org secret (only `image.yml` may (write access to this repository only, no admin, no other repository) whose token is the repository
reference those). The job container is `renovate/renovate:<version>-full@sha256:...` from Docker Hub 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:<version>-full@sha256:...` from Docker Hub
(the `-full` flavour for `python3`), same version as the cluster's CronJob, hand-bumped (renovate.json (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 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. 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`). 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 - **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 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 source (confirm by the log line for the post-upgrade task), also runs `postUpgradeTasks`. Dry run 2445
LIVE run proves the writes: (1) that the job token can push a branch and open a PR. Git auth: Renovate already showed that git over HTTPS works with the global `http.<server>/.extraheader`
puts the token in the clone URL, which git drops on a redirect (dry run 2439 failed so: `could not read (`AUTHORIZATION: bearer <token>`, like `lint.yml`; Renovate does not pass `GIT_CONFIG_*` from its
Username`). `renovate.yml` therefore writes a global git config `http.<server>/.extraheader` environment to git but does pass `HOME`), which fixed the redirect failure of run 2439. Still unproven
(`AUTHORIZATION: bearer <job token>`, like `lint.yml`); Renovate does not pass `GIT_CONFIG_*` from its until a run with the bot token: (1) that the bearer header is accepted for a personal access token (if
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 not, use basic auth with the bot user name); (2) that the first LIVE run can push a branch and open a
start workflows for events created by the job token, in which case the required `Lint` and `Build` PR; (3) that PRs opened by the bot user trigger the PR workflows (it is a normal user, so they should; if
checks never run and automerge cannot work. If so, the decision is the operator's: either push the PR the required `Lint` and `Build` never start, automerge cannot work); (4) that bot PRs are held by
with a user token held as a repo secret from a Kamino-only user, or have `renovate.yml` dispatch lint `main`'s required status checks (check the branch protection). Also confirm in the log: Renovate clones
against the branch; until then bot PRs need a manual run. (3) That bot PRs are held by `main`'s required blobless with full history, so `origin/main` exists for the script (source-based); `python3` is in the
status checks (check the branch protection). Also confirm in the log: Renovate clones blobless with full image; `github.head_ref` is populated (the gate fails closed on an empty one, via `EVENT_NAME`). Safety
history, so `origin/main` exists for the script (source-based); `python3` is in the image; the net: a failing or disallowed post-upgrade command opens the PR WITHOUT the bump plus a red
`permissions:` block is enforced on this Gitea; `github.head_ref` is populated (the gate fails closed `renovate/artifacts` status, and `check_image_versions.py bump` then fails lint.
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 - **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 `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. Lint, Build and Molecule checks queue behind it.
+3 -3
View File
@@ -35,11 +35,11 @@
bumps the version and tags. bumps the version and tags.
- `renovate.json` configures dependency bumps (minor and patch automerge, majors by hand). Renovate - `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 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 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 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. `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 - Workflows must not mention `git.rkdr.net/defame1297/` (the production image set); the
`Check image pins` step fails if they do. `Check image pins` step fails if they do.