Skip to content

Drop unnecessary pull-requests: write scope from the Maven CI job - #187

Merged
AndreasIgel merged 5 commits into
java-helpers:mainfrom
AndreasIgel:feature/165-narrow-pr-write-scope
Jul 20, 2026
Merged

AndreasIgel merged 5 commits into
java-helpers:mainfrom
AndreasIgel:feature/165-narrow-pr-write-scope

Conversation

@AndreasIgel

Copy link
Copy Markdown
Collaborator

Upstream counterpart of fork PR AndreasIgel#12. Head branch: AndreasIgel/simple-builders-fork:feature/165-narrow-pr-write-scope → base java-helpers/simple-builders:main.

Summary

Applies least-privilege to the build job's GITHUB_TOKEN.

Fixes #165

The build job granted pull-requests: write, but no step uses the workflow token to write to PRs — SonarCloud and Codecov PR decoration/comments are done by their GitHub Apps with their own tokens. Removed the scope:

permissions:
  contents: read
  checks: write        # pull-requests: write removed

This limits blast radius if a build step or third-party action is compromised. pull-requests: write remains where it is genuinely needed (the dependency-review workflow's PR summary comment).

Validation

  • actionlint passes.
  • Workflow-only change; Maven build unaffected.

Red build/dependency-review checks on the fork are the missing SONAR_TOKEN/CODECOV_TOKEN and disabled Dependency graph (unrelated to permission scope).

The build job's steps never use GITHUB_TOKEN to write to PRs (SonarCloud
and Codecov decorate PRs via their own GitHub Apps), so pull-requests:
write is unneeded. Reduce to least privilege: contents: read + checks:
write.

Refs java-helpers#165

Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@AndreasIgel

Copy link
Copy Markdown
Collaborator Author

Please check the description of the commit and the pullrequest, which introduced this permission. I guess this has been done on purpose because something did not work without!

Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
@AndreasIgel

Copy link
Copy Markdown
Collaborator Author

I checked the origin of pull-requests: write. It was added in #27 ("Update maven.yml", no description) when the job only ran mvn package — before the SonarCloud (#58) and Codecov (#71) integrations existed, so it cannot have been added for decoration.

On current main no step passes GITHUB_TOKEN to the scanner and nothing uses github.token/gh pr to write to PRs. SonarCloud/Codecov PR decoration is done server-side using tokens configured in their project settings (not the workflow GITHUB_TOKEN). So the permission is genuinely unused and safe to drop. I reworded the code comment accordingly (removing the inaccurate "GitHub Apps" wording).

Comment thread .github/workflows/maven.yml Outdated
Comment on lines +22 to +26
# Least privilege: the build job only reads the repo and writes check
# output. No step uses the workflow token to write to pull requests, and
# SonarCloud/Codecov PR decoration is done server-side using tokens
# configured in their project settings (not the workflow GITHUB_TOKEN).
# This permission predates those integrations and is unused, so drop it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Comment for a removed permission should be removed. There should be only a comment about the still demanded permissions here and there background.

Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
@AndreasIgel

Copy link
Copy Markdown
Collaborator Author

Addressed. The code comment now only documents the retained permissions and their rationale (contents: read for checkout/build, checks: write for test/analysis check output), with no explanation of the removed pull-requests: write. The reasoning for the removal lives in this PR description, not in the workflow file. Pushed to feature/165-narrow-pr-write-scope.

Co-Authored-By: Andreas Igel <andreas.igel@computacenter.com>
@AndreasIgel
AndreasIgel merged commit 3ccc431 into java-helpers:main Jul 20, 2026
6 checks passed
@devin-ai-integration
devin-ai-integration Bot deleted the feature/165-narrow-pr-write-scope branch August 16, 2026 21:11
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.

Drop unnecessary pull-requests: write scope from the Maven CI job

1 participant