Self-hosted runner security with public repositories #26722
-
Documentation [1] says:
Do I understand correctly that if self-hosted runner is only used in workflow which is triggered by push, it’s completely secure? |
Beta Was this translation helpful? Give feedback.
Replies: 16 comments 5 replies
-
Yeah, you are right. If your workflows is not triggered by pull request event, then dangerous code on fork repos could not run on your self-hosted runner. Only collaborators has permission to push to your public repositories directly. If you could make sure your collaborators are safe , then workflows triggered by push event is secure. |
Beta Was this translation helpful? Give feedback.
-
Thanks! Then I suggest to change wording in documentation to be less scaring, and maybe add validation in runner which prints big bold warning whenever self-hosted runner is triggered in PR event in public repo. |
Beta Was this translation helpful? Give feedback.
-
I’m not sure this is safe. What happens if someaone creates a PR modifying the workflow to run on pull_requests? |
Beta Was this translation helpful? Give feedback.
-
Once a repo has been forked you aren’t in control of changes on the fork right? So it seems fine to me as long as the malicious code is not run on the main repo |
Beta Was this translation helpful? Give feedback.
-
@vivekteega Yeah, you are right. Please pay attention to pull requests from fork repo to your main repo. A workflow on pull_request event will get premerged code of forked repo to main repo and the codes in forked repo could be run in your self-hosted runner. |
Beta Was this translation helpful? Give feedback.
-
Thank you for this info. I was very spooked as well by the big warning in the docs. I’m considering deploying a self-hosted running and just making a big comment in the workflow to say “DO NOT TRIGGER ON PRs”. But it seems pretty fragile to me to “just” not run on PRs. That is a very easy thing to change without someone realizing that they’ve just opened themselves up a cybersecurity hole. The rule I would expect from Github is: a self-hosted runner can only be triggered by code in repos where the self-hosted runner is active. So, basically, a hard-ban on PR/issue/etc triggers. For a data point of comparison, Azure Pipelines makes you manually click a Permit button the first time a pipeline accesses a new runner. So it …should be? … impossible for it to have the same problem? |
Beta Was this translation helpful? Give feedback.
-
We’re investigating using self hosted runners at my work, but we’ve got hundreds of public repos so this issue is quite a blocker for us - something like @kousu suggests where you can prevent forked repos using self hosted runners at an organisation level would be very helpful. |
Beta Was this translation helpful? Give feedback.
-
What with a situation, where we have a public repository and would like to run the tests with some physical device, e.x. webcamera? |
Beta Was this translation helpful? Give feedback.
-
I am sorry to tell you that there is no alternatives. To test with physical device , you need to use self-hosted runner. |
Beta Was this translation helpful? Give feedback.
-
I think a good feature is if in the future we could trigger a workflow when an authorised user comments on an open PR. At the current moment it is hard to see how to deploy a self hosted runner in my development as ideally I would like to run CI before I push any new code to any of my branches. |
Beta Was this translation helpful? Give feedback.
-
Yeah I like the suggestion from @bdevierno1 . I would be great if the action can be triggered only by comment (e.g. or what about blocking merging unless 1 approval from an owner is required? If that’s the case I would be great to have an action that can be triggered based on the “approved” status of a PR. |
Beta Was this translation helpful? Give feedback.
-
I think it would also be useful to have different event types for “internal” and “external” pull requests, where “internal” means pull request originates from the same repo with workflow. If workflow is triggered by internal PRs only it would require having write access to repo to run code on self-hosted runner. |
Beta Was this translation helpful? Give feedback.
-
But isn’t it more dangerous that was discussed before in this thread? According to this thread How to prevent GitHub Actions workflow being triggered by a forked repository events? - Stack Overflow if you have a self-hosted runner, than anyone can create a workflow that targets self-hosted runner and create a PR. This will trigger the workflow to be executed on a self-hosted runner even if you haven’t accepted the PR? |
Beta Was this translation helpful? Give feedback.
-
You are correct, I tested this myself. The conditions for a potential security breach are like so:
Then a malicious actor can simply open a PR from a forked repo where they add a new workflow file like so:
The script will run on the available self-hosted runner of the maintainer’s repo. The best (and most cumbersome) way to prevent this is to check Require approval for all outside collaborators in the repo settings as explained here. Then you have to manually approve workflows running on each PR, after you have first checked the PR for any changes to workflow files. Another way to mitigate the risk would be to have a private “companion” repo to your public repo that the self-hosted runner is assigned to as explained here but I haven’t tried this myself. |
Beta Was this translation helpful? Give feedback.
-
I don't understand what is not safe about running on self hosted when it's not a fork, but a commit to a branch or PR from a branch on the same repository. And I thought there were already such conditionals in the case of github actions secrets.
https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/ |
Beta Was this translation helpful? Give feedback.
-
I'm using a standard GitHub provided runner for PRs where it runs tests and validates that a Linux build passes. For releases I build binaries in my pipelines and publish them to a github release. Right now I am using
|
Beta Was this translation helpful? Give feedback.
Yeah, you are right. If your workflows is not triggered by pull request event, then dangerous code on fork repos could not run on your self-hosted runner.
Only collaborators has permission to push to your public repositories directly. If you could make sure your collaborators are safe , then workflows triggered by push event is secure.