You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Non-chiseled .NET images (APP_UID defined but no USER instruction) create a false sense of non-root security #7502
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.
$ 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
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?
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.
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.
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.
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.
Activity
richlander commentedon Nov 17, 2026
This is how I check the user:
This is a conventional way to check the user. The way you demonstrated is also fine. For distro-full images, I prefer
whoamisince is the effective result of theUSERvalue. 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
USERas non-root by default.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.
gallotiankarim commentedon Nov 18, 2026
Thanks Rich, understood on the default, and
whoamiis 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=0inside a container built on the non-chiseledaspnetimage. The team apparently believed the workload was non-root, probably becauseAPP_UIDand theappuser are present in the image, but noUSERinstruction was ever set. That gap significantly increased the impact.My request isn't to change the default, only to improve discoverability, for example:
ContainerUsernorUSERis set,USER $APP_UID.Would either of those be acceptable, or is there a better place (docs, template) to land it?
richlander commentedon Nov 18, 2026
If you publish with the SDK, the ContainerUser is set. Did you publish with the SDK or a Dockerfile?
APP_UIDis 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.gallotiankarim commentedon Nov 18, 2026
Good question: it was not an SDK publish, it was a container built with no
USERinstruction applied (the image'sAPP_UIDenv var was present but never consumed, so the runtime ran as root).ContainerUserwouldn'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 checkswhoamior inspectsConfig.User. A short comment in generated/sample Dockerfiles pointing toUSER $APP_UID, or a doc callout, would help there.richlander commentedon Nov 18, 2026
I think the real issue is that there is no gap. The container ecosystem is
rootby 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:
Node.js works the same way.
Same behaviors as dotnet images for the same reasons.