Skip to content

mcp: run image as numeric non-root user#94

Open
SarthakB11 wants to merge 1 commit into
kagent-dev:mainfrom
SarthakB11:harden/mcp-rootless-user
Open

mcp: run image as numeric non-root user#94
SarthakB11 wants to merge 1 commit into
kagent-dev:mainfrom
SarthakB11:harden/mcp-rootless-user

Conversation

@SarthakB11

Copy link
Copy Markdown

What

mcp/Dockerfile creates a non-root user but never sets USER, so the container runs as root. This sets USER to the numeric UID 14000 and aligns the runtime user with the root image's doc2vec:14000 account.

Why

With no USER, the image runs as root, which forces consumers to pin runAsUser in their pod spec and blocks rootless or OpenShift-style deployments. A numeric USER lets kubelet verify runAsNonRoot at admission time (a non-numeric username cannot be checked). It also lets downstream charts, such as kagent's querydoc subchart that pulls this image, drop their runAsUser pin.

How verified

Built with buildx and ran the image:

  • docker run --entrypoint id reports uid=14000(doc2vec) gid=14000(doc2vec)
  • docker inspect -f '{{.Config.User}}' reports 14000
  • /app and /app/build are owned by doc2vec, and the runtime user can write to /app/build (needed for SQLite journal/WAL files)
  • the entrypoint starts as UID 14000 with no permission errors

The mcp image created a non-root user but never set USER, so the
container still ran as root. Set USER to the numeric UID 14000 and
align the user with the root image's doc2vec:14000 account.

A numeric USER lets kubelet enforce runAsNonRoot and lets downstream
charts (such as kagent's querydoc subchart) drop their runAsUser pin.

Signed-off-by: Sarthak Bhardwaj <sarthak.bhardwaj21b@iiitg.ac.in>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant