Repository navigation
ci(workflows): drop publish credentials from pull-request jobs - #1211
ti-chi-bot[bot] merged 1 commit into
Conversation
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
There was a problem hiding this comment.
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
justrecipes 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).
- File:
-
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, thepermissionssection still listscontents: 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.
- Files: All modified workflows (e.g.,
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-actionandpackages: writehas 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
justfileRemoval:- 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.
- File:
-
Workflow Naming Consistency:
- File:
.github/workflows/pull-cd-builder-images-centos7.yamland 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.yamlcould be confusing if CentOS versioning changes. - Suggestion: Document or standardize workflow names for better maintainability.
- File:
Optional Improvements
- Rate Limit Mitigation for Anonymous Pulls:
- Files: All workflows
- Issue: The PR notes that anonymous
ghcrimage pulls are rate-limited and suggests using apackages: readtoken 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
ghcraccess.
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.
|
/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) |
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
…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
Problem
Nine pull-request-triggered jobs requested
packages: write— theGITHUB_TOKENscope that publishes toghcr.io/pingcap-qe/*(bases, builders, product runtimes) — although every build inside them runs with--push=falseand 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: thejust-buildjob heldpackages: write+pull-requests: write, logged in to ghcr, and then ranjust "$TASK"against the pull request's owndockerfiles/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. (ItsMY_GITHUB_TOKENwas already removed in a previous change; the write scope and the login were not.)Changes
.github/workflows/pull-cd-builder-msb.yaml— thejust/<task>preview path is gone. The multi-stage builds it exercised are covered by the release builder workflows.packages: writeand thedocker/login-actionghcr step from the eight remaining PR jobs; they keepcontents: read.dockerfiles/Justfilestays 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→ noneactionlinton the four edited workflows → only the pre-existingubuntu-26.04runner-label warnings and pre-existing SC2086 info notes in the matrix step (identical before this change; the diff only deletes lines)crane manifest ghcr.io/pingcap-qe/cd/builders/tidb:<tag>→ OK without login, so the builds can pull their base images withcontents: readgh pr checks→ zizmor, pre-commit, license/cla pass. The builder workflows are path-filtered todockerfiles/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
packages: read), not restoringpackages: write.just/<task>label to preview a multi-stage build loses that trigger;dockerfiles/Justfilestill documents the local equivalent.Stack