-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci: Try backporting via pull_request_target #9430
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @The-Compiler for finding this. I read the article and while it's not particularly easy to understand, I believe this is safe, because: it can only be triggered by trusted users (label), and doesn't actually execute anything from the base branch.
As an added bit of safety, I'd also restrict backporting to only merged PRs, i.e. add
if: github.event.pull_request.merged
Finally, with pull_request_target
the checkout in on the target repository not the base repository so I'm not sure whether the git cherry-pick -x --mainline 1 ${{ github.event.pull_request.merge_commit_sha }}
part will work, but maybe it will, let's try it :)
@@ -1,7 +1,7 @@ | |||
name: backport | |||
|
|||
on: | |||
pull_request: | |||
pull_request_target: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would add a comment here:
pull_request_target: | |
# Note that `pull_request_target` has security implications: | |
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ | |
# In particular: | |
# - Only allow triggers that can be used only be trusted users | |
# - Don't execute any code from the target branch | |
# - Don't use cache | |
pull_request_target: |
Apologies for the delay! Updated now. As for whether it will actually work or not, I guess we can only find out easily after merging... |
It worked: #9474 🎉 However I did had to add the label after it was merged, is that expected? Seems more convenient to be able to add the label while the PR is still running in CI. |
Yep, I was thinking about that as well - that would probably need to be a slightly different trigger (or even a separate workflow) though, which triggers when a PR is merged and then checks that PR's labels. I think ideally we would have both, so that the labels can be applied at any time and the proper thing will happen. @bluetech is this something you'd be interested in? Personally I should take care of some dayjob stuff at the moment, so pytest 7 keeps me busy enough 🙂 |
Another problem is that CI is not running for it 😕 |
Closing and reopening the PR is a workaround |
Regarding the merged requirement, I suggested it out of caution because I'm not 100% sure which commit the Regarding CI not running, right - CI doesn't run when triggered this way - this also happens for the create-pull-request actions and similar. Workaround is to close & reopen, then it triggers. It's also possible to use a user token (pytestbot), but that has its own security considerations. |
It's not as easy as removing the As for using a |
In #9416, @bluetech says:
And indeed the debug output reveals:
which I think is due to this:
I assume it worked in @bluetech's test because that wasn't a PR from a forked repository?
When using
pull_request_target
instead, things look different:Note the security warning:
But I think we should be fine here: We don't run anything, and this is triggered by labeling PRs, so it should not run on untrusted stuff anyways. For some more context and security considerations, see Keeping your GitHub Actions and workflows secure Part 1: Preventing pwn requests | GitHub Security Lab
I don't really understand whether the workflow itself will need any changes due to the context now referring to the base - but we can't really know until we try, I guess.