---
title: Service explicitly runs as root
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Infrastructure as Code (IaC)
  Security > IaC Security Rules > Service explicitly runs as root
---

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

# Service explicitly runs as root

{% 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:** `dockercompose-service-explicitly-runs-as-root` 

**Platform:** DockerCompose

**Severity:** Medium

**Category:** Least Privilege

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

- [Provider Reference](https://docs.docker.com/reference/compose-file/services/#user)

### Description{% #description %}

Explicitly running a service as the root user (`user: root` or `user: 0`) means any process breakout or file-system exploit has immediate root-level access to the host filesystem and kernel. Running as root also bypasses many file permission checks, increasing the blast radius of a container compromise. Services should run as a dedicated non-root user by setting `user` to a non-zero UID or a named non-root account.

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

```yaml
services:
  non_root:
    image: alpine
    user: "1000"
  named_user:
    image: alpine
    user: appuser
  no_user:
    image: alpine
```

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

```yaml
services:
  root_name:
    image: alpine
    user: root
  uid_zero:
    image: alpine
    user: "0"
  root_group:
    image: alpine
    user: root:root
  padded_uid:
    image: alpine
    user: "00"
  padded_uid_with_group:
    image: alpine
    user: "000:1000"
```
