---
title: Missing user instruction
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Infrastructure as Code (IaC)
  Security > IaC Security Rules > Missing user instruction
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Missing user instruction

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com, us2.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ({% placeholder "user-datadog-site-name" /%}).
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**Id:** `dockerfile-missing-user-instruction` 

**Platform:** Dockerfile

**Severity:** High

**Category:** Build Process

#### Learn More{% #learn-more %}

- [Provider Reference](https://docs.docker.com/engine/reference/builder/#user)

### Description{% #description %}

Specify a non-root user in the Dockerfile so containers do not run as root by default, which reduces the blast radius of a compromise and prevents easy privilege escalation.

This check inspects the final build stage (excluding `scratch`) and flags it when neither that stage nor any earlier stage it is built from (`FROM <stage>`) contains a `USER` instruction. Stages built from base images documented to run as a non-root user by default are not flagged:

- AWS Lambda base images (`public.ecr.aws/lambda/*`, where the Lambda runtime enforces a least-privileged user);
- Distroless `nonroot` and `debug-nonroot` tags (`gcr.io/distroless/*`);
- Language and framework Docker Hardened Images on `dhi.io` (excluding `dev` and `sdk` build variants, and root-running tool images).

For Distroless and `dhi.io` images, digest-pinned references (`@sha256:...`) stay flagged because the digest selects the image rather than the tag. Parameterized `FROM` references resolve literal global `ARG` defaults; adding an explicit `USER` instruction remains the safest option when build arguments may be overridden at build time.

This rule detects the absence of a `USER` instruction but does not validate the value—ensure the user is not `root` or UID `0` and that the user account is created in the image before switching to it.

Secure example:

```dockerfile
FROM python:3.11-slim AS builder
# build steps...
FROM python:3.11-slim
RUN groupadd -r app && useradd -r -g app app
COPY --from=builder /app /app
USER app
CMD ["python", "/app/app.py"]
```

## Compliant Code Examples{% #compliant-code-examples %}

```dockerfile
FROM python:2.7
RUN pip install Flask==0.11.1
RUN useradd -ms /bin/bash patrick
COPY --chown=patrick:patrick app /app
WORKDIR /app
USER patrick
CMD ["python", "app.py"]

FROM scratch
RUN pip install Flask==0.11.1
RUN useradd -ms /bin/bash patrick
COPY --chown=patrick:patrick app /app
WORKDIR /app
CMD ["python", "app.py"]
```

```dockerfile
ARG DEBIAN_VERSION=bookworm
FROM debian:${DEBIAN_VERSION}-slim AS build
RUN apt-get update && apt-get install -y --no-install-recommends wget

ARG DISTROLESS_IMAGE=static-debian12
FROM gcr.io/distroless/${DISTROLESS_IMAGE}:nonroot
COPY --from=build /usr/bin/wget /usr/bin/wget
ENTRYPOINT ["/usr/bin/wget"]
```

```dockerfile
FROM public.ecr.aws/lambda/nodejs:22 AS base
WORKDIR ${LAMBDA_TASK_ROOT}

FROM base AS build
COPY . .
RUN npm ci && npm run build

FROM base AS runtime
COPY --from=build /var/task/dist ./
CMD [ "index.handler" ]
```

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```dockerfile
FROM python:2.7
RUN pip install Flask==0.11.1
RUN useradd -ms /bin/bash patrick
COPY --chown=patrick:patrick app /app
WORKDIR /app
CMD ["python", "app.py"]
```

```dockerfile
FROM public.ecr.aws/lambda/nodejs:22 AS base
RUN echo build

FROM alpine:3.20 AS final
COPY --from=base /var/task /app
CMD ["/app/index.js"]
```

```dockerfile
FROM dhi.io/node:22 AS base
WORKDIR /app

FROM dhi.io/node:22-dev AS final
COPY . .
CMD ["node", "index.js"]
```
