Skip to content

Non-chiseled .NET images (APP_UID defined but no USER instruction) create a false sense of non-root security #7502

Open

Description

@gallotiankarim

Describe the Problem

The official mcr.microsoft.com/dotnet/aspnet tags (non-chiseled) define ENV APP_UID=1654 and create the app user, but ship with no USER instruction, so Config.User is empty and containers run as root by default.

This is documented behavior, not a bug, but in practice it creates a misleading signal: the presence of APP_UID and the app user gives the impression that non-root is already handled, when it actually requires an explicit USER $APP_UID (or <ContainerUser> via SDK publish, or switching to the -chiseled tag).

Running root by default in the non-chiseled tag isn't a host compromise by itself, but it removes a layer of defense-in-depth. Combined with no seccomp profile, no capability drop, or other common misconfigurations (privileged mode, mounted docker.sock, hostPath mounts), it turns what should be a contained incident into a much larger blast radius, up to host-level compromise in the worst configurations.

mcr.microsoft.com/dotnet/aspnet is the officially recommended base image across .NET containerization docs, and it's the default generated by Visual Studio and dotnet new container templates, so the exposure surface here is broad by construction.

Describe the Solution

  • Consider a build-time warning (via the SDK or a doc note surfaced during dotnet publish) when a project targets a container and no USER/ContainerUser is set.
  • Alternatively, make the APP_UID/non-root behavior more discoverable, for example a comment injected at the top of any Dockerfile generated via tooling/templates, or a more prominent callout in the base image's docker inspect labels.

Not asking for a breaking default change (understood why that's been pushed back on before in similar repos), just a nudge so teams don't mistake APP_UID's presence for an active protection.

Additional Context

You can verify this yourself:

docker image inspect mcr.microsoft.com/dotnet/aspnet:10.0 | grep -A2 '"User"'

Result: empty

docker image inspect mcr.microsoft.com/dotnet/aspnet:10.0-noble-chiseled | grep -A2 '"User"'

Result: "1654"

Activity

  1. richlander commented on Nov 17, 2026

    @richlander
    Member

    This is how I check the user:

    $ docker run --rm mcr.microsoft.com/dotnet/aspnet:10.0 whoami
    root

    This is a conventional way to check the user. The way you demonstrated is also fine. For distro-full images, I prefer whoami since is the effective result of the USER value. If a user is capable of checking the other image settings, they can check these settings/values, too.

    This is what would happen if we set USER as non-root by default.

    rich@merritt:~/scratch$ cat Dockerfile
    FROM mcr.microsoft.com/dotnet/aspnet:10.0
    USER app
    RUN apt-get update
    rich@merritt:~/scratch$ docker build -t test .
    [+] Building 0.2s (5/5) FINISHED                                                                                                                                         docker:default
     => [internal] load build definition from Dockerfile                                                                                                                               0.0s
     => => transferring dockerfile: 107B                                                                                                                                               0.0s
     => [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:10.0                                                                                                              0.0s
     => [internal] load .dockerignore                                                                                                                                                  0.0s
     => => transferring context: 2B                                                                                                                                                    0.0s
     => CACHED [1/2] FROM mcr.microsoft.com/dotnet/aspnet:10.0@sha256:bfd912c83295ce66d4b706ebb8541b9f14259b0e76fbb88b2751f58ce2399d2e                                                 0.0s
     => => resolve mcr.microsoft.com/dotnet/aspnet:10.0@sha256:bfd912c83295ce66d4b706ebb8541b9f14259b0e76fbb88b2751f58ce2399d2e                                                        0.0s
     => ERROR [2/2] RUN apt-get update                                                                                                                                                 0.1s
    ------
     > [2/2] RUN apt-get update:
    0.096 Reading package lists...
    0.100 E: List directory /var/lib/apt/lists/partial is missing. - Acquire (13: Permission denied)
    ------
    Dockerfile:3
    --------------------
       1 |     FROM mcr.microsoft.com/dotnet/aspnet:10.0
       2 |     USER app
       3 | >>> RUN apt-get update
       4 |
    --------------------
    ERROR: failed to build: failed to solve: process "/bin/sh -c apt-get update" did not complete successfully: exit code: 100

    We didn't consider this to be an acceptable default experience. That experience is working exactly correctly, which is the point. This is what we propose instead: https://github.com/dotnet/dotnet-docker/blob/main/samples/ConsoleApp/Dockerfile.

    Here is a post that describes more of the intent: https://devblogs.microsoft.com/dotnet/securing-containers-with-rootless/. Hope that helps.

  2. gallotiankarim commented on Nov 18, 2026

    @gallotiankarim
    Author

    Thanks Rich, understood on the default, and whoami is a fair check.

    To give some real-world context for why I raised this: during an authorized security assessment, I was able to get command execution as uid=0 inside a container built on the non-chiseled aspnet image. The team apparently believed the workload was non-root, probably because APP_UID and the app user are present in the image, but no USER instruction was ever set. That gap significantly increased the impact.

    My request isn't to change the default, only to improve discoverability, for example:

    • an SDK warning when neither ContainerUser nor USER is set,
    • or a short comment in generated Dockerfiles/templates pointing to USER $APP_UID.

    Would either of those be acceptable, or is there a better place (docs, template) to land it?

  3. richlander commented on Nov 18, 2026

    @richlander
    Member

    If you publish with the SDK, the ContainerUser is set. Did you publish with the SDK or a Dockerfile?

    APP_UID is solely an environment variable. No trust decision should be made or implied by its presence. That's a generally bad assumption. It is trivial to determine what the state of a container image is, particularly for non-distroless. If it is unclear how to determine that, that's the place to start. Did my blog post help to fill in any gaps? I just took a look at it again. I think it is pretty clear.

  4. gallotiankarim commented on Nov 18, 2026

    @gallotiankarim
    Author

    Good question: it was not an SDK publish, it was a container built with no USER instruction applied (the image's APP_UID env var was present but never consumed, so the runtime ran as root). ContainerUser wouldn't have applied to that path.

    Fair point on APP_UID, it's just an env var and shouldn't imply a trust decision on its own. That's part of why I raised the discoverability angle: for the Dockerfile/non-SDK path, nothing surfaces that gap until someone checks whoami or inspects Config.User. A short comment in generated/sample Dockerfiles pointing to USER $APP_UID, or a doc callout, would help there.

  5. richlander commented on Nov 18, 2026

    @richlander
    Member

    I think the real issue is that there is no gap. The container ecosystem is root by default. Our images match that. That's the fundamental insight. If there is a security analysis that makes an assumption that a certain image is non-root w/o proving that, it's a flawed analysis w/a misunderstanding of the container ecosystem at large.

    Here is a related example:

    rich@merritt:~$ docker run --rm ubuntu cat /etc/passwd | grep bash
    root:x:0:0:root:/root:/bin/bash
    ubuntu:x:1000:1000:Ubuntu:/home/ubuntu:/bin/bash
    rich@merritt:~$ docker run --rm -it ubuntu apt update
    Get:1 http://security.ubuntu.com/ubuntu resolute-security InRelease [137 kB]
    Get:2 http://archive.ubuntu.com/ubuntu resolute InRelease [136 kB]
    Get:3 http://security.ubuntu.com/ubuntu resolute-security/multiverse amd64 Packages [24.6 kB]
    Get:4 http://security.ubuntu.com/ubuntu resolute-security/restricted amd64 Packages [723 kB]
    Get:5 http://security.ubuntu.com/ubuntu resolute-security/universe amd64 Packages [276 kB]
    Get:6 http://security.ubuntu.com/ubuntu resolute-security/main amd64 Packages [883 kB]
    Get:7 http://archive.ubuntu.com/ubuntu resolute-updates InRelease [137 kB]
    Get:8 http://archive.ubuntu.com/ubuntu resolute-backports InRelease [137 kB]
    Get:9 http://archive.ubuntu.com/ubuntu resolute/restricted amd64 Packages [189 kB]
    Get:10 http://archive.ubuntu.com/ubuntu resolute/main amd64 Packages [1874 kB]
    Get:11 http://archive.ubuntu.com/ubuntu resolute/universe amd64 Packages [20.1 MB]
    Get:12 http://archive.ubuntu.com/ubuntu resolute/multiverse amd64 Packages [352 kB]
    Get:13 http://archive.ubuntu.com/ubuntu resolute-updates/multiverse amd64 Packages [26.1 kB]
    Get:14 http://archive.ubuntu.com/ubuntu resolute-updates/restricted amd64 Packages [743 kB]
    Get:15 http://archive.ubuntu.com/ubuntu resolute-updates/main amd64 Packages [1077 kB]
    Get:16 http://archive.ubuntu.com/ubuntu resolute-updates/universe amd64 Packages [494 kB]
    Get:17 http://archive.ubuntu.com/ubuntu resolute-backports/universe amd64 Packages [3308 B]
    Fetched 27.3 MB in 3s (8608 kB/s)
    4 packages can be upgraded. Run 'apt list --upgradable' to see them.
    rich@merritt:~$ docker run --rm -it -u ubuntu ubuntu apt update
    Error: List directory /var/lib/apt/lists/partial is missing. - Acquire (13: Permission denied)
    rich@merritt:~$

    Node.js works the same way.

    rich@merritt:~$ docker run --rm node cat /etc/passwd | grep bash
    root:x:0:0:root:/root:/bin/bash
    node:x:1000:1000::/home/node:/bin/bash
    rich@merritt:~$ docker run --rm -u node node apt update
    
    WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
    
    Reading package lists...
    Error: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
    Error: Unable to lock directory /var/lib/apt/lists/
    rich@merritt:~$

    Same behaviors as dotnet images for the same reasons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions