fix(security): run gateway container as non-root and remove shell=True in cleanup - #3981
Closed
dlkakbs wants to merge 2 commits into
Closed
fix(security): run gateway container as non-root and remove shell=True in cleanup#3981dlkakbs wants to merge 2 commits into
dlkakbs wants to merge 2 commits into
Conversation
…e in cleanup Dockerfile ran the entire agent process as root with no USER directive, maximising the blast radius of any container escape. - Create a dedicated hermes user (uid/gid 1000) and switch to it before the entrypoint; ownership of /opt/hermes and /opt/data is transferred - Replace the two shell=True + f-string subprocess.Popen calls in DockerEnvironment.cleanup() with list-form equivalents; eliminates the same shell-injection pattern that was fixed in NousResearch#1241 and removes the implicit dependency on a POSIX shell in the cleanup path
dlkakbs
force-pushed
the
fix/docker-root-and-shell-injection
branch
from
March 30, 2026 15:23
a64792f to
0d1948d
Compare
Collaborator
1 similar comment
Collaborator
19 tasks
Collaborator
|
Thanks for this, @dlkakbs — closing as superseded. Both halves of your fix have since landed on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Two independent container security issues:
1. Dockerfile ran as root — no
USERdirective meant the entire gateway process (and the entrypoint) executed as uid 0. A container escape via kernel exploit or Docker daemon vulnerability would immediately grant full root access to the host.2.
shell=True+ f-string inDockerEnvironment.cleanup()—tools/environments/docker.pyusedsubprocess.Popen(f"... {self._container_id} ...", shell=True)in two places incleanup(). While_container_idis Docker-daemon-generated (low injection risk in practice), this is the same root-cause pattern that was fixed in #1241. List-form subprocess eliminates the risk entirely and removes the implicit dependency on a POSIX shell in the cleanup path.Dockerfile changes
hermesgroup (gid 1000) and user (uid 1000)/opt/hermesand/opt/datatohermesUSER hermes:hermesbeforeENTRYPOINTdocker.py changes
Popen(shell=True)cleanup calls withPopen([...], stdout=DEVNULL, stderr=DEVNULL, start_new_session=True)— preserves the background/non-blocking behaviourRelated Issue
Fixes #3969
Type of Change
Changes Made
Dockerfile: createhermesuser/group, chown install directories, addUSER hermes:hermestools/environments/docker.py(cleanup): replace twoshell=TruePopen calls with list-formHow to Test
docker build -t hermes-test .and verifydocker inspect hermes-test | grep -i usershowshermesdocker run --rm hermes-test whoami— should printhermes, notrootDockerEnvironment.cleanup()still terminates containers cleanly in an integration testChecklist
Code
pytest tests/ -qand all tests passDocumentation & Housekeeping