---
title: "Dynamic scanning (DAST) services"
sidebarTitle: "Dynamic scanning (DAST)"
description: "The two services that run dynamic scans in a self-hosted deployment, how they are isolated, and the settings that control them."
---

Dynamic scanning is **on in the default deployment**. The production Compose
file and the Kubernetes manifests both run the two services it needs, and no
setting is required. This page says what they are, what they cost, and how to
change or remove them.

## The two services

| Service | Image | What it is |
|---|---|---|
| `zap` | `ghcr.io/zaproxy/zaproxy`, pinned by digest | The scan engine, ZAP 2.17 (Apache License 2.0) |
| `dast-egress` | The TRUSTIVAN backend image, `/app/dastgw` | The gateway between the engine and everything else |

```
worker ──► dast-egress ──► zap
               │
               └──► the one host a scan is allowed to reach
```

**`zap` is on a network with no route out.** In Compose that is the `dast`
network, declared `internal: true`; in Kubernetes it is a NetworkPolicy that
allows the pod no egress but the gateway. It cannot reach your database, your
cache, the API, the internet or your cloud provider's metadata address. A scan
engine parses hostile pages for a living, so it is given nothing to reach.

**`dast-egress` is the only door.** It forwards the engine's requests to one
host and port at a time, the one the current scan is for, and refuses private,
loopback, link-local and metadata addresses when each connection is made. When
a scan's time limit passes it stops forwarding and resets the engine, even if
the worker has died.

<Warning>
Do not publish the `zap` service's port, attach it to another network, or
change its Service type. The engine's port is also an open forward proxy, and
its API key is disabled on the basis that only the gateway can reach it.
</Warning>

## Resources

The engine uses about 1 GB of memory at rest and is limited to 2 GB and 2 CPUs.
The gateway is limited to 256 MB. Both run read-only, with all capabilities
dropped and no privilege escalation. The engine keeps its working data in
memory (a `tmpfs` in Compose, a memory-backed `emptyDir` in Kubernetes), so
nothing from a scan survives a restart of the container.

There is **one engine and it runs one scan at a time**. Other dynamic scans
wait for it. Do not scale `zap` or `dast-egress` beyond one replica: the
gateway's single lease is what stops two organizations' scans sharing the
engine's session.

## Settings

| Variable | Set on | Default | Purpose |
|---|---|---|---|
| `DAST_GATEWAY_URL` | api, worker | `http://dast-egress:8790` | Where the gateway is. `off` removes dynamic scanning |
| `DAST_ALLOW_PRIVATE_TARGETS` | api, worker, dast-egress | `false` | Permit targets on private and loopback addresses |
| `DAST_ZAP_URL` | dast-egress | `http://zap:8080` | Where the engine's API is |
| `DAST_PROXY_ADVERTISE` | dast-egress | `dast-egress` | The address the engine uses to reach the gateway's proxy port |
| `TOKEN_ENCRYPTION_KEY` | dast-egress | required | The same value the worker has |

The worker authenticates to the gateway with a credential both derive from
`TOKEN_ENCRYPTION_KEY`, so there is no separate secret to create. The gateway
uses that key for nothing else: it opens no database and decrypts nothing.

### Scanning applications on your own network

By default a target on a private address is refused, in the API and again at
the gateway. To scan internal applications from a self-hosted deployment, set
`DAST_ALLOW_PRIVATE_TARGETS=true` on the **api**, the **worker** and
**dast-egress**. Link-local addresses, which include `169.254.169.254`, stay
refused.

On Kubernetes the gateway's NetworkPolicy also denies private ranges. Add an
egress rule for the addresses you want reachable in your overlay; the variable
opens the application's check, not the network policy.

### Turning it off

Set `DAST_GATEWAY_URL=off` on the api and the worker and remove the two
services. The DAST page then says dynamic scanning is switched off.

## If the engine is not running

Targets can still be added and verified. A scan waits for the engine and then
fails with a message naming the two services. The DAST page shows a notice
that the engine is not reachable. Check:

```bash
docker compose -f infra/docker/docker-compose.prod.yml ps zap dast-egress
docker compose -f infra/docker/docker-compose.prod.yml logs --tail 50 dast-egress
```

`dast-egress` reports healthy only when it can reach the engine, which takes
about a minute after the engine starts.

## Network policy enforcement

On Kubernetes the engine's isolation is a NetworkPolicy, and a NetworkPolicy
is only enforced by a CNI plugin that implements it. On a cluster whose CNI
does not, the engine is held only by its proxy setting, which is not
sufficient. Do not run dynamic scanning on such a cluster.

## Upgrading the engine

The engine image is pinned by digest in `infra/docker/docker-compose.prod.yml`
and `infra/k8s/base/dast.yaml`. TRUSTIVAN's own end-to-end test runs real scans
against that exact digest. Change the digest only with a TRUSTIVAN release
that names the new one.

## Licence

ZAP is licensed under the Apache License 2.0 and is not redistributed with
TRUSTIVAN: your deployment pulls the project's own image. If you copy that
image into a private registry for others, you are its redistributor; see
`NOTICE`.
