fix(gha): only push images on merge/release #180
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've noticed all PRs have failing builds because the github action tries to push images to ghcr, which throws a 403 error.
After reading through https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/ , I'm pretty sure the original goal of pushing images tagged with the PR number is not possible to do securely.
The GITHUB_TOKEN used for authenticating to ghcr by default does not have write permissions, hence the 403 error. We could "fix" this by using
pull_request_target
, but that is very insecure since anyone could fork the repo and use the GITHUB_TOKEN inside the pipeline to overwrite any image in ghcr (or worse).So since there's no secure way (as far as I know) to allow pushing to ghcr in the context of PRs, I disabled it.
Now, PRs will just trigger the linting and testing steps. Merges to
main
and tag pushes will still trigger builds.