Skip to content

ci: harden GitHub Actions supply chain and token permissions - #319

Merged
overtrue merged 1 commit into
mainfrom
ci/harden-actions-supply-chain
Nov 26, 2026
Merged

overtrue merged 1 commit into
mainfrom
ci/harden-actions-supply-chain

Conversation

@overtrue

Copy link
Copy Markdown
Collaborator

Pull Request

Description

Harden all GitHub Actions workflows in rustfs/console to reduce the CI/CD supply-chain attack surface and prepare the repository for least-privilege default workflow token settings (default_workflow_permissions: read and can_approve_pull_request_reviews: false):

  • Pin every external uses: action across all 5 workflows (.github/workflows/build.yml, dependencies.yml, quality.yml, release.yml, test.yml) to its verified 40-character commit SHA with inline semantic version comments, and set persist-credentials: false on all actions/checkout steps.
  • Set explicit empty top-level permissions: {} on every workflow and declare minimal per-job permissions so read-only jobs never receive write tokens.
  • Isolate release-chain write privileges and deployment credentials away from pnpm execution: split build.yml into build (contents: read, no R2 secrets), upload-r2 (permissions: {}, downloads build artifacts only), and upload-release-asset (contents: write, release events only, no pnpm); scope contents: write in release.yml solely to create-release (no pnpm); remove unused pages: write / id-token: write permissions from build.yml.
  • Pass release tags, workflow inputs, and audit summaries through env: variables with version format validation to prevent shell or script expression injection.
  • Harden .github/workflows/dependencies.yml and .github/workflows/quality.yml: remove unpinned runtime pnpm dlx npm-check-updates, runtime pnpm add -D vitest jsdom @vitest/ui c8, unused runtime pnpm add -D eslint-plugin-complexity, and automated GITHUB_TOKEN PR creation (peter-evans/create-pull-request). Scheduled dependency runs are now strictly read-only (security-audit, check-updates, dependency-analysis) with isolated report-security-issue (issues: write, no pnpm), while manual workflow_dispatch runs (patch/latest, defaulting to check-only) prepare and verify updates with pinned pnpm, pnpm run test:run, and pnpm run type-check, uploading a reviewable dependency-update-patch artifact instead of mutating repository branches. Also fixes pnpm list --depth=0 --json array parsing in dependency-analysis and prevents pipefail SIGPIPE when truncating diff previews.
  • Add tests/lib/workflow-supply-chain-source.test.js to guard SHA pinning, explicit permissions, absence of runtime pnpm dlx/pnpm add and auto-PR bots, and build/release privilege separation.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test improvements
  • Security fix

Testing

  • Unit tests added/updated
  • Manual testing completed

Commands run locally against the final commit:

node --test tests/lib/quality-workflow-source.test.js tests/lib/workflow-supply-chain-source.test.js
actionlint -shellcheck="" -ignore 'label "sm-standard-2" is unknown' .github/workflows/*.yml
ruby -rdate -ryaml -e 'Dir.glob(".github/workflows/*.yml").sort.each { |f| YAML.safe_load(File.read(f), permitted_classes: [Date, Time]) }'
git diff --check origin/main..HEAD

All 7 unique external action pins were verified against live GitHub API tag refs (peeling annotated tags to their target commit SHAs). Local Prettier verification confirmed all 6 touched files conform to .prettierrc. Full pnpm run lint, pnpm run test:run, pnpm run format:check, and pnpm run build are delegated to the PR CI workflows (Tests and Code Quality).

Checklist

  • Code follows the project's style guidelines
  • Self-review completed
  • TypeScript types are properly defined
  • All commit messages are in English (Conventional Commits)
  • All existing tests pass
  • No new dependencies added, or they are justified

Related Issues

Refs: rustfs/backlog#1187

Screenshots (if applicable)

N/A

Additional Notes

  • Material risks: build.yml now passes built zip archives between build and the isolated upload-r2 / upload-release-asset jobs via a short-lived console-publish-artifacts workflow artifact (retention-days: 1), while preserving the existing rustfs-console-latest.zip default artifact upload. dependencies.yml no longer opens automated PRs on schedule; maintainers trigger workflow_dispatch with patch or latest to generate a verified dependency-update-patch artifact.
  • Follow-up after merge: Once merged to main, repository Actions workflow defaults can safely be tightened to default_workflow_permissions: "read" and can_approve_pull_request_reviews: false without breaking builds, releases, tests, or security alerts.
  • Rollback: Revert this commit to restore the previous workflow definitions (if repository workflow defaults have already been flipped to read, restore explicit job permissions before reverting).

Pin all external GitHub Actions references across every workflow to verified 40-character commit SHAs with inline tag comments and disable persisted checkout credentials.

Set explicit empty top-level permissions across all workflows and assign minimal per-job permissions so switching repository defaults to read-only with pull request approval disabled remains safe. Isolate contents: write and Cloudflare R2 secrets away from pnpm build and validation jobs in build.yml and release.yml, and isolate issues: write in dependencies.yml.

Remove runtime pnpm dlx npm-check-updates, runtime pnpm add -D package installs (vitest/jsdom/@vitest/ui/c8 in dependencies.yml and eslint-plugin-complexity in quality.yml), and automated GITHUB_TOKEN pull request creation. Split dependencies.yml into read-only scheduled checks plus manual workflow_dispatch patch preparation verified with the repository's declared test and type-check commands, and fix pnpm list JSON parsing in dependency-analysis.

Add a source regression test guarding action SHA pinning, explicit permissions, runtime package installs, and release-chain privilege separation.

Refs: rustfs/backlog#1187
@overtrue
overtrue merged commit 6339450 into main Nov 26, 2026
10 checks passed
@overtrue
overtrue deleted the ci/harden-actions-supply-chain branch November 26, 2026 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant