Skip to content

CI: support specifying the GitHub auth lambda per workflow - #111220

Merged
maxknv merged 5 commits into
masterfrom
ci-gh-auth-per-workflow-lambda
Jul 22, 2026
Merged

maxknv merged 5 commits into
masterfrom
ci-gh-auth-per-workflow-lambda

Conversation

@maxknv

@maxknv maxknv commented Jul 21, 2026 •

Copy link
Copy Markdown
Member

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) and MergeQueueCI (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 the global Settings.GH_AUTH_LAMBDA_NAME.

As part of this, the USE_CUSTOM_GH_AUTH setting and the duplicated _GH_Auth wrappers are removed: 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 relies on enable_gh_auth=True on its job config instead.

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Version info

  • Merged into: 26.7.1.1324 (included in 26.7 and later)

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]>
@maxknv
maxknv force-pushed the ci-gh-auth-per-workflow-lambda branch from d577b73 to be8b25b Compare July 21, 2026 11:59
@clickhouse-gh

clickhouse-gh Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e99b429]

Summary: ✅


AI Review

Summary

This PR centralizes GitHub CLI authentication and adds a per-workflow lambda override, but the current tree still regresses NightlyChangelog token refresh and still contains previously raised fail-open auth paths. Because these affect scheduled CI behavior and the fail-closed boundary around privileged GitHub operations, this is not ready to merge.

Findings

❌ Blockers

  • [ci/jobs/changelog_nightly.py:636; ci/jobs/changelog_nightly.py:717; ci/jobs/changelog_nightly.py:854] The intended token refreshes are now cached no-ops. Prepare changelog already authenticates via enable_gh_auth=True, and GHAuth.auth returns immediately once _authenticated is set unless force=True. After a long edit attempt, the later gh pr view, gh auth token push, and gh pr create calls still run with the original expired token. Use force=True at each refresh point.
  • [dismissed by author -- https://github.com/CI: support specifying the GitHub auth lambda per workflow #111220#discussion_r3628917986] [ci/praktika/native_jobs.py:987; ci/jobs/changelog_nightly.py:636; ci/jobs/changelog_nightly.py:717; ci/jobs/changelog_nightly.py:854] Required GitHub operations still continue after auth failure. These call sites all pass no_strict=True and ignore the boolean result, so a broken lambda/secrets setup only prints a warning. In MergeQueueCI and MasterCI, the downstream hooks against ClickHouse/clickhouse-private then skip green on empty gh output instead of failing at the auth boundary; in NightlyChangelog, the failure is deferred until much later gh or git push calls.

⚠️ Majors

  • [dismissed by author -- https://github.com/CI: support specifying the GitHub auth lambda per workflow #111220#discussion_r3621947127] [ci/praktika/validator.py:45] The new per-workflow override is still not valid when the global default auth source is the GitHub App secrets. Validation keeps requiring every reporting workflow to export SECRET_GH_APP_* whenever Settings.GH_AUTH_LAMBDA_NAME is empty, even if that workflow sets workflow.gh_auth_lambda_name and GHAuth.auth(workflow) would mint through the lambda instead. That leaves a real configuration matrix unsupported.
  • [dismissed by author -- https://github.com/CI: support specifying the GitHub auth lambda per workflow #111220#discussion_r3621947124] [ci/praktika/gh_auth.py:201] Partial SECRET_GH_APP_* configuration still falls back silently to the ambient gh token. Because the secrets path is keyed only off SECRET_GH_APP_ID, setting only the PEM or installation secret is treated as "no custom auth" instead of a misconfiguration, which changes permission scope fail-open.
Final Verdict
  • Status: ❌ Block

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 21, 2026
Comment thread ci/praktika/gh_auth.py Resolved
Comment thread ci/praktika/validator.py Resolved
@maxknv
maxknv requested a review from leshikus July 21, 2026 14:18

@leshikus leshikus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but maybe we should not allow different lambda names in different workflows

Comment thread ci/praktika/gh_auth.py

class GHAuth:
# Set once a token has been minted, so it is done at most once per process.
_authenticated = False

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a class var despite the fact the current design assumes there could be different lambdas in different workflows

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runner process always works in the context of the same workflow. Why is this a problem?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a 1-to-many relation, not the other way around, unless someone wants to break it intentionally

@leshikus leshikus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more comment

Comment thread ci/praktika/gh_auth.py Resolved
@maxknv

maxknv commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

Looks good, but maybe we should not allow different lambda names in different workflows

There are trusted / untrusted runner roles that restrict using permissive lambda/token in "untrusted" workflows

Comment thread ci/praktika/gh_auth.py Resolved
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]>
Comment thread ci/praktika/gh_auth.py Resolved
maxknv and others added 2 commits July 22, 2026 11:33
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]>
Comment thread ci/jobs/changelog_nightly.py Resolved
@maxknv
maxknv enabled auto-merge July 22, 2026 11:21
@maxknv
maxknv added this pull request to the merge queue Jul 22, 2026
Merged via the queue into master with commit 20aae84 Jul 22, 2026
179 of 180 checks passed
@maxknv
maxknv deleted the ci-gh-auth-per-workflow-lambda branch July 22, 2026 11:33
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 22, 2026
Comment thread ci/praktika/runner.py
from .digest import Digest
from .event import EventFeed
from .gh import GH
from .gh_auth import GHAuth

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. I'll fix it

maxknv added a commit that referenced this pull request Jul 30, 2026
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]>
pull Bot pushed a commit to SINHASantos/ClickHouse that referenced this pull request Aug 25, 2026
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
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
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]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
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]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…orkflow-lambda

CI: support specifying the GitHub auth lambda per workflow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants