<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi James,<div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 25 Jan 2021, at 17:22, Hunt, James O <<a href="mailto:james.o.hunt@intel.com" class="">james.o.hunt@intel.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hi Christophe,<br class=""><br class="">I've checked and we do actually have a couple of GitHub actions using the "pull_request_target" event:<br class=""></div></div></blockquote><div><br class=""></div><div>Thanks for taking the time to follow up!</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class="">- Action to enforce the PR porting labels [1]<br class="">- Action to move all issues to "in progress" when a PR references them [2]<br class=""><br class="">Note that both these actions are in *all* our repos.<br class=""><br class=""><br class=""># What is the "pull_request_target" event?<br class=""><br class="">If you want a GitHub acction to trigger when a pull request is opened, the obvious choice seems to be the "pull_request" event. However, GitHub documents in [2] that:<br class=""><br class=""><blockquote type="cite" class="">Pull request events for forked repositories<br class="">Note: Workflows do not run on private base repositories when you open a pull request from a forked repository.<br class=""></blockquote><br class="">That's a problem because all the PRs the community raises are on "forked repositories".<br class=""><br class="">Enter the "pull_request_target" event. The event *does* work with "forked repositories" and allows actions to run in the context of the PR rather than the main repo. However, quoting from [3],<br class=""><br class=""><blockquote type="cite" class="">Warning: The pull_request_target event is granted a read/write repository token and can access secrets, even when it is triggered from a fork.<br class=""></blockquote><br class="">This seems somewhat odd given the event appears to have been created to make actions safer and you have to wonder if GitHub might introduce a new event that sits somewhere between "pull_request" and "pull_request_target" at some point.<br class=""><br class="">______<br class=""><br class="">Taking each of our actions in turn...<br class=""><br class=""><br class=""># Porting labels action<br class=""><br class="">## What is it for?<br class=""><br class="">The action checks to ensure that the PR is correctly labelled with respect to porting labels [3]. Note that the action is ultimately only checking to ensure the PR has a number of labels set.<br class=""><br class="">## Can we survive without it?<br class=""></div></div></blockquote><div><br class=""></div><blockquote type="cite" class=""><div class=""><div class=""><br class="">I'd say yes. The action is only reminding the community of the need to perform the porting - it cannot enforce it due to the complexities of bi-directional porting and timing [3].<br class=""><br class="">## Can the action be run without "pull_request_target"?<br class=""><br class="">I think it could. I'm going to test this and see if we can change the event to "pull_request" instead...<br class=""><br class=""><br class=""># Move issue to in progress label<br class=""><br class="">## What is it for?<br class=""><br class="">The action is triggered when a PR is opened and if that PR has an associated (linked) issue number (aka a "fixes #XXX" comment), that issue is resolved and moved into the issue backlog GitHub board [1]. GitHub allows us to move newly opened issue into the project automatically, but the GitHub API does not support "linked (issues|prs)" well, hence the need for the action.<br class=""><br class="">## Can we survive without it?<br class=""><br class="">Possibly. This was added specifically for the project board [1]. But since creating it, we have been hampered somewhat by GitHub's very restricted set of queries (filters) that can be run in a project. In fact, the weekly issue backlog "scrub" doesn't use that project - it uses a simple GitHub query (which is not restriected in the filters that can be applied).<br class=""><br class="">Ariel may wish to comment on this further.<br class=""><br class="">## Can the action be run without "pull_request_target"?<br class=""><br class="">afaik, no it cannot. That event is required to allow access to the PR. However, I'll re-test to see if that is still the case...<br class=""><br class=""><br class=""># TL;DR<br class=""><br class="">The all important summary ;) fwics, a "rogue PR" that attempts to install a bad action that does naughty things won't actually get run until it is itself merged in the main branch.</div></div></blockquote><div><br class=""></div><blockquote type="cite" class=""><div class=""><div class="">The bad code would only run on the *next* PR raised after the bad PR was merged. This is good and bad. However, looking on the positive side, it seems that if we want to keep these two actions there are two relatively easy changes we can make:<br class=""><br class="">1) Adopt GitHub's suggestion to make our actions only trigger when labelled with something like `safe-to-test`<br class=""><br class=""> This effectively makes the actions "manually triggered".<br class=""><br class="">2) Rotate the GitHub secrets (effectively the "uid" the actions run as) and check they have the absolute minimum set of privileges.<br class=""></div></div></blockquote><div><br class=""></div><div><br class=""></div><div><div>To me, there are two categories of rogue PR:</div><div><br class=""></div><div>1/ The ones you describe, which try to install bad stuff in the infrastructure, typically a github action. I believe you have covered that relatively exhaustively in your report. I agree with your analysis. I would add that we might be able to flag any commit that targets github actions with a specific label. Make sure we have eyes on them.</div><div><br class=""></div><div>2/ PRs that take advantage of the testing infrastructure to execute malicious code disguised as unit tests. In a chat with Ariel, I described that as a "unit test" doing some bitcoin mining. This was the case I was more concerned with in the context of a discussion about merging test and code repos. Frankly, I'm surprised we don't get more spammers trying to do this kind of things, given that our testing infrastructure runs containers as well as unit tests that could do practically anything.</div><div><br class=""></div><div>I suspect that what makes this hard today is the relatively low traffic in terms of number of PRs. We would notice bad PRs rapidly during review. It's probably much more beneficial to attempt to get access to AWS instances (see <a href="https://www.theregister.com/2015/01/06/dev_blunder_shows_github_crawling_with_keyslurping_bots/" class="">https://www.theregister.com/2015/01/06/dev_blunder_shows_github_crawling_with_keyslurping_bots/</a> for an example). But I can't completely shake the idea now that I had it.</div><div><br class=""></div><div><br class=""></div><div>Thanks</div><div>Christophe</div><div><br class=""></div></div><blockquote type="cite" class=""><div class=""><div class=""><br class=""><br class="">Cheers,<br class=""><br class="">James<br class=""><br class="">[1] - <a href="https://github.com/orgs/kata-containers/projects/23" class="">https://github.com/orgs/kata-containers/projects/23</a><br class="">[2] - <a href="https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request" class="">https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request</a><br class="">[3] - <a href="https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target" class="">https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target</a><br class=""><br class="">---<br class=""><a href="https://katacontainers.io/" class="">https://katacontainers.io/</a> | <a href="https://github.com/kata-containers" class="">https://github.com/kata-containers</a><br class="">Open Source Technology Center<br class="">Intel Corporation (UK) Ltd. - Co. Reg. #1134945 - Pipers Way, Swindon SN3 1RJ.<br class=""><br class="">________________________________________<br class="">From: Christophe de Dinechin <<a href="mailto:dinechin@redhat.com" class="">dinechin@redhat.com</a>><br class="">Sent: Tuesday, 19 January 2021 08:02<br class="">To: <a href="mailto:kata-dev@lists.katacontainers.io" class="">kata-dev@lists.katacontainers.io</a><br class="">Subject: [kata-dev] GitHub actions security recommendations<br class=""><br class="">Hello,<br class=""><br class=""><br class="">I don't know if you are aware of the security recommendations in this paper: <a href="https://securitylab.github.com/research/github-actions-preventing-pwn-requests" class="">https://securitylab.github.com/research/github-actions-preventing-pwn-requests</a>.<br class=""><br class="">I thought this was interesting notably in the context of the discussion regarding unifying testing/CI and code repos. While it is true that a single repo makes it possible to commit a test along with the change, it also means a malicious PR now has a much larger attack surface, something that I personally was not aware of.<br class=""><br class="">Food for thought.<br class=""><br class=""><br class="">Thanks,<br class="">Christophe<br class=""><br class=""><br class="">_______________________________________________<br class="">kata-dev mailing list<br class=""><a href="mailto:kata-dev@lists.katacontainers.io" class="">kata-dev@lists.katacontainers.io</a><br class="">http://lists.katacontainers.io/cgi-bin/mailman/listinfo/kata-dev<br class="">---------------------------------------------------------------------<br class="">Intel Corporation (UK) Limited<br class="">Registered No. 1134945 (England)<br class="">Registered Office: Pipers Way, Swindon SN3 1RJ<br class="">VAT No: 860 2173 47<br class=""><br class="">This e-mail and any attachments may contain confidential material for<br class="">the sole use of the intended recipient(s). Any review or distribution<br class="">by others is strictly prohibited. If you are not the intended<br class="">recipient, please contact the sender and delete all copies.<br class=""><br class=""></div></div></blockquote></div><br class=""></div></body></html>