Use codeql-ci-app token for integration tests - #1472
Open
redsun82 wants to merge 3 commits into
Open
Conversation
BOT_TOKEN is a PAT on the codeql-remote-query-bot machine user that has to
be rotated manually every 90 days. Mint a short-lived codeql-ci-app
installation token instead, scoped to this repo with only the permissions
the four API calls need: contents:write for the variant-analyses endpoints
and actions:read for actions/runs.
One mint at job start is enough — the token outlives the job's 30 minute
timeout. GITHUB_TOKEN is unused here, so the job takes permissions: {}.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The scoped token omits target-result details, causing the integration test to fail.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review tier: Balanced
Findings: 1
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
.github/workflows/integration-tests.yml — Scoping the installation token to only this repository prevents this test from reading the… |
What changed in this PR
Replaces the rotating BOT_TOKEN with a short-lived GitHub App token for integration tests.
Changes:
- Mints a narrowly scoped
codeql-ci-apptoken. - Uses it for all four API requests.
- Documents non-main ref requirements.
| File | Description |
|---|---|
.github/workflows/integration-tests.yml |
Configures and uses GitHub App authentication. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The analysis jobs 403 with "Resource not accessible by integration" on
PATCH .../variant-analyses/{id}/repositories/{id}/status. Unclear whether
the monolith derives that callback token's rights from the creating
token's narrowed scope, or whether the endpoint rejects integrations
outright. Dropping the narrowing distinguishes the two in one run.
Revert to a minimal explicit set once the answer is known.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: dbc6e83c-5423-4f13-abb7-6131972c2247
The widened-token run reproduced the identical 403, and the server names the required permission outright: x-accepted-github-permissions: contents=write That is exactly what the minimal token already requested and what the app already holds, so no permission set expressible here can fix it. The RemoteAuth callback token the monolith mints for an integration-created variant analysis does not carry it. Restoring the minimal narrowing. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: dbc6e83c-5423-4f13-abb7-6131972c2247
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Why
BOT_TOKENis a PAT on thecodeql-remote-query-botmachine user. It has to be rotated by hand every 90 days, tracked by a recurring Slack reminder. This replaces it with short-livedcodeql-ci-appinstallation tokens, which expire on their own and need no rotation.Approach
A single
Generate CI tokenstep at the top of the job mints one installation token, and all four API call sites use it. Minting once is safe because the job'stimeout-minutes: 30sits comfortably inside the ~1 hour token lifetime.The token is scoped as narrowly as the calls allow:
contents: writefor the variant-analyses endpoints, which runcontrol_access :write_multi_repository_variant_analysis/:read_...and map torepo_contents_writeractions: readforGET /actions/runs/{id}repositories: codeql-variant-analysis-action, so the token only reaches this repoBoth endpoints already set
allow_integrations: true, so app tokens are accepted.Notes for reviewers
The token scope and the analysis targets are unrelated. The JSON payload still lists
docker/compose,hashicorp/terraform, andgithub/does-not-exist. Those are the variant analysis targets and are untouched. They resolve regardless of token scope because public repos are unioned into the accessible set, so scoping the token to one repo does not affect them.permissions: {}added to the job. Nothing here usesGITHUB_TOKEN: every call passes an explicitAuthorizationheader, andcreate-github-app-tokenauthenticates with a private-key JWT, including its post-run token revocation. Worth knowing for later, since a future step that expectsGITHUB_TOKENwill fail with a 403 that does not obviously point back at this line.action_repo_refis unchanged and deliberately notmain. The workflow passes the PR head ref so the test exercises the action code from the pull request. Non-default refs are gated on themrva_allow_non_default_action_reffeature flag, andcodeql-ci-app[bot]is enrolled. I added a comment at theREFcomputation recording this, because a failure here surfaces asInvalid ref provided. You are only allowed to use main., which reads like a workflow bug and invites pinning the ref tomain. That would make the test pass while no longer testing the PR's code.This PR validates itself. It is a same-repo PR, so secrets are available and the integration test runs with the new auth path against this branch.
Follow-up, not in this PR
BOT_TOKENstill exists as a repository secret. It should stay until the integration test goes green here, so there is a fallback, and then be deleted along with the rotation reminder.Fork PRs cannot run this workflow, since secrets are unavailable to them. That is pre-existing rather than new:
BOT_TOKENwas equally a secret. The only difference is that failure now surfaces at the minting step instead of later as a null variant analysis ID.