Skip to content

Skip GHCR publishing for Dependabot pull requests - #156

Draft
dati18 wants to merge 1 commit into
mainfrom
pr-permission
Draft

dati18 wants to merge 1 commit into
mainfrom
pr-permission

Conversation

@dati18

@dati18 dati18 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Dependabot PR builds use a "read-only" GITHUB_TOKEN, so publishing the image to GHCR fails even though the Docker build succeeds.

  • Grant the workflow contents: read and packages: write permission
  • Continue building images for PRs without pushing them
  • Keep publishing images on pushes to main.

Note: This PR is my a testing ground; no need to take it serious

@dati18
dati18 marked this pull request as draft October 21, 2026 12:18
@tarrow

tarrow commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

@dati18 sorry for being slow. Why do we need to tweak the permissions AND change the conditions that the workflow runs? Isn't the idea that if it's not pushing on the PR then the token it runs with will have less restrictions anyway?

@dati18

dati18 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor Author

@tarrow

  • I set push: false for a pull_request event and true for other eevents. it tells Buildx not to upload the image but it can't reduce the token's permission
  • permissions: packages: write requests package-write access for the workflow to publish on a push to main, but placed at workflow level, it also applies to PR runs where Github allows it.
  • contents: read lets actions/checkout fetch Cradle’s source and allows the workflow’s Git reads; it grants no write access.

The permission change is not really needed, I added them to test

Comment on lines -54 to +58
push: true
push: ${{ github.event_name != 'pull_request' }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would like to keep publishing images on pull_requests if possible as it makes it easier to test PRs in minikube if there is an image in the GHCR to pull.

How about only trying to push the image for PRs that aren't created by dependabot?
E.g. see option 1 of these github docs: https://docs.github.com/en/code-security/reference/supply-chain-security/troubleshoot-dependabot/dependabot-on-actions#troubleshooting-failures-when-dependabot-triggers-existing-workflows

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.

3 participants