Skip to content

chore: apply least privilege permissions to github actions - #40687

Merged
julio-rocketchat merged 6 commits into
developfrom
least-privilege-gh-actions
Jul 2, 2026
Merged

chore: apply least privilege permissions to github actions#40687
julio-rocketchat merged 6 commits into
developfrom
least-privilege-gh-actions

Conversation

@yasnagat

@yasnagat yasnagat commented May 25, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

This PR applies the principle of least privilege to GITHUB_TOKEN permissions across all GitHub Actions workflows by setting permissions: {} globally and explicitly re-granting only the minimum permissions required per job, as part of a supply chain security hardening effort.

Workflows relied on GitHub’s default token scopes, which may grant more access than most jobs actually need. Scoping permissions at the job level reduces the attack surface in the event that a GitHub Action, third-party dependency, or CI component is compromised, helping mitigate the impact of potential supply chain attacks and limiting unnecessary repository access.

This change only affects the permissions granted to the workflow GITHUB_TOKEN. Operations authenticated using explicitly configured Personal Access Tokens (PATs) continue to have the scopes assigned to those tokens and are not affected by workflow permissions settings.

Issue(s)

SB-975

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • Chores
    • Applied explicit, least-privilege GitHub Actions token permissions across CI/CD workflows by disabling default workflow permissions and granting only the required job scopes (typically contents: read), with targeted exceptions for publishing (e.g., GitHub Pages deploy with contents: write) and security reporting (e.g., CodeQL with security-events: write).

@dionisio-bot

dionisio-bot Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented May 25, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: c573e49

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 77178877-7187-4dd1-95dd-9f1e0286af70

📥 Commits

Reviewing files that changed from the base of the PR and between dbed9d0 and c573e49.

📒 Files selected for processing (12)
  • .github/workflows/ci-code-check.yml
  • .github/workflows/ci-deploy-gh-pages.yml
  • .github/workflows/ci-test-e2e.yml
  • .github/workflows/ci-test-storybook.yml
  • .github/workflows/ci-test-unit.yml
  • .github/workflows/ci.yml
  • .github/workflows/codeql-analysis.yml
  • .github/workflows/new-release.yml
  • .github/workflows/pr-update-description.yml
  • .github/workflows/publish-release.yml
  • .github/workflows/release-candidate.yml
  • .github/workflows/update-version-durability.yml
🚧 Files skipped from review as they are similar to previous changes (11)
  • .github/workflows/release-candidate.yml
  • .github/workflows/ci-test-storybook.yml
  • .github/workflows/publish-release.yml
  • .github/workflows/update-version-durability.yml
  • .github/workflows/new-release.yml
  • .github/workflows/ci-code-check.yml
  • .github/workflows/ci-test-unit.yml
  • .github/workflows/pr-update-description.yml
  • .github/workflows/ci-deploy-gh-pages.yml
  • .github/workflows/ci-test-e2e.yml
  • .github/workflows/codeql-analysis.yml
📜 Recent review details
⏰ Context from checks skipped due to timeout. (3)
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build
  • GitHub Check: Hacktron Security Check
⚠️ CI failures not shown inline (1)

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ✅ **Has milestone or project**
- ✅ **Valid PR title**
- ✅ **Correct target version**
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-04-27T18:32:21.871Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 40321
File: .github/workflows/ci.yml:137-145
Timestamp: 2026-04-27T18:32:21.871Z
Learning: In .github/workflows/ci.yml, the `diff` step under `release-versions` intentionally uses a bash `if` with `gh pr diff ... | grep -q ...; then ... fi`. For non-`pull_request` workflow triggers where `GH_PR_NUM` can be empty, the `gh` command may fail, but the surrounding bash `if` is relied on to treat that failure as the condition being false and skip the `then` block, allowing the step/job to exit cleanly. Do not add extra guards for non-PR event types unless this failure/skip behavior is intentionally changed.

Applied to files:

  • .github/workflows/ci.yml
🪛 zizmor (1.26.1)
.github/workflows/ci.yml

[error] 201-201: runtime artifacts potentially vulnerable to a cache poisoning attack (cache-poisoning): enables caching by default

(cache-poisoning)


[error] 247-247: runtime artifacts potentially vulnerable to a cache poisoning attack (cache-poisoning): enables caching by default

(cache-poisoning)

🔇 Additional comments (2)
.github/workflows/ci.yml (2)

29-34: LGTM!


201-201: 🔒 Security & Privacy

No cache-poisoning issue here. Both cache steps stay within the PR scope, and the cached tarball only short-circuits packages-build before the artifact is uploaded and consumed downstream.

			> Likely an incorrect or invalid review comment.

Walkthrough

GitHub Actions workflows now declare explicit token permissions at the workflow and job levels. Several jobs are limited to read-only scopes, while deployment and CodeQL jobs receive the specific write access they need.

Changes

Explicit GitHub Actions Permissions

Layer / File(s) Summary
Workflow permission defaults
.github/workflows/auto-close-duplicates.yml, .github/workflows/dedupe-issues.yml, .github/workflows/ci-deploy-gh-pages.yml, .github/workflows/ci-test-e2e.yml, .github/workflows/ci-test-storybook.yml, .github/workflows/ci-test-unit.yml, .github/workflows/ci.yml, .github/workflows/new-release.yml, .github/workflows/pr-update-description.yml, .github/workflows/publish-release.yml, .github/workflows/release-candidate.yml, .github/workflows/update-version-durability.yml
Workflow-level permission blocks are added to restrict or define default GITHUB_TOKEN access in several workflows.
Job read-scoped permissions
.github/workflows/ci-code-check.yml, .github/workflows/ci-test-e2e.yml, .github/workflows/ci.yml, .github/workflows/new-release.yml, .github/workflows/pr-update-description.yml, .github/workflows/publish-release.yml, .github/workflows/release-candidate.yml, .github/workflows/update-version-durability.yml
Job-level permissions are added to grant read-only access for check, release, update, and test jobs.
Job write-scoped permissions
.github/workflows/ci-deploy-gh-pages.yml, .github/workflows/codeql-analysis.yml
Job-level permissions are added to grant write access for GitHub Pages deployment and CodeQL security event reporting.

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

Suggested labels: type: chore

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: tightening GitHub Actions permissions to least privilege.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • SB-975: Request failed with status code 401

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

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented May 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.88%. Comparing base (b6e0d3b) to head (8e87cf2).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #40687      +/-   ##
===========================================
+ Coverage    69.14%   69.88%   +0.74%     
===========================================
  Files         3433     3379      -54     
  Lines       132323   130505    -1818     
  Branches     23091    22890     -201     
===========================================
- Hits         91489    91198     -291     
+ Misses       37472    36004    -1468     
+ Partials      3362     3303      -59     
Flag Coverage Δ
unit 70.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yasnagat yasnagat changed the title Least privilege gh actions chore: least privilege gh actions May 26, 2026
@yasnagat yasnagat changed the title chore: least privilege gh actions chore: apply least privilege permissions to github actions May 26, 2026
@yasnagat
yasnagat marked this pull request as ready for review June 12, 2026 16:25
@yasnagat
yasnagat requested a review from a team as a code owner June 12, 2026 16:25
@julio-rocketchat julio-rocketchat added this to the 8.6.0 milestone Jun 12, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/ci.yml:
- Around line 25-26: The workflow default grants repository read to all jobs;
change the workflow-level permissions from "contents: read" to an empty mapping
(permissions: {}) and then add "contents: read" to only the jobs that need it
(e.g., the release-versions job and any jobs that run checkout/git operations).
Update the job definitions (for example, the release-versions job) to include a
job-level permissions block granting contents: read so those jobs retain
required access while other jobs remain least-privilege.

In @.github/workflows/new-release.yml:
- Around line 23-24: The workflow currently passes the PAT to actions/checkout
(via with: token: ${{ secrets.CI_PAT }}) and also sets env: GITHUB_TOKEN at job
level, which persists the PAT for subsequent steps; update the actions/checkout
step(s) that use ${{ secrets.CI_PAT }} to include persist-credentials: false,
remove the workflow/job-level env: GITHUB_TOKEN: ${{ secrets.CI_PAT }}, and
instead pass the PAT only to the specific step(s) that need it (e.g., the
./packages/release-action step) by setting env or with on that step alone so
checkout doesn't leave a PAT-backed credential available to later steps.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3af1d1cc-4784-4269-a2f3-8dbd7107970d

📥 Commits

Reviewing files that changed from the base of the PR and between 10266c1 and 28c4684.

📒 Files selected for processing (14)
  • .github/workflows/auto-close-duplicates.yml
  • .github/workflows/ci-code-check.yml
  • .github/workflows/ci-deploy-gh-pages.yml
  • .github/workflows/ci-test-e2e.yml
  • .github/workflows/ci-test-storybook.yml
  • .github/workflows/ci-test-unit.yml
  • .github/workflows/ci.yml
  • .github/workflows/codeql-analysis.yml
  • .github/workflows/dedupe-issues.yml
  • .github/workflows/new-release.yml
  • .github/workflows/pr-update-description.yml
  • .github/workflows/publish-release.yml
  • .github/workflows/release-candidate.yml
  • .github/workflows/update-version-durability.yml
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Hacktron Security Check
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-04-27T18:32:21.871Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 40321
File: .github/workflows/ci.yml:137-145
Timestamp: 2026-04-27T18:32:21.871Z
Learning: In .github/workflows/ci.yml, the `diff` step under `release-versions` intentionally uses a bash `if` with `gh pr diff ... | grep -q ...; then ... fi`. For non-`pull_request` workflow triggers where `GH_PR_NUM` can be empty, the `gh` command may fail, but the surrounding bash `if` is relied on to treat that failure as the condition being false and skip the `then` block, allowing the step/job to exit cleanly. Do not add extra guards for non-PR event types unless this failure/skip behavior is intentionally changed.

Applied to files:

  • .github/workflows/ci.yml
🔇 Additional comments (10)
.github/workflows/auto-close-duplicates.yml (1)

8-16: LGTM!

.github/workflows/ci-code-check.yml (1)

16-22: LGTM!

.github/workflows/ci-deploy-gh-pages.yml (1)

11-17: LGTM!

.github/workflows/ci-test-e2e.yml (1)

71-77: LGTM!

.github/workflows/ci-test-storybook.yml (1)

22-28: LGTM!

.github/workflows/ci-test-unit.yml (1)

26-32: LGTM!

.github/workflows/ci.yml (1)

32-34: LGTM!

.github/workflows/codeql-analysis.yml (1)

15-18: LGTM!

.github/workflows/dedupe-issues.yml (1)

13-14: LGTM!

Also applies to: 19-21

.github/workflows/update-version-durability.yml (1)

16-17: Permission change is safe for publishing (local action doesn’t rely on checkout’s push remote).

.github/actions/update-version-durability/index.js publishes via Document360 (D360_TOKEN) and only reads GitHub releases via Octokit using the provided GH_TOKEN; there’s no git push/remote configuration in the action, so contents: read on GITHUB_TOKEN doesn’t affect the publish path.

Comment thread .github/workflows/ci.yml
Comment thread .github/workflows/new-release.yml

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2 issues found across 14 files

Tip: cubic used a learning from your PR history. Let your coding agent read cubic learnings directly with the cubic MCP.

Re-trigger cubic

Comment thread .github/workflows/ci-test-e2e.yml
Comment thread .github/workflows/ci.yml
@julio-rocketchat julio-rocketchat modified the milestones: 8.6.0, 8.7.0 Jun 27, 2026
tassoevan
tassoevan previously approved these changes Jul 1, 2026
@tassoevan
tassoevan force-pushed the least-privilege-gh-actions branch from 8e87cf2 to 28c4684 Compare July 1, 2026 14:14
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@tassoevan tassoevan added the stat: QA assured Means it has been tested and approved by a company insider label Jul 2, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Jul 2, 2026
@julio-rocketchat
julio-rocketchat merged commit 5e5990a into develop Jul 2, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge type: chore

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants