Skip to content

ci(workflows): drop publish credentials from pull-request jobs - #1211

Merged
ti-chi-bot[bot] merged 1 commit into
fix/delivery-generator-input-validation-p2from
ci/pr-jobs-least-privilege-p4
Nov 12, 2026
Merged

ti-chi-bot[bot] merged 1 commit into
fix/delivery-generator-input-validation-p2from
ci/pr-jobs-least-privilege-p4

Conversation

@wuhuizuo

@wuhuizuo wuhuizuo commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Nine pull-request-triggered jobs requested packages: write — the GITHUB_TOKEN scope that publishes to ghcr.io/pingcap-qe/* (bases, builders, product runtimes) — although every build inside them runs with --push=false and needs no push scope:

  • pull-cd-builder-images.yaml (3 jobs), pull-cd-builder-images-centos7.yaml (3), pull-cd-util-images.yaml (1), pull-prod-runtime-images.yaml (1).
  • pull-cd-builder-msb.yaml: the just-build job held packages: write + pull-requests: write, logged in to ghcr, and then ran just "$TASK" against the pull request's own dockerfiles/Justfile. The label allowlist gated only the task name; the recipe body came from the PR. An actor able to add a label could therefore run an arbitrary recipe in a runner holding publish credentials. (Its MY_GITHUB_TOKEN was already removed in a previous change; the write scope and the login were not.)

Changes

  • Delete .github/workflows/pull-cd-builder-msb.yaml — the just/<task> preview path is gone. The multi-stage builds it exercised are covered by the release builder workflows.
  • Remove packages: write and the docker/login-action ghcr step from the eight remaining PR jobs; they keep contents: read.
  • Release workflows are untouched (they publish, so they keep the scope).

dockerfiles/Justfile stays as a local development helper; it is no longer executed by CI, so its recipe body is no longer PR-controlled in a credentialed runner.

Verification

  • grep -rn ": write" .github/workflows/pull-*.yaml → none
  • actionlint on the four edited workflows → only the pre-existing ubuntu-26.04 runner-label warnings and pre-existing SC2086 info notes in the matrix step (identical before this change; the diff only deletes lines)
  • anonymous crane manifest ghcr.io/pingcap-qe/cd/builders/tidb:<tag> → OK without login, so the builds can pull their base images with contents: read
  • gh pr checks → zizmor, pre-commit, license/cla pass. The builder workflows are path-filtered to dockerfiles/cd/builders/**, so they do not run on a workflow-only change; the first run that exercises the new permissions is the next PR touching those paths. Until then the anonymous-pull check above is the evidence that no login is needed.

Risk / Rollback

  • Risk: anonymous ghcr pulls are rate-limited per runner IP. If a build starts hitting the pull limit, the fix is a read-only credential (separate token, packages: read), not restoring packages: write.
  • Risk: anyone relying on the just/<task> label to preview a multi-stage build loses that trigger; dockerfiles/Justfile still documents the local equivalent.
  • Rollback: revert this commit (restores the workflow and the scopes).

Stack

Nine pull-request jobs requested the `packages: write` scope of the
GITHUB_TOKEN — the credential that publishes to ghcr.io/pingcap-qe/* — although
every build inside them runs with `--push=false` and needs no push scope at all.
One of them, the `just/<task>`-labelled job in pull-cd-builder-msb.yaml, also
established ghcr credentials in the runner and then executed the pull request's
own dockerfiles/Justfile, so a contributor able to add a label could run an
arbitrary recipe inside a runner that held publish credentials.

- remove the `just/<task>` workflow: it executed PR-authored recipes with write
  scope; the multi-stage builds it previewed are still covered by the release
  builder workflows
- remove `packages: write` and the ghcr login step from the PR builder jobs;
  ghcr.io/pingcap-qe/* pulls anonymously (checked with crane), so the builds keep
  working with `contents: read` only
- release workflows keep their scopes unchanged
@wuhuizuo
wuhuizuo added this pull request to stack #1210 November 12, 2026 11:32

@ti-chi-bot ti-chi-bot 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.

I have already done a preliminary review for you, and I hope to help you do a better job.

Summary

This PR removes unnecessary packages: write permissions and the associated docker/login-action steps from pull-request workflows to improve security by reducing credential exposure. It also deletes the pull-cd-builder-msb.yaml workflow, which previously enabled PR authors to execute arbitrary just recipes in CI, a potential security risk. The changes are well-scoped, and verification steps were detailed in the description. Overall, this PR effectively addresses its goals, though some minor improvements could further enhance clarity and robustness.


Critical Issues

None identified. The changes significantly improve security by removing overly broad permissions and risky functionality.


Code Improvements

  • Unused Workflow Removal:

    • File: .github/workflows/pull-cd-builder-msb.yaml (entire file)
    • Issue: The PR describes removing this workflow because it allowed executing arbitrary just recipes with elevated permissions. While the removal is valid, consider documenting this decision clearly in the repository's CI/README or related documentation to preempt questions from developers who used this workflow.
    • Suggestion: Add a short note to the CI documentation explaining the deprecation of this workflow and the rationale (e.g., security concerns).
  • Redundant Permissions Cleanup:

    • Files: All modified workflows (e.g., pull-cd-builder-images.yaml, pull-cd-util-images.yaml, pull-prod-runtime-images.yaml)
    • Issue: While the PR removes packages: write, the permissions section still lists contents: read. Although this is harmless, it may be worth explicitly documenting why this permission is retained, given the tightened scope of the workflows.
    • Suggestion: Document in each workflow (e.g., via comments) the purpose of the remaining permissions (contents: read), especially for clarity during future maintenance.

Best Practices

  • Testing Coverage:

    • Files: All modified workflows
    • Issue: The PR description does not mention whether any tests or mock runs were performed to verify that removing docker/login-action and packages: write has no unintended side effects on pull-request workflows.
    • Suggestion: If not already done, consider using a dry-run setup or a test branch to ensure that all pull-request workflows function as expected without docker/login-action. Update the PR description to reflect such verification.
  • Documentation of justfile Removal:

    • File: dockerfiles/Justfile
    • Issue: While the PR mentions that this file remains as a local development helper, it would be helpful to add a comment or update its documentation to clarify that it is no longer executed in CI.
    • Suggestion:
      # dockerfiles/Justfile
      # Note: This file is no longer executed in CI. It remains as a local development helper.
  • Workflow Naming Consistency:

    • File: .github/workflows/pull-cd-builder-images-centos7.yaml and others
    • Issue: While not directly related to this PR, consider reviewing workflow names to ensure they accurately represent their purpose. For example, pull-cd-builder-images-centos7.yaml could be confusing if CentOS versioning changes.
    • Suggestion: Document or standardize workflow names for better maintainability.

Optional Improvements

  • Rate Limit Mitigation for Anonymous Pulls:
    • Files: All workflows
    • Issue: The PR notes that anonymous ghcr image pulls are rate-limited and suggests using a packages: read token if limits are hit. However, no proactive measures are included in this PR to detect and handle such scenarios.
    • Suggestion: Monitor for pull limits in CI logs and consider adding logging or alerts to notify maintainers if limits are approached. Alternatively, proactively implement a read-only token for ghcr access.

Conclusion

This PR effectively addresses a significant security concern by removing unnecessary permissions and a vulnerable workflow. The changes are well-justified and low-risk overall. To further improve transparency and maintainability, consider adding documentation for the removed features, clarifying the purpose of retained permissions, and verifying the impact of these changes on CI functionality.

@ti-chi-bot ti-chi-bot Bot added the size/L label Nov 12, 2026
@wuhuizuo

Copy link
Copy Markdown
Contributor Author

/approve

Pull-request jobs no longer hold packages: write or a ghcr login, and the PR-authored Justfile workflow is removed. zizmor, pre-commit and license/cla pass; ghcr base images pull anonymously. (user confirmed 2026-11-12)

@ti-chi-bot

ti-chi-bot Bot commented Nov 12, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wuhuizuo

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 12, 2026
@ti-chi-bot
ti-chi-bot Bot merged commit 7b0f66e into main Nov 12, 2026
4 checks passed
@ti-chi-bot
ti-chi-bot Bot deleted the ci/pr-jobs-least-privilege-p4 branch November 12, 2026 11:59
ti-chi-bot Bot pushed a commit that referenced this pull request Nov 13, 2026
…eir digest (#1214)

## Problem

The offline packages are shipped to customers, and their composer
fetched component binaries with a bare `wget {{ .src.url }}`: no scheme
check, no host check, no expected digest. The `sha256sum` it wrote was
computed *after* the download and compared to nothing, so it attested
the bytes received rather than the bytes expected.

The one concrete instance is `mydumper` in the 6.1–7.5 bundles:
`http://fileserver.pingcap.net/download/builds/pingcap/mydumper/0042e179…/centos7/mydumper-linux-amd64.tar.gz`
— plaintext, and the object is no longer on the file server
(`NoSuchKey`), so those rebuilds could not fetch it at all.

## Changes

- `lib/validate.sh`: new `assert_src_url` — https only, host allowlist
(`github.com`, `objects.githubusercontent.com`, `cdn.jsdelivr.net`,
`tiup-mirrors.pingcap.com`), no userinfo, no `..`.
- The three generators (`gen-package-images-with-config.sh`,
`gen-package-artifacts-with-config.sh`,
`gen-package-offline-package-with-config.sh`) apply it to every `type:
http` source (`url` and `checksum_url`). `type: oci` sources are
registry references, not URLs, and are untouched.
- Generated scripts refuse a non-https source at run time as well, and
verify the digest published next to the artifact: `checksum_url` → look
the archive's basename up in `sha256sums.txt` → `sha256sum -c` → only
then extract/copy. A missing checksum entry or a mismatch aborts.
- The four legacy `mydumper` entries now point at the release asset
rebuilt from `pingcap/mydumper@0042e179` plus its `sha256sums.txt`. This
also removes the last `fileserver.pingcap.net` reference from this
repository.
- `verify-input-validation.sh`: negative cases for the new validator and
for a plaintext `src.url` in a real template, plus a positive case
asserting the generated script carries both the https guard and the
digest check.

The release asset itself:
<https://github.com/pingcap/mydumper/releases/tag/build-0042e179> — same
source commit, rebuilt on CentOS 7 (glibc 2.17), statically linked,
reproducible (two clean builds produce identical `sha256`). That
repository's tree is unchanged; the tag only points at the existing
commit.

## Verification

- `./packages/scripts/verify-input-validation.sh` → PASS (all cases,
including the plaintext-source rejection and the digest-check
assertions)
- `shellcheck -S error packages/scripts/*.sh packages/scripts/lib/*.sh`
→ PASS
- generated script for `v6.5.0`/community parses (`bash -n`) and
carries, for `mydumper`:
`case "https://github.com/…/mydumper-linux-amd64.tar.gz" in https://*)
;; *) refuse` + `sha256sum -c -`
- ran the generated block itself in a CentOS 7 container: asset
downloaded, digest matched (`4eecdceb…`), `mydumper` extracted to the
archive dir, `mydumper --version` → `mydumper 0.9.5 (0042e179…), built
against MySQL 5.7.44`
- same block with the URL rewritten to `http://…` → exits 1 with
`refusing to fetch 'mydumper' from a non-https source`
- `grep -rn "fileserver.pingcap.net"` → none
- `gh pr checks` → pending (this PR)

## Risk / Rollback

- Risk: a future `type: http` source on a host outside the allowlist now
fails at generation time instead of downloading; the allowlist is one
variable (`ALLOWED_SRC_HOSTS`) at the top of `lib/validate.sh`.
- Risk: the release asset is an immutable public artifact; if it ever
has to change, publish a new tag rather than overwrite (documented in
the vault runbook).
- Rollback: revert this commit; the template returns to the previous
source. The release can be removed with `gh release delete
build-0042e179 --cleanup-tag`.

## Stack

- Previous: #1211 (merged)
- Next: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant