question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

allow self-hosted runner to be restricted to container builds only

See original GitHub issue

Describe the enhancement Right now the security recommendation for self-hosted runners is not to host them on machines where there is any sensitive data. Because third party code can be injected via pull-requests.

It would be nice if self-hosted runner could be configured in a way to accept only jobs which have container: attribute, i.e. only jobs running inside of a docker container. This would allow to host such runners on machines without being afraid for sensitive data. I.e. if third party pull request modifies the workflow by removing the container: attribute then the job will be failed by the self-hosted runner.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:6

github_iconTop GitHub Comments

3reactions
j3parkercommented, Dec 1, 2020

Disclaimer: I’m not a GitHub employee.

This sounds good but unfortunately wouldn’t work, at least without very big redesigns. Docker containers, at least they way GitHub Actions uses them, don’t provide that level of isolation. Here’s a dumb example:

on: push
jobs:
  job:
    runs-on: ubuntu-latest
    container: alpine
    steps:
      - run: poweroff -f || true # will fail
      - run: apk add docker
      - run: docker run --privileged alpine sh -c 'poweroff -f'
      - run: echo hello # won't run

The job runs inside a container. The first poweroff -f will fail with this error:

poweroff: Operation not permitted

but to make uses: work (which often launches containers) GitHub Actions mounts /var/run/docker.sock into the jobs container. This socket lets your docker client communicate with the outside host e.g. to launch containers. So any containers used in uses: run adjacent to your job container, not inside it. Maybe this sounds weird, but Docker unfortunately wasn’t built for nesting (even if some of the technologies like cgroups and namespaces are).

A big consequence of being able to run containers on the host like this is that you’re effectively unsandboxed. Here we run a container with --privlieged and can actually power off the machine (the echo hello will never run.)

But you can do whatever, really. You could mount the root volume and read any file from the host, etc.

So how do you get sandboxing with GitHub Actions? The usual boring way: run one job per VM (tear down the VM after the job is done – #510 is needed to make this good as far as I know) and don’t make the VM’s more privileged than you need (e.g. if you’re running in AWS, pay mind to what VPC they’re running in and what their instance role is.)

TL;DR: job containers aren’t a security feature.

2reactions
jeromewaibelcommented, Dec 3, 2020

@j3parker I tried to use rootless docker to avoid your poweroff scenario from above, but, alas, this won’t work either because of https://github.com/actions/runner/issues/827

Read more comments on GitHub >

github_iconTop Results From Across the Web

About self-hosted runners
A self-hosted runner is a system that you deploy and manage to execute jobs from GitHub Actions on GitHub.com. For more information about...
Read more >
Self-Hosted GitHub Runners Are Backdoors
Configure self-hosted runners at the repository level and not the organization for any repositories containing more sensitive source code.
Read more >
Is the GitHub Actions self-hosted runner safe for Open Source?
GitHub warns against using self-hosted Actions runners for public repositories - but why? And are there alternatives?
Read more >
GitHub Actions - Self-hosted runners - Installation & Calling
When using GitHub Actions, you have the option to use GitHub hosted runners, or to run your own runners, called self - hosted...
Read more >
Securing Your CI/CD Pipeline: Exploring the Dangers of ...
Self -hosted runners can be physical, virtual, in a container, on-premises, or in a cloud environment. The alternative is to use a build-as-a-service...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found