Deployment context.

Tell Rivex how your image is built and how your container runs, so that its findings match your deployment.

Why context matters.

A Dockerfile does not say how its container is started. Without a context, Rivex assumes nothing about your deployment and applies every rule in full.

Take a Dockerfile with no USER instruction. Rivex reports that the container runs as root, and it adds a USER line. If your platform already starts the container as user 1000, send this context:

{
  "runtime": {
    "user": "1000"
  }
}

Rivex still reports the finding, with a note that runtime.user changed it. It adds no USER line, because your platform sets the user.

Write the context.

The context is a JSON object with two parts. Both parts are optional, and so is every field in them.

  • runtime (object): How the container runs.
  • build (object): How the image is built.

This example uses both parts:

{
  "runtime": {
    "user": "1000:1000",
    "read_only_root_fs": true,
    "tmpfs": ["/tmp"],
    "volumes": [
      {"target": "/data", "type": "volume", "read_only": false, "owner_uid": 1000, "owner_gid": 1000}
    ],
    "published_ports": [
      {"container": "8080", "host": "443", "protocol": "tcp"}
    ],
    "cap_drop": ["ALL"],
    "cap_add": ["NET_BIND_SERVICE"],
    "security_opt": ["no-new-privileges"],
    "overrides": {
      "command": ["serve", "--port", "8080"]
    },
    "env_names": ["LOG_LEVEL"]
  },
  "build": {
    "target": "release",
    "args": {"APP_VERSION": "1.4.2"},
    "platforms": ["linux/amd64", "linux/arm64"],
    "secrets": ["npm_token"],
    "builder": "buildkit"
  }
}

Rivex rejects a context that has a field this page does not list, at any level of the object.

Never put a secret value in a context. runtime.env_names, build.secrets and build.ssh take names and ids only. build.args takes values, so give it only values that are not secret.

Send the context.

Read the field lists.

Each line in the lists below names one field, its type and what the field tells Rivex. A line that ends with "Not used by any rule yet." names a field that Rivex accepts and checks, but that changes no finding today.

Runtime fields.

These fields go in runtime.

  • runtime.user (string): UID or UID:GID, e.g. 1000:1000. If your runtime sets the user, Rivex won't add a USER line.
  • runtime.group_add (list of strings): Extra groups for the process, as with --group-add. Not used by any rule yet.
  • runtime.userns_mode (string): User namespace mode, as with --userns. If set, Rivex adds no USER line.
  • runtime.volumes (list of objects): Mounts, as with -v or --mount. Rivex flags RUN chown/chmod on paths they hide.
  • runtime.tmpfs (list of strings): tmpfs mounts, as with --tmpfs. Rivex flags RUN chown/chmod on paths they hide.
  • runtime.devices (list of strings): Host devices mapped in, as with --device. Not used by any rule yet.
  • runtime.read_only_root_fs (boolean): Root filesystem read-only, as with --read-only. Rivex flags uncovered writes.
  • runtime.published_ports (list of objects): Ports published with -p. Risky EXPOSE ports not published here rank lower.
  • runtime.network_mode (string): Container network, as with --network. Not used by any rule yet.
  • runtime.cap_add (list of strings): Capabilities added, as with --cap-add. Undoes the cap_drop ALL downgrade.
  • runtime.cap_drop (list of strings): Capabilities dropped, as with --cap-drop. ALL lowers setcap/SUID findings.
  • runtime.privileged (boolean): Full host privileges, as with --privileged. Yes makes setcap/SUID critical.
  • runtime.security_opt (list of strings): Security options, as with --security-opt. Rivex checks for no-new-privileges.
  • runtime.sysctls (map of strings): Kernel parameters, as with --sysctl. Not used by any rule yet.
  • runtime.ulimits (map of strings): Resource limits, as with --ulimit. Not used by any rule yet.
  • runtime.pid_mode (string): PID namespace, as with --pid. Not used by any rule yet.
  • runtime.ipc_mode (string): IPC namespace, as with --ipc. Not used by any rule yet.
  • runtime.init (boolean): Runs an init process as PID 1, as with --init. Not used by any rule yet.
  • runtime.overrides (object): Settings of the image that are replaced at run time.
  • runtime.env_names (list of strings): Names only, e.g. LOG_LEVEL. Values are never sent. Not used by any rule yet.
  • runtime.platform (string): Platform the container runs on, as with --platform. Not used by any rule yet.

Fields of a runtime.volumes entry.

Each entry of runtime.volumes is an object with these fields. An entry must have a target.

  • runtime.volumes.target (string): Path of the mount inside the container, e.g. /data. Required.
  • runtime.volumes.type (string): Kind of mount: bind, volume or tmpfs. Rivex treats every kind alike.
  • runtime.volumes.read_only (boolean): Whether the mount is read-only. Rivex treats both values alike.
  • runtime.volumes.owner_uid (integer): UID that owns the mount path. Rivex names it in the finding about the mount.
  • runtime.volumes.owner_gid (integer): GID that owns the mount path. Rivex names it in the finding about the mount.

Fields of a runtime.published_ports entry.

Each entry of runtime.published_ports is an object with these fields. An entry must have a container.

  • runtime.published_ports.container (string): Port inside the container, e.g. 8080. Required. Rivex compares it with the ports the Dockerfile exposes.
  • runtime.published_ports.host (string): Port or port range on the host. Leave it out when the host port is chosen at run time.
  • runtime.published_ports.protocol (string): tcp, udp or sctp.

Fields of runtime.overrides.

  • runtime.overrides.entrypoint (list of strings): Replaces ENTRYPOINT at run time. Shell-form findings it replaces rank low.
  • runtime.overrides.command (list of strings): Replaces CMD at run time. A shell-form CMD finding it replaces ranks low.
  • runtime.overrides.healthcheck (string): Health check set at run time. Rivex notes it on the HEALTHCHECK finding.
  • runtime.overrides.working_dir (string): Replaces WORKDIR at run time. Not used by any rule yet.

Build fields.

These fields go in build.

  • build.target (string): The stage name passed to docker build --target.
  • build.args (map of strings): Names and non-secret values only, as with docker build --build-arg. Never paste secrets.
  • build.platforms (list of strings): Build platforms, as with --platform. Two or more add a multi-arch pin note.
  • build.secrets (list of strings): Ids only, e.g. npm_token. Values are never sent.
  • build.ssh (list of strings): Ids only, e.g. default. Values are never sent.
  • build.network (string): RUN network, as with docker build --network. Rivex notes when it is none.
  • build.cache_from (list of strings): Cache sources, as with --cache-from. Not used by any rule yet.
  • build.cache_to (list of strings): Cache export targets, as with --cache-to. Not used by any rule yet.
  • build.no_cache (boolean): Builds without the layer cache, as with --no-cache. Not used by any rule yet.
  • build.additional_contexts (map of strings): Named extra build contexts, as with --build-context. Not used by any rule yet.
  • build.builder (string): BuildKit or the classic builder. Rivex tailors BuildKit-only advice to it.
  • build.provenance (boolean): Attaches SLSA provenance, as with --provenance. Not used by any rule yet.
  • build.sbom (boolean): Attaches an SBOM, as with --sbom. Not used by any rule yet.
  • build.base_image (string): the image your final stage is really built from, e.g. python:3.12-slim@sha256:…

What Rivex does with the context.

Rivex takes the context as you state it. It cannot check the context against your real deployment, so a wrong context gives wrong findings.

Rivex never rewrites FROM. With build.base_image, it analyses the image you name in place of the FROM of the stage you ship, and the hardened Dockerfile keeps the original FROM line.

A result that was made with a context has a context_digest: the SHA-256 digest of the context you sent. Two results with the same digest were made with the same context.