Skip to content

fix: narrow down action permissions to per-job ones#828

Open
steveiliop56 wants to merge 1 commit intomainfrom
fix/token-permissions
Open

fix: narrow down action permissions to per-job ones#828
steveiliop56 wants to merge 1 commit intomainfrom
fix/token-permissions

Conversation

@steveiliop56
Copy link
Copy Markdown
Member

@steveiliop56 steveiliop56 commented Apr 29, 2026

Summary by CodeRabbit

  • Chores
    • Enhanced security posture by implementing least-privilege permissions across CI/CD workflows. Permission scopes have been tightened at the workflow level and selectively granted only to jobs that require them, reducing potential exposure in automated processes.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

📝 Walkthrough

Walkthrough

This PR implements least-privilege permission scoping across four GitHub Actions workflows by reducing top-level workflow permissions to read-only and adding explicit job-level permission grants. Each job now receives only the specific permissions it requires.

Changes

Cohort / File(s) Summary
GitHub Actions Workflow Permission Scoping
.github/workflows/nightly.yml, .github/workflows/release.yml, .github/workflows/sponsors.yml, .github/workflows/stale.yml
Implements least-privilege model by reducing top-level permissions to read-only and adding explicit job-level permission overrides. Release/push jobs granted contents: write or packages: write only where needed; build jobs restricted to packages: read.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

size:XS, lgtm

Suggested reviewers

  • Rycochet

Poem

🐰 With careful whiskers and security in mind,
Permissions trimmed down, least-privilege aligned,
Each job gets just what it needs to proceed,
No extra access—a rabbit's best creed! 🔐

🚥 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 'fix: narrow down action permissions to per-job ones' directly and clearly describes the main change: refactoring GitHub Actions workflows to use least-privilege permissions by narrowing global permissions and defining explicit per-job permissions.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/token-permissions

Review rate limit: 1/3 review remaining, refill in 30 minutes and 6 seconds.

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

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 29, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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 the current code and only fix it if needed.

Inline comments:
In @.github/workflows/nightly.yml:
- Around line 149-150: The image-build jobs currently declare only "packages:
read" which prevents checkout and GHCR pushes; update each image-build job (the
four image-build job definitions referenced) to set job-level permissions to
include "contents: read" and "packages: write" so checkout works and images can
be pushed (i.e., replace or augment the existing permissions block for those
image-build jobs with contents: read and packages: write).

In @.github/workflows/release.yml:
- Around line 119-120: The job-level permissions for the image build jobs
currently only specify "packages: read", which prevents actions/checkout and
docker build-push from working; update each image build job's permissions block
to include both "contents: read" and "packages: write" (in addition to or
replacing the existing packages: read) so actions/checkout can access the repo
and docker/build-push-action can push to GHCR using GITHUB_TOKEN; locate the
YAML permission blocks that currently contain "permissions: packages: read" in
the four image build jobs and add "contents: read" and "packages: write" there.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ecc0114b-139a-4130-9d49-13254c9e0daf

📥 Commits

Reviewing files that changed from the base of the PR and between 956d2f5 and 44c763c.

📒 Files selected for processing (4)
  • .github/workflows/nightly.yml
  • .github/workflows/release.yml
  • .github/workflows/sponsors.yml
  • .github/workflows/stale.yml

Comment on lines +149 to +150
permissions:
packages: read
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.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

In GitHub Actions, when jobs.<job_id>.permissionsdefines onlypackages: read, are unspecified scopes (like contents) set to none? Also, what GITHUB_TOKENscope is required to push Docker images to GHCR usingdocker/build-push-action?

💡 Result:

Yes, when jobs.<job_id>.permissions defines only packages: read, unspecified scopes like contents are set to none. To push Docker images to GHCR using docker/build-push-action, the GITHUB_TOKEN requires packages: write permission (and typically contents: read for checkout).

Citations:


🏁 Script executed:

fd -t f "nightly.yml" --path "*workflows*"

Repository: tinyauthapp/tinyauth

Length of output: 298


🏁 Script executed:

fd -t f "nightly.yml"

Repository: tinyauthapp/tinyauth

Length of output: 46


🏁 Script executed:

find . -name "*.yml" -o -name "*.yaml" | grep -i workflow

Repository: tinyauthapp/tinyauth

Length of output: 252


🏁 Script executed:

wc -l ./.github/workflows/nightly.yml

Repository: tinyauthapp/tinyauth

Length of output: 100


🏁 Script executed:

cat -n ./.github/workflows/nightly.yml | sed -n '140,160p;200,220p;260,280p;320,340p'

Repository: tinyauthapp/tinyauth

Length of output: 2778


🏁 Script executed:

cat -n ./.github/workflows/nightly.yml | sed -n '151,195p;211,255p;271,315p;331,375p'

Repository: tinyauthapp/tinyauth

Length of output: 8276


Build jobs are under-scoped and will fail image publishing.

All four image-build jobs (at lines 149-150, 209-210, 269-270, and 329-330) have permissions set to packages: read, but these jobs perform checkout and push container images to GHCR with push=true. When job-level permissions are defined with only packages: read, unspecified scopes default to none. This means these jobs lack the required packages: write permission to push images and contents: read permission for checkout to function properly.

🔧 Proposed fix
   image-build:
     runs-on: ubuntu-latest
     needs:
       - create-release
       - generate-metadata
     permissions:
-      packages: read
+      contents: read
+      packages: write

   image-build-distroless:
     runs-on: ubuntu-latest
     needs:
       - create-release
       - generate-metadata
       - image-build
     permissions:
-      packages: read
+      contents: read
+      packages: write

   image-build-arm:
     runs-on: ubuntu-24.04-arm
     needs:
       - create-release
       - generate-metadata
     permissions:
-      packages: read
+      contents: read
+      packages: write

   image-build-arm-distroless:
     runs-on: ubuntu-24.04-arm
     needs:
       - create-release
       - generate-metadata
       - image-build-arm
     permissions:
-      packages: read
+      contents: read
+      packages: write
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
permissions:
packages: read
permissions:
contents: read
packages: write
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/nightly.yml around lines 149 - 150, The image-build jobs
currently declare only "packages: read" which prevents checkout and GHCR pushes;
update each image-build job (the four image-build job definitions referenced) to
set job-level permissions to include "contents: read" and "packages: write" so
checkout works and images can be pushed (i.e., replace or augment the existing
permissions block for those image-build jobs with contents: read and packages:
write).

Comment on lines +119 to +120
permissions:
packages: read
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.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

For GitHub Actions job-level permissions, do unspecified scopes become none? For GHCR image publishing with docker/build-push-actionandGITHUB_TOKEN, is packages: write required?

💡 Result:

Yes, for GitHub Actions job-level permissions, unspecified scopes are set to none. Yes, packages: write is required for publishing images to GHCR using docker/build-push-action with GITHUB_TOKEN.

Citations:


🏁 Script executed:

# Check if the file exists and get its structure
file_path=".github/workflows/release.yml"
if [ -f "$file_path" ]; then
  echo "File exists. Line count:"
  wc -l "$file_path"
  echo ""
  echo "=== Lines 115-125 (around line 119) ==="
  sed -n '115,125p' "$file_path"
  echo ""
  echo "=== Lines 172-182 (around line 176) ==="
  sed -n '172,182p' "$file_path"
  echo ""
  echo "=== Lines 229-239 (around line 233) ==="
  sed -n '229,239p' "$file_path"
  echo ""
  echo "=== Lines 286-296 (around line 290) ==="
  sed -n '286,296p' "$file_path"
else
  echo "File not found at $file_path"
  git ls-files | grep -i release.yml
fi

Repository: tinyauthapp/tinyauth

Length of output: 1347


🏁 Script executed:

# Get full job definitions for the image-build jobs
echo "=== image-build job (lines 115-170) ==="
sed -n '115,170p' .github/workflows/release.yml

echo ""
echo "=== image-build-distroless job (lines 172-227) ==="
sed -n '172,227p' .github/workflows/release.yml

echo ""
echo "=== Checking for docker/build-push-action usage ==="
grep -n "docker/build-push-action" .github/workflows/release.yml

Repository: tinyauthapp/tinyauth

Length of output: 4738


Image build jobs missing required permissions for checkout and publish.

All four image build jobs (lines 119, 176, 233, 290) currently have only packages: read. With job-level permission blocks, unspecified scopes default to none, causing these jobs to fail:

  • actions/checkout requires contents: read to access repository code
  • docker/build-push-action with push=true to GHCR requires packages: write to publish images using GITHUB_TOKEN

Add both permissions to each affected job:

🔧 Proposed fix
   image-build:
     runs-on: ubuntu-latest
     needs:
       - generate-metadata
     permissions:
-      packages: read
+      contents: read
+      packages: write

   image-build-distroless:
     runs-on: ubuntu-latest
     needs:
       - generate-metadata
       - image-build
     permissions:
-      packages: read
+      contents: read
+      packages: write

   image-build-arm:
     runs-on: ubuntu-24.04-arm
     needs:
       - generate-metadata
     permissions:
-      packages: read
+      contents: read
+      packages: write

   image-build-arm-distroless:
     runs-on: ubuntu-24.04-arm
     needs:
       - generate-metadata
       - image-build-arm
     permissions:
-      packages: read
+      contents: read
+      packages: write
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/release.yml around lines 119 - 120, The job-level
permissions for the image build jobs currently only specify "packages: read",
which prevents actions/checkout and docker build-push from working; update each
image build job's permissions block to include both "contents: read" and
"packages: write" (in addition to or replacing the existing packages: read) so
actions/checkout can access the repo and docker/build-push-action can push to
GHCR using GITHUB_TOKEN; locate the YAML permission blocks that currently
contain "permissions: packages: read" in the four image build jobs and add
"contents: read" and "packages: write" there.

Copy link
Copy Markdown
Member

@scottmckendry scottmckendry left a comment

Choose a reason for hiding this comment

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

If coderabbit's comments are false positives (which I think they are) should be all good.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants