Skip to content

Commit b3df08f

Browse files
committed
fix: run Docker container as non-root user to reduce blast radius
- Add non-root mcpuser and switch to it via USER directive - Set P4TICKETS env var to /home/mcpuser/.p4tickets - Update README mount paths from /root to /home/mcpuser - Ensure /app/logs is writable by mcpuser
1 parent 187c96c commit b3df08f

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ RUN apt-get update && apt-get install -y \
55
build-essential \
66
&& rm -rf /var/lib/apt/lists/*
77

8+
RUN useradd -m mcpuser
89
# Set working directory
910
WORKDIR /app
1011

@@ -17,6 +18,9 @@ COPY src/ ./src/
1718

1819
# Set environment variables
1920
ENV PYTHONPATH=/app
21+
ENV P4TICKETS=/home/mcpuser/.p4tickets
2022

23+
RUN mkdir -p /app/logs && chown mcpuser:mcpuser /app/logs
24+
USER mcpuser
2125
# Run the server with HTTP transport
2226
CMD ["python3", "-m", "src.main", "--transport", "stdio"]

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Add the following to your `mcp.json`:
131131
"-e", "P4PORT=ssl:perforce.example.com:1666",
132132
"-e", "P4USER=your_username",
133133
"-e", "P4CLIENT=your_workspace",
134-
"-v", "/Users/your_username/.p4tickets:/root/.p4tickets:ro",
134+
"-v", "/Users/your_username/.p4tickets:/home/mcpuser/.p4tickets:ro",
135135
"p4-mcp-server"
136136
]
137137
}
@@ -156,7 +156,7 @@ Add the following to your `mcp.json`:
156156
Using P4 tickets:
157157
```bash
158158
# macOS/Linux
159-
-v /Users/your_username/.p4tickets:/root/.p4tickets:ro
159+
-v /Users/your_username/.p4tickets:/home/mcpuser/.p4tickets:ro
160160
```
161161

162162
> **Note:** Use the full path to your tickets file (not `~`). After running `p4 login`, restart the MCP server to pick up the new ticket.
@@ -203,7 +203,7 @@ Example configuration with client root mounted:
203203
"-e", "P4PORT=ssl:perforce.example.com:1666",
204204
"-e", "P4USER=your_username",
205205
"-e", "P4CLIENT=your_workspace",
206-
"-v", "/Users/your_username/.p4tickets:/root/.p4tickets",
206+
"-v", "/Users/your_username/.p4tickets:/home/mcpuser/.p4tickets",
207207
"-v", "/path/to/client/root:/path/to/client/root",
208208
"p4-mcp-server"
209209
]

0 commit comments

Comments
 (0)