Skip to content

ci: keep GitHub tokens out of process arguments - #24678

Merged
ti-chi-bot[bot] merged 2 commits into
pingcap:masterfrom
lilin90:codex/protect-workflow-credentials
Nov 11, 2026
Merged

ti-chi-bot[bot] merged 2 commits into
pingcap:masterfrom
lilin90:codex/protect-workflow-credentials

Conversation

@lilin90

@lilin90 lilin90 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

What is changed, added, or deleted? (Required)

  • pass the docs-staging token to GitHub CLI through GH_TOKEN instead of placing it in curl authorization arguments
  • use structured gh api workflow-dispatch fields for both staging workflows
  • keep the regular and nextgen dispatches independent so one HTTP failure does not suppress the other
  • remove default GITHUB_TOKEN permissions from the dispatch workflow
  • make the two operator scripts read GitHub tokens from GITHUB_TOKEN or GH_TOKEN instead of hardcoded plaintext files
  • fail clearly when neither token environment variable is set

Related credential handling in the media upload and Cloud ZH TOC workflows is covered by #24662 and #24677.

Validation:

  • parsed .github/workflows/dispatch.yml as YAML
  • parsed both modified Python scripts with Python AST
  • verified the affected files contain no hardcoded token-file path or authorization header with an interpolated secret
  • verified the nextgen dispatch remains eligible after a failure in the preceding step
  • ran git diff --check

Which TiDB version(s) do your changes apply to? (Required)

  • master (the latest development version)
  • v9.0 (TiDB 9.0 versions)
  • v8.5 (TiDB 8.5 versions)
  • v8.1 (TiDB 8.1 versions)
  • v7.5 (TiDB 7.5 versions)
  • v7.1 (TiDB 7.1 versions)
  • v6.5 (TiDB 6.5 versions)

What is the related PR or file link(s)?

AI agent involvement

  • The changes in this PR were primarily made by an AI agent on behalf of the PR author.

Do your changes match any of the following descriptions?

  • Delete files
  • Change aliases
  • Need modification after applied to another branch
  • Might cause conflicts after applied to another branch

Summary by CodeRabbit

  • Chores
    • Updated staging automation to use the GitHub CLI while preserving its dispatch targets and inputs. The next-generation dispatch now runs only if the workflow has not been cancelled, and workflow permissions are restricted.
    • Updated helper scripts to read GitHub credentials from environment variables. They now report an error when no supported credential is configured, rather than reading credentials from a local file.

@ti-chi-bot ti-chi-bot Bot added missing-translation-status This PR does not have translation status info. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 11, 2026
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The staging workflow now uses gh api for both dispatches. Two scripts now read GitHub tokens from environment variables instead of a hard-coded token file.

Changes: GitHub token handling

Layer / File(s) Summary
Script token input
scripts/create_empty_translation_pr.py, scripts/release_notes_update_pr_author_info_add_dup.py
Both scripts read GITHUB_TOKEN first and fall back to GH_TOKEN. They raise RuntimeError if neither variable has a value. Setup comments describe the environment-variable requirement.
Staging workflow dispatches
.github/workflows/dispatch.yml
The workflow sets permissions: {}. Both dispatches use gh api with environment variables for the token and source details. They retain their respective workflow targets and branches, and send full=false. The next-generation dispatch runs only when the workflow has not been cancelled.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant DispatchWorkflow
  participant GHCLI
  participant TargetWorkflow
  DispatchWorkflow->>GHCLI: Dispatch workflow with token and source inputs
  GHCLI->>TargetWorkflow: Send API dispatch request
Loading

Possibly related PRs

  • pingcap/docs#24677: Restricts which actors can trigger jobs that use secrets, complementing this change to staging credential handling.
  • pingcap/docs#24662: Changes credential handling in CI workflows and removes credentials from command arguments.

Suggested reviewers: qiancai, shhdgit

Merge Risk: Minimal · up to 85125

The change keeps GitHub tokens out of process arguments and removes hard-coded token-file reads from two scripts. The nextgen dispatch still runs after a first-dispatch failure. No actionable merge risk remains.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main change: preventing GitHub tokens from appearing in process arguments.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The pull request description covers the required change summary, affected TiDB version, related references, AI involvement, and change-type checklists. It also records validation steps. The first-time…
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files. (1 skipped: 1 unsupported.)

Full details: Description check

Explanation

The pull request description covers the required change summary, affected TiDB version, related references, AI involvement, and change-type checklists. It also records validation steps. The first-time contributor checklist is omitted, which is allowed when not applicable.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: pingcap/docs
  • Branch: master
  • File: .coderabbit.yaml
  • Commit: 16b9550
  • Layers: Repository YAML
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 3b41b0c3-3530-464f-8a0b-95032c5f036a
Commits

Reviewing files that changed from the base of the PR and between 11b7f30 and 851256a.

Files selected for processing: 1

  • .github/workflows/dispatch.yml

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: pingcap/docs
  • Branch: master
  • File: .coderabbit.yaml
  • Commit: 16b9550
  • Layers: Repository YAML
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 8c52172a-9442-4bcb-86a8-e5b608345bbd
Commits

Reviewing files that changed from the base of the PR and between 16b9550 and 11b7f30.

Files selected for processing: 3

  • .github/workflows/dispatch.yml
  • scripts/create_empty_translation_pr.py
  • scripts/release_notes_update_pr_author_info_add_dup.py

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

Comment thread .github/workflows/dispatch.yml Resolved
@lilin90 lilin90 self-assigned this Nov 11, 2026
@lilin90 lilin90 added ONCALL Relates to documentation oncall. translation/no-need No need to translate this PR. labels Nov 11, 2026
@ti-chi-bot ti-chi-bot Bot removed the missing-translation-status This PR does not have translation status info. label Nov 11, 2026
@lilin90
lilin90 requested a lite review from Copilot November 11, 2026 09:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Approval should wait until the privileged CI authentication and request encoding are validated against the docs-staging workflow inputs in a live staging run.

No open issues 🎉

What changed in this PR

This pull request hardens GitHub credential handling across staging automation and operator scripts by moving tokens out of command-line arguments and plaintext files while preserving existing workflow targets and dispatch inputs.

Changes:

  • Uses GH_TOKEN with structured gh api requests for both staging workflow dispatches.
  • Updates both Python scripts to read tokens from GITHUB_TOKEN or GH_TOKEN and report an error when neither is configured.
  • create_empty_translation_pr.py still uses a literal authorization value in its HTTP requests instead of the loaded token, so authenticated operations require correction.
File Description
scripts/​release_notes_update_pr_author_info_add_dup.py Replaces plaintext token-file loading with environment-based GitHub credential lookup and validation.
scripts/​create_empty_translation_pr.py Replaces the hardcoded token-file dependency with environment-based credential loading, but its authenticated requests still do not use the loaded token.
.github/​workflows/​dispatch.yml Replaces token-bearing curl dispatches with authenticated gh api calls using GH_TOKEN and structured workflow inputs.

Review effort: Lite

@lilin90

lilin90 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member Author

Checked the Copilot review note about create_empty_translation_pr.py: the Authorization headers use access_token, which is loaded from GITHUB_TOKEN or GH_TOKEN at startup and passed to the authenticated helper functions. There is no literal or hardcoded token remaining, so no code change is needed for that note.

The actionable dispatch-independence finding is fixed in 851256a.

@lilin90
lilin90 requested a review from shhdgit November 11, 2026 09:38
@ti-chi-bot

ti-chi-bot Bot commented Nov 11, 2026

Copy link
Copy Markdown

@shhdgit: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@lilin90 lilin90 added the lgtm label Nov 11, 2026

@lilin90 lilin90 left a comment

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.

/approve

@ti-chi-bot

ti-chi-bot Bot commented Nov 11, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lilin90

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added the approved label Nov 11, 2026
@ti-chi-bot
ti-chi-bot Bot merged commit 6471f5c into pingcap:master Nov 11, 2026
12 checks passed
@lilin90
lilin90 deleted the codex/protect-workflow-credentials branch November 11, 2026 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm ONCALL Relates to documentation oncall. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. translation/no-need No need to translate this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants