Repository navigation
CI: support specifying the GitHub auth lambda per workflow - #111220
Conversation
Add support for specifying the GitHub authentication lambda per workflow so that we can control the permission scope of the minted token. Pull request workflows keep the least-privilege token, while the master and merge queue workflows get a more permissive token. `Workflow.Config` gains a `gh_auth_lambda_name` field; when set, `GHAuth` mints the token from that lambda for the workflow's jobs instead of `Settings.GH_AUTH_LAMBDA_NAME`. This also removes the `USE_CUSTOM_GH_AUTH` setting and the duplicated `_GH_Auth` wrappers: authentication is now driven purely by the presence of a lambda name (per workflow or in settings), and call sites invoke `GHAuth.auth_from_settings` directly, passing the workflow object they already have. The copilot review job no longer authenticates itself and instead relies on `enable_gh_auth=True` on its job config. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
d577b73 to
be8b25b
Compare
|
Workflow [PR], commit [e99b429] Summary: ✅ AI ReviewSummaryThis PR centralizes GitHub CLI authentication and adds a per-workflow lambda override, but the current tree still regresses Findings❌ Blockers
Final Verdict
|
leshikus
left a comment
There was a problem hiding this comment.
Looks good, but maybe we should not allow different lambda names in different workflows
|
|
||
| class GHAuth: | ||
| # Set once a token has been minted, so it is done at most once per process. | ||
| _authenticated = False |
There was a problem hiding this comment.
this is a class var despite the fact the current design assumes there could be different lambdas in different workflows
There was a problem hiding this comment.
The runner process always works in the context of the same workflow. Why is this a problem?
There was a problem hiding this comment.
this is not a problem of a type "this will break things right now", just inconsistency if someone decides to use several workflow objects in one process
There was a problem hiding this comment.
It is a 1-to-many relation, not the other way around, unless someone wants to break it intentionally
There are trusted / untrusted runner roles that restrict using permissive lambda/token in "untrusted" workflows |
Rename `auth_from_settings` to `auth` (and the previous low-level `auth` to `auth_with_app`, mirroring `auth_with_lambda`). Add a `no_strict=False` parameter to the auth methods so that, by default, an authentication failure raises instead of silently returning False - this restores the original contract for callers. Passing `no_strict=True` keeps the historical "print a warning and return False" behaviour, which all current callers use for now. Addresses #111220 (comment) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The rename of `GHAuth.auth_from_settings` left the `NightlyChangelog` workflow calling a method that no longer exists at ci/jobs/changelog_nightly.py:636, :717, and :854. Update those callers to `GHAuth.auth(no_strict=True)`, preserving the non-raising behaviour. Addresses #111220 (comment) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
| from .digest import Digest | ||
| from .event import EventFeed | ||
| from .gh import GH | ||
| from .gh_auth import GHAuth |
There was a problem hiding this comment.
This has made jwt a requirement to run integration tests locally:
Traceback (most recent call last):
File "/mnt/ch/ClickHouse/ci/praktika/gh_auth.py", line 7, in <module>
import jwt # From pyjwt
^^^^^^^^^^
ModuleNotFoundError: No module named 'jwt'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<frozen runpy>", line 203, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/mnt/ch/ClickHouse/ci/praktika/__main__.py", line 429, in <module>
main()
~~~~^^
File "/mnt/ch/ClickHouse/ci/praktika/__main__.py", line 346, in main
from .runner import Runner
File "/mnt/ch/ClickHouse/ci/praktika/runner.py", line 18, in <module>
from .gh_auth import GHAuth
File "/mnt/ch/ClickHouse/ci/praktika/gh_auth.py", line 16, in <module>
from jwt import jwk_from_pem, JWT
ModuleNotFoundError: No module named 'jwt'
Warning: pyjwt not available. Falling back to 'jwt' module (not recommended)
EXIT=1
runner.py imports GHAuth, and gh_auth imported jwt (pyjwt) at module load, so `python -m ci.praktika` failed with ModuleNotFoundError for anyone without pyjwt installed - e.g. running integration tests locally. Defer the JWT backend import to first use (only GitHub App auth needs it). Reported at #111220 (comment) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The `NightlyChangelog` job has not updated ClickHouse#111720 since 2026-08-13: every run since then fails with RuntimeError: Failed to push auto/changelog-26.8 preceded by `HTTP 401: Bad credentials` from every `gh` call in the second half of the run. The GitHub App installation token is valid for an hour, and a run is much longer than that (1h12m to 1h43m in the last ten days). The job does try to refresh it before the editing attempts and before creating the pull request, but `GHAuth.auth` mints a token at most once per process unless `force` is set, so those calls have always been no-ops, and there was no refresh before the push at all. In the run of 2026-08-24 the token was minted at 02:50:30, the first `Bad credentials` appeared at 03:47:57, and the push failed at 04:32:17. Mint a fresh token in every step that talks to GitHub - `changelog.py`, each editing attempt, the revert resolution of the edit verification, the push, the pull request lookup, and the per-version processing - through a `refresh_gh_token` helper that passes `force=True`. What made the runs cross the one-hour mark is `prepare repository`: the CI checkout is shallow, and `git fetch --unshallow origin` pulled the trees and blobs of the entire history plus every branch, which took 30 to 36 minutes of each run. The job only walks the commit graph (the range from the cycle start tag to master), so fetch the commits without contents: `--filter=tree:0` against the master refspec only, the same way praktika unshallows the repository for its own jobs. The few old file versions the job does read are fetched lazily from the promisor remote. With the push working again, the raw entries land on the branch and the `Changelog-generated-up-to:` trailer advances, which also ends the loop where each night regenerated a bigger block than the night before (579 entries on 2026-08-24 instead of the usual ~50) and so took even longer. The editing step itself has been failing its own fail-closed verification since 2026-08-12 (`Entries disappeared in the edit without a matching revert`), which is a separate problem: that run finished inside the hour with a valid token. This change makes the raw entries reach the pull request again while that is investigated. Related: ClickHouse#111255 Related: ClickHouse#111220
Rename `auth_from_settings` to `auth` (and the previous low-level `auth` to `auth_with_app`, mirroring `auth_with_lambda`). Add a `no_strict=False` parameter to the auth methods so that, by default, an authentication failure raises instead of silently returning False - this restores the original contract for callers. Passing `no_strict=True` keeps the historical "print a warning and return False" behaviour, which all current callers use for now. Addresses ClickHouse#111220 (comment) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The rename of `GHAuth.auth_from_settings` left the `NightlyChangelog` workflow calling a method that no longer exists at ci/jobs/changelog_nightly.py:636, :717, and :854. Update those callers to `GHAuth.auth(no_strict=True)`, preserving the non-raising behaviour. Addresses ClickHouse#111220 (comment) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…orkflow-lambda CI: support specifying the GitHub auth lambda per workflow
Add support for specifying the GitHub authentication lambda per workflow so that we can control the permission scope of the minted token. Pull request workflows keep the least-privilege token, while the
MasterCI(master push) andMergeQueueCI(merge queue) workflows get a more permissive token.Workflow.Configgains agh_auth_lambda_namefield; when set,GHAuthmints the token from that lambda for the workflow's jobs instead of the globalSettings.GH_AUTH_LAMBDA_NAME.As part of this, the
USE_CUSTOM_GH_AUTHsetting and the duplicated_GH_Authwrappers are removed: authentication is now driven purely by the presence of a lambda name (per workflow, or in settings), and call sites invokeGHAuth.auth_from_settingsdirectly, passing theworkflowobject they already have. The Copilot review job no longer authenticates itself and relies onenable_gh_auth=Trueon its job config instead.Changelog category (leave one):
Version info
26.7.1.1324(included in26.7and later)