> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ankra.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Pipeline Build Security

> What contains an image build in Ankra Pipelines - where the build runs, how the rootless builder is confined, what it can reach, what a pull request or a fork cannot widen, and how the image gets from the build to a deploy.

A `build` step runs your Dockerfile, and every `RUN` line in it is code. Anyone who can push a branch can change that code, and on a public repository so can anyone who opens a pull request from a fork. This page is for a security review: where a build runs, what confines it, what it can reach, and which of those you control. Each section links to the page with the detail.

***

## Where a build runs

| Where | When | What leaves your infrastructure |
| - | - | - |
| **Your CI cluster**, namespace `ankra-ci-build` | The cluster's agent runs pipeline steps and its nodes let the rootless builder start | The image, pushed to your organisation's registry, and the step's log and results. The build reads the source from the run's workspace and does not fetch it again |
| **Ankra's build cluster** | Your cluster cannot build, and **Build on Ankra when your cluster cannot** is on, which is the default. Never for a pull request from a fork | Your source: Ankra's builders fetch the commit and build it there |
| **A CI playground** on Ankra Cloud | The run's largest step fits no node of your CI cluster, and the CI playground setting is on, which is the default | The whole run: it is checked out, built and tested on an Ankra Cloud cluster Ankra builds for your organisation |

Both fallbacks are organisation settings that an owner or admin can turn off, and with both off every pipeline step stays on your own clusters. Ankra can also start builds on its build cluster outside a pipeline run, such as the first build of a new application, only while the build fallback is on; a build someone starts there by name still runs. [Where your pipeline runs](https://docs.ankra.ai/pipelines/where-pipelines-run.md#keep-everything-in-your-own-cluster) has both settings and the commands, and [What Ankra keeps about a run](https://docs.ankra.ai/pipelines/where-pipelines-run.md#what-ankra-keeps-about-a-run) lists the logs and results that reach Ankra wherever a step runs.

The image goes to the registry your application publishes to: your organisation's private project in Ankra's registry, unless the application [names a registry of your own](https://docs.ankra.ai/concepts/applications.md#using-your-own-registry).

***

## The builder in your cluster

Each build gets a pod of its own in `ankra-ci-build`, running rootless BuildKit. The daemon starts inside that pod, builds one image and exits with it, so no daemon, layer store or process is shared with another build. The agent deletes the pod and the objects it created for the step when the step ends.

The build pod:

* runs as uid 1000, never as root, on a read-only root filesystem
* is never privileged, uses no host namespace or host path, and gets no Kubernetes service account token
* drops every Linux capability except `SETUID` and `SETGID`, which the builder needs to map its own user namespace
* is admitted under the Pod Security Standards' Baseline profile. Every other step runs in `ankra-ci` under the Restricted profile ([What a step runs as](https://docs.ankra.ai/guides/ankra-pipelines.md#what-a-step-runs-as))
* runs Ankra's own builder image, pinned by digest. A pipeline cannot name another

### What the builder runs without

Rootless BuildKit builds inside an unprivileged user namespace it creates itself. That needs system calls and mounts that a container runtime's default confinement denies, so the builder gives up some confinement an ordinary step keeps:

* **No seccomp filter.** The build pod names no seccomp profile, because the Baseline profile forbids naming `Unconfined`. On a kubelet that does not apply a default seccomp profile, the builder runs with none. On one that applies `RuntimeDefault`, the builder cannot start and the build is refused as `build_runtime_confined`, or goes to Ankra's build cluster while the build fallback is on.
* **AppArmor only when you choose it.** Unless the cluster names an AppArmor profile for the builder, the runtime's default applies, and on AppArmor nodes that default stops the builder. The `ankra-managed` profile confines the builder to the mounts and namespaces it needs: see [Let Ankra load the AppArmor profile](https://docs.ankra.ai/guides/ankra-ci-troubleshooting.md#let-ankra-load-the-apparmor-profile).
* **No process sandbox per `RUN`.** The commands your Dockerfile runs share the builder's process namespace.

So treat a build like any other code on the branch: whatever the build pod holds, assume the commands in its Dockerfile can read it. That covers the registry login it pushes with and any secret the stage declares. A build for a pull request from a fork gets no registry login.

To contain builds further, put CI on nodes of its own with a [step placement](https://docs.ankra.ai/guides/ankra-pipelines.md#step-placement) on a tainted node group, so a build shares a node only with other pipeline steps.

***

## What a build can reach

**Network.** Every step gets a NetworkPolicy of its own, and a build's allows no ingress. A build's default tier, `egress-https`, allows DNS to the cluster's own resolver and 443/TCP and 80/TCP to public addresses only. Private ranges, link-local addresses and every cloud metadata endpoint are excluded unless your organisation lists a range in `ci_egress_allowed_cidrs`. A NetworkPolicy only takes effect on a network plugin that enforces it, so check that yours does. The exact ranges are in [the pipeline reference](https://docs.ankra.ai/guides/pipeline-reference.md#fields-common-to-every-stage).

**The registry.** A build pushes by digest only, to a CI staging repository next to the application's repositories. It never tags an image and never pushes to the repository you deploy from: only `publish` gives an image a tag, after the gate passed it ([From the build to a deploy](#from-the-build-to-a-deploy)).

**Secrets.** A build cannot pass a secret into the image build. Build arguments are literal `NAME=value` entries written in the pipeline file, and one named after a declared secret is refused, so no secret ends up in a build argument, where it can be recorded in the image's history and provenance. When a build needs a private package, fetch it in a `run` stage that declares the secret, then copy it into the image from the workspace, which is the build's context.

**The layer cache.** The BuildKit layer cache lives next to the images in the CI staging repository. A run on the default branch writes the trusted cache that later builds read. Pull request runs and other branches share a separate branch cache, which a default-branch or tag build never reads, so a pull request cannot poison the image the default branch builds. A run from a fork neither reads nor writes either. See [Caching](https://docs.ankra.ai/pipelines/caching.md).

***

## What a pull request cannot change

Anyone who can push can change what a pipeline does: its stages, scripts and Dockerfile. What a run may touch comes only from the definition on the default branch, once an organisation administrator has approved it. For a build that covers any network beyond `egress-https`, its resources and placement, its caches, and the secrets and credentials of the run. A pull request that widens any of them still runs, under the approved authority, and its check says what was ignored.

Approving needs a person: a service account token is refused, and so is Ankra's AI. See [Logic is open, authority is closed](https://docs.ankra.ai/guides/ankra-pipelines.md#logic-is-open-authority-is-closed) for the full list of protected sections.

### Pull requests from forks

With `fork_policy: read_only`, the default, a pull request whose head lives in a fork runs restricted:

* no secrets, no credentials, and no registry login, so its build produces an image that is never pushed
* no shared cache, read or written
* network only for `checkout`, `build` and `scan`, and none for any other stage
* a fixed budget: at most 8 matrix legs per stage, a 60-minute step timeout, 2 CPU and 4Gi per step, no sidecar services and 256 MiB of artifacts and logs per run
* never sent to Ankra's build cluster, and never the source of a promoted image

`fork_policy: trusted` gives a fork's head the pipeline's full declared authority, but only once a reviewer with that authority approves the head; until then it runs with no secrets, no credentials and no network. `none` refuses fork pull requests. The fork policy is itself protected, so a pull request cannot change it for its own run. See [Forks](https://docs.ankra.ai/guides/ankra-pipelines.md#what-a-step-runs-as).

***

## Ankra's build cluster

When a build moves to Ankra's build cluster, the builder receives the repository, the commit, a GitHub installation token to fetch it that expires within the hour, the Dockerfile path and the registry login the image is pushed with. [Ankra's build cluster](https://docs.ankra.ai/pipelines/where-pipelines-run.md#ankra%E2%80%99s-build-cluster) has the details and the notice the step carries.

The builders are a pool shared by every organisation that uses it:

* Each builder runs its own rootless BuildKit daemon and takes one build at a time. Builds of different organisations run one after another on a builder, and builders can share a node.
* Before every build, the builder clears every layer, cache record and checkout its daemon kept, and refuses the build if it cannot. It clears them again afterwards, so every build starts cold.
* A build pushes with its own registry login only, never with a login another build used.
* One organisation runs at most three builds at a time there. A fourth waits in order.

Builds there are separated by containers on shared nodes, not by a virtual machine per organisation. If your policy requires that your source is built only on infrastructure you control, turn the build fallback off, as [Keep everything in your own cluster](https://docs.ankra.ai/pipelines/where-pipelines-run.md#keep-everything-in-your-own-cluster) shows, before you create an application.

***

## From the build to a deploy

An image only moves forward when the stage before it passed:

1. `build` pushes the image by digest to the staging repository.
2. `scan` runs Trivy, Semgrep and Checkov against that digest and your source, from images pinned by digest that a pipeline cannot replace. Trivy takes no settings from your repository.
3. `gate` judges the run's own findings against your organisation's image gate. A pipeline can make the gate stricter for itself, never looser, and a scanner that recorded nothing fails it.
4. `publish` tags the exact digest the gate judged. It refuses when the gate is missing, failed or judged a different digest, and it never rebuilds.

With [verified provenance](https://docs.ankra.ai/security/deploy-provenance.md) in `enforce`, an application also refuses to deploy an image from its registry that `publish` did not sign for your organisation, so an image built on a laptop or pushed there by hand is never rolled out. See [One digest from commit to registry](https://docs.ankra.ai/pipelines/how-it-works.md#one-digest-from-commit-to-registry).

***

## How to restrict it

| To | Do this | Where |
| - | - | - |
| Keep your source on your own infrastructure | Turn off the build fallback and the CI playground | [Keep everything in your own cluster](https://docs.ankra.ai/pipelines/where-pipelines-run.md#keep-everything-in-your-own-cluster) |
| Confine the builder on AppArmor nodes | Use the `ankra-managed` AppArmor profile, or install your own and name it | [The build step fails before the Dockerfile is read](https://docs.ankra.ai/guides/ankra-ci-troubleshooting.md#the-build-step-fails-before-the-dockerfile-is-read) |
| Keep builds away from your workloads | Give the CI cluster a step placement on a tainted node group | [Step placement](https://docs.ankra.ai/guides/ankra-pipelines.md#step-placement) |
| Keep your images in your own account | Name a registry of your own on the application | [Using your own registry](https://docs.ankra.ai/concepts/applications.md#using-your-own-registry) |
| Keep fork pull requests restricted | Leave `fork_policy` at `read_only`, or set `none` | [Forks](https://docs.ankra.ai/guides/ankra-pipelines.md#what-a-step-runs-as) |
| Stop a pull request widening what a build touches | Review the protected sections before you approve a definition | [Logic is open, authority is closed](https://docs.ankra.ai/guides/ankra-pipelines.md#logic-is-open-authority-is-closed) |
| Deploy only images your gate passed | Set verified provenance to `enforce` | [Verified Provenance at Deploy](https://docs.ankra.ai/security/deploy-provenance.md) |

***

## Related

> [card] [How Ankra Pipelines works](https://docs.ankra.ai/pipelines/how-it-works.md)
>
> The moving parts, in diagrams.

> [card] [Where your pipeline runs](https://docs.ankra.ai/pipelines/where-pipelines-run.md)
>
> Which cluster runs each step, and the settings that keep them on yours.

> [card] [What Ankra Can See and Do](https://docs.ankra.ai/security/overview.md)
>
> What leaves your cluster, where it is stored, and how to restrict it.

> [card] [Shared Responsibility](https://docs.ankra.ai/security/shared-responsibility.md)
>
> Where Ankra's responsibility ends and yours begins.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.