Skip to content

Adjust permissions and when to push in docker build action - #147

Open
dati18 wants to merge 3 commits into
mainfrom
fix-gh-workflow
Open

dati18 wants to merge 3 commits into
mainfrom
fix-gh-workflow

Conversation

@dati18

@dati18 dati18 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

This change fixes[1] failures caused by GitHub Container Registry authorization during pull_request runs.

PR workflows from dependabot completed the the GHCR login step but with read-only permission and then still attempted to push images with buildx.

The PR does two things:

  • it more tightly scopes the permissions for these workflows to ensure they only have the permissions they need
  • it prevents any PR from trying to push
    • this means we will now only keep images built from main in GHCR

[1] https://github.com/wbstack/widar/actions/runs/36420982691/job/108923351027?pr=105

Bug: T438725

dependabot Bot and others added 3 commits September 28, 2026 14:17
Bumps [docker/login-action](https://github.com/docker/login-action) from 1.10.0 to 2.1.0.
- [Release notes](https://github.com/docker/login-action/releases)
- [Commits](docker/login-action@v1.10.0...v2.1.0)

---
updated-dependencies:
- dependency-name: docker/login-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
@tarrow

tarrow commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

I'm having deja vu and wonder if I typed this already on another repo. Reasoning which half of this commit solves the issue vs which half is heading to a more tightly constrained set of permissions as a future best practice is below:

I don't believe we need to grant additional permissions to push when this is run on main. The github token has different permissions when run on main vs a dependabot PR (https://github.blog/changelog/2021-10-06-github-actions-workflows-triggered-by-dependabot-prs-will-respect-permissions-key-in-workflows/)

However this is probably not a bad thing to be explicit about; we should in general follow the principle of least privilege.

There are multiple places these permissions can be defined which is confusing.

I initially wondered if this started breaking because someone has clicked a clickops setting somewhere like: https://github.com/wbstack/widar/settings/actions or https://github.com/organizations/wbstack/settings/actions but this doesn't seem to be the case. Both are still set to be super permissive.

I assume this is actually because dependabot PRs are run and have permissions as though they are created from a fork.

This patch does change the status quo that now PRs written by human authors will also not be pushed (see for example the successful push here). I think this is acceptable but we need to adjust the description of this PR to make it clear

@tarrow tarrow changed the title Fix GHCR 403 on PR builds by disabling image push on pull_request Adjust permissions and when to push in docker build action Nov 20, 2026

@outdooracorn outdooracorn left a comment •

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'm having deja vu and wonder if I typed this already on another repo.

I'm having deja vu too! 😅 I think we might have discussed this verbally at some point (maybe at the end of a daily?).

I don't believe we need to grant additional permissions to push when this is run on main.

Agreed 👍

However this is probably not a bad thing to be explicit about; we should in general follow the principle of least privilege.

Indeed, I was thinking about this yesterday evening.

This patch does change the status quo that now PRs written by human authors will also not be pushed (see for example the successful push here). I think this is acceptable but we need to adjust the description of this PR to make it clear

I was saying just recently, I think to @dati18 about the queryservice-ui, that I wanted CI (particularly the docker build workflow) to run on every push1 as I think having dev images for code not yet merged into main in a container registry that we can more easily pull into our local minikube clusters is useful. We need to make sure we handle permissions sensibly (especially around things like forked repositories and dependabot), but I would prefer it if we kept building and pushing for PRs created by trusted repo members.

1: I don't think it always runs on every commit. If you push several commits at once I think the CI workflow(s) only run for the last pushed commit. That's not a problem, just explaining my word choice.

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