---
title: "Block Malicious Packages in Docker Builds on CI Runners"
description: "On self-hosted CI runners that run the Docker daemon in the runner container, by default PMG does not check the packages that docker build, docker run and job containers install. An opt-in switch, PMG_CONTAINER_TRUST, closes that gap with no Dockerfile change. The post shows how pmg-runc works, how to set it up, and job logs with the switch off and on."
url: "https://safedep.io/blog/block-malicious-packages-docker-builds"
author: "Sahil Bansal"
published: "2026-11-26"
---

# Block Malicious Packages in Docker Builds on CI Runners

[Self-hosted CI runners](https://safedep.io/blog/github-actions-wfx-credential-stealer) often build images with Docker. PMG checks the
packages that a job step installs. On runners where Docker runs inside the runner container, the installs inside a
Docker build skip that check by default. A malicious package then installs, and the build passes. SafeDep reproduced
this on a lab runner. With the PMG container trust switch on, the same build failed at the malicious
package.

This post covers runners where the Docker daemon runs inside the runner container, such as summerwind Actions Runner
Controller (ARC). The same gap applies to containers that a job starts with Docker and to job containers.

## TL;DR

- Without the switch, PMG blocked the malicious test packages (`safedep-test-pkg` for npm and pip) only in the job
  step. The image build, `docker run` with npm and pip, and the job container installed them, and their steps passed.
- With `PMG_CONTAINER_TRUST=1`, every place got a 403 for the malicious package, and the normal packages installed.
- If the containers use a forward proxy in the runner container, PMG intercepts their installs, but the containers do
  not trust the PMG certificate authority (CA). With the switch off, the npm installs in the lab failed on the certificate. With the switch on,
  they gave the same results as without a proxy.
- The switch puts `pmg-runc`, a wrapper for runc, between the Docker daemon and runc. It gives each container the PMG CA
  before the container starts.

## Why container installs skip the check

On a runner, PMG runs as a persistent proxy daemon. It attaches eBPF programs to the cgroup of the runner container.
The kernel then sends each registry connection of a job step to PMG
([how it works](https://docs.safedep.io/package-security/pmg/kubernetes-ci-runners-how-it-works)). The Docker daemon
starts each container in another cgroup and another network namespace, so container traffic does not pass through PMG.

With no forward proxy, a container install goes straight to the registry, and PMG does not check it.

Through a forward proxy in the runner container, such as Squid, the install fails. PMG enforces the cgroup of the
runner container, so it intercepts the connections from the proxy to the registry. It answers with a certificate from
the PMG CA, and the container does not trust that CA. In a lab run with Squid at `http://172.17.0.1:3128`, npm retried
for about 70 seconds, then failed:

```text title="docker build safedep-test-pkg, through a proxy (switch off)"
#6 [3/3] RUN npm install --no-audit --no-fund safedep-test-pkg@0.1.3
#6 70.34 npm error code UNABLE_TO_VERIFY_LEAF_SIGNATURE
#6 70.34 npm error errno UNABLE_TO_VERIFY_LEAF_SIGNATURE
#6 70.34 npm error request to https://registry.npmjs.org/safedep-test-pkg failed, reason: unable to verify the first certificate
#6 70.34 npm error A complete log of this run can be found in: /root/.npm/_logs/2026-11-24T19_12_28_131Z-debug-0.log
ERROR: failed to solve: process "/bin/sh -c npm install --no-audit --no-fund ${PKG}" did not complete successfully: exit code: 1
```

`is-number@7.0.0` failed in the same way, so the build breaks for normal packages too.

A wrapper around the Docker CLI can add a volume and a variable to `docker run` and pass the CA in. A `RUN` step of a
Docker build has no such options. Only a Dockerfile change, such as a secret mount, or the container runtime can reach
it ([trust inside a container](https://docs.safedep.io/package-security/pmg/kernel-enforcement#trust-inside-a-container)).

PMG has a container redirect, the `--enforce-namespaces redirect` flag, that sends container traffic to PMG. Alone, it
does not make the container trust the PMG CA, so the TLS handshake still fails
([trust inside a container](https://docs.safedep.io/package-security/pmg/kernel-enforcement#trust-inside-a-container)).
The switch turns on the redirect and gives each container the CA through `pmg-runc`.

## How `pmg-runc` works

The Docker daemon and the BuildKit inside it start every container with the first runc on `PATH`. When the switch is
on, the runner entrypoint links `/usr/local/sbin/runc` to `pmg-runc`, so the daemon finds the wrapper first
([`pmg-entrypoint.sh` L210-224](https://github.com/safedep/pmg/blob/v0.37.0/scripts/container/pmg-entrypoint.sh#L210-L224)).
This is the Open Container Initiative (OCI) runtime wrapper pattern that the
[NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/arch-overview.html)
uses for GPUs.

![Flow diagram. Container start: dockerd, for docker run and container jobs, and BuildKit, for the RUN steps of docker build, call pmg-runc, the first runc on PATH. pmg-runc edits the OCI config.json to mount the CA at /dev/pmg-ca and set the CA variables. Install: the real runc starts the changed container, npm install in it trusts the PMG CA, and the PMG proxy answers a malicious package with 403.](https://safedep.io/_next/static/immutable/media/block-malicious-packages-docker-builds-pmg-runc.44qn16waycus3.png)

For each container that runc creates, `pmg-runc` edits the OCI `config.json` of the container
([`main.go` L211-293](https://github.com/safedep/pmg/blob/v0.37.0/scripts/container/pmg-runc/main.go#L211-L293)).
Then it runs the real runc with the same arguments. The edit does these things:

- It mounts the PMG CA and a CA bundle read-only in `/dev/pmg-ca`. That directory is on the tmpfs of the container, so
  an image build does not keep the files in a layer.
- It sets `NODE_EXTRA_CA_CERTS`, `SSL_CERT_FILE`, `REQUESTS_CA_BUNDLE`, `PIP_CERT` and `UV_NATIVE_TLS`
  ([`main.go` L389-413](https://github.com/safedep/pmg/blob/v0.37.0/scripts/container/pmg-runc/main.go#L389-L413)).
  If the image sets a CA variable, such as `SSL_CERT_FILE`, to its own CA file, the container gets a copy of it. The
  copy has the PMG CA added
  ([`main.go` L360-387](https://github.com/safedep/pmg/blob/v0.37.0/scripts/container/pmg-runc/main.go#L360-L387)).
  Any other variable that the container sets keeps its value.
- When buildx runs BuildKit in its own container (the `docker-container` driver), `pmg-runc` mounts itself in front of
  the runc of that BuildKit. The build steps then get the same edit.
- For a process that `runc exec` starts, it adds the same variables.

`pmg-runc` refuses any file that holds a private key
([`main.go` L295-316](https://github.com/safedep/pmg/blob/v0.37.0/scripts/container/pmg-runc/main.go#L295-L316))
and opens image files with `openat2` and `RESOLVE_IN_ROOT`
([`main.go` L466-492](https://github.com/safedep/pmg/blob/v0.37.0/scripts/container/pmg-runc/main.go#L466-L492)).
If it cannot change a container, it starts the container unchanged, and an install there fails on the certificate.

In the lab runner with the switch on, a shell in the runner container started a `node:22-slim` container (ID
28d8cc35a8f2, PID 3802). It then showed the variables and read-only mounts of that container, the wrapper log and the runc link:

```console title="Runner container, PMG_CONTAINER_TRUST=1"
$ sudo cat /proc/3802/environ | tr '\0' '\n'
UV_NATIVE_TLS=1
NODE_EXTRA_CA_CERTS=/dev/pmg-ca/ca.pem
NODE_VERSION=22.23.5
HOSTNAME=28d8cc35a8f2
YARN_VERSION=1.22.22
HOME=/root
SSL_CERT_FILE=/dev/pmg-ca/ca-bundle.pem
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
REQUESTS_CA_BUNDLE=/dev/pmg-ca/ca-bundle.pem
PWD=/
PIP_CERT=/dev/pmg-ca/ca-bundle.pem
$ sudo grep pmg-ca /proc/3802/mountinfo | cut -d' ' -f4,5,6
/etc/pmg-runc/ca.pem /dev/pmg-ca/ca.pem ro,relatime
/etc/pmg-runc/ca-bundle.pem /dev/pmg-ca/ca-bundle.pem ro,relatime
$ sudo grep 28d8cc35a8f2 /var/log/pmg-runc.log
2026-11-24T18:35:11Z pmg-runc: ca added to 28d8cc35a8f260573509acefd088d925b90b3a7184f92f025bc752749e20ebe5
$ ls -l /usr/local/sbin/runc
lrwxrwxrwx 1 root root 29 Nov 24 18:32 /usr/local/sbin/runc -> /opt/safedep/pmg/bin/pmg-runc
```

## Set it up

You need PMG v0.37.0 or later, and a runner image that starts with the PMG runner entrypoint. The
[ARC runners guide](https://docs.safedep.io/package-security/pmg/kubernetes-ci-runners) shows how to build it. The nodes
need Linux 5.15 or later, kernel BTF and cgroup v2. The image is three lines on top of the summerwind dind image:

```dockerfile title="Dockerfile"
FROM summerwind/actions-runner-dind:ubuntu-22.04
COPY --from=ghcr.io/safedep/pmg:v0.37.0 /opt/safedep/pmg /opt/safedep/pmg
ENTRYPOINT ["/opt/safedep/pmg/bin/pmg-entrypoint.sh"]
CMD ["entrypoint-dind.sh"]
```

Then set `PMG_CONTAINER_TRUST=1` on the runner container:

```yaml title="runnerdeployment.yaml"
apiVersion: actions.summerwind.dev/v1alpha1
kind: RunnerDeployment
metadata:
  name: pmg-pilot
spec:
  template:
    spec:
      organization: <your-org>
      labels: [pmg-pilot]
      image: <your-registry>/actions-runner-dind-pmg:<tag>
      dockerdWithinRunnerContainer: true
      env:
        - name: PMG_CONTAINER_TRUST
          value: '1'
```

When the switch is on, the entrypoint does three things before the runner starts:

1. It starts PMG with the container redirect.
2. It copies the PMG CA certificate and the CA bundle to `/etc/pmg-runc`.
3. It links `/usr/local/sbin/runc` to `pmg-runc`.

The Docker daemon must run in the runner container. If `DOCKER_HOST` is set, as with a Docker-in-Docker (dind)
sidecar, the entrypoint stops with an error
([`pmg-entrypoint.sh` L191-194](https://github.com/safedep/pmg/blob/v0.37.0/scripts/container/pmg-entrypoint.sh#L191-L194)).
To turn the switch off, remove the variable and start the Pod again.

## Check it on your runner

Build an image that installs the test package `safedep-test-pkg`. The package is benign, and SafeDep flags it as
malicious, so anyone can test a block. The lab used this Dockerfile:

```dockerfile title="docker/Dockerfile"
FROM node:22-slim
ARG PKG
WORKDIR /app
RUN npm install --no-audit --no-fund ${PKG}
```

This step from the full lab workflow, in the Results section, builds it:

```yaml title=".github/workflows/container-build.yml (one step)"
      - name: docker build safedep-test-pkg
        if: always()
        run: docker build --no-cache --progress plain --build-arg PKG=safedep-test-pkg@0.1.3 docker
```

The excerpts below come from the GitHub Actions job logs. They drop the timestamps, the step header and the build
steps before the RUN step. The switch-on build also drops the BuildKit repeat of the npm error.

Without the switch, the build installed the malicious package and the step passed:

```text title="docker build safedep-test-pkg (switch off)"
#6 [3/3] RUN npm install --no-audit --no-fund safedep-test-pkg@0.1.3
#6 0.442 
#6 0.442 added 1 package in 260ms
#6 DONE 0.5s

#7 exporting to image
#7 exporting layers 0.0s done
#7 writing image sha256:ec0144d529753fdc36680b5f21ab5097aaa47b5b16a7187a88ec82e94542354f done
#7 DONE 0.1s
```

In the switch-on build, npm got a 403 from PMG, and the step failed:

```text title="docker build safedep-test-pkg (switch on)"
#6 [3/3] RUN npm install --no-audit --no-fund safedep-test-pkg@0.1.3
#6 0.326 npm error code E403
#6 0.326 npm error 403 403 Forbidden - GET https://registry.npmjs.org/safedep-test-pkg/-/safedep-test-pkg-0.1.3.tgz
#6 0.326 npm error 403 In most cases, you or one of your dependencies are requesting
#6 0.326 npm error 403 a package version that is forbidden by your security policy, or
#6 0.326 npm error 403 on a server you do not have access to.
#6 0.326 npm error A complete log of this run can be found in: /root/.npm/_logs/2026-11-24T18_34_13_995Z-debug-0.log
#6 ERROR: process "/bin/sh -c npm install --no-audit --no-fund ${PKG}" did not complete successfully: exit code: 1
ERROR: failed to solve: process "/bin/sh -c npm install --no-audit --no-fund ${PKG}" did not complete successfully: exit code: 1
##[error]Process completed with exit code 1.
```

On your runner, expect the 403 from PMG and a failed step. If the step passes, the containers on that runner get no
PMG check.

## Results

The lab used this setup:

- Cluster: a local Kubernetes cluster, with one runner Pod for each phase, first with the switch off and then on.
- Image: `summerwind/actions-runner-dind:ubuntu-22.04` with PMG and buildx v0.24.0 added.
- Versions: Docker 28.0.4, runner 2.338.2, Node.js v22.23.5 and npm 10.9.9.
- PMG: commit [472e1f9](https://github.com/safedep/pmg/commit/472e1f9f53d3ebded5a299bcb8797fc0d29dfd17) from
  [pull request #638](https://github.com/safedep/pmg/pull/638), before any release.
- Label: the lab used a test label. To run the workflow on your own pool, change only the `pmg-pilot` label.

The malicious packages were `safedep-test-pkg@0.1.3` for npm and `safedep-test-pkg==0.0.4` for pip.

| Where the install runs        | Switch off                                                 | Switch on                                            |
| ----------------------------- | ---------------------------------------------------------- | ---------------------------------------------------- |
| Job step                      | Blocked (403)       | Blocked (403) |
| Image build (`docker build`)  | Installed (step passed) | Blocked (403) |
| Container, npm (`docker run`) | Installed (step passed) | Blocked (403) |
| Container, pip (`docker run`) | Installed (step passed) | Blocked (403) |
| Job container (`container:`)  | Installed (step passed) | Blocked (403) |

The normal packages, `is-number@7.0.0` and `six==1.16.0`, installed in every place, with the switch off and on.

The job container showed the same change as the image build:

```text title="npm install safedep-test-pkg in the job container (switch off)"

added 1 package in 203ms
```

```text title="npm install safedep-test-pkg in the job container (switch on)"
npm error code E403
npm error 403 403 Forbidden - GET https://registry.npmjs.org/safedep-test-pkg/-/safedep-test-pkg-0.1.3.tgz
npm error 403 In most cases, you or one of your dependencies are requesting
npm error 403 a package version that is forbidden by your security policy, or
npm error 403 on a server you do not have access to.
npm error A complete log of this run can be found in: /github/home/.npm/_logs/2026-11-24T18_33_35_774Z-debug-0.log
##[error]Process completed with exit code 1.
```

A second lab run gave the containers Squid, in the runner container, as their proxy at `http://172.17.0.1:3128`. It
tested the image build, `docker run` and the job container, with npm only:

| Where the install runs        | Switch off                                                                     | Switch on                                            |
| ----------------------------- | ------------------------------------------------------------------------------ | ---------------------------------------------------- |
| Image build (`docker build`)  | Failed (certificate error, no check) | Blocked (403) |
| Container, npm (`docker run`) | Failed (certificate error, no check) | Blocked (403) |
| Job container (`container:`)  | Failed (certificate error, no check) | Blocked (403) |

The normal package `is-number@7.0.0` failed with the same certificate error when the switch was off, and it installed
when the switch was on.

**Full lab workflow (two jobs, twelve steps)**

```yaml title=".github/workflows/container-build.yml"
name: Container build
on: push
jobs:
  install:
    runs-on: [self-hosted, pmg-pilot]
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: {node-version: 22}
      - name: npm install is-number (runner step)
        run: npm install --no-audit --no-fund is-number@7.0.0
      - name: npm install safedep-test-pkg (runner step)
        if: always()
        run: npm install --no-audit --no-fund safedep-test-pkg@0.1.3
      - name: docker build is-number
        if: always()
        run: docker build --no-cache --progress plain --build-arg PKG=is-number@7.0.0 docker
      - name: docker build safedep-test-pkg
        if: always()
        run: docker build --no-cache --progress plain --build-arg PKG=safedep-test-pkg@0.1.3 docker
      - name: docker run npm install is-number
        if: always()
        run: docker run --rm -w /app node:22-slim npm install --no-audit --no-fund is-number@7.0.0
      - name: docker run npm install safedep-test-pkg
        if: always()
        run: docker run --rm -w /app node:22-slim npm install --no-audit --no-fund safedep-test-pkg@0.1.3
      - name: docker run pip install six
        if: always()
        run: docker run --rm python:3.12-slim pip install --no-cache-dir six==1.16.0
      - name: docker run pip install safedep-test-pkg
        if: always()
        run: docker run --rm python:3.12-slim pip install --no-cache-dir safedep-test-pkg==0.0.4

  container-job:
    runs-on: [self-hosted, pmg-pilot]
    container: node:22-slim
    defaults:
      run:
        working-directory: /tmp
    steps:
      - name: npm install is-number (job container)
        run: npm install --no-audit --no-fund is-number@7.0.0
      - name: npm install safedep-test-pkg (job container)
        if: always()
        run: npm install --no-audit --no-fund safedep-test-pkg@0.1.3
```

## Limits

- **Host network containers get no check.** A malicious package installs in a `--network host` container.
- **Some containers get no CA, so their installs fail.** This covers containers started with `-v /dev:/dev` and the
  containers that a `docker:dind` container starts. For a `-v /dev:/dev` container, `/var/log/pmg-runc.log` names the
  cause.
- **Some clients ignore the CA variables and fail.** Java, wget built with GnuTLS, Bun 1.2 and code that sets its own
  CA file fail on the certificate.
- **A proxy on the Docker bridge sees runner traffic from `169.254.200.1`.** With the switch on, PMG adds this address
  in the runner container, and runner traffic to that proxy comes from it. Add the address to the proxy access list.
- **A Docker daemon in a sidecar is not supported.** With the switch on, the entrypoint stops with an error when
  `DOCKER_HOST` is set.

The
[`pmg-runc` docs](https://github.com/safedep/pmg/blob/v0.37.0/docs/persistent-proxy.md#trust-in-the-containers-of-a-runner-image)
give the details.

## Get started

Build the runner image from the ARC runners guide above and set `PMG_CONTAINER_TRUST=1` on one pilot pool. Then run the check above on that pool, and read
[kernel enforcement](https://docs.safedep.io/package-security/pmg/kernel-enforcement) for the kernel side of the setup.

## Related reading

- [Binance Hack Lessons: Sandbox the Take-Home Assignment](https://safedep.io/blog/binance-hack-lessons)
- [Endpoint Protection for Developer Machines](https://safedep.io/blog/endpoint-protection-developer-security)
- [wfx: GitHub Actions Credential Stealer Hits 8,000 Repositories](https://safedep.io/blog/github-actions-wfx-credential-stealer)
- [PMG on self-hosted CI runners with ARC](https://docs.safedep.io/package-security/pmg/kubernetes-ci-runners)
- [Kernel enforcement on Linux](https://docs.safedep.io/package-security/pmg/kernel-enforcement)
